// returns true, if there were some problems (like domain-name addresses) // which require the source to be dumped to file in corrected form qbool Update_Source_From_File(source_data *s, char *fname, server_data **servers, int *pserversn) { vfsfile_t *f; char line[2048]; qbool should_dump = false; //length = COM_FileOpenRead (fname, &f); f = FS_OpenVFS(fname, "rb", FS_ANY); if (f) { while (VFS_GETS(f, line, sizeof(line))) { netadr_t addr; if (!strchr(line, ':')) strlcat (line, ":27000", sizeof (line)); if (!NET_StringToAdr(line, &addr)) continue; servers[(*pserversn)++] = Create_Server2(addr); if (line[0] <= '0' || line[0] >= '9') should_dump = true; } VFS_CLOSE(f); } else { //Com_Printf ("Updating %15.15s failed: file not found\n", s->name); // ?????? should_dump = true; } return should_dump; }
static int QDECL VMEnumMods(const char *match, qofs_t size, time_t modtime, void *args, searchpathfuncs_t *spath) { char *check; char desc[1024]; int newlen; int desclen; qboolean foundone; vfsfile_t *f; newlen = strlen(match)+1; if (newlen <= 2) return true; //make sure match is a directory if (match[newlen-2] != '/') return true; if (!stricmp(match, "baseq3/")) return true; //we don't want baseq3. FIXME: should be any basedir, rather than hardcoded. foundone = false; Sys_EnumerateFiles(va("%s%s/", ((vmsearch_t *)args)->dir, match), "*.pk3", IfFound, &foundone, spath); if (foundone == false) return true; //we only count directories with a pk3 file Q_strncpyz(desc, match, sizeof(desc)); f = FS_OpenVFS(va("%sdescription.txt", match), "rb", FS_ROOT); if (f) { VFS_GETS(f, desc, sizeof(desc)); VFS_CLOSE(f); } desclen = strlen(desc)+1; if (newlen+desclen+5 > ((vmsearch_t *)args)->bufferleft) return false; //too many files for the buffer check = ((vmsearch_t *)args)->initialbuffer; while(check < ((vmsearch_t *)args)->buffer) { if (!stricmp(check, match)) return true; //we found this one already check += strlen(check)+1; check += strlen(check)+1; } memcpy(((vmsearch_t *)args)->buffer, match, newlen); ((vmsearch_t *)args)->buffer+=newlen; ((vmsearch_t *)args)->bufferleft-=newlen; memcpy(((vmsearch_t *)args)->buffer, desc, desclen); ((vmsearch_t *)args)->buffer+=desclen; ((vmsearch_t *)args)->bufferleft-=desclen; ((vmsearch_t *)args)->found++; return true; }
/* =============== Host_Loadgame_f =============== */ void Host_Loadgame_f (void) { char name[MAX_OSPATH], temp[MAX_OSPATH]; vfsfile_t *f; char mapname[MAX_QPATH]; float time, tfloat; char str[32768], *start, *c; int i, r, len, n; edict_t *ent; int entnum; int version; float spawn_parms[NUM_SPAWN_PARMS]; if (cmd_source != src_command) return; if (Cmd_Argc() != 2) { Con_Printf ("load <savename> : load a game\n"); return; } cls.demonum = -1; // stop demo loop in case this fails // sprintf (name, "%s", Cmd_Argv(1)); strcpy (name, Cmd_Argv(1)); COM_DefaultExtension (name, ".sav"); // we can't call SCR_BeginLoadingPlaque, because too much stack space has // been used. The menu calls it before stuffing loadgame command // SCR_BeginLoadingPlaque (); Con_Printf ("Loading game from %s...\n", name); // f = fopen (name, "r"); f = FS_OpenVFS(name, "rb", FS_GAMEONLY); if (!f) { Con_Printf ("ERROR: couldn't open.\n"); return; } // fscanf (f, "%i\n", &version); version = atoi(VFS_GETS(f, name, sizeof(name))); if (version != SAVEGAME_VERSION) { // fclose (f); Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION); VFS_CLOSE (f); return; } // fscanf (f, "%s\n", str); VFS_GETS(f, str, sizeof(str)); for (i=0 ; i<NUM_SPAWN_PARMS ; i++) spawn_parms[i] = atof(VFS_GETS(f, temp, sizeof(temp))); // fscanf (f, "%f\n", &spawn_parms[i]); // this silliness is so we can load 1.06 save files, which have float skill values // fscanf (f, "%f\n", &tfloat); tfloat = atof(VFS_GETS(f, temp, sizeof(temp))); // temp buf current_skill = (int)(tfloat + 0.1); Cvar_SetValue ("skill", (float)current_skill); #ifdef QUAKE2 Cvar_SetValue ("deathmatch", 0); Cvar_SetValue ("coop", 0); Cvar_SetValue ("teamplay", 0); #endif // fscanf (f, "%s\n",mapname); // fscanf (f, "%f\n",&time); VFS_GETS(f, mapname, sizeof(mapname)); for (c = mapname+strlen(mapname)-1; c>=mapname && (*c == '\n' || *c == '\r'); *c--='\0'); time = atof(VFS_GETS(f, temp, sizeof(temp))); CL_Disconnect_f (); allowcheats = sv_cheats.value != 0; // sv_cheats // if the video isn't initialized already, it needs to be Host_InitVideo(); #ifdef QUAKE2 SV_SpawnServer (mapname, NULL); #else SV_SpawnServer (mapname); #endif if (!sv.active) { Con_Printf ("Couldn't load map\n"); VFS_CLOSE (f); return; } sv.paused = true; // pause until all clients connect sv.loadgame = true; // load the light styles for (i=0 ; i<MAX_LIGHTSTYLES ; i++) { // fscanf (f, "%s\n", str); VFS_GETS(f, str, sizeof(str)); // sv.lightstyles[i] = Hunk_Alloc (strlen(str)+1); // this is no longer necessary, changed to straight array for (c = str+strlen(str)-1; c>=str && (*c == '\n' || *c == '\r'); *c--='\0'); strcpy (sv.lightstyles[i], str); } // load the edicts out of the savegame file entnum = -1; // -1 is the globals len = VFS_GETLEN(f); n = 0; // while (!feof(f)) for(;;) { for (i=0 ; i<sizeof(str)-1 ; i++) { // r = fgetc (f); r = VFS_GETC(f); if (r == -1 || !r) break; str[i] = r; if (r == '}') { i++; break; } } if (r == -1 || !r) break; if (i == sizeof(str)-1) Sys_Error ("Loadgame buffer overflow"); str[i] = 0; start = str; start = COM_Parse(str); if (!com_token[0]) break; // end of file if (strcmp(com_token,"{")) Sys_Error ("First token isn't a brace"); if (entnum == -1) { // parse the global vars ED_ParseGlobals (start); } else { // parse an edict ent = EDICT_NUM(entnum); memset (&ent->v, 0, progs->entityfields * 4); ent->free = false; ED_ParseEdict (start, ent); // link it into the bsp tree if (!ent->free) SV_LinkEdict (ent, false); } entnum++; n++; } sv.num_edicts = entnum; sv.time = time; // fclose (f); VFS_CLOSE (f); for (i=0 ; i<NUM_SPAWN_PARMS ; i++) svs.clients->spawn_parms[i] = spawn_parms[i]; if (cls.state != ca_dedicated) { CL_EstablishConnection ("local"); Host_Reconnect_f (); } }
void Reload_Sources(void) { int i; vfsfile_t *f; char ln[2048]; source_data *s; SB_ServerList_Lock(); for (i=0; i < sourcesn; i++) Delete_Source(sources[i]); sourcesn = 0; // create dummy unbound source sources[0] = Create_Source(); sources[0]->type = type_dummy; strlcpy (sources[0]->name, "Unbound", sizeof (sources[0]->name)); sources[0]->servers = (server_data **) Q_malloc(MAX_UNBOUND*sizeof(server_data *)); sources[0]->serversn = 0; sources[0]->servers_allocated = MAX_UNBOUND; sourcesn = 1; f = FS_OpenVFS(SOURCES_LIST_FILENAME, "rb", FS_ANY); if (!f) { //Com_Printf ("sources file not found: %s\n", SOURCES_PATH); SB_ServerList_Unlock(); return; } s = Create_Source(); while (VFS_GETS(f, ln, sizeof(ln))) { char line[2048]; char *p, *q; if (sscanf(ln, "%[ -~ ]s", line) != 1) { continue; } p = next_nonspace(line); if (*p == '/') continue; // comment q = next_space(p); if (!strncmp(p, "master", q-p)) { s->type = type_master; } else if (!strncmp(p, "file", q-p)) { s->type = type_file; } else if (!strncmp(p, "url", q-p)) { s->type = type_url; } else { continue; } p = next_nonspace(q); q = (*p == '\"') ? next_quote(++p) : next_space(p); if (q-p <= 0) continue; strlcpy (s->name, p, min(q-p+1, MAX_SOURCE_NAME+1)); p = next_nonspace(q+1); q = next_space(p); *q = 0; if (q-p <= 0) continue; if (s->type == type_file) strlcpy (s->address.filename, p, sizeof (s->address.filename)); else if (s->type == type_url) strlcpy (s->address.url, p, sizeof (s->address.url)); else if (!NET_StringToAdr(p, &(s->address.address))) continue; sources[sourcesn] = Create_Source(); i = sources[sourcesn]->unique; memcpy(sources[sourcesn], s, sizeof(source_data)); sources[sourcesn]->unique = i; sourcesn++; } Delete_Source(s); VFS_CLOSE(f); //Com_Printf("Read %d sources for Server Browser\n", sourcesn); // update all file sources for (i=0; i < sourcesn; i++) if (sources[i]->type == type_file) Update_Source(sources[i]); else if (sources[i]->type == type_master || sources[i]->type == type_url) Precache_Source(sources[i]); rebuild_servers_list = 1; resort_sources = 1; SB_ServerList_Unlock(); }