Xonotic
generic.qc File Reference
#include "generic.qh"
+ Include dependency graph for generic.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void Curl_URI_Get_Callback (int id, float status, string data)
 
 GENERIC_COMMAND (dumpcommands, "Dump all commands on the program to <program>_cmd_dump.txt", false)
 
 GENERIC_COMMAND (addtolist, "Add a string to a cvar", true)
 
 GENERIC_COMMAND (maplist, "Automatic control of maplist", true)
 
 GENERIC_COMMAND (nextframe, "Execute the given command next frame of this VM", true)
 
 GENERIC_COMMAND (qc_curl, "Queries a URL", true)
 
 GENERIC_COMMAND (removefromlist, "Remove a string from a cvar", true)
 
 GENERIC_COMMAND (restartnotifs, "Re-initialize all notifications", false)
 
 GENERIC_COMMAND (rpn, "RPN calculator", true)
 
 GENERIC_COMMAND (settemp, "Temporarily set a value to a cvar which is restored later", false)
 
 GENERIC_COMMAND (settemp_restore, "Restore all cvars set by settemp command", false)
 
 GENERIC_COMMAND (runtest, "Run unit tests", false)
 
float GenericCommand (string command)
 
void GenericCommand_addtolist (int request, int argc)
 
float GenericCommand_macro_command (int argc, string command)
 
void GenericCommand_macro_help ()
 
float GenericCommand_macro_usage (int argc)
 
void GenericCommand_macro_write_aliases (float fh)
 
void GenericCommand_maplist (int request, int argc)
 
void GenericCommand_nextframe (int request, string command)
 
void GenericCommand_qc_curl (int request, int argc)
 
void GenericCommand_removefromlist (int request, int argc)
 
void GenericCommand_restartnotifs (int request)
 
void GenericCommand_runtest (int request, int argc)
 
void GenericCommand_settemp (int request, int argc)
 
void GenericCommand_settemp_restore (int request)
 

Function Documentation

◆ Curl_URI_Get_Callback()

void Curl_URI_Get_Callback ( int  id,
float  status,
string  data 
)

Definition at line 31 of file generic.qc.

References curl_uri_get_cvar, curl_uri_get_exec, cvar_set(), localcmd, LOG_INFO, LOG_TRACEF, strunzone(), and URI_GET_CURL.

Referenced by URI_Get_Callback().

32 {
33  int i = id - URI_GET_CURL;
34  float do_exec = curl_uri_get_exec[i];
35  string do_cvar = curl_uri_get_cvar[i];
36  if(status != 0)
37  {
38  LOG_TRACEF("error: status is %d", status);
39  if(do_cvar)
40  strunzone(do_cvar);
41  return;
42  }
43  if(do_exec)
44  localcmd(data);
45  if(do_cvar)
46  {
47  cvar_set(do_cvar, data);
48  strunzone(do_cvar);
49  }
50  if(!do_exec)
51  if (!do_cvar)
52  LOG_INFO(data);
53 }
const int URI_GET_CURL
Definition: urllib.qh:7
#define LOG_INFO(...)
Definition: log.qh:70
#define LOG_TRACEF(...)
Definition: log.qh:82
float curl_uri_get_exec[URI_GET_CURL_END - URI_GET_CURL+1]
Definition: generic.qh:39
string curl_uri_get_cvar[URI_GET_CURL_END - URI_GET_CURL+1]
Definition: generic.qh:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GENERIC_COMMAND() [1/11]

GENERIC_COMMAND ( dumpcommands  ,
"Dump all commands on the program to <program>_cmd_dump.txt"  ,
false   
)

Definition at line 172 of file generic.qc.

References BanCommand_macro_write_aliases(), ClientCommand_macro_write_aliases(), CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, CMD_Write, CommonCommand_macro_write_aliases(), fclose(), FILE_WRITE, fopen(), GameCommand_macro_write_aliases(), GenericCommand_macro_write_aliases(), LocalCommand_macro_write_aliases(), LOG_HELP, LOG_INFO, and strcat().

