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