1 #include "../../common/mapinfo.qh"
4 CLASS(XonoticServerInfoDialog) EXTENDS(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)
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)
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)
45 void Join_Click(entity btn, entity me);
49 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
51 float m, pure, freeslots, j, numh, maxp, numb, sflags;
52 string s, typestr, versionstr, k, v, modname;
54 // ====================================
55 // First clear and unzone the strings
56 // ====================================
57 if(me.currentServerName)
58 strunzone(me.currentServerName);
59 me.currentServerName = string_null;
61 if(me.currentServerCName)
62 strunzone(me.currentServerCName);
63 me.currentServerCName = string_null;
65 if(me.currentServerType)
66 strunzone(me.currentServerType);
67 me.currentServerType = string_null;
69 if(me.currentServerMap)
70 strunzone(me.currentServerMap);
71 me.currentServerMap = string_null;
73 if(me.currentServerPlayers)
74 strunzone(me.currentServerPlayers);
75 me.currentServerPlayers = string_null;
77 if(me.currentServerNumPlayers)
78 strunzone(me.currentServerNumPlayers);
79 me.currentServerNumPlayers = string_null;
81 if(me.currentServerNumBots)
82 strunzone(me.currentServerNumBots);
83 me.currentServerNumBots = string_null;
85 if(me.currentServerNumFreeSlots)
86 strunzone(me.currentServerNumFreeSlots);
87 me.currentServerNumFreeSlots = string_null;
89 if(me.currentServerMod)
90 strunzone(me.currentServerMod);
91 me.currentServerMod = string_null;
93 if(me.currentServerVersion)
94 strunzone(me.currentServerVersion);
95 me.currentServerVersion = string_null;
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;
105 if(me.currentServerKey)
106 strunzone(me.currentServerKey);
107 me.currentServerKey = string_null;
109 if(me.currentServerID)
110 strunzone(me.currentServerID);
111 me.currentServerID = string_null;
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);
119 me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
120 me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
124 versionstr = _("N/A");
126 s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
127 m = tokenizebyseparator(s, ":");
131 versionstr = argv(1);
136 for(j = 2; j < m; ++j)
140 k = substring(argv(j), 0, 1);
141 v = substring(argv(j), 1, -1);
152 #ifdef COMPAT_NO_MOD_IS_XONOTIC
157 s = gethostcachestring(SLIST_FIELD_MOD, i);
159 modname = sprintf("%s (%s)", modname, s);
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
164 me.currentServerType = strzone(typestr);
165 me.typeLabel.setText(me.typeLabel, me.currentServerType);
167 me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
168 me.mapLabel.setText(me.mapLabel, me.currentServerMap);
170 me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
171 me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
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);
180 me.currentServerNumBots = strzone(s);
181 me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
183 if(freeslots < 0) { freeslots = maxp - numh - numb; }
185 me.currentServerNumFreeSlots = strzone(s);
186 me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
188 me.currentServerMod = ((modname == "Xonotic") ? _("Default") : modname);
189 me.currentServerMod = strzone(me.currentServerMod);
190 me.modLabel.setText(me.modLabel, me.currentServerMod);
192 me.currentServerVersion = strzone(versionstr);
193 me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
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);
199 s = crypto_getencryptlevel(me.currentServerCName);
202 if(cvar("crypto_aeslevel") >= 3)
203 me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
205 me.currentServerEncrypt = _("N/A (auth library missing)");
207 else switch(stof(substring(s, 0, 1)))
210 if(cvar("crypto_aeslevel") >= 3)
211 me.currentServerEncrypt = _("Not supported (can't connect)");
213 me.currentServerEncrypt = _("Not supported (won't encrypt)");
216 if(cvar("crypto_aeslevel") >= 2)
217 me.currentServerEncrypt = _("Supported (will encrypt)");
219 me.currentServerEncrypt = _("Supported (won't encrypt)");
222 if(cvar("crypto_aeslevel") >= 1)
223 me.currentServerEncrypt = _("Requested (will encrypt)");
225 me.currentServerEncrypt = _("Requested (won't encrypt)");
228 if(cvar("crypto_aeslevel") <= 0)
229 me.currentServerEncrypt = _("Required (can't connect)");
231 me.currentServerEncrypt = _("Required (will encrypt)");
234 me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
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);
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);
247 void XonoticServerInfoDialog_fill(entity 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;
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;
265 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
266 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
270 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
271 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
275 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
276 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
280 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
281 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
285 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
286 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
292 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
293 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
295 me.numPlayersLabel = e;
297 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
298 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
302 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
303 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
305 me.numFreeSlotsLabel = e;
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, ""));
313 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
314 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
318 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
319 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
323 me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
324 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
326 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
327 me.rawPlayerList = e;
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;
342 void Join_Click(entity btn, entity me)
344 localcmd("connect ", me.currentServerCName, "\n");