]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/command/menu_cmd.qc
Merge remote-tracking branch 'origin/terencehill/hud_skin_files_sync'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / command / menu_cmd.qc
1 string _dumptree_space;
2 void _dumptree_open(entity pass, entity me)
3 {
4         string s;
5         s = me.toString(me);
6         if(s == "")
7                 s = me.classname;
8         else
9                 s = strcat(me.classname, ": ", s);
10         print(_dumptree_space, etos(me), " (", s, ")");
11         if(me.firstChild)
12         {
13                 print(" {\n");
14                 _dumptree_space = strcat(_dumptree_space, "  ");
15         }
16         else
17                 print("\n");
18 }
19 void _dumptree_close(entity pass, entity me)
20 {
21         if(me.firstChild)
22         {
23                 _dumptree_space = substring(_dumptree_space, 0, strlen(_dumptree_space) - 2);
24                 print(_dumptree_space, "}\n");
25         }
26 }
27
28 float curl_uri_get_pos;
29 float curl_uri_get_exec[URI_GET_CURL_END - URI_GET_CURL + 1];
30 string curl_uri_get_cvar[URI_GET_CURL_END - URI_GET_CURL + 1];
31 void Curl_URI_Get_Callback(float id, float status, string data)
32 {
33         float i;
34         float do_exec;
35         string do_cvar;
36         i = id - URI_GET_CURL;
37         do_exec = curl_uri_get_exec[i];
38         do_cvar = curl_uri_get_cvar[i];
39         if(status != 0)
40         {
41                 print(sprintf(_("error: status is %d\n"), status));
42                 if(do_cvar)
43                         strunzone(do_cvar);
44                 return;
45         }
46         if(do_exec)
47                 localcmd(data);
48         if(do_cvar)
49         {
50                 cvar_set(do_cvar, data);
51                 strunzone(do_cvar);
52         }
53         if(!do_exec && !do_cvar)
54                 print(data);
55 }
56
57 void GameCommand(string theCommand)
58 {
59         float argc;
60         argc = tokenize_console(theCommand);
61
62         if(argv(0) == "help" || argc == 0)
63         {
64                 print(_("Usage: menu_cmd command..., where possible commands are:\n"));
65                 print(_("  sync - reloads all cvars on the current menu page\n"));
66                 print(_("  directmenu ITEM - select a menu item as main item\n"));
67                 GenericCommand("help");
68                 return;
69         }
70
71         if(GenericCommand(theCommand))
72                 return;
73
74         if(argv(0) == "sync")
75         {
76                 m_sync();
77                 return;
78         }
79
80         if(argv(0) == "directmenu") if(argc == 2)
81         {
82                 // switch to a menu item
83                 if(!isdemo()) // don't allow this command in demos
84                         m_goto(argv(1));
85                 return;
86         }
87
88         if(argv(0) == "directpanelhudmenu")
89         {
90                 // switch to a menu item
91                 m_goto(strcat("HUD", argv(1)));
92                 return;
93         }
94
95         if(argv(0) == "skinselect")
96         {
97                 m_goto_skin_selector();
98                 return;
99         }
100
101         if(argv(0) == "languageselect")
102         {
103                 m_goto_language_selector();
104                 return;
105         }
106
107         if(argv(0) == "videosettings")
108         {
109                 m_goto_video_settings();
110                 return;
111         }
112
113         if(argv(0) == "dumptree")
114         {
115                 _dumptree_space = "";
116                 depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
117                 return;
118         }
119
120         if(argv(0) == "curl")
121         {
122                 float do_exec;
123                 string do_cvar;
124                 float key;
125                 float i, j;
126                 string url;
127                 float buf;
128                 float r;
129
130                 do_exec = FALSE;
131                 do_cvar = string_null;
132                 key = -1;
133
134                 for(i = 1; i+1 < argc; ++i)
135                 {
136                         if(argv(i) == "--cvar" && i+2 < argc)
137                         {
138                                 ++i;
139                                 do_cvar = strzone(argv(i));
140                                 continue;
141                         }
142                         if(argv(i) == "--exec")
143                         {
144                                 do_exec = TRUE;
145                                 continue;
146                         }
147                         if(argv(i) == "--key" && i+2 < argc)
148                         {
149                                 ++i;
150                                 key = stof(argv(i));
151                                 continue;
152                         }
153                         break;
154                 }
155
156                 // now, argv(i) is the URL
157                 // following args may be POST parameters
158                 url = argv(i);
159                 ++i;
160                 buf = buf_create();
161                 j = 0;
162                 for(; i+1 < argc; i += 2)
163                         bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i+1))));
164                 if(i < argc)
165                         bufstr_set(buf, ++j, sprintf("submit=%s", uri_escape(argv(i))));
166
167                 if(j == 0) // no args: GET
168                         r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, string_null, string_null, -1, key);
169                 else // with args: POST
170                         r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, "application/x-www-form-urlencoded", "&", buf, key);
171
172                 if(r)
173                 {
174                         curl_uri_get_exec[curl_uri_get_pos] = do_exec;
175                         curl_uri_get_cvar[curl_uri_get_pos] = do_cvar;
176                         curl_uri_get_pos = mod(curl_uri_get_pos + 1, URI_GET_CURL_END - URI_GET_CURL + 1);
177                 }
178                 else
179                         print(_("error creating curl handle\n"));
180
181                 buf_del(buf);
182
183                 return;
184         }
185
186         print(_("Invalid command. For a list of supported commands, try menu_cmd help.\n"));
187 }