173 {
174  switch(request)
175  {
176  case CMD_REQUEST_COMMAND:
177  {
178  float fh;
179  string filename = strcat(GetProgramCommandPrefix(), "_dump.txt");
180  fh = fopen(filename, FILE_WRITE);
181 
182  if(fh >= 0)
183  {
184  #ifdef SVQC
185  CMD_Write("dump of server console commands:\n");
187  CMD_Write("\n");
188 
189  CMD_Write("dump of networked client only commands:\n");
191  CMD_Write("\n");
192 
193  CMD_Write("dump of common commands:\n");
195  CMD_Write("\n");
196 
197  CMD_Write("dump of ban commands:\n");
199  CMD_Write("\n");
200  #endif
201 
202  #ifdef CSQC
203  CMD_Write("dump of client commands:\n");
205  CMD_Write("\n");
206  #endif
207 
208  CMD_Write("dump of generic commands:\n");
210 
211  LOG_INFO("Completed dump of aliases in ^2data/data/", GetProgramCommandPrefix(), "_dump.txt^7.");
212 
213  fclose(fh);
214  }
215  else
216  {
217  LOG_INFO("^1Error: ^7Could not dump to file!");
218  }
219  return;
220  }
221 
222  default:
223  case CMD_REQUEST_USAGE:
224  {
225  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " dumpcommands");
226  LOG_HELP(" No arguments required.");
227  return;
228  }
229  }
230 }
void GameCommand_macro_write_aliases(float fh)
Definition: sv_cmd.qc:1711
const int CMD_REQUEST_USAGE
Definition: command.qh:4
void BanCommand_macro_write_aliases(float fh)
Definition: banning.qc:307
#define CMD_Write(s)
Definition: generic.qh:33
void GenericCommand_macro_write_aliases(float fh)
Definition: generic.qc:571
void ClientCommand_macro_write_aliases(float fh)
Definition: cmd.qc:852
#define LOG_HELP(...)
Definition: log.qh:95
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
#define LOG_INFO(...)
Definition: log.qh:70
const float FILE_WRITE
Definition: csprogsdefs.qc:233
void CommonCommand_macro_write_aliases(float fh)
Definition: common.qh:188
void LocalCommand_macro_write_aliases(int fh)
Definition: cl_cmd.qc:491
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [2/11]

GENERIC_COMMAND ( addtolist  ,
"Add a string to a cvar ,
true   
)

Definition at line 535 of file generic.qc.

References GenericCommand_addtolist().

535 { GenericCommand_addtolist(request, arguments); }
void GenericCommand_addtolist(int request, int argc)
Definition: generic.qc:60
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [3/11]

GENERIC_COMMAND ( maplist  ,
"Automatic control of maplist"  ,
true   
)

Definition at line 536 of file generic.qc.

References GenericCommand_maplist().

536 { GenericCommand_maplist(request, arguments); }
void GenericCommand_maplist(int request, int argc)
Definition: generic.qc:232
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [4/11]

GENERIC_COMMAND ( nextframe  ,
"Execute the given command next frame of this VM"  ,
true   
)

Definition at line 537 of file generic.qc.

References GenericCommand_nextframe().

537 { GenericCommand_nextframe(request, command); }
void GenericCommand_nextframe(int request, string command)
Definition: generic.qc:315
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [5/11]

GENERIC_COMMAND ( qc_curl  ,
"Queries a URL"  ,
true   
)

Definition at line 538 of file generic.qc.

References GenericCommand_qc_curl().

538 { GenericCommand_qc_curl(request, arguments); }
void GenericCommand_qc_curl(int request, int argc)
Definition: generic.qc:100
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [6/11]

GENERIC_COMMAND ( removefromlist  ,
"Remove a string from a cvar ,
true   
)

Definition at line 539 of file generic.qc.

References GenericCommand_removefromlist().

539 { GenericCommand_removefromlist(request, arguments); }
void GenericCommand_removefromlist(int request, int argc)
Definition: generic.qc:335
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [7/11]

GENERIC_COMMAND ( restartnotifs  ,
"Re-initialize all notifications"  ,
false   
)

Definition at line 540 of file generic.qc.

References GenericCommand_restartnotifs().

