/* ============ Cmd_Trigger_f ============ */ static void Cmd_Trigger_f( void ) { cmd_trigger_t *trigger; const char *command, *match; int cmdLen, matchLen; if(Cmd_Argc() == 1) { Com_Printf ("Usage: %s <command> <match>\n", LOG_GENERAL, Cmd_Argv(0)); if(!cmd_triggers) { Com_Printf ("No current message triggers\n", LOG_GENERAL); return; } Com_Printf ("Current message triggers:\n", LOG_GENERAL); for (trigger = cmd_triggers; trigger; trigger = trigger->next) { Com_Printf ( "\"%s\" = \"%s\"\n", LOG_GENERAL, trigger->command, trigger->match); } return; } if (Cmd_Argc() < 3) { Com_Printf ("Usage: %s <command> <match>\n", LOG_GENERAL, Cmd_Argv(0)); return; } command = Cmd_Argv(1); match = Cmd_Args2(2); // don't create the same trigger twice for( trigger=cmd_triggers; trigger; trigger=trigger->next ) { if (!strcmp(trigger->command, command) && !strcmp(trigger->match, match)) { //Com_Printf( "Exactly same trigger allready exists\n" ); return; } } cmdLen = strlen(command) + 1; matchLen = strlen(match) + 1; if(matchLen < 4) { Com_Printf ("Match is too short.\n", LOG_GENERAL); return; } //!!!!!!! FIXME HACK XXXXXXXX maniac you are insane trigger = Z_TagMalloc( sizeof( cmd_trigger_t ) + cmdLen + matchLen, TAGMALLOC_TRIGGER); trigger->command = (char *)((byte *)trigger + sizeof( cmd_trigger_t )); trigger->match = trigger->command + cmdLen; strcpy (trigger->command, command); strcpy (trigger->match, match); trigger->next = cmd_triggers; cmd_triggers = trigger; }
/* ============ Cvar_Set_f Allows setting and defining of arbitrary cvars from console ============ */ static void Cvar_Set_f (void) { int c; int flags; c = Cmd_Argc(); //if (c != 3 && c != 4) if (c < 3) { Com_Printf ("usage: set <variable> <value> [u / s] (line: set %s)\n", LOG_GENERAL, Cmd_Args()); return; } //r1: fixed so that 'set variable some thing' results in variable -> "some thing" //so that set command can be used in aliases to set things with spaces without //requring quotes. if (!strcmp(Cmd_Argv(c-1), "u")) flags = CVAR_USERINFO; else if (!strcmp(Cmd_Argv(3), "s")) flags = CVAR_SERVERINFO; else flags = 0; if (flags) { /*char string[2048]; int i; string[0] = 0; for (i=2 ; i<c-1 ; i++) { strcat (string, Cmd_Argv(i)); if (i+1 != c-1) strcat (string, " "); }*/ //note, we don't do the above to get the full string since userinfo vars //have to use same format as 3.20 (eg set undef $undef u should set undef "u") //for q2admin and other userinfo checking mods. Cvar_FullSet (Cmd_Argv(1), Cmd_Argv(2), flags); } else { Cvar_Set (Cmd_Argv(1), Cmd_Args2(2)); } }
static void Cmd_UnTrigger_f( void ) { cmd_trigger_t *trigger, *next, **back; const char *command, *match; int count = 0; if(!cmd_triggers) { Com_Printf ("No current message triggers\n", LOG_GENERAL); return; } if (Cmd_Argc() == 1) { Com_Printf ("Usage: %s <command> <match>\n", LOG_GENERAL, Cmd_Argv(0)); Com_Printf ("Current message triggers:\n", LOG_GENERAL); for (trigger = cmd_triggers; trigger; trigger = trigger->next) { Com_Printf ("\"%s\" = \"%s\"\n", LOG_GENERAL, trigger->command, trigger->match); } return; } if (Cmd_Argc() == 2) { if (!Q_stricmp(Cmd_Argv(1), "all")) { for(trigger = cmd_triggers; trigger; trigger = next) { next = trigger->next; Z_Free(trigger); count++; } cmd_triggers = NULL; if(count) Com_Printf("Removed all (%i) triggers\n", LOG_GENERAL, count); return; } Com_Printf("Usage: %s <command> <match>\n", LOG_GENERAL, Cmd_Argv(0)); return; } command = Cmd_Argv (1); match = Cmd_Args2 (2); back = &cmd_triggers; for(;;) { trigger = *back; if(!trigger) { Com_Printf ("Cant find trigger \"%s\" = \"%s\".\n", LOG_GENERAL, command, match); return; } if(!strcmp(trigger->command, command) && !strcmp(trigger->match, match)) { *back = trigger->next; Com_Printf ("Removed trigger \"%s\" = \"%s\"\n", LOG_GENERAL, trigger->command, trigger->match ); Z_Free (trigger); return; } back = &trigger->next; } }
/* =============== Cmd_Alias_f Creates a new command that executes a command string (possibly ; seperated) =============== */ void Cmd_Alias_f (void) { cmdalias_t *a; char cmd[1024]; char *s; void **data; if (Cmd_Argc() == 1) { Com_Printf ("Current alias commands:\n", LOG_GENERAL); Cmd_Aliaslist_f (); return; } s = Cmd_Argv(1); if (strlen(s) >= MAX_ALIAS_NAME) { Com_Printf ("Alias name is too long\n", LOG_GENERAL); return; } // if the alias already exists, reuse it /*for (a = cmd_alias ; a ; a=a->next) { if (!strcmp(s, a->name)) { Z_Free (a->value); break; } }*/ data = rbfind (s, aliastree); if (data) a = *(cmdalias_t **)data; else a = NULL; if (!a) { a = Z_TagMalloc (sizeof(cmdalias_t), TAGMALLOC_ALIAS); a->next = cmd_alias; cmd_alias = a; strcpy (a->name, s); data = rbsearch (a->name, aliastree); *data = a; } else { //strcpy (a->name, s); //memleak fix, thanks Maniac- Z_Free (a->value); } // copy the rest of the command line /*cmd[0] = 0; // start out with a null string c = Cmd_Argc(); for (i=2 ; i< c ; i++) { strcat (cmd, Cmd_Argv(i)); if (i != (c - 1)) strcat (cmd, " "); }*/ Q_strncpy (cmd, Cmd_Args2(2), sizeof(cmd)-2); /*s = strchr (Cmd_Args(), ' '); if (s) s++; else s = Cmd_Args (); Q_strncpy (cmd, s, sizeof(cmd)-2);*/ strcat (cmd, "\n"); a->value = CopyString (cmd, TAGMALLOC_ALIAS); }