// generic commands (across all programs)
alias addtolist "qc_cmd_svmenu addtolist ${* ?}" // Add a string to a cvar
+alias qc_curl "qc_cmd_svmenu curl ${* ?}" // curl requests
alias dumpcommands "qc_cmd_svmenu dumpcommands ${* ?}" // Dump all commands on the program to *_cmd_dump.txt
alias maplist "qc_cmd_svmenu maplist ${* ?}" // Automatic control of maplist
alias nextframe "qc_cmd_svmenu nextframe ${* ?}" // do something next frame
return FALSE;
}
+
+void URI_Get_Callback(float id, float status, string data)
+{
+ if(url_URI_Get_Callback(id, status, data))
+ {
+ // handled
+ }
+ else if (id == URI_GET_DISCARD)
+ {
+ // discard
+ }
+ else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
+ {
+ // sv_cmd curl
+ Curl_URI_Get_Callback(id, status, data);
+ }
+ else
+ {
+ print(sprintf(_("Received HTTP request data for an invalid id %d.\n"), id));
+ }
+}
../common/command/rpn.qh
../common/command/generic.qh
../common/command/shared_defs.qh
+../common/urllib.qh
command/cl_cmd.qh
../common/items.qc
../server/w_all.qc
../common/explosion_equation.qc
+../common/urllib.qc
command/cl_cmd.qc
}
}
+float curl_uri_get_pos;
+float curl_uri_get_exec[URI_GET_CURL_END - URI_GET_CURL + 1];
+string curl_uri_get_cvar[URI_GET_CURL_END - URI_GET_CURL + 1];
+void Curl_URI_Get_Callback(float id, float status, string data)
+{
+ float i;
+ float do_exec;
+ string do_cvar;
+ i = id - URI_GET_CURL;
+ do_exec = curl_uri_get_exec[i];
+ do_cvar = curl_uri_get_cvar[i];
+ if(status != 0)
+ {
+ print(sprintf(_("error: status is %d\n"), status));
+ if(do_cvar)
+ strunzone(do_cvar);
+ return;
+ }
+ if(do_exec)
+ localcmd(data);
+ if(do_cvar)
+ {
+ cvar_set(do_cvar, data);
+ strunzone(do_cvar);
+ }
+ if(!do_exec && !do_cvar)
+ print(data);
+}
+
+void GenericCommand_curl(float request, float argc)
+{
+ switch(request)
+ {
+ case CMD_REQUEST_COMMAND:
+ {
+ float do_exec;
+ string do_cvar;
+ float key;
+ float i, j;
+ string url;
+ float buf;
+ float r;
+
+ do_exec = FALSE;
+ do_cvar = string_null;
+ key = -1;
+
+ for(i = 1; i+1 < argc; ++i)
+ {
+ if(argv(i) == "--cvar" && i+2 < argc)
+ {
+ ++i;
+ do_cvar = strzone(argv(i));
+ continue;
+ }
+ if(argv(i) == "--exec")
+ {
+ do_exec = TRUE;
+ continue;
+ }
+ if(argv(i) == "--key" && i+2 < argc)
+ {
+ ++i;
+ key = stof(argv(i));
+ continue;
+ }
+ break;
+ }
+
+ // now, argv(i) is the URL
+ // following args may be POST parameters
+ url = argv(i);
+ ++i;
+ buf = buf_create();
+ j = 0;
+ for(; i+1 < argc; i += 2)
+ bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i+1))));
+ if(i < argc)
+ bufstr_set(buf, ++j, sprintf("submit=%s", uri_escape(argv(i))));
+
+ if(j == 0) // no args: GET
+ r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, string_null, string_null, -1, key);
+ else // with args: POST
+ r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, "application/x-www-form-urlencoded", "&", buf, key);
+
+ if(r)
+ {
+ curl_uri_get_exec[curl_uri_get_pos] = do_exec;
+ curl_uri_get_cvar[curl_uri_get_pos] = do_cvar;
+ curl_uri_get_pos = mod(curl_uri_get_pos + 1, URI_GET_CURL_END - URI_GET_CURL + 1);
+ }
+ else
+ print(_("error creating curl handle\n"));
+
+ buf_del(buf);
+
+ return;
+ }
+
+ default:
+ case CMD_REQUEST_USAGE:
+ {
+ print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " curl [--key N] [--cvar] [--exec] URL [postargs...]"));
+ return;
+ }
+ }
+}
+
void GenericCommand_dumpcommands(float request)
{
switch(request)
// Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
#define GENERIC_COMMANDS(request,arguments,command) \
GENERIC_COMMAND("addtolist", GenericCommand_addtolist(request, arguments), "Add a string to a cvar") \
+ GENERIC_COMMAND("curl", GenericCommand_curl(request, arguments), "Queries an URL") \
GENERIC_COMMAND("dumpcommands", GenericCommand_dumpcommands(request), "Dump all commands on the program to *_cmd_dump.txt") \
GENERIC_COMMAND("maplist", GenericCommand_maplist(request, arguments), "Automatic control of maplist") \
GENERIC_COMMAND("nextframe", GenericCommand_nextframe(request, arguments, command), "Execute the given command next frame of this VM") \
#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))
void GenericCommand_macro_write_aliases(float fh);
+
+void Curl_URI_Get_Callback(float id, float status, string data);
#define SPAWN_PRIO_NEAR_TEAMMATE_SAMETEAM 100
#define SPAWN_PRIO_RACE_PREVIOUS_SPAWN 50
#define SPAWN_PRIO_GOOD_DISTANCE 10
+
+// URI handles
+#define URI_GET_DISCARD 0
+#define URI_GET_IPBAN 1
+#define URI_GET_IPBAN_END 16
+#define URI_GET_CURL 17
+#define URI_GET_CURL_END 32
+#define URI_GET_UPDATENOTIFICATION 33
+#define URI_GET_URLLIB 128
+#define URI_GET_URLLIB_END 191
.url_ready_func url_ready;
.entity url_ready_pass;
+// for multi handles
+.float url_attempt;
+.float url_mode;
+
entity url_fromid[NUM_URL_ID];
float autocvar__urllib_nextslot;
remove(me);
return;
}
- me.cnt += 1;
+ me.url_attempt += 1;
n = tokenize_console(me.url_url);
- if(n <= me.cnt)
+ if(n <= me.url_attempt)
{
me.url_ready(fh, me.url_ready_pass, status);
strunzone(me.url_url);
remove(me);
return;
}
- url_single_fopen(argv(me.cnt), me.lip, url_multi_ready, me);
+ url_single_fopen(argv(me.url_attempt), me.url_mode, url_multi_ready, me);
return;
}
me.url_ready(fh, me.url_ready_pass, status);
me = spawn();
me.classname = "url_multi";
me.url_url = strzone(url);
- me.cnt = 0;
- me.lip = mode;
+ me.url_attempt = 0;
+ me.url_mode = mode;
me.url_ready = rdy;
me.url_ready_pass = pass;
url_single_fopen(argv(0), mode, url_multi_ready, me);
// returns true if handled
float url_URI_Get_Callback(float id, float status, string data);
-#define MIN_URL_ID 128
-#define NUM_URL_ID 64
+#define MIN_URL_ID URI_GET_URLLIB
+#define NUM_URL_ID (URI_GET_URLLIB_END - URI_GET_URLLIB + 1)
void url_multi_fopen(string url, float mode, url_ready_func rdy, entity pass);
}
}
-float curl_uri_get_pos;
-float curl_uri_get_exec[URI_GET_CURL_END - URI_GET_CURL + 1];
-string curl_uri_get_cvar[URI_GET_CURL_END - URI_GET_CURL + 1];
-void Curl_URI_Get_Callback(float id, float status, string data)
-{
- float i;
- float do_exec;
- string do_cvar;
- i = id - URI_GET_CURL;
- do_exec = curl_uri_get_exec[i];
- do_cvar = curl_uri_get_cvar[i];
- if(status != 0)
- {
- print(sprintf(_("error: status is %d\n"), status));
- if(do_cvar)
- strunzone(do_cvar);
- return;
- }
- if(do_exec)
- localcmd(data);
- if(do_cvar)
- {
- cvar_set(do_cvar, data);
- strunzone(do_cvar);
- }
- if(!do_exec && !do_cvar)
- print(data);
-}
-
void GameCommand(string theCommand)
{
float argc;
if(argv(0) == "curl")
{
- float do_exec;
- string do_cvar;
- float key;
- float i, j;
- string url;
- float buf;
- float r;
-
- do_exec = FALSE;
- do_cvar = string_null;
- key = -1;
-
- for(i = 1; i+1 < argc; ++i)
- {
- if(argv(i) == "--cvar" && i+2 < argc)
- {
- ++i;
- do_cvar = strzone(argv(i));
- continue;
- }
- if(argv(i) == "--exec")
- {
- do_exec = TRUE;
- continue;
- }
- if(argv(i) == "--key" && i+2 < argc)
- {
- ++i;
- key = stof(argv(i));
- continue;
- }
- break;
- }
-
- // now, argv(i) is the URL
- // following args may be POST parameters
- url = argv(i);
- ++i;
- buf = buf_create();
- j = 0;
- for(; i+1 < argc; i += 2)
- bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i+1))));
- if(i < argc)
- bufstr_set(buf, ++j, sprintf("submit=%s", uri_escape(argv(i))));
-
- if(j == 0) // no args: GET
- r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, string_null, string_null, -1, key);
- else // with args: POST
- r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, "application/x-www-form-urlencoded", "&", buf, key);
-
- if(r)
- {
- curl_uri_get_exec[curl_uri_get_pos] = do_exec;
- curl_uri_get_cvar[curl_uri_get_pos] = do_cvar;
- curl_uri_get_pos = mod(curl_uri_get_pos + 1, URI_GET_CURL_END - URI_GET_CURL + 1);
- }
- else
- print(_("error creating curl handle\n"));
-
- buf_del(buf);
-
- return;
}
print(_("Invalid command. For a list of supported commands, try menu_cmd help.\n"));
../common/command/rpn.qh
../common/command/generic.qh
../common/command/shared_defs.qh
+../common/urllib.qh
command/menu_cmd.qh
menu.qh
../common/campaign_setup.qc
../common/mapinfo.qc
../common/items.qc
+../common/urllib.qc
../warpzonelib/mathlib.qc
void URI_Get_Callback(float id, float status, string data)
{
- if (id == URI_GET_DISCARD)
+ if(url_URI_Get_Callback(id, status, data))
{
- // discard
+ // handled
}
- else if(id == URI_GET_UPDATENOTIFICATION)
+ else if (id == URI_GET_DISCARD)
{
- UpdateNotification_URI_Get_Callback(id, status, data);
+ // discard
}
- else if(id >= URI_GET_CURL && id <= URI_GET_CURL_END)
+ else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
{
+ // sv_cmd curl
Curl_URI_Get_Callback(id, status, data);
}
+ else if (id == URI_GET_UPDATENOTIFICATION)
+ {
+ UpdateNotification_URI_Get_Callback(id, status, data);
+ }
else
{
print(sprintf(_("Received HTTP request data for an invalid id %d.\n"), id));
string resolvemod(string m);
-float URI_GET_DISCARD = 0;
-
-float URI_GET_UPDATENOTIFICATION = 1;
void UpdateNotification_URI_Get_Callback(float id, float status, string data);
-float URI_GET_CURL = 2;
-float URI_GET_CURL_END = 9;
-void Curl_URI_Get_Callback(float id, float status, string data);
-
void URI_Get_Callback(float id, float status, string data);
// game type list box stuff (does not NEED to contain all game types, other
* server IP that registered the ban
*/
+#define MAX_IPBAN_URIS (URI_GET_IPBAN_END - URI_GET_IPBAN + 1)
+
float Ban_Insert(string ip, float bantime, string reason, float dosync);
void OnlineBanList_SendBan(string ip, float bantime, string reason)
}
#define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
-float MAX_IPBAN_URIS = 16;
-
-float URI_GET_DISCARD = 0;
-float URI_GET_IPBAN = 1;
-float URI_GET_IPBAN_END = 16;
-
void URI_Get_Callback(float id, float status, string data)
{
- dprint("Received HTTP request data for id ", ftos(id), "; status is ", ftos(status), "\nData is:\n");
- dprint(data);
- dprint("\nEnd of data.\n");
-
- if(url_URI_Get_Callback(id, status, data))
- {
- // handled
- }
- else if (id == URI_GET_DISCARD)
- {
- // discard
- }
- else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
- {
- // online ban list
- OnlineBanList_URI_Get_Callback(id, status, data);
- }
- else
- {
- print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
- }
+ if(url_URI_Get_Callback(id, status, data))
+ {
+ // handled
+ }
+ else if (id == URI_GET_DISCARD)
+ {
+ // discard
+ }
+ else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
+ {
+ // sv_cmd curl
+ Curl_URI_Get_Callback(id, status, data);
+ }
+ else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
+ {
+ // online ban list
+ OnlineBanList_URI_Get_Callback(id, status, data);
+ }
+ else
+ {
+ print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
+ }
}
string uid2name(string myuid) {