]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_join_serverinfo.qc
Merge CLASS and EXTENDS, #define NEW(cname) (spawn##cname())
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_join_serverinfo.qc
1 #include "../../common/mapinfo.qh"
2
3 #ifdef INTERFACE
4 CLASS(XonoticServerInfoDialog, XonoticDialog)
5         METHOD(XonoticServerInfoDialog, fill, void(entity))
6         METHOD(XonoticServerInfoDialog, loadServerInfo, void(entity, float))
7         ATTRIB(XonoticServerInfoDialog, title, string, _("Server Information"))
8         ATTRIB(XonoticServerInfoDialog, color, vector, SKINCOLOR_DIALOG_SERVERINFO)
9         ATTRIB(XonoticServerInfoDialog, intendedWidth, float, 0.8)
10         ATTRIB(XonoticServerInfoDialog, rows, float, 18)
11         ATTRIB(XonoticServerInfoDialog, columns, float, 6.2)
12
13         ATTRIB(XonoticServerInfoDialog, currentServerName, string, string_null)
14         ATTRIB(XonoticServerInfoDialog, currentServerCName, string, string_null)
15         ATTRIB(XonoticServerInfoDialog, currentServerType, string, string_null)
16         ATTRIB(XonoticServerInfoDialog, currentServerMap, string, string_null)
17         ATTRIB(XonoticServerInfoDialog, currentServerPlayers, string, string_null)
18         ATTRIB(XonoticServerInfoDialog, currentServerNumPlayers, string, string_null)
19         ATTRIB(XonoticServerInfoDialog, currentServerNumBots, string, string_null)
20         ATTRIB(XonoticServerInfoDialog, currentServerNumFreeSlots, string, string_null)
21         ATTRIB(XonoticServerInfoDialog, currentServerMod, string, string_null)
22         ATTRIB(XonoticServerInfoDialog, currentServerVersion, string, string_null)
23         ATTRIB(XonoticServerInfoDialog, currentServerKey, string, string_null)
24         ATTRIB(XonoticServerInfoDialog, currentServerID, string, string_null)
25         ATTRIB(XonoticServerInfoDialog, currentServerEncrypt, string, string_null)
26         ATTRIB(XonoticServerInfoDialog, currentServerPure, string, string_null)
27
28         ATTRIB(XonoticServerInfoDialog, nameLabel, entity, NULL)
29         ATTRIB(XonoticServerInfoDialog, cnameLabel, entity, NULL)
30         ATTRIB(XonoticServerInfoDialog, typeLabel, entity, NULL)
31         ATTRIB(XonoticServerInfoDialog, mapLabel, entity, NULL)
32         ATTRIB(XonoticServerInfoDialog, rawPlayerList, entity, NULL)
33         ATTRIB(XonoticServerInfoDialog, numPlayersLabel, entity, NULL)
34         ATTRIB(XonoticServerInfoDialog, numBotsLabel, entity, NULL)
35         ATTRIB(XonoticServerInfoDialog, numFreeSlotsLabel, entity, NULL)
36         ATTRIB(XonoticServerInfoDialog, modLabel, entity, NULL)
37         ATTRIB(XonoticServerInfoDialog, versionLabel, entity, NULL)
38         ATTRIB(XonoticServerInfoDialog, keyLabel, entity, NULL)
39         ATTRIB(XonoticServerInfoDialog, idLabel, entity, NULL)
40         ATTRIB(XonoticServerInfoDialog, encryptLabel, entity, NULL)
41         ATTRIB(XonoticServerInfoDialog, canConnectLabel, entity, NULL)
42         ATTRIB(XonoticServerInfoDialog, pureLabel, entity, NULL)
43 ENDCLASS(XonoticServerInfoDialog)
44
45 void Join_Click(entity btn, entity me);
46 #endif
47
48 #ifdef IMPLEMENTATION
49 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
50 {
51         float m, pure, freeslots, j, numh, maxp, numb, sflags;
52         string s, typestr, versionstr, k, v, modname;
53
54         // ====================================
55         //  First clear and unzone the strings
56         // ====================================
57         if(me.currentServerName)
58                 strunzone(me.currentServerName);
59         me.currentServerName = string_null;
60
61         if(me.currentServerCName)
62                 strunzone(me.currentServerCName);
63         me.currentServerCName = string_null;
64
65         if(me.currentServerType)
66                 strunzone(me.currentServerType);
67         me.currentServerType = string_null;
68
69         if(me.currentServerMap)
70                 strunzone(me.currentServerMap);
71         me.currentServerMap = string_null;
72
73         if(me.currentServerPlayers)
74                 strunzone(me.currentServerPlayers);
75         me.currentServerPlayers = string_null;
76
77         if(me.currentServerNumPlayers)
78                 strunzone(me.currentServerNumPlayers);
79         me.currentServerNumPlayers = string_null;
80
81         if(me.currentServerNumBots)
82                 strunzone(me.currentServerNumBots);
83         me.currentServerNumBots = string_null;
84
85         if(me.currentServerNumFreeSlots)
86                 strunzone(me.currentServerNumFreeSlots);
87         me.currentServerNumFreeSlots = string_null;
88
89         if(me.currentServerMod)
90                 strunzone(me.currentServerMod);
91         me.currentServerMod = string_null;
92
93         if(me.currentServerVersion)
94                 strunzone(me.currentServerVersion);
95         me.currentServerVersion = string_null;
96
97         // not zoned!
98         //if(me.currentServerEncrypt)
99         //      strunzone(me.currentServerEncrypt);
100         //me.currentServerEncrypt = string_null;
101         if(me.currentServerPure)
102                 strunzone(me.currentServerPure);
103         me.currentServerPure = string_null;
104
105         if(me.currentServerKey)
106                 strunzone(me.currentServerKey);
107         me.currentServerKey = string_null;
108
109         if(me.currentServerID)
110                 strunzone(me.currentServerID);
111         me.currentServerID = string_null;
112
113         // ==========================
114         //  Now, fill in the strings
115         // ==========================
116         me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
117         me.nameLabel.setText(me.nameLabel, me.currentServerName);
118
119         me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
120         me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
121
122         pure = -1;
123         typestr = _("N/A");
124         versionstr = _("N/A");
125
126         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
127         m = tokenizebyseparator(s, ":");
128         if(m >= 2)
129         {
130                 typestr = argv(0);
131                 versionstr = argv(1);
132         }
133         freeslots = -1;
134         sflags = -1;
135         modname = "";
136         for(j = 2; j < m; ++j)
137         {
138                 if(argv(j) == "")
139                         break;
140                 k = substring(argv(j), 0, 1);
141                 v = substring(argv(j), 1, -1);
142                 if(k == "P")
143                         pure = stof(v);
144                 else if(k == "S")
145                         freeslots = stof(v);
146                 else if(k == "F")
147                         sflags = stof(v);
148                 else if(k == "M")
149                         modname = v;
150         }
151
152 #ifdef COMPAT_NO_MOD_IS_XONOTIC
153         if(modname == "")
154                 modname = "Xonotic";
155 #endif
156
157         s = gethostcachestring(SLIST_FIELD_MOD, i);
158         if(s != "data")
159                 modname = sprintf("%s (%s)", modname, s);
160
161         j = MapInfo_Type_FromString(typestr); // try and get the real name of the game type
162         if(j) { typestr = MapInfo_Type_ToText(j); } // only set it if we actually found it
163
164         me.currentServerType = strzone(typestr);
165         me.typeLabel.setText(me.typeLabel, me.currentServerType);
166
167         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
168         me.mapLabel.setText(me.mapLabel, me.currentServerMap);
169
170         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
171         me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
172
173         numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
174         maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
175         numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
176         me.currentServerNumPlayers = strzone(sprintf("%d/%d", numh, maxp));
177         me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
178
179         s = ftos(numb);
180         me.currentServerNumBots = strzone(s);
181         me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
182
183         if(freeslots < 0) { freeslots = maxp - numh - numb; }
184         s = ftos(freeslots);
185         me.currentServerNumFreeSlots = strzone(s);
186         me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
187
188         me.currentServerMod = ((modname == "Xonotic") ? _("Default") : modname);
189         me.currentServerMod = strzone(me.currentServerMod);
190         me.modLabel.setText(me.modLabel, me.currentServerMod);
191
192         me.currentServerVersion = strzone(versionstr);
193         me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
194
195         me.currentServerPure = ((pure < 0) ? _("N/A") : (pure == 0) ? _("Official") : sprintf(_("%d modified"), pure));
196         me.currentServerPure = strzone(me.currentServerPure);
197         me.pureLabel.setText(me.pureLabel, me.currentServerPure);
198
199         s = crypto_getencryptlevel(me.currentServerCName);
200         if(s == "")
201         {
202                 if(cvar("crypto_aeslevel") >= 3)
203                         me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
204                 else
205                         me.currentServerEncrypt = _("N/A (auth library missing)");
206         }
207         else switch(stof(substring(s, 0, 1)))
208         {
209                 case 0:
210                         if(cvar("crypto_aeslevel") >= 3)
211                                 me.currentServerEncrypt = _("Not supported (can't connect)");
212                         else
213                                 me.currentServerEncrypt = _("Not supported (won't encrypt)");
214                         break;
215                 case 1:
216                         if(cvar("crypto_aeslevel") >= 2)
217                                 me.currentServerEncrypt = _("Supported (will encrypt)");
218                         else
219                                 me.currentServerEncrypt = _("Supported (won't encrypt)");
220                         break;
221                 case 2:
222                         if(cvar("crypto_aeslevel") >= 1)
223                                 me.currentServerEncrypt = _("Requested (will encrypt)");
224                         else
225                                 me.currentServerEncrypt = _("Requested (won't encrypt)");
226                         break;
227                 case 3:
228                         if(cvar("crypto_aeslevel") <= 0)
229                                 me.currentServerEncrypt = _("Required (can't connect)");
230                         else
231                                 me.currentServerEncrypt = _("Required (will encrypt)");
232                         break;
233         }
234         me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
235
236         s = crypto_getidfp(me.currentServerCName);
237         if (!s) { s = _("N/A"); }
238         me.currentServerID = strzone(s);
239         me.idLabel.setText(me.idLabel, me.currentServerID);
240
241         s = crypto_getkeyfp(me.currentServerCName);
242         if (!s) { s = _("N/A"); }
243         me.currentServerKey = strzone(s);
244         me.keyLabel.setText(me.keyLabel, me.currentServerKey);
245 }
246
247 void XonoticServerInfoDialog_fill(entity me)
248 {
249         entity e;
250         me.TR(me);
251                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Hostname:")));
252                 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
253                 e.colorL = SKINCOLOR_SERVERINFO_NAME;
254                 e.allowCut = 1;
255                 me.nameLabel = e;
256         me.TR(me);
257                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Address:")));
258                 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
259                 e.colorL = SKINCOLOR_SERVERINFO_IP;
260                 e.allowCut = 1;
261                 me.cnameLabel = e;
262
263         me.TR(me);
264         me.TR(me);
265                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
266                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
267                 e.allowCut = 1;
268                 me.typeLabel = e;
269         me.TR(me);
270                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
271                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
272                 e.allowCut = 1;
273                 me.mapLabel = e;
274         me.TR(me);
275                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
276                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
277                 e.allowCut = 1;
278                 me.modLabel = e;
279         me.TR(me);
280                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
281                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
282                 e.allowCut = 1;
283                 me.versionLabel = e;
284         me.TR(me);
285                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
286                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
287                 e.allowCut = 1;
288                 me.pureLabel = e;
289
290         me.TR(me);
291         me.TR(me);
292                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
293                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
294                 e.allowCut = 1;
295                 me.numPlayersLabel = e;
296         me.TR(me);
297                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
298                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
299                 e.allowCut = 1;
300                 me.numBotsLabel = e;
301         me.TR(me);
302                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
303                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
304                 e.allowCut = 1;
305                 me.numFreeSlotsLabel = e;
306
307         me.gotoRC(me, me.rows - 5, 0);
308                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Encryption:")));
309                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
310                         e.allowCut = 1;
311                         me.encryptLabel = e;
312         me.TR(me);
313                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
314                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
315                         e.allowCut = 1;
316                         me.keyLabel = e;
317         me.TR(me);
318                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
319                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
320                         e.allowCut = 1;
321                         me.idLabel = e;
322
323         me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
324                 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
325         me.TR(me);
326                 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
327                         me.rawPlayerList = e;
328
329         me.gotoRC(me, me.rows - 1, 0);
330                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Close"), '0 0 0'));
331                         e.onClick = Dialog_Close;
332                         e.onClickEntity = me;
333                 //me.TD(me, 1, me.columns/3, e = makeXonoticButton("", '0 0 0')); // TODO: Add bookmark button here
334                 //      e.onClick = ServerList_Favorite_Click;
335                 //      e.onClickEntity = slist;
336                 //      slist.favoriteButton = e;
337                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Join!"), '0 0 0'));
338                         e.onClick = Join_Click;
339                         e.onClickEntity = me;
340 }
341
342 void Join_Click(entity btn, entity me)
343 {
344         localcmd("connect ", me.currentServerCName, "\n");
345 }
346
347 #endif