540 { GenericCommand_restartnotifs(request); }
void GenericCommand_restartnotifs(int request)
Definition: generic.qc:370
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [8/11]

GENERIC_COMMAND ( rpn  ,
"RPN calculator"  ,
true   
)

Definition at line 541 of file generic.qc.

References GenericCommand_rpn().

541 { GenericCommand_rpn(request, arguments, command); }
void GenericCommand_rpn(int request, int argc, string command)
Definition: rpn.qc:63
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [9/11]

GENERIC_COMMAND ( settemp  ,
"Temporarily set a value to a cvar which is restored later"  ,
false   
)

Definition at line 542 of file generic.qc.

References GenericCommand_settemp().

542 { GenericCommand_settemp(request, arguments); }
void GenericCommand_settemp(int request, int argc)
Definition: generic.qc:427
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [10/11]

GENERIC_COMMAND ( settemp_restore  ,
"Restore all cvars set by settemp command"  ,
false   
)

Definition at line 543 of file generic.qc.

References GenericCommand_settemp_restore().

543 { GenericCommand_settemp_restore(request); }
void GenericCommand_settemp_restore(int request)
Definition: generic.qc:458
+ Here is the call graph for this function:

◆ GENERIC_COMMAND() [11/11]

GENERIC_COMMAND ( runtest  ,
"Run unit tests"  ,
false   
)

Definition at line 544 of file generic.qc.

References GenericCommand_runtest().

544 { GenericCommand_runtest(request, arguments); }
void GenericCommand_runtest(int request, int argc)
Definition: generic.qc:485
+ Here is the call graph for this function:

◆ GenericCommand()

float GenericCommand ( string  command)

Definition at line 582 of file generic.qc.

References argv(), argv_end_index, argv_start_index, floor(), GenericCommand_macro_command(), GenericCommand_markup(), hsl_to_rgb(), localcmd, max(), random(), rgb_to_hexcolor(), s2, strcat(), strlen(), substring(), tokenize_console, and vector().

Referenced by GameCommand().

