1 #include "dialog_multiplayer_join_serverinfo.qh"
2 #include <common/mapinfo.qh>
4 #ifndef DIALOG_MULTIPLAYER_JOIN_SERVERINFO_H
5 #define DIALOG_MULTIPLAYER_JOIN_SERVERINFO_H
7 CLASS(XonoticServerInfoDialog, XonoticDialog)
8 METHOD(XonoticServerInfoDialog, fill, void(entity));
9 METHOD(XonoticServerInfoDialog, loadServerInfo, void(entity, float));
10 ATTRIB(XonoticServerInfoDialog, title, string, _("Server Information"))
11 ATTRIB(XonoticServerInfoDialog, color, vector, SKINCOLOR_DIALOG_SERVERINFO)
12 ATTRIB(XonoticServerInfoDialog, intendedWidth, float, 0.8)
13 ATTRIB(XonoticServerInfoDialog, rows, float, 18)
14 ATTRIB(XonoticServerInfoDialog, columns, float, 6.2)
16 ATTRIB(XonoticServerInfoDialog, currentServerName, string, string_null)
17 ATTRIB(XonoticServerInfoDialog, currentServerCName, string, string_null)
18 ATTRIB(XonoticServerInfoDialog, currentServerType, string, string_null)
19 ATTRIB(XonoticServerInfoDialog, currentServerMap, string, string_null)
20 ATTRIB(XonoticServerInfoDialog, currentServerPlayers, string, string_null)
21 ATTRIB(XonoticServerInfoDialog, currentServerNumPlayers, string, string_null)
22 ATTRIB(XonoticServerInfoDialog, currentServerNumBots, string, string_null)
23 ATTRIB(XonoticServerInfoDialog, currentServerNumFreeSlots, string, string_null)
24 ATTRIB(XonoticServerInfoDialog, currentServerMod, string, string_null)
25 ATTRIB(XonoticServerInfoDialog, currentServerVersion, string, string_null)
26 ATTRIB(XonoticServerInfoDialog, currentServerKey, string, string_null)
27 ATTRIB(XonoticServerInfoDialog, currentServerID, string, string_null)
28 ATTRIB(XonoticServerInfoDialog, currentServerEncrypt, string, string_null)
29 ATTRIB(XonoticServerInfoDialog, currentServerPure, string, string_null)
31 ATTRIB(XonoticServerInfoDialog, nameLabel, entity, NULL)
32 ATTRIB(XonoticServerInfoDialog, cnameLabel, entity, NULL)
33 ATTRIB(XonoticServerInfoDialog, typeLabel, entity, NULL)
34 ATTRIB(XonoticServerInfoDialog, mapLabel, entity, NULL)
35 ATTRIB(XonoticServerInfoDialog, rawPlayerList, entity, NULL)
36 ATTRIB(XonoticServerInfoDialog, numPlayersLabel, entity, NULL)
37 ATTRIB(XonoticServerInfoDialog, numBotsLabel, entity, NULL)
38 ATTRIB(XonoticServerInfoDialog, numFreeSlotsLabel, entity, NULL)
39 ATTRIB(XonoticServerInfoDialog, modLabel, entity, NULL)
40 ATTRIB(XonoticServerInfoDialog, versionLabel, entity, NULL)
41 ATTRIB(XonoticServerInfoDialog, keyLabel, entity, NULL)
42 ATTRIB(XonoticServerInfoDialog, idLabel, entity, NULL)
43 ATTRIB(XonoticServerInfoDialog, encryptLabel, entity, NULL)
44 ATTRIB(XonoticServerInfoDialog, canConnectLabel, entity, NULL)
45 ATTRIB(XonoticServerInfoDialog, pureLabel, entity, NULL)
46 ENDCLASS(XonoticServerInfoDialog)
48 void Join_Click(entity btn, entity me);
52 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
55 float m, pure_violations, freeslots, j, numh, maxp, numb, sflags;
56 string s, typestr, versionstr, k, v, modname;
58 // ====================================
59 // First clear and unzone the strings
60 // ====================================
61 if(me.currentServerName)
62 strunzone(me.currentServerName);
63 me.currentServerName = string_null;
65 if(me.currentServerCName)
66 strunzone(me.currentServerCName);
67 me.currentServerCName = string_null;
69 if(me.currentServerType)
70 strunzone(me.currentServerType);
71 me.currentServerType = string_null;
73 if(me.currentServerMap)
74 strunzone(me.currentServerMap);
75 me.currentServerMap = string_null;
77 if(me.currentServerPlayers)
78 strunzone(me.currentServerPlayers);
79 me.currentServerPlayers = string_null;
81 if(me.currentServerNumPlayers)
82 strunzone(me.currentServerNumPlayers);
83 me.currentServerNumPlayers = string_null;
85 if(me.currentServerNumBots)
86 strunzone(me.currentServerNumBots);
87 me.currentServerNumBots = string_null;
89 if(me.currentServerNumFreeSlots)
90 strunzone(me.currentServerNumFreeSlots);
91 me.currentServerNumFreeSlots = string_null;
93 if(me.currentServerMod)
94 strunzone(me.currentServerMod);
95 me.currentServerMod = string_null;
97 if(me.currentServerVersion)
98 strunzone(me.currentServerVersion);
99 me.currentServerVersion = string_null;
102 //if(me.currentServerEncrypt)
103 // strunzone(me.currentServerEncrypt);
104 //me.currentServerEncrypt = string_null;
105 if(me.currentServerPure)
106 strunzone(me.currentServerPure);
107 me.currentServerPure = string_null;
109 if(me.currentServerKey)
110 strunzone(me.currentServerKey);
111 me.currentServerKey = string_null;
113 if(me.currentServerID)
114 strunzone(me.currentServerID);
115 me.currentServerID = string_null;
117 // ==========================
118 // Now, fill in the strings
119 // ==========================
120 me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
121 me.nameLabel.setText(me.nameLabel, me.currentServerName);
123 me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
124 me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
126 pure_available = false;
127 pure_violations = -1;
129 versionstr = _("N/A");
131 s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
132 m = tokenizebyseparator(s, ":");
136 versionstr = argv(1);
141 for(j = 2; j < m; ++j)
145 k = substring(argv(j), 0, 1);
146 v = substring(argv(j), 1, -1);
149 pure_available = true;
150 pure_violations = stof(v);
160 #ifdef COMPAT_NO_MOD_IS_XONOTIC
165 s = gethostcachestring(SLIST_FIELD_MOD, i);
167 modname = sprintf("%s (%s)", modname, s);
169 j = MapInfo_Type_FromString(typestr); // try and get the real name of the game type
170 if(j) { typestr = MapInfo_Type_ToText(j); } // only set it if we actually found it
172 me.currentServerType = strzone(typestr);
173 me.typeLabel.setText(me.typeLabel, me.currentServerType);
175 me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
176 me.mapLabel.setText(me.mapLabel, me.currentServerMap);
178 me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
179 me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
181 numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
182 maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
183 numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
184 me.currentServerNumPlayers = strzone(sprintf("%d/%d", numh, maxp));
185 me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
188 me.currentServerNumBots = strzone(s);
189 me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
191 if(freeslots < 0) { freeslots = maxp - numh - numb; }
193 me.currentServerNumFreeSlots = strzone(s);
194 me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
196 me.currentServerMod = ((modname == "Xonotic") ? ZCTX(_("MOD^Default")) : modname);
197 me.currentServerMod = strzone(me.currentServerMod);
198 me.modLabel.setText(me.modLabel, me.currentServerMod);
200 me.currentServerVersion = strzone(versionstr);
201 me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
203 me.currentServerPure = ((!pure_available) ? _("N/A") : (pure_violations == 0) ? _("Official") : sprintf(_("%d modified"), pure_violations));
204 me.currentServerPure = strzone(me.currentServerPure);
205 me.pureLabel.setText(me.pureLabel, me.currentServerPure);
207 s = crypto_getencryptlevel(me.currentServerCName);
210 if(cvar("crypto_aeslevel") >= 3)
211 me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
213 me.currentServerEncrypt = _("N/A (auth library missing)");
215 else switch(stof(substring(s, 0, 1)))
218 if(cvar("crypto_aeslevel") >= 3)
219 me.currentServerEncrypt = _("Not supported (can't connect)");
221 me.currentServerEncrypt = _("Not supported (won't encrypt)");
224 if(cvar("crypto_aeslevel") >= 2)
225 me.currentServerEncrypt = _("Supported (will encrypt)");
227 me.currentServerEncrypt = _("Supported (won't encrypt)");
230 if(cvar("crypto_aeslevel") >= 1)
231 me.currentServerEncrypt = _("Requested (will encrypt)");
233 me.currentServerEncrypt = _("Requested (won't encrypt)");
236 if(cvar("crypto_aeslevel") <= 0)
237 me.currentServerEncrypt = _("Required (can't connect)");
239 me.currentServerEncrypt = _("Required (will encrypt)");
242 me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
244 s = crypto_getidfp(me.currentServerCName);
245 if (!s) { s = _("N/A"); }
246 me.currentServerID = strzone(s);
247 me.idLabel.setText(me.idLabel, me.currentServerID);
249 s = crypto_getkeyfp(me.currentServerCName);
250 if (!s) { s = _("N/A"); }
251 me.currentServerKey = strzone(s);
252 me.keyLabel.setText(me.keyLabel, me.currentServerKey);
255 void XonoticServerInfoDialog_fill(entity me)
259 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Hostname:")));
260 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
261 e.colorL = SKINCOLOR_SERVERINFO_NAME;
265 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Address:")));
266 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
267 e.colorL = SKINCOLOR_SERVERINFO_IP;
273 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
274 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
278 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
279 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
283 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
284 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
288 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
289 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
293 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
294 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
300 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
301 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
303 me.numPlayersLabel = e;
305 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
306 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
310 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
311 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
313 me.numFreeSlotsLabel = e;
315 me.gotoRC(me, me.rows - 5, 0);
316 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Encryption:")));
317 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
321 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
322 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
326 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
327 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
331 me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
332 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
334 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
335 me.rawPlayerList = e;
337 me.gotoRC(me, me.rows - 1, 0);
338 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Close"), '0 0 0'));
339 e.onClick = Dialog_Close;
340 e.onClickEntity = me;
341 //me.TD(me, 1, me.columns/3, e = makeXonoticButton("", '0 0 0')); // TODO: Add bookmark button here
342 // e.onClick = ServerList_Favorite_Click;
343 // e.onClickEntity = slist;
344 // slist.favoriteButton = e;
345 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Join!"), '0 0 0'));
346 e.onClick = Join_Click;
347 e.onClickEntity = me;
350 void Join_Click(entity btn, entity me)
352 localcmd("connect ", me.currentServerCName, "\n");