1 void GameCommand_Init()
3 // make gg call menu QC theCommands
4 localcmd("alias qc_cmd \"menu_cmd $*\"\n");
7 string _dumptree_space;
8 void _dumptree_open(entity pass, entity me)
15 s = strcat(me.classname, ": ", s);
16 print(_dumptree_space, etos(me), " (", s, ")");
20 _dumptree_space = strcat(_dumptree_space, " ");
25 void _dumptree_close(entity pass, entity me)
29 _dumptree_space = substring(_dumptree_space, 0, strlen(_dumptree_space) - 2);
30 print(_dumptree_space, "}\n");
34 float curl_uri_get_pos;
35 float curl_uri_get_exec[URI_GET_CURL_END - URI_GET_CURL + 1];
36 string curl_uri_get_cvar[URI_GET_CURL_END - URI_GET_CURL + 1];
37 void Curl_URI_Get_Callback(float id, float status, string data)
42 i = id - URI_GET_CURL;
43 do_exec = curl_uri_get_exec[i];
44 do_cvar = curl_uri_get_cvar[i];
47 print(sprintf(_("error: status is %d\n"), status));
53 cvar_set(do_cvar, data);
54 if(!do_exec && !do_cvar)
58 void GameCommand(string theCommand)
61 argc = tokenize_console(theCommand);
63 if(argv(0) == "help" || argc == 0)
65 print(_("Usage: menu_cmd command..., where possible commands are:\n"));
66 print(_(" sync - reloads all cvars on the current menu page\n"));
67 print(_(" directmenu ITEM - select a menu item as main item\n"));
68 GameCommand_Generic("help");
72 if(GameCommand_Generic(theCommand))
81 if(argv(0) == "directmenu") if(argc == 2)
83 // switch to a menu item
84 if(!isdemo()) // don't allow this command in demos
89 if(argv(0) == "directpanelhudmenu")
91 // switch to a menu item
92 m_goto(strcat("HUD", argv(1)));
96 if(argv(0) == "skinselect")
98 m_goto_skin_selector();
102 if(argv(0) == "languageselect")
104 m_goto_language_selector();
108 if(argv(0) == "videosettings")
110 m_goto_video_settings();
114 if(argv(0) == "dumptree")
116 _dumptree_space = "";
117 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
121 if(argv(0) == "curl")
132 do_cvar = string_null;
135 for(i = 1; i+1 < argc; ++i)
137 if(argv(i) == "--cvar" && i+2 < argc)
143 if(argv(i) == "--exec")
148 if(argv(i) == "--key" && i+2 < argc)
157 // now, argv(i) is the URL
158 // following args may be POST parameters
163 for(; i+1 < argc; i += 2)
164 bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i+1))));
166 bufstr_set(buf, ++j, sprintf("submit=%s", uri_escape(argv(i))));
168 if(j == 0) // no args: GET
169 r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, string_null, string_null, -1, key);
170 else // with args: POST
171 r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, "application/x-www-form-urlencoded", "&", buf, key);
175 curl_uri_get_exec[curl_uri_get_pos] = do_exec;
176 curl_uri_get_cvar[curl_uri_get_pos] = do_cvar;
177 curl_uri_get_pos = mod(curl_uri_get_pos + 1, URI_GET_CURL_END - URI_GET_CURL + 1);
180 print(_("error creating curl handle\n"));
187 print(_("Invalid command. For a list of supported commands, try menu_cmd help.\n"));