1 #include "../../common/mapinfo.qh"
3 #ifndef DIALOG_MULTIPLAYER_JOIN_SERVERINFO_H
4 #define DIALOG_MULTIPLAYER_JOIN_SERVERINFO_H
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)
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)
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)
47 void Join_Click(entity btn, entity me);
51 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
54 float m, pure_violations, freeslots, j, numh, maxp, numb, sflags;
55 string s, typestr, versionstr, k, v, modname;
57 // ====================================
58 // First clear and unzone the strings
59 // ====================================
60 if(me.currentServerName)
61 strunzone(me.currentServerName);
62 me.currentServerName = string_null;
64 if(me.currentServerCName)
65 strunzone(me.currentServerCName);
66 me.currentServerCName = string_null;
68 if(me.currentServerType)
69 strunzone(me.currentServerType);
70 me.currentServerType = string_null;
72 if(me.currentServerMap)
73 strunzone(me.currentServerMap);
74 me.currentServerMap = string_null;
76 if(me.currentServerPlayers)
77 strunzone(me.currentServerPlayers);
78 me.currentServerPlayers = string_null;
80 if(me.currentServerNumPlayers)
81 strunzone(me.currentServerNumPlayers);
82 me.currentServerNumPlayers = string_null;
84 if(me.currentServerNumBots)
85 strunzone(me.currentServerNumBots);
86 me.currentServerNumBots = string_null;
88 if(me.currentServerNumFreeSlots)
89 strunzone(me.currentServerNumFreeSlots);
90 me.currentServerNumFreeSlots = string_null;
92 if(me.currentServerMod)
93 strunzone(me.currentServerMod);
94 me.currentServerMod = string_null;
96 if(me.currentServerVersion)
97 strunzone(me.currentServerVersion);
98 me.currentServerVersion = string_null;
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;
108 if(me.currentServerKey)
109 strunzone(me.currentServerKey);
110 me.currentServerKey = string_null;
112 if(me.currentServerID)
113 strunzone(me.currentServerID);
114 me.currentServerID = string_null;
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);
122 me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
123 me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
125 pure_available = false;
126 pure_violations = -1;
128 versionstr = _("N/A");
130 s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
131 m = tokenizebyseparator(s, ":");
135 versionstr = argv(1);
140 for(j = 2; j < m; ++j)
144 k = substring(argv(j), 0, 1);
145 v = substring(argv(j), 1, -1);
148 pure_available = true;
149 pure_violations = stof(v);
159 #ifdef COMPAT_NO_MOD_IS_XONOTIC
164 s = gethostcachestring(SLIST_FIELD_MOD, i);
166 modname = sprintf("%s (%s)", modname, s);
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
171 me.currentServerType = strzone(typestr);
172 me.typeLabel.setText(me.typeLabel, me.currentServerType);
174 me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
175 me.mapLabel.setText(me.mapLabel, me.currentServerMap);
177 me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
178 me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
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);
187 me.currentServerNumBots = strzone(s);
188 me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
190 if(freeslots < 0) { freeslots = maxp - numh - numb; }
192 me.currentServerNumFreeSlots = strzone(s);
193 me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
195 me.currentServerMod = ((modname == "Xonotic") ? ZCTX(_("MOD^Default")) : modname);
196 me.currentServerMod = strzone(me.currentServerMod);
197 me.modLabel.setText(me.modLabel, me.currentServerMod);
199 me.currentServerVersion = strzone(versionstr);
200 me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
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);
206 s = crypto_getencryptlevel(me.currentServerCName);
209 if(cvar("crypto_aeslevel") >= 3)
210 me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
212 me.currentServerEncrypt = _("N/A (auth library missing)");
214 else switch(stof(substring(s, 0, 1)))
217 if(cvar("crypto_aeslevel") >= 3)
218 me.currentServerEncrypt = _("Not supported (can't connect)");
220 me.currentServerEncrypt = _("Not supported (won't encrypt)");
223 if(cvar("crypto_aeslevel") >= 2)
224 me.currentServerEncrypt = _("Supported (will encrypt)");
226 me.currentServerEncrypt = _("Supported (won't encrypt)");
229 if(cvar("crypto_aeslevel") >= 1)
230 me.currentServerEncrypt = _("Requested (will encrypt)");
232 me.currentServerEncrypt = _("Requested (won't encrypt)");
235 if(cvar("crypto_aeslevel") <= 0)
236 me.currentServerEncrypt = _("Required (can't connect)");
238 me.currentServerEncrypt = _("Required (will encrypt)");
241 me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
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);
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);
254 void XonoticServerInfoDialog_fill(entity 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;
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;
272 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
273 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
277 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
278 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
282 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
283 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
287 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
288 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
292 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
293 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
299 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
300 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
302 me.numPlayersLabel = e;
304 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
305 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
309 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
310 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
312 me.numFreeSlotsLabel = e;
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, ""));
320 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
321 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
325 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
326 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
330 me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
331 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
333 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
334 me.rawPlayerList = e;
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;
349 void Join_Click(entity btn, entity me)
351 localcmd("connect ", me.currentServerCName, "\n");