/* Start watching event for all maps */ void rspamd_map_watch (struct rspamd_config *cfg, struct event_base *ev_base, struct rspamd_dns_resolver *resolver) { GList *cur = cfg->maps; struct rspamd_map *map; struct file_map_data *fdata; /* First of all do synced read of data */ while (cur) { map = cur->data; map->ev_base = ev_base; map->r = resolver; event_base_set (map->ev_base, &map->ev); if (map->protocol == MAP_PROTO_FILE) { evtimer_set (&map->ev, file_callback, map); /* Read initial data */ fdata = map->map_data; if (fdata->st.st_mtime != -1) { /* Do not try to read non-existent file */ read_map_file (map, map->map_data); } /* Plan event with jitter */ jitter_timeout_event (map, FALSE, TRUE, FALSE); } else if (map->protocol == MAP_PROTO_HTTP) { evtimer_set (&map->ev, http_callback, map); jitter_timeout_event (map, FALSE, TRUE, FALSE); } cur = g_list_next (cur); } }
/** * Common file callback */ static void file_callback (gint fd, short what, void *ud) { struct rspamd_map *map = ud; struct file_map_data *data = map->map_data; struct stat st; rspamd_mempool_t *pool; pool = map->pool; if (g_atomic_int_get (map->locked)) { msg_info_pool ( "don't try to reread map as it is locked by other process, will reread it later"); jitter_timeout_event (map, TRUE, FALSE); return; } g_atomic_int_inc (map->locked); jitter_timeout_event (map, FALSE, FALSE); if (stat (data->filename, &st) != -1 && (st.st_mtime > data->st.st_mtime || data->st.st_mtime == -1)) { /* File was modified since last check */ memcpy (&data->st, &st, sizeof (struct stat)); } else { g_atomic_int_set (map->locked, 0); return; } msg_info_pool ("rereading map file %s", data->filename); read_map_file (map, data); g_atomic_int_set (map->locked, 0); }
void comp_Jah(struct param *pptr, struct map_param *mptr, int *mapset) { static int first_call = TRUE; char *funcname; funcname = "comp_Jah"; if (first_call == TRUE) { read_map_file(pptr, mptr); comp_Jboundaries(mptr); first_call = FALSE; } quantize_jah(pptr, mptr, mapset); }
static void rspamd_map_file_read_callback (gint fd, short what, void *ud) { struct rspamd_map *map; struct map_periodic_cbdata *periodic = ud; struct file_map_data *data; struct rspamd_map_backend *bk; map = periodic->map; bk = g_ptr_array_index (map->backends, periodic->cur_backend); data = bk->data.fd; msg_info_map ("rereading map file %s", data->filename); if (!read_map_file (map, data, bk, periodic)) { periodic->errored = TRUE; } /* Switch to the next backend */ periodic->cur_backend ++; rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic); }
/** Read binary code and data files */ static int read_binary_files(t_state *s, t_args *args){ FILE *in; uint8_t *target; uint32_t bytes=0, i, files_read=0; /* read map file if requested */ if(args->map_filename!=NULL){ if(read_map_file(args->map_filename, &map_info)<0){ printf("Trouble reading map file '%s', quitting!\n", args->map_filename); return 0; } printf("Read %d functions from the map file; call trace enabled.\n\n", map_info.num_functions); } /* read object code binaries */ for(i=0;i<NUM_MEM_BLOCKS;i++){ bytes = 0; if(args->bin_filename[i]!=NULL){ in = fopen(args->bin_filename[i], "rb"); if(in == NULL){ free_cpu(s); printf("Can't open file %s, quitting!\n",args->bin_filename[i]); return(0); } /* FIXME load offset 0x2000 for linux kernel hardcoded! */ //bytes = fread((s->blocks[i].mem + 0x2000), 1, s->blocks[i].size, in); target = (uint8_t *)(s->blocks[i].mem + args->offset[i]); while(!feof(in) && ((bytes+1024+args->offset[i]) < (s->blocks[i].size))){ bytes += fread(&(target[bytes]), 1, 1024, in); if(errno!=0){ printf("ERROR: file load failed with code %d ('%s')\n", errno, strerror(errno)); free_cpu(s); return 0; } } fclose(in); /* Now reverse the endianness of the data we just read, if it's necessary. */ /* FIXME handle little-endian stuff (?) */ //reverse_endianess(target, bytes); files_read++; } fprintf(stderr,"%-16s [size= %6dKB, start= 0x%08x] loaded %d bytes.\n", s->blocks[i].area_name, s->blocks[i].size/1024, s->blocks[i].start, bytes); } if(!files_read){ free_cpu(s); fprintf(stderr,"No binary object files read, quitting\n"); return 0; } return files_read; }
void InitGame (void) { int i; #ifdef _DEBUG _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG ); // _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG ); _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF |_CRTDBG_CHECK_ALWAYS_DF // |_CRTDBG_CHECK_CRT_DF |_CRTDBG_LEAK_CHECK_DF); gi.dprintf ("!!!! DEBUGGING !!!! \n"); #endif gi.dprintf ("==== InitGame ====\n"); srand( (unsigned)time( NULL ) ); gun_x = gi.cvar ("gun_x", "0", 0); gun_y = gi.cvar ("gun_y", "0", 0); gun_z = gi.cvar ("gun_z", "0", 0); //FIXME: sv_ prefix is wrong for these sv_rollspeed = gi.cvar ("sv_rollspeed", "200", 0); sv_rollangle = gi.cvar ("sv_rollangle", "0", 0); sv_maxvelocity = gi.cvar ("sv_maxvelocity", "2000", 0); sv_gravity = gi.cvar ("sv_gravity", "800", 0); // noset vars dedicated = gi.cvar ("dedicated", "0", CVAR_NOSET); // latched vars sv_cheats = gi.cvar ("cheats", "0", CVAR_LATCH); gi.cvar ("gamename", GAMEVERSION , CVAR_SERVERINFO | CVAR_LATCH); gi.cvar ("gamedate", __DATE__ , CVAR_SERVERINFO | CVAR_LATCH); no_spec = gi.cvar ("no_spec", "0", 0); no_shadows = gi.cvar ("no_shadows", "0", 0); no_zoom = gi.cvar ("no_zoom", "0", 0); maxclients = gi.cvar ("maxclients", "4", CVAR_SERVERINFO | CVAR_LATCH); // deathmatch = gi.cvar ("deathmatch", "0", CVAR_LATCH); // coop = gi.cvar ("coop", "0", CVAR_LATCH); // JOSEPH 16-OCT-98 maxentities = gi.cvar ("maxentities", /*"1024"*/"2048", CVAR_LATCH); // change anytime vars dmflags = gi.cvar ("dmflags", "0", CVAR_SERVERINFO|CVAR_ARCHIVE); fraglimit = gi.cvar ("fraglimit", "0", CVAR_SERVERINFO); timelimit = gi.cvar ("timelimit", "0", CVAR_SERVERINFO); password = gi.cvar ("password", "", CVAR_USERINFO); filterban = gi.cvar ("filterban", "1", 0); antilag = gi.cvar("antilag", "1", CVAR_SERVERINFO); props = gi.cvar("props", "0", 0); bonus = gi.cvar("bonus", "0", 0); if (kpded2 && (int)gi.cvar("sv_uptime", "0", 0)->value) { // kpded2's uptime status is enabled, so disable ours starttime = 0; } else { char buf[20]; Com_sprintf(buf, sizeof(buf), "%d", time(NULL)); starttime = atoi(gi.cvar("starttime", buf, 0)->string); gi.cvar("uptime", "", CVAR_SERVERINFO); } g_select_empty = gi.cvar ("g_select_empty", "0", CVAR_ARCHIVE); run_pitch = gi.cvar ("run_pitch", "0.002", 0); run_roll = gi.cvar ("run_roll", "0.005", 0); bob_up = gi.cvar ("bob_up", "0.005", 0); bob_pitch = gi.cvar ("bob_pitch", "0.002", 0); bob_roll = gi.cvar ("bob_roll", "0.002", 0); // flood control flood_msgs = gi.cvar ("flood_msgs", "4", 0); flood_persecond = gi.cvar ("flood_persecond", "4", 0); flood_waitdelay = gi.cvar ("flood_waitdelay", "10", 0); kick_flamehack = gi.cvar ("kick_flamehack", "1", CVAR_SERVERINFO); anti_spawncamp = gi.cvar ("anti_spawncamp", "1", 0); idle_client = gi.cvar("idle_client", "120", 0); // Ridah, new cvar's developer = gi.cvar ("developer", "0", 0); g_vehicle_test = gi.cvar ("g_vehicle_test", "0", CVAR_LATCH); // Enables Hovercars for all players dm_locational_damage = gi.cvar ("dm_locational_damage", "0", 0); showlights = gi.cvar ("showlights", "0", 0); timescale = gi.cvar("timescale", "1.0", 0); // speed hack fix gi.cvar_set("sv_enforcetime", "1"); teamplay = gi.cvar("teamplay", "0", CVAR_LATCH|CVAR_SERVERINFO); if (teamplay->value != 0 && teamplay->value != 1 && teamplay->value != 4) gi.cvar_set("teamplay", "1"); cashlimit = gi.cvar ("cashlimit", "0", teamplay->value == 1 ? CVAR_SERVERINFO : 0); g_cashspawndelay = gi.cvar("g_cashspawndelay", "5", CVAR_ARCHIVE|CVAR_LATCH); dm_realmode = gi.cvar( "dm_realmode", "0", CVAR_LATCH|CVAR_SERVERINFO); g_mapcycle_file = gi.cvar( "g_mapcycle_file", "", 0); // Ridah, done. // snap - team tags gi.cvar(TEAMNAME, "", CVAR_SERVERINFO); gi.cvar_set(TEAMNAME, ""); gi.cvar(SCORENAME, "", CVAR_SERVERINFO); gi.cvar_set(SCORENAME, ""); // the "rconx serverinfo" command needs this to be the final serverinfo cvar gi.cvar(TIMENAME, "", CVAR_SERVERINFO); gi.cvar_set(TIMENAME, ""); // items InitItems (); // initialize all entities for this game game.maxentities = maxentities->value; g_edicts = gi.TagMalloc (game.maxentities * sizeof(g_edicts[0]), TAG_GAME); globals.edicts = g_edicts; globals.max_edicts = game.maxentities; // initialize all clients for this game game.maxclients = maxclients->value; game.clients = gi.TagMalloc (game.maxclients * sizeof(game.clients[0]), TAG_GAME); globals.num_edicts = game.maxclients+1; // disable single player and co-op modes gi.cvar_set("deathmatch", "1"); gi.cvar_set("coop", "0"); i = proccess_ini_file(); if (i != OK) gi.dprintf("Error opening comp ini file\n"); else gi.dprintf("Processed comp.ini file\n"); if (!map_list_filename[0]) strcpy(map_list_filename, g_mapcycle_file->string); if (map_list_filename[0]) { i = read_map_file(); if (i != OK) gi.dprintf("Error opening map list file (%s)\n", map_list_filename); else gi.dprintf("Processed map list file (%s)\n", map_list_filename); } if (!num_maps) allow_map_voting = false; cmd_check[0] = '\176'; for (i=1; i<7; i++) cmd_check[i] = 'A'+(rand()%26)+(rand()&32); cmd_check[i] = 0; // load & initialize GeoIP library if (!disable_geoip) { #ifdef _WIN32 HINSTANCE libgeoip = LoadLibrary("GeoIP"); #else void *libgeoip = dlopen("libGeoIP.so.1", RTLD_LAZY|RTLD_LOCAL); #endif if (libgeoip) { void* (*_GeoIP_new)(int flags); #ifdef _WIN32 *(void**)&_GeoIP_new = GetProcAddress(libgeoip, "GeoIP_new"); *(void**)&_GeoIP_delete = GetProcAddress(libgeoip, "GeoIP_delete"); *(void**)&_GeoIP_country_name_by_addr = GetProcAddress(libgeoip, "GeoIP_country_name_by_addr"); #else _GeoIP_new = dlsym(libgeoip, "GeoIP_new"); _GeoIP_delete = dlsym(libgeoip, "GeoIP_delete"); _GeoIP_country_name_by_addr = dlsym(libgeoip, "GeoIP_country_name_by_addr"); #endif geoip = _GeoIP_new(0); if (!geoip) { #ifdef _WIN32 FreeLibrary(libgeoip); #else dlclose(libgeoip); #endif gi.dprintf("Failed to load GeoIP database\n"); } else gi.dprintf("Loaded GeoIP database\n"); } } if (kpded2) { /* enable kpded2 features: GMF_CLIENTPOV - improved eyecam chase mode GMF_CLIENTTEAM - team info in server browsers GMF_CLIENTNOENTS - removes everything when spectating is disabled GMF_WANT_ALL_DISCONNECTS - cancelled connection notifications */ char buf[10]; sprintf(buf, "%d", GMF_CLIENTPOV | GMF_CLIENTNOENTS | GMF_WANT_ALL_DISCONNECTS | (teamplay->value ? GMF_CLIENTTEAM : 0)); gi.cvar_forceset("g_features", buf); } }