583 {
584  int argc = tokenize_console(command);
585  float n, j, f, i;
586  string s, s2, c;
587  vector rgb;
588 
589  // Guide for working with argc arguments by example:
590  // argc: 1 - 2 - 3 - 4
591  // argv: 0 - 1 - 2 - 3
592  // cmd vote - master - login - password
593 
594  if(GenericCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
595  {
596  return true; // handled by one of the above GenericCommand_* functions
597  }
598  else if(argc >= 3 && argv(0) == "red")
599  {
600  s = substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2));
602  return true;
603  }
604  else if(argc >= 3 && crc16(0, argv(0)) == 38566 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 59830)
605  {
606  // other test case
607  s = strconv(2, 0, 0, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
608 
609  n = floor(random() * 6 + 2);
610 
611  s2 = "";
612  for(i = 0; i < n; ++i)
613  {
614  s2 = strcat(s2, "AH");
615  }
616 
617  if(random() < 0.1)
618  s2 = strcat(substring(s2, 1, strlen(s2) - 1), "A");
619 
620  if(s == "")
621  s = s2;
622  else
623  if(random() < 0.8)
624  s = strcat(s, " ", s2);
625  else
626  s = strcat(s2, " ", s);
627 
628  s2 = substring(s, strlen(s) - 2, 2);
629  if(s2 == "AH" || s2 == "AY")
630  s = strcat(s, "))");
631  else
632  s = strcat(s, " ))");
633 
634  if(random() < 0.1)
635  s = substring(s, 0, strlen(s) - 1);
636 
637  if(random() < 0.1)
638  s = strconv(1, 0, 0, s);
639 
640  localcmd(strcat(argv(1), " ", s));
641 
642  return true;
643  }
644  else if(argc >= 3 && crc16(0, argv(0)) == 3826 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 55790)
645  {
646  // test case for terencehill's color codes
647  s = strdecolorize(substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
648  s2 = "";
649 
650  n = strlen(s);
651  j = ((6 * max(1, floor(strlen(s)/32 + random() * 2 - 1))) / n) * (1 - 2 * (random() > 0.5));
652  f = random() * 6;
653 
654  for(i = 0; i < n; ++i)
655  {
656  c = substring(s, i, 1);
657 
658  if(c == ";")
659  c = ":";
660  else if(c == "^")
661  {
662  c = "^^";
663  if(substring(s, i+1, 1) == "^")
664  ++i;
665  }
666 
667  if(c != " ")
668  {
669  rgb = hsl_to_rgb('1 0 0' * (j * i + f) + '0 1 .5');
670  c = strcat(rgb_to_hexcolor(rgb), c);
671  }
672  s2 = strcat(s2, c);
673  }
674 
675  localcmd(strcat(argv(1), " ", s2));
676 
677  return true;
678  }
679 
680  return false;
681 }
ERASEABLE vector hsl_to_rgb(vector hsl)
Definition: color.qh:167
spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2 f1 f1points s1 s2
Definition: all.inc:438
#define argv_end_index
Definition: dpextensions.qh:30
string GenericCommand_markup(string s2)
Definition: markup.qc:61
float GenericCommand_macro_command(int argc, string command)
Definition: generic.qc:551
#define argv_start_index
Definition: dpextensions.qh:27
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define tokenize_console
Definition: dpextensions.qh:24
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition: color.qh:183
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_addtolist()

void GenericCommand_addtolist ( int  request,
int  argc 
)

Definition at line 60 of file generic.qc.

References argv(), CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, cons(), cvar_set(), cvar_string(), FOREACH_WORD, LOG_HELP, and LOG_INFOF.

Referenced by GENERIC_COMMAND().

61 {
62  switch(request)
63  {
65  {
66  if(argc >= 2)
67  {
68  string original_cvar = argv(1);
69  string tmp_string = argv(2);
70 
71  if(cvar_string(original_cvar) == "") // cvar was empty
72  {
73  cvar_set(original_cvar, tmp_string);
74  }
75  else // add it to the end of the list if the list doesn't already have it
76  {
77  FOREACH_WORD(cvar_string(original_cvar), it == tmp_string,
78  {
79  return; // already in the list
80  });
81 
82  cvar_set(original_cvar, cons(cvar_string(original_cvar), tmp_string));
83  }
84  return;
85  }
86  }
87 
88  default:
89  LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
90  case CMD_REQUEST_USAGE:
91  {
92  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " addtolist <cvar> <value>");
93  LOG_HELP(" Where <cvar> is the cvar to add <value> to.");
94  LOG_HELP("See also: ^2removefromlist^7");
95  return;
96  }
97  }
98 }
const int CMD_REQUEST_USAGE
Definition: command.qh:4
#define LOG_HELP(...)
Definition: log.qh:95
#define FOREACH_WORD(words, cond, body)
Definition: iter.qh:33
#define LOG_INFOF(...)
Definition: log.qh:71
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
ERASEABLE string cons(string a, string b)
Definition: string.qh:257
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_macro_command()

float GenericCommand_macro_command ( int  argc,
string  command 
)

Definition at line 551 of file generic.qc.

References argv(), and FOREACH.

Referenced by GenericCommand().

552 {
553  string c = strtolower(argv(0));
554  FOREACH(GENERIC_COMMANDS, it.m_name == c, {
555  it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
556  return true;
557  });
558  return false;
559 }
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_macro_help()

void GenericCommand_macro_help ( )

Definition at line 546 of file generic.qc.

References FOREACH, and LOG_HELPF.

Referenced by GameCommand().

547 {
548  FOREACH(GENERIC_COMMANDS, true, LOG_HELPF(" ^2%s^7: %s", it.m_name, it.m_description));
549 }
#define LOG_HELPF(...)
Definition: log.qh:96
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ GenericCommand_macro_usage()

float GenericCommand_macro_usage ( int  argc)

Definition at line 561 of file generic.qc.

References argv(), and FOREACH.

Referenced by GameCommand().

562 {
563  string c = strtolower(argv(1));
564  FOREACH(GENERIC_COMMANDS, it.m_name == c, {
565  it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
566  return true;
567  });
568  return false;
569 }
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_macro_write_aliases()

