/** * @brief */ static void Frame(const uint32_t msec) { Cbuf_Execute(); if (threads->modified) { threads->modified = false; Thread_Shutdown(); Thread_Init(threads->integer); } if (game->modified) { game->modified = false; Fs_SetGame(game->string); if (Fs_Exists("autoexec.cfg")) { Cbuf_AddText("exec autoexec.cfg\n"); Cbuf_Execute(); } } Sv_Frame(msec); Cl_Frame(msec); }
void Com_ExecuteCfg(void) { Cbuf_ExecuteText(EXEC_NOW, "exec default.cfg\n"); Cbuf_Execute(); // Always execute after exec to prevent text buffer overflowing if(!Com_SafeMode()) { // skip the q3config.cfg and autoexec.cfg if "safe" is on the command line Cbuf_ExecuteText(EXEC_NOW, "exec " Q3CONFIG_NAME "\n"); Cbuf_Execute(); Cbuf_ExecuteText(EXEC_NOW, "exec autoexec_sp.cfg\n"); Cbuf_Execute(); } }
void Sys_AddDefaultConfig(void) { FILE *fp; struct stat st; size_t len, r; fp = fopen(SYS_SITE_CFG, "r"); if (!fp) { return; } if (fstat(fileno(fp), &st) == 0) { len = st.st_size; if (len >= cmd_buffer.maxsize) { len = cmd_buffer.maxsize - 1; } r = fread(cmd_buffer.text, 1, len, fp); cmd_buffer.text[r] = 0; cmd_buffer.cursize = COM_Compress(cmd_buffer.text); } fclose(fp); if (cmd_buffer.cursize) { Com_Printf("Execing %s\n", SYS_SITE_CFG); Cbuf_Execute(&cmd_buffer); } }
static void ControlsResetDefaultsFunc (void *unused) { Cbuf_AddText ("exec default.cfg\n"); Cbuf_Execute (); ControlsSetMenuItemValues (); }
/* ================== Host_Frame Runs all active servers ================== */ void _Host_Frame (float time) { if (setjmp (host_abortserver)) return; // something bad happened, or the server disconnected // keep the random time dependent rand (); // decide the simulation time if (!Host_FilterTime (time)) return; // don't run too fast, or packets will flood out // get new key events Sys_SendKeyEvents (); // process console commands Cbuf_Execute (); NET_Poll(); // check for commands typed to the host Host_GetConsoleCommands (); if (sv.active) Host_ServerFrame (); }
/* ============ Cbuf_ExecuteText ============ */ void Cbuf_ExecuteText(int exec_when, const char *text) { switch (exec_when) { case EXEC_NOW: if (text && strlen(text) > 0) { Com_DPrintf(S_COLOR_YELLOW "EXEC_NOW %s\n", text); Cmd_ExecuteString(text); } else { Com_DPrintf(S_COLOR_YELLOW "EXEC_NOW %s\n", cmd_text.data); Cbuf_Execute(); } break; case EXEC_INSERT: Cbuf_InsertText(text); break; case EXEC_APPEND: Cbuf_AddText(text); break; default: Com_Error(ERR_FATAL, "Cbuf_ExecuteText: bad exec_when"); } }
void CServerRemoteAccess::SetValue(const char *variable, const char *value) { FileHandle_t f; struct cvar_s *var; if (!Q_stricmp(variable, "map")) { Cbuf_AddText("changelevel "); Cbuf_AddText((char*)value); Cbuf_AddText("\n"); Cbuf_Execute(); } else if (!Q_stricmp(variable, "mapcycle")) { f = FS_Open(mapcyclefile.string, "wt"); if (!f) { Con_Printf("Couldn't write to read-only file %s, using file _dev_mapcycle.txt instead.\n", mapcyclefile.string); Cvar_DirectSet(&mapcyclefile, "_temp_mapcycle.txt"); f = FS_Open(mapcyclefile.string, "wt"); } if (f) { FS_Write(value, Q_strlen(value) + 1, 1, f); FS_Close(f); } } else { var = Cvar_FindVar(variable); if (var) Cvar_DirectSet(var, value); } }
/** * @brief Console command to load a savegame * @sa SAV_GameLoad */ static void SAV_GameLoad_f (void) { const char *error = NULL; /* get argument */ if (Cmd_Argc() < 2) { Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0)); return; } /* Check if savegame exists */ if (FS_CheckFile("save/%s.%s", Cmd_Argv(1), SAVEGAME_EXTENSION) <= 0) { Com_Printf("savegame file '%s' doesn't exist or an empty file\n", Cmd_Argv(1)); return; } Com_DPrintf(DEBUG_CLIENT, "load file '%s'\n", Cmd_Argv(1)); /* load and go to map */ if (!SAV_GameLoad(Cmd_Argv(1), &error)) { Cbuf_Execute(); /* wipe outstanding campaign commands */ cgi->UI_Popup(_("Error"), "%s\n%s", _("Error loading game."), error ? error : ""); Cmd_ExecuteString("game_exit"); } }
/* ================= Com_AddLateCommands Adds command line parameters as script statements Commands lead with a + and continue until another + Returns qtrue if any late commands were added, which will keep the demoloop from immediately starting Assumes +set commands are already filtered out ================= */ static qboolean Com_AddLateCommands(void) { int i; char *s; qboolean ret = qfalse; for (i = 1; i < com_argc; i++) { s = com_argv[i]; if (!s) { continue; } if (*s == '+') { if (ret) { Cbuf_AddText(&cmd_buffer, "\n"); } s++; } else if (ret) { Cbuf_AddText(&cmd_buffer, " "); } Cbuf_AddText(&cmd_buffer, s); ret = qtrue; } if (ret) { Cbuf_AddText(&cmd_buffer, "\n"); Cbuf_Execute(&cmd_buffer); } return ret; }
/* ==================== SV_Init ==================== */ void SV_Init (void) { Sys_Printf ("Host_Init\n"); Memory_Init (host_parms->membase, host_parms->memsize); Cbuf_Init (); Cmd_Init (); COM_Init (); FS_Init (); PR_Init (); Mod_Init (); SV_InitNet (); SV_InitLocal (); Pmove_Init (); Hunk_AllocName (0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark (); Cbuf_InsertText ("exec server.cfg\n"); Cbuf_Execute (); // unlock the early-set cvars after init Cvar_UnlockAll (); host_initialized = true; Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); Con_Printf ("%4.1f megabyte heap\n", host_parms->memsize/(1024*1024.0)); Con_Printf ("======== HexenWorld Initialized ========\n"); // process command line arguments Cmd_StuffCmds_f (); Cbuf_Execute (); // if a map wasn't specified on the command line, spawn demo1.map if (sv.state == ss_dead) Cmd_ExecuteString ("map demo1", src_command); if (sv.state == ss_dead) SV_Error ("Couldn't spawn a server"); }
/* ================== SV_Frame ================== */ void SV_Frame (float time) { static double start, end; start = Sys_DoubleTime (); svs.stats.idle += start - end; // keep the random time dependent rand (); // decide the simulation time realtime += time; sv.time += time; // check timeouts SV_CheckTimeouts (); // toggle the log buffer if full SV_CheckLog (); // move autonomous things around if enough time has passed SV_Physics (); // get packets SV_ReadPackets (); // check for commands typed to the host SV_GetConsoleCommands (); // process console commands Cbuf_Execute (); SV_CheckVars (); // send messages back to the clients that had packets read this frame SV_SendClientMessages (); // send a heartbeat to the master if needed Master_Heartbeat (); // collect timing statistics end = Sys_DoubleTime (); svs.stats.active += end-start; if (++svs.stats.count == STATFRAMES) { svs.stats.latched_active = svs.stats.active; svs.stats.latched_idle = svs.stats.idle; svs.stats.latched_packets = svs.stats.packets; svs.stats.active = 0; svs.stats.idle = 0; svs.stats.packets = 0; svs.stats.count = 0; } }
void Com_AddConfigFile(const char *name, unsigned flags) { qerror_t ret; ret = Cmd_ExecuteFile(name, flags); if (ret == Q_ERR_SUCCESS) { Cbuf_Execute(&cmd_buffer); } else if (ret != Q_ERR_NOENT) { Com_WPrintf("Couldn't exec %s: %s\n", name, Q_ErrorString(ret)); } }
void Host_Quit (void) { // execute user's trigger TP_ExecTrigger ("f_exit"); Cbuf_Execute(); // save config (conditional) Config_QuitSave(); // turn off Host_Shutdown (); Sys_Quit (); }
//----------------------------------------------------------------------------- // Purpose: Sets a cvar or value //----------------------------------------------------------------------------- void CServerRemoteAccess::SetValue(const char *variable, const char *value) { // check for special types if (!stricmp(variable, "map")) { // push a map change command Cbuf_AddText( va( "changelevel %s\n", value ) ); Cbuf_Execute(); } else if (!stricmp(variable, "mapcycle")) { // write out a new mapcycle file ConVarRef mapcycle( "mapcyclefile" ); if ( mapcycle.IsValid() ) { FileHandle_t f = g_pFileSystem->Open(mapcycle.GetString(), "wt"); if (!f) { // mapcycle file probably read only, fall pack to temporary file Msg("Couldn't write to read-only file %s, using file _temp_mapcycle.txt instead.\n", mapcycle.GetString()); mapcycle.SetValue("_temp_mapcycle.txt" ); f = g_pFileSystem->Open(mapcycle.GetString(), "wt"); if (!f) { return; } } g_pFileSystem->Write(value, Q_strlen(value) + 1, f); g_pFileSystem->Close(f); } } else { // Stick the cvar set in the command string, so client notification, replication, etc happens Cbuf_AddText( va("%s %s", variable, value) ); Cbuf_AddText("\n"); Cbuf_Execute(); } }
/* * CL_UserInputFrame */ void CL_UserInputFrame( void ) { // let the mouse activate or deactivate IN_Frame(); // get new key events Sys_SendKeyEvents(); // get new key events from mice or external controllers IN_Commands(); // process console commands Cbuf_Execute(); }
/* ================== CL_NextDemo Called when a demo or cinematic finishes If the "nextdemo" cvar is set, that command will be issued ================== */ void CL_NextDemo( void ) { char v[MAX_STRING_CHARS]; Q_strncpyz( v, Cvar_VariableString ("nextdemo"), sizeof(v) ); v[MAX_STRING_CHARS-1] = 0; Com_DPrintf("CL_NextDemo: %s\n", v ); if (!v[0]) { return; } Cvar_Set ("nextdemo",""); Cbuf_AddText (v); Cbuf_AddText ("\n"); Cbuf_Execute(); }
/** * @brief Loads the quick save slot * @sa SAV_GameQuickSave_f */ static void SAV_GameQuickLoad_f (void) { const char *error = NULL; if (cgi->CL_OnBattlescape()) { Com_Printf("Could not load the campaign while you are on the battlefield\n"); return; } if (!SAV_GameLoad("slotquick", &error)) { Cbuf_Execute(); /* wipe outstanding campaign commands */ CP_Popup(_("Error"), "%s\n%s", _("Error loading game."), error ? error : ""); } else { MS_AddNewMessage(_("Campaign loaded"), _("Quicksave campaign was successfully loaded."), MSG_INFO); CP_CheckBaseAttacks(); } }
qboolean CL_ReadRawNetworkData( byte *buffer, size_t *length ) { int msglen = 0; ASSERT( buffer != NULL ); ASSERT( length != NULL ); *length = 0; // assume we fail FS_Read( cls.demofile, &msglen, sizeof( int )); if( msglen < 0 ) { MsgDev( D_ERROR, "Demo message length < 0\n" ); CL_DemoCompleted(); return false; } if( msglen < 8 ) { MsgDev( D_NOTE, "read runt demo message\n" ); } if( msglen > NET_MAX_PAYLOAD ) { MsgDev( D_ERROR, "Demo message %i > %i\n", msglen, NET_MAX_PAYLOAD ); CL_DemoCompleted(); return false; } if( msglen > 0 ) { if( FS_Read( cls.demofile, buffer, msglen ) != msglen ) { MsgDev( D_ERROR, "Error reading demo message data\n" ); CL_DemoCompleted(); return false; } } *length = msglen; if( cls.state != ca_active ) Cbuf_Execute(); return true; }
/* * CL_UserInputFrame */ void CL_UserInputFrame( void ) { // let the mouse activate or deactivate IN_Frame(); // get new key events Sys_SendKeyEvents(); // get new key events from mice or external controllers IN_Commands(); // let the game handle touch events if( cls.key_dest == key_game ) CL_GameModule_TouchFrame(); // process console commands Cbuf_Execute(); }
/* ============ Cbuf_ExecuteText ============ */ void EXPORT Cbuf_ExecuteText (int exec_when, char *text) { switch (exec_when) { case EXEC_NOW: Cmd_ExecuteString (text); Cbuf_Execute (); break; case EXEC_INSERT: Cbuf_InsertText (text); break; case EXEC_APPEND: Cbuf_AddText (text); break; default: Com_Error (ERR_FATAL, "Cbuf_ExecuteText: bad exec_when"); } }
/** * @sa CL_Frame */ static void CL_SendCommand (void) { /* get new key events */ IN_SendKeyEvents(); /* process console commands */ Cbuf_Execute(); /* send intentions now */ CL_SendChangedUserinfos(); /* fix any cheating cvars */ Cvar_FixCheatVars(); switch (cls.state) { case ca_disconnected: /* if the local server is running and we aren't connected then connect */ if (Com_ServerState()) { cls.servername[0] = '\0'; cls.serverport[0] = '\0'; CL_SetClientState(ca_connecting); return; } break; case ca_connecting: if (CL_Milliseconds() - cls.connectTime > cl_connecttimeout->integer) { if (GAME_IsMultiplayer()) Com_Error(ERR_DROP, "Server is not reachable"); } break; case ca_connected: if (cls.waitingForStart) { if (CL_Milliseconds() - cls.waitingForStart > cl_connecttimeout->integer) { Com_Error(ERR_DROP, "Server aborted connection - the server didn't response in %is. You can try to increase the cvar cl_connecttimeout", cl_connecttimeout->integer / 1000); } else { SCR_DrawLoading(100); } } break; default: break; } }
/** * @brief Parse and execute a test windows */ static void UFO_ExecuteTestWindow (const char* windowName) { /* look and feed */ Com_Printf("\n"); TEST_ParseScript(va("ufos/uitest/%s.ufo", windowName)); Cmd_ExecuteString("ui_push %s", windowName); /* while the execution buffer is not empty */ for (int i = 0; i < 20; i++) { Cbuf_Execute(); } UFO_AnalyseTestWindow(windowName); /* look and feed */ Com_Printf(" ---> "); }
/* ============ Cbuf_ExecuteText ============ */ void Cbuf_ExecuteText( int exec_when, const char *text ) { switch ( exec_when ) { case EXEC_NOW: if ( text && strlen( text ) > 0 ) { Cmd_ExecuteString( text ); } else { Cbuf_Execute(); } break; case EXEC_INSERT: Cbuf_InsertText( text ); break; case EXEC_APPEND: Cbuf_AddText( text ); break; default: Com_Error( ERR_FATAL, "Cbuf_ExecuteText: bad exec_when" ); } }
/* ============ Cbuf_ExecuteText ============ */ void Cbuf_ExecuteText( int exec_when, const char *text ) { switch( exec_when ) { case EXEC_NOW: if( text && com.strlen( text )) Cmd_ExecuteString( text ); else Cbuf_Execute(); break; case EXEC_INSERT: Cbuf_InsertText( text ); break; case EXEC_APPEND: Cbuf_AddText( text ); break; default: MsgDev( D_ERROR, "Cbuf_ExecuteText: bad execute target\n" ); break; } }
int main(int argc, char **argv) { char cmdline[] = "+set sv_pure 0 +set vm_ui 0 +set vm_game 0 +set vm_cgame 0 +set fs_basepath ./app/native"; cvar_t *cv = NULL; char cmd_rundemo[100]; Sys_SetDefaultCDPath("./app/native"); //saved_euid = geteuid(); // Clear the queues memset( &eventQue[0], 0, MAX_QUED_EVENTS*sizeof(sysEvent_t) ); memset( &sys_packetReceived[0], 0, MAX_MSGLEN*sizeof(byte) ); // Initialize game Com_Init(cmdline); NET_Init(); // Start game with running demo #if 0 cv = Cvar_Get("rundemo", "0", 0); Cvar_Set("rundemo", "demo1.dm_68"); if (strcmp(cv->string, "0")) { memset(cmd_rundemo, 0, sizeof(cmd_rundemo)); sprintf(cmd_rundemo, "demo %s", cv->string, sizeof(cmd_rundemo)); Cbuf_AddText(cmd_rundemo); Com_Printf(" -- starting execution --- "); Cbuf_Execute(); Com_Printf(" -- execution done --- "); } #endif while (1) { #if 0 Cvar_Set("nextdemo", "demo1.dm_68"); #endif Com_Frame( ); } }
void CL_Init(void) { if (dedicated->value) { return; /* nothing running on the client */ } /* all archived variables will now be loaded */ Con_Init(); S_Init(); SCR_Init(); VID_Init(); IN_Init(); V_Init(); net_message.data = net_message_buffer; net_message.maxsize = sizeof(net_message_buffer); M_Init(); cls.disable_screen = true; /* don't draw yet */ #ifdef CDA CDAudio_Init(); #endif CL_InitLocal(); FS_ExecAutoexec(); Cbuf_Execute(); Key_ReadConsoleHistory(); }
/** * @brief Loads the last saved game * @note At saving the archive cvar cl_lastsave was set to the latest savegame * @sa SAV_GameLoad */ static void SAV_GameContinue_f (void) { const char *error = NULL; if (cgi->CL_OnBattlescape()) { cgi->UI_PopWindow(false); return; } if (!CP_IsRunning()) { /* try to load the last saved campaign */ if (!SAV_GameLoad(cl_lastsave->string, &error)) { Cbuf_Execute(); /* wipe outstanding campaign commands */ cgi->UI_Popup(_("Error"), "%s\n%s", _("Error loading game."), error ? error : ""); Cmd_ExecuteString("game_exit"); } } else { /* just continue the current running game */ cgi->UI_PopWindow(false); } }
void CL_SendCommand(void) { /* update windowed_mouse cvar */ CL_UpdateWindowedMouse(); /* get new key events */ Sys_SendKeyEvents(); /* process console commands */ Cbuf_Execute(); /* fix any cheating cvars */ CL_FixCvarCheats(); /* send intentions now */ CL_SendCmd(); /* resend a connection request if necessary */ CL_CheckForResend(); }
int Daisy_main ( void ) { char cmdline[] = "+set sv_pure 0 +set vm_ui 0 +set vm_game 0 +set vm_cgame 0 +set fs_basepath /media/usd"; cvar_t *cv = NULL; char cmd_rundemo[100]; Sys_SetDefaultCDPath("/media/usd"); //saved_euid = geteuid(); // Clear the queues memset( &eventQue[0], 0, MAX_QUED_EVENTS*sizeof(sysEvent_t) ); memset( &sys_packetReceived[0], 0, MAX_MSGLEN*sizeof(byte) ); // Initialize game Com_Init(cmdline); // Start game with running demo #if 0 cv = Cvar_Get("rundemo", "0", 0); Cvar_Set("rundemo", "demo1.dm_68"); if (strcmp(cv->string, "0")) { memset(cmd_rundemo, 0, sizeof(cmd_rundemo)); sprintf(cmd_rundemo, "demo %s", cv->string, sizeof(cmd_rundemo)); // Cbuf_AddText("demo FOUR.DM_68"); Cbuf_AddText(cmd_rundemo); log_printf(LOG_INFO, " -- starting execution --- "); Cbuf_Execute();` log_printf(LOG_INFO, " -- execution done --- "); } #endif while (1) { Com_Frame( ); } }
/* <3617e> ../engine/host.c:201 */ NOXREF void Host_EndGame(const char *message, ...) { int oldn; va_list argptr; char string[1024]; va_start(argptr,message); Q_vsnprintf(string, sizeof(string), message, argptr); va_end(argptr); Con_DPrintf("Host_EndGame: %s\n", string); oldn = g_pcls.demonum; if (g_psv.active) Host_ShutdownServer(FALSE); g_pcls.demonum = oldn; if (!g_pcls.state) { Sys_Error("Host_EndGame: %s\n", string); } if (oldn != -1) { CL_Disconnect_f(); g_pcls.demonum = oldn; Host_NextDemo(); longjmp(host_enddemo, 1); } CL_Disconnect(); Cbuf_AddText("cd stop\n"); Cbuf_Execute(); longjmp(host_abortserver, 1); }