void SV_Snap (int uid) { client_t *cl; char pcxname[80]; char checkname[MAX_OSPATH]; int i; for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { if (!cl->state) continue; if (cl->userid == uid) break; } if (i >= MAX_CLIENTS) { Con_Printf ("userid not found\n"); return; } sprintf(pcxname, "%d-00.pcx", uid); sprintf(checkname, "%s/snap", gamedirfile); Sys_mkdir(gamedirfile); Sys_mkdir(checkname); for (i=0 ; i<=99 ; i++) { pcxname[strlen(pcxname) - 6] = i/10 + '0'; pcxname[strlen(pcxname) - 5] = i%10 + '0'; sprintf (checkname, "%s/snap/%s", gamedirfile, pcxname); if (Sys_FileTime(checkname) == -1) break; // file doesn't exist } if (i==100) { Con_Printf ("Snap: Couldn't create a file, clean some out.\n"); return; } strcpy(cl->uploadfn, checkname); memcpy(&cl->snap_from, &net_from, sizeof(net_from)); if (sv_redirected != RD_NONE) cl->remote_snap = true; else cl->remote_snap = false; ClientReliableWrite_Begin (cl, svc_stufftext, 24); ClientReliableWrite_String (cl, "cmd snap"); Con_Printf ("Requesting snap from user %d...\n", uid); }
void DumpSource(source_data *s) { FILE *f; int i; char buf[1024]; if (s->type == type_file) snprintf(buf, sizeof (buf), "sb/%s", s->address.filename); else if (s->type == type_master) { Sys_mkdir("sb/cache"); snprintf(buf, sizeof (buf), "sb/cache/%d_%d_%d_%d_[%d].txt", s->address.address.ip[0], s->address.address.ip[1], s->address.address.ip[2], s->address.address.ip[3], ntohs(s->address.address.port)); } else return; // f = fopen(buf, "wt"); // if (f == NULL) // return; if (!FS_FCreateFile(buf, &f, "ezquake", "wt")) return; for (i=0; i < s->serversn; i++) fprintf(f, "%d.%d.%d.%d:%d\n", s->servers[i]->address.ip[0], s->servers[i]->address.ip[1], s->servers[i]->address.ip[2], s->servers[i]->address.ip[3], ntohs(s->servers[i]->address.port)); fclose(f); }
void QTVList_Refresh_Cache(qbool force_redownload) { vfsfile_t *cache_file; sb_qtvlist_parse_state_t *sb_qtvparse; Sys_mkdir(va("%s/" QTVLIST_CACHE_FILE_DIR, com_basedir)); if (force_redownload || !(cache_file = QTVList_Cache_File_Open("rb")) || QTVList_Cache_File_Is_Old()) { sb_qtvlist_cache.status = QTVLIST_DOWNLOADING; QTVList_Cache_File_Download(); cache_file = QTVList_Cache_File_Open("rb"); if (!cache_file) { Com_Printf("Can't open QTV cache file\n"); return; } } sb_qtvlist_cache.status = QTVLIST_PARSING; sb_qtvparse = QTVList_Parse_Init(); QTVList_Process_Full_List(cache_file, sb_qtvparse); VFS_CLOSE(cache_file); sb_qtvlist_cache.sb_qtventries = sb_qtvparse->list; Q_free(sb_qtvparse); sb_qtvlist_cache.status = QTVLIST_RESOLVING; QTVList_Resolve_Hostnames(); }
void CheckGLCacheVersion(const char* baseDir) { char cachePath[1024]; if ((int) (sizeof(cachePath)-1) < snprintf(cachePath, sizeof(cachePath), "%s" GLQUAKE_RELPATH "/cacheversion", baseDir)) { return; // buffer overflow } bool validCache = false; { GLCacheVersion vernum = 0; FILE* f = fopen(cachePath, "rb"); if (f) { if (1 == fread(&vernum, sizeof(vernum), 1, f)) { if (vernum == kCurrentCacheVersion) { validCache = true; } } fclose(f); } } #ifdef FORCE_INVALIDATE_CACHE validCache = false; #endif if(!validCache) { PMPLOG(("Invalidating glquake cache.")); char cacheDirPath[1024]; if ( (int)(sizeof(cacheDirPath)-1) < snprintf(cacheDirPath, sizeof(cacheDirPath), "%s" GLQUAKE_RELPATH, baseDir)) { return; // Ran out ot memory } rmDir(cacheDirPath); Sys_mkdir(cacheDirPath); FILE* f = fopen(cachePath, "wb"); if (f) { GLCacheVersion vernum = kCurrentCacheVersion; fwrite(&vernum, sizeof(vernum), 1, f); fclose(f); } else { PMPLOG(("Could not write %s %d.\n", cachePath, errno)); } } }
/* ================== SCR_ScreenShot_f ================== */ void SCR_ScreenShot_f (void) { int i; char pcxname[80]; char checkname[MAX_OSPATH]; sprintf (checkname, "%s/shots", com_gamedir); Sys_mkdir (checkname); // // find a file name to save it to // strcpy(pcxname,"shots/hexen00.pcx"); for (i=0 ; i<=99 ; i++) { pcxname[11] = i/10 + '0'; pcxname[12] = i%10 + '0'; sprintf (checkname, "%s/%s", com_gamedir, pcxname); if (Sys_FileTime(checkname) == -1) break; // file doesn't exist } if (i==100) { Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX file\n"); return; } // // save the pcx file // D_EnableBackBufferAccess (); // enable direct drawing of console to back // buffer WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes, host_basepal); D_DisableBackBufferAccess (); // for adapters that can't stay mapped in // for linear writes all the time Con_Printf ("Wrote %s\n", pcxname); }
static int Sys_GetUserdir (char *dst, size_t dstsize) { char *home_dir = NULL; #if USE_PASSWORD_FILE struct passwd *pwent; pwent = getpwuid( getuid() ); if (pwent == NULL) perror("getpwuid"); else home_dir = pwent->pw_dir; #endif if (home_dir == NULL) home_dir = getenv("HOME"); if (home_dir == NULL) return 1; if (strlen(home_dir) + strlen(AOT_USERDIR) + strlen(LAUNCHER_CONFIG_FILE) + 2 >= dstsize) return 1; snprintf (dst, dstsize, "%s/%s", home_dir, AOT_USERDIR); return Sys_mkdir(dst); }
void SV_MVDEasyRecord_f (void) { int c; dir_t dir; char name[1024]; char name2[MAX_OSPATH*7]; // scream int i; FILE *f; c = Cmd_Argc(); if (c > 2) { Com_Printf ("easyrecord [demoname]\n"); return; } if (sv.state < ss_game) { Com_Printf("Server isn't running or is still loading\n"); return; } dir = Sys_listdir(va("%s/%s", fs_gamedir,sv_demoDir.string), ".*", false); if (sv_demoMaxDirSize.value && dir.size > sv_demoMaxDirSize.value*1024) { Com_Printf("insufficient directory space, increase sv_demoMaxDirSize\n"); return; } if (c == 2) Q_strncpyz (name, Cmd_Argv(1), sizeof(name)); else { i = Dem_CountPlayers(); if (teamplay.value >= 1 && i > 2) { // Teamplay _snprintf (name, sizeof(name), "%don%d_", Dem_CountTeamPlayers(Dem_Team(1)), Dem_CountTeamPlayers(Dem_Team(2))); if (sv_demoExtraNames.value > 0) { Q_strncatz (name, va("[%s]_%s_vs_[%s]_%s_%s", Dem_Team(1), Dem_PlayerNameTeam(Dem_Team(1)), Dem_Team(2), Dem_PlayerNameTeam(Dem_Team(2)), sv.mapname), sizeof(name)); } else Q_strncatz (name, va("%s_vs_%s_%s", Dem_Team(1), Dem_Team(2), sv.mapname), sizeof(name)); } else { if (i == 2) { // Duel _snprintf (name, sizeof(name), "duel_%s_vs_%s_%s", Dem_PlayerName(1), Dem_PlayerName(2), sv.mapname); } else { // FFA _snprintf (name, sizeof(name), "ffa_%s(%d)", sv.mapname, i); } } } // Make sure the filename doesn't contain illegal characters Q_strncpyz(name, va("%s%s", sv_demoPrefix.string, SV_CleanName(name)), MAX_MVD_NAME - strlen(sv_demoSuffix.string) - 7); Q_strncatz(name, sv_demoSuffix.string, sizeof(name)); Q_strncpyz(name, va("%s/%s/%s", fs_gamedir, sv_demoDir.string, name), sizeof(name)); // find a filename that doesn't exist yet Q_strncpyz(name2, name, sizeof(name2)); Sys_mkdir(va("%s/%s", fs_gamedir, sv_demoDir.string)); // FS_StripExtension(name2, name2, sizeof(name2)); strcat (name2, ".mvd"); if ((f = fopen (name2, "rb")) == 0) f = fopen(va("%s.gz", name2), "rb"); if (f) { i = 1; do { fclose (f); _snprintf(name2, sizeof(name2), "%s_%02i", name, i); // FS_StripExtension(name2, name2, sizeof(name2)); strcat (name2, ".mvd"); if ((f = fopen (name2, "rb")) == 0) f = fopen(va("%s.gz", name2), "rb"); i++; } while (f); } SV_MVD_Record (SV_InitRecordFile(name2)); }
/* =============== Host_Savegame_f =============== */ static void Host_Savegame_f (void) { FILE *f; int i, error_state; char comment[SAVEGAME_COMMENT_LENGTH+1]; const char *p; if (cmd_source != src_command) return; if (!sv.active) { Con_Printf ("Not playing a local game.\n"); return; } if (cl.intermission) { Con_Printf ("Can't save in intermission.\n"); return; } #ifndef TESTSAVE if (svs.maxclients != 1) { Con_Printf ("Can't save multiplayer games.\n"); return; } #endif if (Cmd_Argc() != 2) { Con_Printf ("save <savename> : save a game\n"); return; } p = Cmd_Argv(1); if (*p == '.' || strstr(p, "..")) { Con_Printf ("Invalid save name.\n"); return; } for (i = 0; i < svs.maxclients; i++) { if (svs.clients[i].active && (svs.clients[i].edict->v.health <= 0) ) { Con_Printf ("Can't savegame with a dead player\n"); return; } } error_state = SaveGamestate (false); // don't bother doing more if SaveGamestate failed if (error_state) return; FS_MakePath_BUF (FS_USERDIR, &error_state, savename, sizeof(savename), p); if (error_state) { Con_Printf ("%s: save directory name too long\n", __thisfunc__); return; } if (Sys_mkdir(savename, false) != 0) { Con_Printf ("Unable to create save directory\n"); return; } Host_RemoveGIPFiles(savename); FS_MakePath_BUF (FS_USERDIR, NULL, savename, sizeof(savename), "clients.gip"); Sys_unlink(savename); FS_MakePath_BUF (FS_USERDIR, NULL, savedest, sizeof(savedest), p); Con_Printf ("Saving game to %s...\n", savedest); error_state = Host_CopyFiles(FS_GetUserdir(), "*.gip", savedest); if (error_state) goto finish; FS_MakePath_VABUF (FS_USERDIR, &error_state, savedest, sizeof(savedest), "%s/info.dat", p); if (error_state) { Host_Error("%s: %d: string buffer overflow!", __thisfunc__, __LINE__); return; } f = fopen (savedest, "w"); if (!f) { error_state = 1; Con_Printf ("%s: Unable to open %s for writing!\n", __thisfunc__, savedest); goto finish; } fprintf (f, "%i\n", SAVEGAME_VERSION); Host_SavegameComment (comment); fprintf (f, "%s\n", comment); for (i = 0; i < NUM_SPAWN_PARMS; i++) fprintf (f, "%f\n", svs.clients->spawn_parms[i]); fprintf (f, "%d\n", current_skill); fprintf (f, "%s\n", sv.name); fprintf (f, "%f\n", sv.time); fprintf (f, "%d\n", svs.maxclients); fprintf (f, "%f\n", deathmatch.value); fprintf (f, "%f\n", coop.value); fprintf (f, "%f\n", teamplay.value); fprintf (f, "%f\n", randomclass.value); fprintf (f, "%f\n", cl_playerclass.value); // mission pack, objectives strings fprintf (f, "%u\n", info_mask); fprintf (f, "%u\n", info_mask2); error_state = ferror(f); fclose(f); finish: if (error_state) Host_Error ("%s: The game could not be saved properly!", __thisfunc__); }
void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr) { int i, j; maliasgroup_t *paliasgroup; int *cmds; trivertx_t *verts; char cache[MAX_QPATH], fullpath[MAX_OSPATH], *c; FILE *f; int len; byte *data; aliasmodel = m; paliashdr = hdr; // (aliashdr_t *)Mod_Extradata (m); // // look for a cached version // strcpy (cache, "glhexen/"); COM_StripExtension (m->name+strlen("models/"), cache+strlen(cache)); strcat (cache, ".ms2"); COM_FOpenFile (cache, &f, qtrue); if (f) { fread (&numcommands, 4, 1, f); fread (&numorder, 4, 1, f); fread (&commands, numcommands * sizeof(commands[0]), 1, f); fread (&vertexorder, numorder * sizeof(vertexorder[0]), 1, f); fclose (f); } else { char dirName[MAX_OSPATH]; // // build it from scratch // Con_Printf ("meshing %s...\n",m->name); BuildTrisH2 (); // trifans or lists // Create a dir to put the cache file in. memset(dirName, 0, MAX_OSPATH); //sprintf(dirName, "%s/glhexen/", com_gamedir); Sys_mkdir(dirName); // // save out the cached version // sprintf (fullpath, "%s/%s", com_gamedir, cache); f = fopen (fullpath, "wb"); if (f) { fwrite (&numcommands, 4, 1, f); fwrite (&numorder, 4, 1, f); fwrite (&commands, numcommands * sizeof(commands[0]), 1, f); fwrite (&vertexorder, numorder * sizeof(vertexorder[0]), 1, f); fclose (f); } } // save the data out paliashdr->poseverts = numorder; cmds = static_cast<int*>(Hunk_Alloc (numcommands * 4)); paliashdr->commands = (byte *)cmds - (byte *)paliashdr; memcpy (cmds, commands, numcommands * 4); verts = static_cast<trivertx_t*>(Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t) )); paliashdr->posedata = (byte *)verts - (byte *)paliashdr; for (i=0 ; i<paliashdr->numposes ; i++) for (j=0 ; j<numorder ; j++) *verts++ = poseverts[i][vertexorder[j]]; }
/* ================ GL_MakeAliasModelDisplayLists ================ */ void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr) { int i, j; int *cmds; trivertx_t *verts; #if 0 char cache[MAX_QPATH], fullpath[MAX_OSPATH]; FILE *f; #endif aliasmodel = m; paliashdr = hdr; // (aliashdr_t *)Mod_Extradata (m); #if 0 // // look for a cached version // strcpy (cache, "glquake/"); COM_StripExtension (m->name+strlen("progs/"), cache+strlen("glquake/")); strcat (cache, ".ms2"); FS_FOpenFile (cache, &f); if (f) { fread (&numcommands, 4, 1, f); fread (&numorder, 4, 1, f); fread (&commands, numcommands * sizeof(commands[0]), 1, f); fread (&vertexorder, numorder * sizeof(vertexorder[0]), 1, f); fclose (f); } else { // // build it from scratch // Com_Printf ("meshing %s...\n",m->name); BuildTris (); // trifans or lists // // save out the cached version // sprintf (fullpath, "%s/%s", com_gamedir, cache); f = fopen (fullpath, "wb"); if (!f) { char gldir[MAX_OSPATH]; sprintf (gldir, "%s/glquake", com_gamedir); Sys_mkdir (gldir); f = fopen (fullpath, "wb"); } if (f) { fwrite (&numcommands, 4, 1, f); fwrite (&numorder, 4, 1, f); fwrite (&commands, numcommands * sizeof(commands[0]), 1, f); fwrite (&vertexorder, numorder * sizeof(vertexorder[0]), 1, f); fclose (f); } } #else // Tonik: don't cache anything, because it seems just as fast // (if not faster) to rebuild the tris instead of loading them from disk BuildTris (); // trifans or lists #endif // save the data out paliashdr->poseverts = numorder; cmds = Hunk_Alloc (numcommands * 4); paliashdr->commands = (byte *)cmds - (byte *)paliashdr; memcpy (cmds, commands, numcommands * 4); verts = Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t) ); paliashdr->posedata = (byte *)verts - (byte *)paliashdr; for (i=0 ; i<paliashdr->numposes ; i++) for (j=0 ; j<numorder ; j++) *verts++ = poseverts[i][vertexorder[j]]; }