void GenericCommand_macro_write_aliases ( float  fh)

Definition at line 571 of file generic.qc.

References CMD_Write_Alias, and FOREACH.

Referenced by GENERIC_COMMAND().

572 {
573  FOREACH(GENERIC_COMMANDS, true, CMD_Write_Alias("qc_cmd_svmenu", it.m_name, it.m_description));
574 }
#define CMD_Write_Alias(execute, command, description)
Definition: generic.qh:34
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ GenericCommand_maplist()

void GenericCommand_maplist ( int  request,
int  argc 
)

Definition at line 232 of file generic.qc.

References argv(), CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, cons(), cvar_set(), cvar_string(), fexists(), FOREACH_WORD, LOG_HELP, LOG_INFO, LOG_INFOF, MapInfo_CheckMap(), MapInfo_CurrentFeatures(), MapInfo_CurrentGametype(), MapInfo_Enumerate(), MapInfo_FilterGametype(), MapInfo_ForbiddenFlags(), MapInfo_RequiredFlags(), shufflewords(), strcat(), strlen(), substring(), and tokenizebyseparator.

Referenced by GENERIC_COMMAND().

233 {
234  switch(request)
235  {
236  case CMD_REQUEST_COMMAND:
237  {
238  string tmp_string;
239  float i;
240 
241  switch(argv(1))
242  {
243  case "add": // appends new maps to the maplist
244  {
245  if(argc == 3)
246  {
247  if (!fexists(strcat("maps/", argv(2), ".bsp")))
248  {
249  LOG_INFO("maplist: ERROR: ", argv(2), " does not exist!");
250  break;
251  }
252 
253  if(cvar_string("g_maplist") == "")
254  cvar_set("g_maplist", argv(2));
255  else
256  cvar_set("g_maplist", strcat(argv(2), " ", cvar_string("g_maplist")));
257 
258  return;
259  }
260  break; // go to usage
261  }
262 
263  case "cleanup": // scans maplist and only adds back the ones which are really usable
264  {
267  string filtered = "";
268  FOREACH_WORD(cvar_string("g_maplist"), MapInfo_CheckMap(it), filtered = cons(filtered, it));
269  cvar_set("g_maplist", filtered);
270  return;
271  }
272 
273  case "remove": // scans maplist and only adds back whatever maps were not provided in argv(2)
274  {
275  if(argc == 3)
276  {
277  argc = tokenizebyseparator(cvar_string("g_maplist"), " ");
278 
279  tmp_string = "";
280  for(i = 0; i < argc; ++i)
281  if(argv(i) != argv(2))
282  tmp_string = strcat(tmp_string, " ", argv(i));
283 
284  tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1);
285  cvar_set("g_maplist", tmp_string);
286 
287  return;
288  }
289  break; // go to usage
290  }
291 
292  case "shuffle": // randomly shuffle the maplist
293  {
294  cvar_set("g_maplist", shufflewords(cvar_string("g_maplist")));
295  return;
296  }
297 
298  default: break;
299  }
300  }
301 
302  default:
303  LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
304  case CMD_REQUEST_USAGE:
305  {
306  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " maplist <action> [<map>]");
307  LOG_HELP(" Where <action> is the command to complete,");
308  LOG_HELP(" and <map> is what it acts upon (for the 'add' and 'remove' actions).");
309  LOG_HELP(" Full list of commands here: add, cleanup, remove, shuffle.");
310  return;
311  }
312  }
313 }
int MapInfo_RequiredFlags()
Definition: mapinfo.qc:1339
const int CMD_REQUEST_USAGE
Definition: command.qh:4
int MapInfo_ForbiddenFlags()
Definition: mapinfo.qc:1324
ERASEABLE string shufflewords(string str)
Definition: string.qh:307
#define LOG_HELP(...)
Definition: log.qh:95
#define FOREACH_WORD(words, cond, body)
Definition: iter.qh:33
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
int MapInfo_CurrentFeatures()
Definition: mapinfo.qc:1140
#define LOG_INFOF(...)
Definition: log.qh:71
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
#define LOG_INFO(...)
Definition: log.qh:70
float MapInfo_CheckMap(string s)
Definition: mapinfo.qc:1170
#define tokenizebyseparator
Definition: dpextensions.qh:21
ERASEABLE string cons(string a, string b)
Definition: string.qh:257
float MapInfo_FilterGametype(Gametype pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
Definition: mapinfo.qc:158
ERASEABLE bool fexists(string f)
Definition: file.qh:4
void MapInfo_Enumerate()
Definition: mapinfo.qc:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_nextframe()

void GenericCommand_nextframe ( int  request,
string  command 
)

Definition at line 315 of file generic.qc.

References argv_end_index, argv_start_index, CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, LOG_HELP, queue_to_execute_next_frame(), and substring().

Referenced by GENERIC_COMMAND().

316 {
317  switch(request)
318  {
319  case CMD_REQUEST_COMMAND:
320  {
322  return;
323  }
324 
325  default:
326  case CMD_REQUEST_USAGE:
327  {
328  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " nextframe <command>");
329  LOG_HELP(" Where <command> will be executed next frame of this VM");
330  return;
331  }
332  }
333 }
const int CMD_REQUEST_USAGE
Definition: command.qh:4
#define LOG_HELP(...)
Definition: log.qh:95
#define argv_end_index
Definition: dpextensions.qh:30
#define argv_start_index
Definition: dpextensions.qh:27
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
void queue_to_execute_next_frame(string s)
Definition: util.qc:1620
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_qc_curl()

