Quake II RTX doxygen
1.0 dev
|
|
Go to the documentation of this file.
21 #define SAVE_MAGIC1 (('2'<<24)|('V'<<16)|('S'<<8)|'S') // "SSV2"
22 #define SAVE_MAGIC2 (('2'<<24)|('V'<<16)|('A'<<8)|'S') // "SAV2"
23 #define SAVE_VERSION 1
25 #define SAVE_CURRENT ".current"
26 #define SAVE_AUTO "save0"
33 char name[MAX_OSPATH];
43 timestamp = (uint64_t)time(NULL);
56 for (var =
cvar_vars; var; var = var->next) {
57 if (!(var->flags & CVAR_LATCH))
59 if (var->flags & CVAR_PRIVATE)
78 if (len >= MAX_OSPATH)
81 ge->WriteGame(
name, autosave);
87 char name[MAX_OSPATH];
91 byte portalbits[MAX_MAP_PORTAL_BYTES];
99 for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
109 MSG_WriteData(s, len);
116 MSG_WriteData(portalbits, len);
119 if (len >= MAX_QPATH)
132 if (len >= MAX_OSPATH)
141 char path[MAX_OSPATH];
148 if (len >= MAX_OSPATH)
151 ifp = fopen(path,
"rb");
156 if (len >= MAX_OSPATH)
162 ofp = fopen(path,
"wb");
167 len = fread(buf, 1,
sizeof(buf), ifp);
168 res = fwrite(buf, 1, len, ofp);
169 }
while (len ==
sizeof(buf) && res == len);
188 char path[MAX_OSPATH];
192 if (len >= MAX_OSPATH)
201 FS_TYPE_REAL | FS_PATH_GAME, count);
207 int i, count, ret = 0;
212 for (i = 0; i < count; i++)
222 int i, count, ret = 0;
227 for (i = 0; i < count; i++)
243 if (len > MAX_MSGLEN)
262 char name[MAX_QPATH], date[MAX_QPATH];
270 if (len >= MAX_QPATH)
289 return Z_CopyString(
va(
"ENTERING %s", name));
294 year = tm ? tm->tm_year : -1;
297 t = (time_t)timestamp;
299 if ((tm = localtime(&t)) != NULL) {
300 if (tm->tm_year == year)
301 len = strftime(date,
sizeof(date),
"%b %d %H:%M", tm);
303 len = strftime(date,
sizeof(date),
"%b %d %Y", tm);
308 return Z_CopyString(
va(
"%s %s", date, name));
318 char name[MAX_OSPATH],
string[MAX_STRING_CHARS];
335 memset(&cmd, 0,
sizeof(cmd));
348 if (len >=
sizeof(cmd.
buffer))
370 if (len >= MAX_QPATH)
371 Com_Error(ERR_DROP,
"Savegame cvar name too long");
374 if (len >=
sizeof(
string))
375 Com_Error(ERR_DROP,
"Savegame cvar value too long");
384 if (!(
g_features->integer & GMF_ENHANCED_SAVEGAMES))
385 Com_Error(ERR_DROP,
"Game does not support enhanced savegames");
390 if (len >= MAX_OSPATH)
391 Com_Error(ERR_DROP,
"Savegame path too long");
405 char name[MAX_OSPATH];
410 if (len >= MAX_QPATH)
430 if (index == MAX_CONFIGSTRINGS)
433 if (index < 0 || index > MAX_CONFIGSTRINGS)
434 Com_Error(ERR_DROP,
"Bad savegame configstring index");
436 maxlen = CS_SIZE(index);
439 Com_Error(ERR_DROP,
"Savegame configstring too long");
443 if (len > MAX_MAP_PORTAL_BYTES)
444 Com_Error(ERR_DROP,
"Savegame portalbits too long");
451 len =
Q_snprintf(name, MAX_OSPATH,
"%s/%s/%s/%s.sav",
453 if (len >= MAX_OSPATH)
454 Com_Error(ERR_DROP,
"Savegame path too long");
465 if (!(
g_features->integer & GMF_ENHANCED_SAVEGAMES))
476 byte bitmap[MAX_CLIENTS / CHAR_BIT];
492 memset(bitmap, 0,
sizeof(bitmap));
507 Com_EPrintf(
"Couldn't write level file.\n");
512 ent->inuse = Q_IsBitSet(bitmap, i);
527 Com_EPrintf(
"Couldn't write level file.\n");
533 Com_EPrintf(
"Couldn't write server file.\n");
539 Com_EPrintf(
"Couldn't wipe '%s' directory.\n",
SAVE_AUTO);
545 Com_EPrintf(
"Couldn't write '%s' directory.\n",
SAVE_AUTO);
559 Com_EPrintf(
"Couldn't read level file.\n");
572 for (i = 0; i < 100; i++)
580 FS_File_g(
"save", NULL, FS_SEARCH_DIRSONLY | FS_TYPE_REAL | FS_PATH_GAME, ctx);
589 Com_Printf(
"Usage: %s <directory>\n",
Cmd_Argv(0));
594 Com_Printf(
"Savegames are for listen servers only.\n");
600 Com_Printf(
"Bad savedir.\n");
605 if (!FS_FileExistsEx(
va(
"%s/%s/server.ssv",
sv_savedir->string, dir), FS_TYPE_REAL | FS_PATH_GAME) ||
606 !FS_FileExistsEx(
va(
"%s/%s/game.ssv",
sv_savedir->string, dir), FS_TYPE_REAL | FS_PATH_GAME)) {
607 Com_Printf (
"No such savegame: %s\n", dir);
613 Com_Printf(
"Couldn't wipe '%s' directory.\n",
SAVE_CURRENT);
619 Com_Printf(
"Couldn't read '%s' directory.\n", dir);
625 Com_Printf(
"Couldn't read server file.\n");
635 Com_Printf(
"You must be in a game to save.\n");
640 Com_Printf(
"Savegames are for listen servers only.\n");
645 if (!(
g_features->integer & GMF_ENHANCED_SAVEGAMES)) {
646 Com_Printf(
"Game does not support enhanced savegames.\n");
651 Com_Printf(
"Can't savegame in a deathmatch.\n");
656 Com_Printf(
"Can't savegame while dead!\n");
661 Com_Printf(
"Usage: %s <directory>\n",
Cmd_Argv(0));
667 Com_Printf(
"Bad savedir.\n");
675 Com_Printf(
"Couldn't write level file.\n");
681 Com_Printf(
"Couldn't write server file.\n");
687 Com_Printf(
"Couldn't wipe '%s' directory.\n", dir);
693 Com_Printf(
"Couldn't write '%s' directory.\n", dir);
697 Com_Printf(
"Game saved.\n");
void SV_Shutdown(const char *finalmsg, error_type_t type)
void SV_RegisterSavegames(void)
#define MVD_SPAWN_DISABLED
void CM_FreeMap(cm_t *cm)
byte msg_read_buffer[MAX_MSGLEN]
size_t Q_snprintf(char *dest, size_t size, const char *fmt,...)
ssize_t FS_Read(void *buf, size_t len, qhandle_t f)
qboolean COM_IsPath(const char *s)
void SV_CheckForSavegame(mapcmd_t *cmd)
static const cmdreg_t c_savegames[]
static int copy_save_dir(const char *src, const char *dst)
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
void FS_FreeList(void **list)
void Com_AbortFunc(void(*func)(void *), void *arg)
static int read_level_file(void)
qerror_t FS_WriteFile(const char *path, const void *data, size_t len)
void SV_AutoSaveBegin(mapcmd_t *cmd)
void MSG_WriteByte(int c)
void SZ_Init(sizebuf_t *buf, void *data, size_t size)
static void SV_Savegame_f(void)
static int wipe_save_dir(const char *dir)
ssize_t FS_FOpenFile(const char *name, qhandle_t *f, unsigned mode)
void Com_Error(error_type_t type, const char *fmt,...)
byte * MSG_ReadData(size_t len)
qboolean SV_ParseMapCmd(mapcmd_t *cmd)
void SV_SpawnServer(mapcmd_t *cmd)
static int copy_file(const char *src, const char *dst, const char *name)
char * va(const char *format,...)
void FS_File_g(const char *path, const char *ext, unsigned flags, genctx_t *ctx)
static int remove_file(const char *dir, const char *name)
int CM_WritePortalBits(cm_t *cm, byte *buffer)
void Cmd_Register(const cmdreg_t *reg)
void ** FS_ListFiles(const char *path, const char *filter, unsigned flags, int *count_p)
static void SV_Loadgame_f(void)
static int write_server_file(qboolean autosave)
static int read_server_file(void)
int Cvar_VariableInteger(const char *var_name)
void SV_AutoSaveEnd(void)
void MSG_WriteShort(int c)
cvar_t * Cvar_UserSet(const char *var_name, const char *value)
static void abort_func(void *arg)
void MSG_WriteString(const char *string)
void MSG_WriteLong(int c)
static void SV_Savegame_c(genctx_t *ctx, int argnum)
void SV_InitGame(unsigned mvd_spawn)
size_t MSG_ReadString(char *dest, size_t size)
char * SV_GetSaveInfo(const char *dir)
qerror_t FS_CreatePath(char *path)
void FS_FCloseFile(qhandle_t f)
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]
static int write_level_file(void)
static void ** list_save_dir(const char *dir, int *count)
void CM_SetPortalStates(cm_t *cm, byte *buffer, int bytes)
char fs_gamedir[MAX_OSPATH]
static int read_binary_file(const char *name)
void SZ_Clear(sizebuf_t *buf)