Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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)
#define CMD_Write_Alias(execute, command, description)
#define GetProgramCommandPrefix()

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)
string maplist_shuffle (string input)

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)
Value:
fputs(fh, s)
void fputs(float fhandle, string s)

Definition at line 33 of file generic.qh.

Referenced by GENERIC_COMMAND().

◆ CMD_Write_Alias

#define CMD_Write_Alias ( execute,
command,
description )
Value:
CMD_Write(sprintf("alias %-20s \"%-13s %-20s ${* ?}\" // %s\n", command, execute, command, description))
#define CMD_Write(s)
Definition generic.qh:33

Definition at line 34 of file generic.qh.

Referenced by ClientCommand_macro_write_aliases(), CommonCommand_macro_write_aliases(), GameCommand_macro_write_aliases(), GenericCommand_macro_write_aliases(), and LocalCommand_macro_write_aliases().

◆ GetProgramCommandPrefix

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.

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}
string curl_uri_get_cvar[URI_GET_CURL_END - URI_GET_CURL+1]
Definition generic.qh:40
float curl_uri_get_exec[URI_GET_CURL_END - URI_GET_CURL+1]
Definition generic.qh:39
#define LOG_TRACEF(...)
Definition log.qh:77
#define LOG_INFO(...)
Definition log.qh:65
void localcmd(string command,...)
void cvar_set(string name, string value)
void strunzone(string s)
const int URI_GET_CURL
Definition urllib.qh:7

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(), and URI_Get_Callback().

◆ GenericCommand()

float GenericCommand ( string command)

Definition at line 603 of file generic.qc.

604{
605 int argc = tokenize_console(command);
606 float n, j, f, i;
607 string s, s2, c;
608 vector rgb;
609
610 // Guide for working with argc arguments by example:
611 // argc: 1 - 2 - 3 - 4
612 // argv: 0 - 1 - 2 - 3
613 // cmd vote - master - login - password
614
615 if(GenericCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
616 {
617 return true; // handled by one of the above GenericCommand_* functions
618 }
619 else if(argc >= 3 && argv(0) == "red")
620 {
623 return true;
624 }
625 else if(argc >= 3 && crc16(0, argv(0)) == 38566 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 59830)
626 {
627 // other test case
628 s = strconv(2, 0, 0, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
629
630 n = floor(random() * 6 + 2);
631
632 s2 = "";
633 for(i = 0; i < n; ++i)
634 {
635 s2 = strcat(s2, "AH");
636 }
637
638 if(random() < 0.1)
639 s2 = strcat(substring(s2, 1, strlen(s2) - 1), "A");
640
641 if(s == "")
642 s = s2;
643 else
644 if(random() < 0.8)
645 s = strcat(s, " ", s2);
646 else
647 s = strcat(s2, " ", s);
648
649 s2 = substring(s, strlen(s) - 2, 2);
650 if(s2 == "AH" || s2 == "AY")
651 s = strcat(s, "))");
652 else
653 s = strcat(s, " ))");
654
655 if(random() < 0.1)
656 s = substring(s, 0, strlen(s) - 1);
657
658 if(random() < 0.1)
659 s = strconv(1, 0, 0, s);
660
661 localcmd(strcat(argv(1), " ", s));
662
663 return true;
664 }
665 else if(argc >= 3 && crc16(0, argv(0)) == 3826 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 55790)
666 {
667 // test case for terencehill's color codes
668 s = strdecolorize(substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
669 s2 = "";
670
671 n = strlen(s);
672 j = ((6 * max(1, floor(strlen(s)/32 + random() * 2 - 1))) / n) * (1 - 2 * (random() > 0.5));
673 f = random() * 6;
674
675 for(i = 0; i < n; ++i)
676 {
677 c = substring(s, i, 1);
678
679 if(c == ";")
680 c = ":";
681 else if(c == "^")
682 {
683 c = "^^";
684 if(substring(s, i+1, 1) == "^")
685 ++i;
686 }
687
688 if(c != " ")
689 {
690 rgb = hsl_to_rgb('1 0 0' * (j * i + f) + '0 1 .5');
691 c = strcat(rgb_to_hexcolor(rgb), c);
692 }
693 s2 = strcat(s2, c);
694 }
695
696 localcmd(strcat(argv(1), " ", s2));
697
698 return true;
699 }
700
701 return false;
702}
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition color.qh:183
ERASEABLE vector hsl_to_rgb(vector hsl)
Definition color.qh:167
#define argv_end_index
#define strlen
#define tokenize_console
#define argv_start_index
float GenericCommand_macro_command(int argc, string command)
Definition generic.qc:572
string GenericCommand_markup(string s2)
Definition markup.qc:61
string substring(string s, float start, float length)
float random(void)
float floor(float f)
string argv(float n)
float max(float f,...)
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 s2 f1points s1 s2
Definition all.inc:469
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
vector
Definition self.qh:92

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(), and GameCommand().

◆ GenericCommand_macro_command()

float GenericCommand_macro_command ( int argc,
string command )

Definition at line 572 of file generic.qc.

573{
574 string c = strtolower(argv(0));
575 FOREACH(GENERIC_COMMANDS, it.m_name == c, {
576 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
577 return true;
578 });
579 return false;
580}
string strtolower(string s)
#define FOREACH(list, cond, body)
Definition iter.qh:19

References argv(), FOREACH, and strtolower().

Referenced by GenericCommand().

◆ GenericCommand_macro_help()

void GenericCommand_macro_help ( )

Definition at line 567 of file generic.qc.

568{
569 FOREACH(GENERIC_COMMANDS, true, LOG_HELPF(" ^2%s^7: %s", it.m_name, it.m_description));
570}
#define LOG_HELPF(...)
Definition log.qh:86

References FOREACH, and LOG_HELPF.

Referenced by GameCommand(), and GameCommand().

◆ GenericCommand_macro_usage()

float GenericCommand_macro_usage ( int argc)

Definition at line 582 of file generic.qc.

583{
584 string c = strtolower(argv(1));
585 FOREACH(GENERIC_COMMANDS, it.m_name == c, {
586 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
587 return true;
588 });
589 return false;
590}

References argv(), FOREACH, and strtolower().

Referenced by GameCommand().

◆ GenericCommand_macro_write_aliases()

void GenericCommand_macro_write_aliases ( float fh)

Definition at line 592 of file generic.qc.

593{
594 FOREACH(GENERIC_COMMANDS, true, CMD_Write_Alias("qc_cmd_svmenu", it.m_name, it.m_description));
595}
#define CMD_Write_Alias(execute, command, description)
Definition generic.qh:34

References CMD_Write_Alias, and FOREACH.

Referenced by GENERIC_COMMAND().

◆ maplist_shuffle()

string maplist_shuffle ( string input)

Definition at line 232 of file generic.qc.

233{
234 int buf = buf_create();
235
236 int _cnt = 0;
237 FOREACH_WORD(input, true,
238 {
239 int _j = floor(random() * (_cnt + 1));
240 if(_j != _cnt)
241 bufstr_set(buf, _cnt, bufstr_get(buf, _j));
242 bufstr_set(buf, _j, it);
243 ++_cnt;
244 });
245
246 string output = buf_implode(buf, " ");
247 buf_del(buf);
248 return substring(output, 1, -1);
249}
#define buf_create
#define FOREACH_WORD(words, cond, body)
Definition iter.qh:33

References buf_create, floor(), FOREACH_WORD, random(), and substring().

Referenced by GenericCommand_maplist().

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().