void GenericCommand_qc_curl ( int  request,
int  argc 
)

Definition at line 100 of file generic.qc.

References argv(), buf_create, CMD_REQUEST_COMMAND, curl_uri_get_cvar, curl_uri_get_exec, curl_uri_get_pos, LOG_INFO, stof(), string_null, strzone(), URI_GET_CURL, and URI_GET_CURL_END.

Referenced by GENERIC_COMMAND().

101 {
102  switch(request)
103  {
104  case CMD_REQUEST_COMMAND:
105  {
106  bool do_exec = false;
107  string do_cvar = string_null;
108  float key = -1;
109  int i;
110  for(i = 1; i+1 < argc; ++i)
111  {
112  if(argv(i) == "--cvar" && i+2 < argc)
113  {
114  ++i;
115  do_cvar = strzone(argv(i));
116  continue;
117  }
118  if(argv(i) == "--exec")
119  {
120  do_exec = true;
121  continue;
122  }
123  if(argv(i) == "--key" && i+2 < argc)
124  {
125  ++i;
126  key = stof(argv(i));
127  continue;
128  }
129  break;
130  }
131 
132  // now, argv(i) is the URL
133  // following args may be POST parameters
134  string url = argv(i);
135  ++i;
136  float buf = buf_create();
137  int j;
138  for(j = 0; i+1 < argc; i += 2)
139  bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i+1))));
140  if(i < argc)
141  bufstr_set(buf, ++j, sprintf("submit=%s", uri_escape(argv(i))));
142 
143  float r;
144  if(j == 0) // no args: GET
145  r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, string_null, string_null, -1, key);
146  else // with args: POST
147  r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, "application/x-www-form-urlencoded", "&", buf, key);
148 
149  if(r)
150  {
154  }
155  else
156  LOG_INFO(_("error creating curl handle"));
157 
158  buf_del(buf);
159 
160  return;
161  }
162 
163  default:
164  case CMD_REQUEST_USAGE:
165  {
166  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " qc_curl [--key <n>] [--cvar] [--exec] <url> [<postargs>]");
167  return;
168  }
169  }
170 }
string string_null
Definition: nil.qh:9
const int CMD_REQUEST_USAGE
Definition: command.qh:4
int curl_uri_get_pos
Definition: generic.qh:38
#define LOG_HELP(...)
Definition: log.qh:95
#define buf_create
Definition: dpextensions.qh:63
const int URI_GET_CURL
Definition: urllib.qh:7
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
#define LOG_INFO(...)
Definition: log.qh:70
const int URI_GET_CURL_END
Definition: urllib.qh:8
float curl_uri_get_exec[URI_GET_CURL_END - URI_GET_CURL+1]
Definition: generic.qh:39
string curl_uri_get_cvar[URI_GET_CURL_END - URI_GET_CURL+1]
Definition: generic.qh:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_removefromlist()

