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

Go to the source code of this file.

Macros

#define CMD_Write(s)   fputs(fh, s)
 
#define CMD_Write_Alias(execute, command, description)   CMD_Write(sprintf("alias %-20s \"%-13s %-20s ${* ?}\" // %s\n", command, execute, command, description))
 

Functions

void Curl_URI_Get_Callback (int id, float status, string data)
 
float GenericCommand (string command)
 
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)
 

Variables

string curl_uri_get_cvar [URI_GET_CURL_END - URI_GET_CURL+1]
 
float curl_uri_get_exec [URI_GET_CURL_END - URI_GET_CURL+1]
 
int curl_uri_get_pos
 

Macro Definition Documentation

◆ CMD_Write

#define CMD_Write (   s)    fputs(fh, s)

Definition at line 33 of file generic.qh.

Referenced by GENERIC_COMMAND().

◆ CMD_Write_Alias

#define CMD_Write_Alias (   execute,
  command,
  description 
)    CMD_Write(sprintf("alias %-20s \"%-13s %-20s ${* ?}\" // %s\n", command, execute, command, description))

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:

◆ 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_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:

Variable Documentation

◆ curl_uri_get_cvar

string curl_uri_get_cvar[URI_GET_CURL_END - URI_GET_CURL+1]

Definition at line 40 of file generic.qh.

Referenced by Curl_URI_Get_Callback(), and GenericCommand_qc_curl().

◆ curl_uri_get_exec

float curl_uri_get_exec[URI_GET_CURL_END - URI_GET_CURL+1]

Definition at line 39 of file generic.qh.

Referenced by Curl_URI_Get_Callback(), and GenericCommand_qc_curl().

◆ curl_uri_get_pos

int curl_uri_get_pos

Definition at line 38 of file generic.qh.

Referenced by GenericCommand_qc_curl().