static void WriteAccounts() { int c; FILE *f; account_t *acc; //Sys_mkdir(ACC_DIR); if ( (f = fopen( va("%s/" ACC_FILE, fs_gamedir) ,"wt")) == NULL) { Con_Printf("Warning: couldn't open for writing " ACC_FILE "\n"); return; } for (acc = accounts, c = 0; c < num_accounts; acc++) { if (acc->state == a_free) continue; if (acc->use == use_log) fprintf(f, "%s %s %d %d\n", acc->login, acc->pass, acc->state, acc->failures); else fprintf(f, "%s %s %d\n", acc->login, acc->pass, acc->state); c++; } fclose(f); // force cache rebuild. FS_FlushFSHash(); }
void SV_SaveGame_f (void) { char fname[MAX_OSPATH], comment[SAVEGAME_COMMENT_LENGTH+1]; FILE *f; int i; if (Cmd_Argc() != 2) { Con_Printf ("Usage: %s <savefname> : save a game\n", Cmd_Argv(0)); return; } else if (strstr(Cmd_Argv(1), "..")) { Con_Printf ("Relative pathfnames are not allowed.\n"); return; } else if (sv.state != ss_active) { Con_Printf ("Not playing a local game.\n"); return; #ifndef SERVERONLY } else if (cl.intermission) { Con_Printf ("Can't save in intermission.\n"); return; #endif } else if (deathmatch.value != 0 || coop.value != 0 || maxclients.value != 1) { Con_Printf ("Can't save multiplayer games.\n"); return; } for (i = 1; i < MAX_CLIENTS; i++) { if (svs.clients[i].state == cs_spawned) { Con_Printf ("Can't save multiplayer games.\n"); return; } } if (svs.clients[0].state != cs_spawned) { Con_Printf ("Can't save, client #0 not spawned.\n"); return; } else if (svs.clients[0].edict->v.health <= 0) { Con_Printf ("Can't save game with a dead player\n"); // in fact, we can, but does it make sense? return; } snprintf (fname, sizeof(fname), "%s/save/%s", fs_gamedir, Cmd_Argv(1)); COM_DefaultExtension (fname, ".sav"); Con_Printf ("Saving game to %s...\n", fname); if (!(f = fopen (fname, "w"))) { FS_CreatePath (fname); if (!(f = fopen (fname, "w"))) { Con_Printf ("ERROR: couldn't open.\n"); return; } } fprintf (f, "%i\n", SAVEGAME_VERSION); SV_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.mapname); fprintf (f, "%f\n", sv.time); // write the light styles for (i = 0; i < MAX_LIGHTSTYLES; i++) { if (sv.lightstyles[i]) fprintf (f, "%s\n", sv.lightstyles[i]); else fprintf (f,"m\n"); } ED_WriteGlobals (f); for (i = 0; i < sv.num_edicts; i++) { ED_Write (f, EDICT_NUM(i)); fflush (f); } fclose (f); Con_Printf ("done.\n"); // force cache rebuild. FS_FlushFSHash(); }