void GenericCommand_removefromlist ( int  request,
int  argc 
)

Definition at line 335 of file generic.qc.

References argv(), CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, cons(), cvar_set(), cvar_string(), FOREACH_WORD, LOG_HELP, and LOG_INFOF.

Referenced by GENERIC_COMMAND().

336 {
337  switch(request)
338  {
339  case CMD_REQUEST_COMMAND:
340  {
341  if(argc == 3)
342  {
343  string original_cvar = argv(1);
344  string removal = argv(2);
345 
346  string tmp_string = "";
347  FOREACH_WORD(cvar_string(original_cvar), it != removal,
348  {
349  tmp_string = cons(tmp_string, it);
350  });
351 
352  cvar_set(original_cvar, tmp_string);
353 
354  return;
355  }
356  }
357 
358  default:
359  LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
360  case CMD_REQUEST_USAGE:
361  {
362  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " removefromlist <cvar> <value>");
363  LOG_HELP(" Where <cvar> is the cvar to remove <value> from.");
364  LOG_HELP("See also: ^2addtolist^7");
365  return;
366  }
367  }
368 }
const int CMD_REQUEST_USAGE
Definition: command.qh:4
#define LOG_HELP(...)
Definition: log.qh:95
#define FOREACH_WORD(words, cond, body)
Definition: iter.qh:33
#define LOG_INFOF(...)
Definition: log.qh:71
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
ERASEABLE string cons(string a, string b)
Definition: string.qh:257
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_restartnotifs()

void GenericCommand_restartnotifs ( int  request)

Definition at line 370 of file generic.qc.

References CALL_ACCUMULATED_FUNCTION, CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, Destroy_All_Notifications(), FOREACH, LOG_HELP, LOG_INFO, and LOG_INFOF.

Referenced by GENERIC_COMMAND().

371 {
372  switch(request)
373  {
374  case CMD_REQUEST_COMMAND:
375  {
376  #ifdef GAMEQC
377  int NOTIF_ANNCE_COUNT = 0;
378  int NOTIF_INFO_COUNT = 0;
379  int NOTIF_CENTER_COUNT = 0;
380  int NOTIF_MULTI_COUNT = 0;
381  int NOTIF_CHOICE_COUNT = 0;
382  FOREACH(Notifications, true, {
383  switch (it.nent_type)
384  {
385  case MSG_ANNCE: ++NOTIF_ANNCE_COUNT; break;
386  case MSG_INFO: ++NOTIF_INFO_COUNT; break;
387  case MSG_CENTER: ++NOTIF_CENTER_COUNT; break;
388  case MSG_MULTI: ++NOTIF_MULTI_COUNT; break;
389  case MSG_CHOICE: ++NOTIF_CHOICE_COUNT; break;
390  }
391  });
392 
393  LOG_INFOF(
394  "Restart_Notifications(): Restarting %d notifications... "
395  "Counts: MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d",
396  (
397  NOTIF_ANNCE_COUNT +
398  NOTIF_INFO_COUNT +
399  NOTIF_CENTER_COUNT +
400  NOTIF_MULTI_COUNT +
401  NOTIF_CHOICE_COUNT
402  ),
403  NOTIF_ANNCE_COUNT,
404  NOTIF_INFO_COUNT,
405  NOTIF_CENTER_COUNT,
406  NOTIF_MULTI_COUNT,
407  NOTIF_CHOICE_COUNT
408  );
410  CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
411  #else
412  LOG_INFO("Notification restart command only works with cl_cmd and sv_cmd.");
413  #endif
414  return;
415  }
416 
417  default:
418  case CMD_REQUEST_USAGE:
419  {
420  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " restartnotifs");
421  LOG_HELP(" No arguments required.");
422  return;
423  }
424  }
425 }
const int CMD_REQUEST_USAGE
Definition: command.qh:4
#define LOG_HELP(...)
Definition: log.qh:95
#define LOG_INFOF(...)
Definition: log.qh:71
void Destroy_All_Notifications()
Definition: all.qc:159
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
#define LOG_INFO(...)
Definition: log.qh:70
#define CALL_ACCUMULATED_FUNCTION(func)
Definition: accumulate.qh:45
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_runtest()

