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