X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=cmd.c;h=64a90e26b008a509cb6927c4fa3d079e10514fbc;hb=27b8e67dec8c8084ba38ed8201dc54ccd46fdb23;hp=48ab043aad008a910423bbd6546c7bf33473fabd;hpb=0b11b24907f6a68f718b5b8d881d53bcf6be17dc;p=xonotic%2Fdarkplaces.git diff --git a/cmd.c b/cmd.c index 48ab043a..64a90e26 100644 --- a/cmd.c +++ b/cmd.c @@ -237,11 +237,11 @@ static void Cbuf_Execute_Deferred (cmd_state_t *cmd) { cmddeferred_t *defcmd, *prev; double eat; - if (realtime - cmd->deferred_oldrealtime < 0 || realtime - cmd->deferred_oldrealtime > 1800) cmd->deferred_oldrealtime = realtime; - eat = realtime - cmd->deferred_oldrealtime; + if (host.realtime - cmd->deferred_oldrealtime < 0 || host.realtime - cmd->deferred_oldrealtime > 1800) cmd->deferred_oldrealtime = host.realtime; + eat = host.realtime - cmd->deferred_oldrealtime; if (eat < (1.0 / 120.0)) return; - cmd->deferred_oldrealtime = realtime; + cmd->deferred_oldrealtime = host.realtime; prev = NULL; defcmd = cmd->deferred_list; while(defcmd) @@ -325,7 +325,7 @@ void Cbuf_Execute (cmd_state_t *cmd) // better than CRASHING on overlong input lines that may SOMEHOW enter the buffer if(i >= MAX_INPUTLINE) { - Con_Warnf("Warning: console input buffer had an overlong line. Ignored.\n"); + Con_Printf(CON_WARN "Warning: console input buffer had an overlong line. Ignored.\n"); line[0] = 0; } else @@ -395,8 +395,6 @@ void Cbuf_Frame(cmd_state_t *cmd) ============================================================================== */ -extern qboolean host_init; - /* =============== Cmd_StuffCmds_f @@ -412,9 +410,9 @@ static void Cmd_StuffCmds_f (cmd_state_t *cmd) int i, j, l; // this is for all commandline options combined (and is bounds checked) char build[MAX_INPUTLINE]; - + // come back later so we don't crash - if(host_init) + if(host.state == host_init) return; if (Cmd_Argc (cmd) != 1) @@ -430,28 +428,28 @@ static void Cmd_StuffCmds_f (cmd_state_t *cmd) host_stuffcmdsrun = true; build[0] = 0; l = 0; - for (i = 0;i < com_argc;i++) + for (i = 0;i < sys.argc;i++) { - if (com_argv[i] && com_argv[i][0] == '+' && (com_argv[i][1] < '0' || com_argv[i][1] > '9') && l + strlen(com_argv[i]) - 1 <= sizeof(build) - 1) + if (sys.argv[i] && sys.argv[i][0] == '+' && (sys.argv[i][1] < '0' || sys.argv[i][1] > '9') && l + strlen(sys.argv[i]) - 1 <= sizeof(build) - 1) { j = 1; - while (com_argv[i][j]) - build[l++] = com_argv[i][j++]; + while (sys.argv[i][j]) + build[l++] = sys.argv[i][j++]; i++; - for (;i < com_argc;i++) + for (;i < sys.argc;i++) { - if (!com_argv[i]) + if (!sys.argv[i]) continue; - if ((com_argv[i][0] == '+' || com_argv[i][0] == '-') && (com_argv[i][1] < '0' || com_argv[i][1] > '9')) + if ((sys.argv[i][0] == '+' || sys.argv[i][0] == '-') && (sys.argv[i][1] < '0' || sys.argv[i][1] > '9')) break; - if (l + strlen(com_argv[i]) + 4 > sizeof(build) - 1) + if (l + strlen(sys.argv[i]) + 4 > sizeof(build) - 1) break; build[l++] = ' '; - if (strchr(com_argv[i], ' ')) + if (strchr(sys.argv[i], ' ')) build[l++] = '\"'; - for (j = 0;com_argv[i][j];j++) - build[l++] = com_argv[i][j]; - if (strchr(com_argv[i], ' ')) + for (j = 0;sys.argv[i][j];j++) + build[l++] = sys.argv[i][j]; + if (strchr(sys.argv[i], ' ')) build[l++] = '\"'; } build[l++] = '\n'; @@ -668,6 +666,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename) Cbuf_InsertText(cmd, "\n" "csqc_polygons_defaultmaterial_nocullface 1\n" "con_chatsound_team_mask 13\n" +"sv_gameplayfix_customstats 1\n" ); break; // Steel Storm: Burning Retribution csqc misinterprets CSQC_InputEvent if type is a value other than 0 or 1 @@ -1127,9 +1126,9 @@ static const char *Cmd_GetCvarValue(cmd_state_t *cmd, const char *var, size_t va { // empty cvar name? if(alias) - Con_Warnf("Warning: Could not expand $ in alias %s\n", alias->name); + Con_Printf(CON_WARN "Warning: Could not expand $ in alias %s\n", alias->name); else - Con_Warnf("Warning: Could not expand $\n"); + Con_Printf(CON_WARN "Warning: Could not expand $\n"); return "$"; } @@ -1175,9 +1174,9 @@ static const char *Cmd_GetCvarValue(cmd_state_t *cmd, const char *var, size_t va if(required) { if(alias) - Con_Errorf("Error: Could not expand $%s in alias %s\n", varname, alias->name); + Con_Printf(CON_ERROR "Error: Could not expand $%s in alias %s\n", varname, alias->name); else - Con_Errorf("Error: Could not expand $%s\n", varname); + Con_Printf(CON_ERROR "Error: Could not expand $%s\n", varname); return NULL; } else if(optional) @@ -1187,9 +1186,9 @@ static const char *Cmd_GetCvarValue(cmd_state_t *cmd, const char *var, size_t va else { if(alias) - Con_Warnf("Warning: Could not expand $%s in alias %s\n", varname, alias->name); + Con_Printf(CON_WARN "Warning: Could not expand $%s in alias %s\n", varname, alias->name); else - Con_Warnf("Warning: Could not expand $%s\n", varname); + Con_Printf(CON_WARN "Warning: Could not expand $%s\n", varname); dpsnprintf(varval, sizeof(varval), "$%s", varname); return varval; } @@ -1434,7 +1433,7 @@ static void Cmd_Apropos_f(cmd_state_t *cmd) partial = Cmd_Args(cmd); else { - Con_Printf("usage: apropos \n"); + Con_Printf("usage: %s \n",Cmd_Argv(cmd, 0)); return; } @@ -1511,19 +1510,19 @@ void Cmd_Init(void) // client console can see server cvars because the user may start a server cmd_client.cvars = &cvars_all; cmd_client.cvars_flagsmask = CVAR_CLIENT | CVAR_SERVER; + cmd_client.cmd_flags = CMD_CLIENT | CMD_CLIENT_FROM_SERVER | CMD_SERVER_FROM_CLIENT; cmd_client.userdefined = &cmd_userdefined_all; // dedicated server console can only see server cvars, there is no client cmd_server.cvars = &cvars_all; cmd_server.cvars_flagsmask = CVAR_SERVER; + cmd_server.cmd_flags = CMD_SERVER; cmd_server.userdefined = &cmd_userdefined_all; // server commands received from clients have no reason to access cvars, cvar expansion seems perilous. cmd_serverfromclient.cvars = &cvars_null; cmd_serverfromclient.cvars_flagsmask = 0; + cmd_serverfromclient.cmd_flags = CMD_SERVER_FROM_CLIENT | CMD_USERINFO; cmd_serverfromclient.userdefined = &cmd_userdefined_null; -} -void Cmd_Init_Commands(qboolean dedicated_server) -{ // // register our commands // @@ -1557,6 +1556,7 @@ void Cmd_Init_Commands(qboolean dedicated_server) Cmd_AddCommand(CMD_SHARED, "cmdlist", Cmd_List_f, "lists all console commands beginning with the specified prefix or matching the specified wildcard pattern"); Cmd_AddCommand(CMD_SHARED, "cvarlist", Cvar_List_f, "lists all console variables beginning with the specified prefix or matching the specified wildcard pattern"); Cmd_AddCommand(CMD_SHARED, "apropos", Cmd_Apropos_f, "lists all console variables/commands/aliases containing the specified string in the name or description"); + Cmd_AddCommand(CMD_SHARED, "find", Cmd_Apropos_f, "lists all console variables/commands/aliases containing the specified string in the name or description"); Cmd_AddCommand(CMD_SHARED, "defer", Cmd_Defer_f, "execute a command in the future"); @@ -1690,100 +1690,91 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const cmd_function_t *func; cmd_function_t *prev, *current; cmd_state_t *cmd; - xcommand_t function_actual; + xcommand_t save = NULL; int i; - for (i = 1; i < (1<<8); i *= 2) + for (i = 0; i < 3; i++) { - function_actual = function; - if ((i == CMD_CLIENT) && (flags & i)) - { - cmd = &cmd_client; - if (flags & 8) - function_actual = Cmd_ForwardToServer_f; - } - else if ((i == CMD_SERVER) && (flags & i)) - cmd = &cmd_server; - else if ((i == 8) && (flags & i)) // CMD_SERVER_FROM_CLIENT - cmd = &cmd_serverfromclient; - else - continue; - - // fail if the command is a variable name - if (Cvar_FindVar(cmd->cvars, cmd_name, ~0)) + cmd = cmd_iter_all[i].cmd; + if (flags & cmd->cmd_flags) { - Con_Printf("Cmd_AddCommand: %s already defined as a var\n", cmd_name); - return; - } + if(cmd == &cmd_client && (flags & CMD_SERVER_FROM_CLIENT) && !(flags & CMD_CLIENT)) + { + save = function; + function = Cmd_ForwardToServer_f; + } + // fail if the command is a variable name + if (Cvar_FindVar(cmd->cvars, cmd_name, ~0)) + { + Con_Printf("Cmd_AddCommand: %s already defined as a var\n", cmd_name); + return; + } - if (function_actual) - { - // fail if the command already exists in this interpreter - for (func = cmd->engine_functions; func; func = func->next) + if (function) { - if (!strcmp(cmd_name, func->name)) + // fail if the command already exists in this interpreter + for (func = cmd->engine_functions; func; func = func->next) { - // Allow overriding forward to server - if(func->function == Cmd_ForwardToServer_f && (func->flags & 8)) - break; - else + if (!strcmp(cmd_name, func->name)) { Con_Printf("Cmd_AddCommand: %s already defined\n", cmd_name); - goto nested_continue; + goto next; } } - } - func = (cmd_function_t *)Mem_Alloc(cmd->mempool, sizeof(cmd_function_t)); - func->flags = flags; - func->name = cmd_name; - func->function = function_actual; - func->description = description; - func->next = cmd->engine_functions; - - // insert it at the right alphanumeric position - for (prev = NULL, current = cmd->engine_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next) - ; - if (prev) { - prev->next = func; - } - else { - cmd->engine_functions = func; + func = (cmd_function_t *)Mem_Alloc(cmd->mempool, sizeof(cmd_function_t)); + func->flags = flags; + func->name = cmd_name; + func->function = function; + func->description = description; + func->next = cmd->engine_functions; + + // insert it at the right alphanumeric position + for (prev = NULL, current = cmd->engine_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next) + ; + if (prev) { + prev->next = func; + } + else { + cmd->engine_functions = func; + } + func->next = current; } - func->next = current; - } - else - { - // mark csqcfunc if the function already exists in the csqc_functions list - for (func = cmd->userdefined->csqc_functions; func; func = func->next) + else { - if (!strcmp(cmd_name, func->name)) + // mark csqcfunc if the function already exists in the csqc_functions list + for (func = cmd->userdefined->csqc_functions; func; func = func->next) { - func->csqcfunc = true; //[515]: csqc - continue; + if (!strcmp(cmd_name, func->name)) + { + func->csqcfunc = true; //[515]: csqc + continue; + } } - } - func = (cmd_function_t *)Mem_Alloc(cmd->mempool, sizeof(cmd_function_t)); - func->name = cmd_name; - func->function = function_actual; - func->description = description; - func->csqcfunc = true; //[515]: csqc - func->next = cmd->userdefined->csqc_functions; + func = (cmd_function_t *)Mem_Alloc(cmd->mempool, sizeof(cmd_function_t)); + func->name = cmd_name; + func->function = function; + func->description = description; + func->csqcfunc = true; //[515]: csqc + func->next = cmd->userdefined->csqc_functions; - // insert it at the right alphanumeric position - for (prev = NULL, current = cmd->userdefined->csqc_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next) - ; - if (prev) { - prev->next = func; - } - else { - cmd->userdefined->csqc_functions = func; + // insert it at the right alphanumeric position + for (prev = NULL, current = cmd->userdefined->csqc_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next) + ; + if (prev) { + prev->next = func; + } + else { + cmd->userdefined->csqc_functions = func; + } + func->next = current; } - func->next = current; + if (save) + function = save; } -nested_continue: +next: continue; } } @@ -2079,7 +2070,8 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb { if((func->flags & CMD_CHEAT) && !sv_cheats.integer) SV_ClientPrintf("No cheats allowed. The server must have sv_cheats set to 1\n"); - func->function(cmd); + else + func->function(cmd); goto done; } } @@ -2105,7 +2097,7 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb } // check cvars - if (!Cvar_Command(cmd) && host_framecount > 0) + if (!Cvar_Command(cmd) && host.framecount > 0) Con_Printf("Unknown command \"%s\"\n", Cmd_Argv(cmd, 0)); done: cmd->tokenizebufferpos = oldpos;