void GenericCommand_runtest ( int  request,
int  argc 
)

Definition at line 485 of file generic.qc.

References argv(), CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, LOG_HELP, RUN_ALL_TESTS(), and TEST_Run().

Referenced by GENERIC_COMMAND().

486 {
487  switch(request)
488  {
489  case CMD_REQUEST_COMMAND:
490  {
491  if(argc > 1)
492  {
493  float i;
494  for(i = 1; i < argc; ++i)
495  TEST_Run(argv(i));
496  }
497  else
498  RUN_ALL_TESTS();
499  return;
500  }
501 
502  default:
503  case CMD_REQUEST_USAGE:
504  {
505  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " <function>");
506  return;
507  }
508  }
509 }
const int CMD_REQUEST_USAGE
Definition: command.qh:4
bool TEST_Run(string s)
Definition: test.qc:19
#define LOG_HELP(...)
Definition: log.qh:95
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
bool RUN_ALL_TESTS()
Definition: test.qc:4
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_settemp()

void GenericCommand_settemp ( int  request,
int  argc 
)

Definition at line 427 of file generic.qc.

References argv(), CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, cvar_settemp(), LOG_HELP, LOG_INFOF, and LOG_TRACE.

Referenced by GENERIC_COMMAND().

428 {
429  switch(request)
430  {
431  case CMD_REQUEST_COMMAND:
432  {
433  if(argc >= 3)
434  {
435  float f = cvar_settemp(argv(1), argv(2));
436  if(f == 1)
437  LOG_TRACE("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.");
438  else if(f == -1)
439  LOG_TRACE("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".");
440  // else cvar_settemp itself errors out
441 
442  return;
443  }
444  }
445 
446  default:
447  LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
448  case CMD_REQUEST_USAGE:
449  {
450  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " settemp <cvar> \"<arguments>\"");
451  LOG_HELP(" Where <cvar> is the cvar you want to temporarily set with <arguments>.");
452  LOG_HELP("See also: ^2settemp_restore^7");
453  return;
454  }
455  }
456 }
float cvar_settemp(string tmp_cvar, string tmp_value)
Definition: util.qc:696
const int CMD_REQUEST_USAGE
Definition: command.qh:4
#define LOG_HELP(...)
Definition: log.qh:95
#define LOG_INFOF(...)
Definition: log.qh:71
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
#define LOG_TRACE(...)
Definition: log.qh:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenericCommand_settemp_restore()

void GenericCommand_settemp_restore ( int  request)

Definition at line 458 of file generic.qc.

References CMD_REQUEST_COMMAND, CMD_REQUEST_USAGE, cvar_settemp_restore(), ftos(), LOG_HELP, and LOG_TRACE.

Referenced by GENERIC_COMMAND().

459 {
460  switch(request)
461  {
462  case CMD_REQUEST_COMMAND:
463  {
464  float i = cvar_settemp_restore();
465 
466  if(i)
467  LOG_TRACE("Restored ", ftos(i), " temporary cvar settings to their original values.");
468  else
469  LOG_TRACE("Nothing to restore.");
470 
471  return;
472  }
473 
474  default:
475  case CMD_REQUEST_USAGE:
476  {
477  LOG_HELP("Usage:^3 ", GetProgramCommandPrefix(), " settemp_restore");
478  LOG_HELP(" No arguments required.");
479  LOG_HELP("See also: ^2settemp^7");
480  return;
481  }
482  }
483 }
const int CMD_REQUEST_USAGE
Definition: command.qh:4
#define LOG_HELP(...)
Definition: log.qh:95
const int CMD_REQUEST_COMMAND
Definition: command.qh:3
#define LOG_TRACE(...)
Definition: log.qh:81
int cvar_settemp_restore()
Definition: util.qc:736
+ Here is the call graph for this function:
+ Here is the caller graph for this function: