rendered paste bodyvoid autoRecord() {
#define TMP_FILE_NAME "demo_in_progress"
static qboolean demoState = qfalse;
int stateTime ;
// Speed return if we don't want record demo
if (!demoState && !seth.value[VAR_RECDEMO])
return;
if ((eth.cg_snap->ps.eFlags != EF_DEAD)
&& (eth.cg_snap->ps.clientNum == eth.cg_clientNum)
&& (eth.clientInfo[eth.cg_clientNum].team != TEAM_SPECTATOR)
&& (eth.cg_snap->ps.stats[STAT_HEALTH] > 0)
&& (eth.cg_snap->ps.pm_flags != PMF_FOLLOW)
&& seth.value[VAR_RECDEMO]
&& !demoState) {
stateTime=0 ;
// FIXME: check if a tmp demo file already exist
syscall_CG_SendConsoleCommand("record " TMP_FILE_NAME "\n");
stateTime1 = eth.cg_time;
#ifdef ETH_DEBUG
ethDebug("demo: start");
ethDebug("demo: start stateTime:[%i]",&stateTime) ;
#endif
demoState = qtrue;
} else if (((eth.cg_snap->ps.eFlags == EF_DEAD)
|| (eth.cg_snap->ps.clientNum != eth.cg_clientNum)
|| (eth.clientInfo[eth.cg_clientNum].team == TEAM_SPECTATOR)
|| (eth.cg_snap->ps.stats[STAT_HEALTH] <= 0)
|| (eth.cg_snap->ps.pm_flags == PMF_FOLLOW)
|| (!seth.value[VAR_RECDEMO]))
&& demoState) {
char buffFrom[MAX_OSPATH];
char buffTo[MAX_OSPATH];
// Get fsgame
char fsGame[MAX_QPATH];
syscall_CG_Cvar_VariableStringBuffer("fs_game", fsGame, sizeof(fsGame));
// Get current time
time_t ethTime = time(NULL);
struct tm *localTime = localtime(ðTime);
orig_Cbuf_ExecuteText(EXEC_NOW, "stoprecord\n");
#ifdef ETH_DEBUG
ethDebug("demo: transite eth.cg_time:[%i]",ð.cg_time) ;
#endif
stateTime = (eth.cg_time - stateTime) ;
#ifdef ETH_DEBUG
ethDebug("demo: final stateTime:[%i]",&stateTime) ;
ethDebug("demo: stop");
#endif
// buffForm = /homepath/fsgame/
syscall_CG_Cvar_VariableStringBuffer("fs_homepath", buffFrom, sizeof(buffFrom));
sprintf(buffFrom, "%s/%s/demos/", buffFrom, fsGame);
strncpy(buffTo, buffFrom, sizeof(buffFrom));
// buffForm = /homepath/fsgame/demos/demoinprogress
strcat(buffFrom, TMP_FILE_NAME ".dm_");
// Contruct final file name, buffTo = /homepath/fsgame/demo/aaaa_mm_dd_hhmmss_mod_map_killcount
sprintf(buffTo,"%s%i-%.2i-%.2i-%.2i%.2i%.2i_%s_%s_%ikills_%i.dm_", buffTo, localTime->tm_year + 1900, localTime->tm_mon + 1,
localTime->tm_mday, localTime->tm_hour, localTime->tm_min, localTime->tm_sec, fsGame,
eth_Info_ValueForKey(eth.cgs_gameState->stringData + eth.cgs_gameState->stringOffsets[CS_SERVERINFO], "mapname"),
eth.autoDemoKillCount,(int)((((stateTime/1000)/seth.value[VAR_RECDEMO])*100)/5));
// Version of the demo
if (!strcmp(sethET->version, "2.55")){
strcat(buffFrom, "82");
strcat(buffTo, "82");
} else if(!strcmp(sethET->version, "2.56")){
strcat(buffFrom, "83");
strcat(buffTo, "83");
} else {
strcat(buffFrom, "84");
strcat(buffTo, "84");
}
#ifdef ETH_DEBUG
ethDebug("demo: got %i kills, need %i kills", eth.autoDemoKillCount, (int)seth.value[VAR_RECDEMO]);
#endif
// If we more than kills threshold then rename the demo
if (eth.autoDemoKillCount >= seth.value[VAR_RECDEMO]) {
#ifdef ETH_DEBUG
ethDebug("demo: move [%s] to [%s]", buffFrom, buffTo);
#endif
rename(buffFrom, buffTo);
// Else delete it
} else {
#ifdef ETH_DEBUG
ethDebug("demo: delete [%s]", buffFrom, buffTo);
#endif
unlink(buffFrom);
}
eth.autoDemoKillCount = 0;
demoState = qfalse;
}