2 CLASS(XonoticServerInfoDialog) EXTENDS(XonoticDialog)
3 METHOD(XonoticServerInfoDialog, fill, void(entity))
4 METHOD(XonoticServerInfoDialog, loadServerInfo, void(entity, float))
5 ATTRIB(XonoticServerInfoDialog, title, string, _("Server Information"))
6 ATTRIB(XonoticServerInfoDialog, color, vector, SKINCOLOR_DIALOG_SERVERINFO)
7 ATTRIB(XonoticServerInfoDialog, intendedWidth, float, 0.8)
8 ATTRIB(XonoticServerInfoDialog, rows, float, 18)
9 ATTRIB(XonoticServerInfoDialog, columns, float, 6.2)
11 ATTRIB(XonoticServerInfoDialog, currentServerName, string, string_null)
12 ATTRIB(XonoticServerInfoDialog, currentServerCName, string, string_null)
13 ATTRIB(XonoticServerInfoDialog, currentServerType, string, string_null)
14 ATTRIB(XonoticServerInfoDialog, currentServerMap, string, string_null)
15 ATTRIB(XonoticServerInfoDialog, currentServerPlayers, string, string_null)
16 ATTRIB(XonoticServerInfoDialog, currentServerNumPlayers, string, string_null)
17 ATTRIB(XonoticServerInfoDialog, currentServerNumBots, string, string_null)
18 ATTRIB(XonoticServerInfoDialog, currentServerNumFreeSlots, string, string_null)
19 ATTRIB(XonoticServerInfoDialog, currentServerMod, string, string_null)
20 ATTRIB(XonoticServerInfoDialog, currentServerVersion, string, string_null)
21 ATTRIB(XonoticServerInfoDialog, currentServerKey, string, string_null)
22 ATTRIB(XonoticServerInfoDialog, currentServerID, string, string_null)
23 ATTRIB(XonoticServerInfoDialog, currentServerEncrypt, string, string_null)
24 ATTRIB(XonoticServerInfoDialog, currentServerPure, string, string_null)
26 ATTRIB(XonoticServerInfoDialog, nameLabel, entity, NULL)
27 ATTRIB(XonoticServerInfoDialog, cnameLabel, entity, NULL)
28 ATTRIB(XonoticServerInfoDialog, typeLabel, entity, NULL)
29 ATTRIB(XonoticServerInfoDialog, mapLabel, entity, NULL)
30 ATTRIB(XonoticServerInfoDialog, rawPlayerList, entity, NULL)
31 ATTRIB(XonoticServerInfoDialog, numPlayersLabel, entity, NULL)
32 ATTRIB(XonoticServerInfoDialog, numBotsLabel, entity, NULL)
33 ATTRIB(XonoticServerInfoDialog, numFreeSlotsLabel, entity, NULL)
34 ATTRIB(XonoticServerInfoDialog, modLabel, entity, NULL)
35 ATTRIB(XonoticServerInfoDialog, versionLabel, entity, NULL)
36 ATTRIB(XonoticServerInfoDialog, keyLabel, entity, NULL)
37 ATTRIB(XonoticServerInfoDialog, idLabel, entity, NULL)
38 ATTRIB(XonoticServerInfoDialog, encryptLabel, entity, NULL)
39 ATTRIB(XonoticServerInfoDialog, canConnectLabel, entity, NULL)
40 ATTRIB(XonoticServerInfoDialog, pureLabel, entity, NULL)
41 ENDCLASS(XonoticServerInfoDialog)
43 float SLIST_FIELD_NAME;
44 float SLIST_FIELD_CNAME;
45 float SLIST_FIELD_QCSTATUS;
46 float SLIST_FIELD_MAP;
47 float SLIST_FIELD_PLAYERS;
48 float SLIST_FIELD_NUMHUMANS;
49 float SLIST_FIELD_MAXPLAYERS;
50 float SLIST_FIELD_NUMBOTS;
51 float SLIST_FIELD_MOD;
52 void Join_Click(entity btn, entity me);
56 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
58 float m, pure, freeslots, j, numh, maxp, numb, sflags;
59 string s, typestr, versionstr, k, v;
61 // ====================================
62 // First clear and unzone the strings
63 // ====================================
64 if(me.currentServerName)
65 strunzone(me.currentServerName);
66 me.currentServerName = string_null;
68 if(me.currentServerCName)
69 strunzone(me.currentServerCName);
70 me.currentServerCName = string_null;
72 if(me.currentServerType)
73 strunzone(me.currentServerType);
74 me.currentServerType = string_null;
76 if(me.currentServerMap)
77 strunzone(me.currentServerMap);
78 me.currentServerMap = string_null;
80 if(me.currentServerPlayers)
81 strunzone(me.currentServerPlayers);
82 me.currentServerPlayers = string_null;
84 if(me.currentServerNumPlayers)
85 strunzone(me.currentServerNumPlayers);
86 me.currentServerNumPlayers = string_null;
88 if(me.currentServerNumBots)
89 strunzone(me.currentServerNumBots);
90 me.currentServerNumBots = string_null;
92 if(me.currentServerNumFreeSlots)
93 strunzone(me.currentServerNumFreeSlots);
94 me.currentServerNumFreeSlots = string_null;
96 if(me.currentServerMod)
97 strunzone(me.currentServerMod);
98 me.currentServerMod = string_null;
100 if(me.currentServerVersion)
101 strunzone(me.currentServerVersion);
102 me.currentServerVersion = string_null;
105 //if(me.currentServerEncrypt)
106 // strunzone(me.currentServerEncrypt);
107 //me.currentServerEncrypt = string_null;
108 if(me.currentServerPure)
109 strunzone(me.currentServerPure);
110 me.currentServerPure = string_null;
112 if(me.currentServerKey)
113 strunzone(me.currentServerKey);
114 me.currentServerKey = string_null;
116 if(me.currentServerID)
117 strunzone(me.currentServerID);
118 me.currentServerID = string_null;
120 // ==========================
121 // Now, fill in the strings
122 // ==========================
123 SLIST_FIELD_NAME = gethostcacheindexforkey("name");
124 me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
125 me.nameLabel.setText(me.nameLabel, me.currentServerName);
127 SLIST_FIELD_CNAME = gethostcacheindexforkey("cname");
128 me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
129 me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
133 versionstr = _("N/A");
135 SLIST_FIELD_QCSTATUS = gethostcacheindexforkey("qcstatus");
136 s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
137 m = tokenizebyseparator(s, ":");
141 versionstr = argv(1);
145 for(j = 2; j < m; ++j)
149 k = substring(argv(j), 0, 1);
150 v = substring(argv(j), 1, -1);
159 j = MapInfo_Type_FromString(typestr); // try and get the real name of the game type
160 if(j) { typestr = MapInfo_Type_ToText(j); } // only set it if we actually found it
162 me.currentServerType = strzone(typestr);
163 me.typeLabel.setText(me.typeLabel, me.currentServerType);
165 SLIST_FIELD_MAP = gethostcacheindexforkey("map");
166 me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
167 me.mapLabel.setText(me.mapLabel, me.currentServerMap);
169 SLIST_FIELD_PLAYERS = gethostcacheindexforkey("players");
170 me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
171 me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
173 SLIST_FIELD_NUMHUMANS = gethostcacheindexforkey("numhumans");
174 numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
175 SLIST_FIELD_MAXPLAYERS = gethostcacheindexforkey("maxplayers");
176 maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
177 SLIST_FIELD_NUMBOTS = gethostcacheindexforkey("numbots");
178 numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
179 me.currentServerNumPlayers = strzone(sprintf(_("%d/%d"), numh, maxp));
180 me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
183 me.currentServerNumBots = strzone(s);
184 me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
186 if(freeslots < 0) { freeslots = maxp - numh - numb; }
188 me.currentServerNumFreeSlots = strzone(s);
189 me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
191 SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
192 s = gethostcachestring(SLIST_FIELD_MOD, i);
193 s = ((s == "data") ? _("Default") : s);
194 me.currentServerMod = strzone(s);
195 me.modLabel.setText(me.modLabel, me.currentServerMod);
197 me.currentServerVersion = strzone(versionstr);
198 me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
200 me.currentServerPure = ((pure < 0) ? "N/A" : (pure == 0) ? _("Official") : sprintf(_("%d modified"), pure));
201 me.currentServerPure = strzone(me.currentServerPure);
202 me.pureLabel.setText(me.pureLabel, me.currentServerPure);
204 s = crypto_getencryptlevel(me.currentServerCName);
207 if(cvar("crypto_aeslevel") >= 3)
208 me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
210 me.currentServerEncrypt = _("N/A (auth library missing)");
212 else switch(stof(substring(s, 0, 1)))
215 if(cvar("crypto_aeslevel") >= 3)
216 me.currentServerEncrypt = _("Not supported (can't connect)");
218 me.currentServerEncrypt = _("Not supported (won't encrypt)");
221 if(cvar("crypto_aeslevel") >= 2)
222 me.currentServerEncrypt = _("Supported (will encrypt)");
224 me.currentServerEncrypt = _("Supported (won't encrypt)");
227 if(cvar("crypto_aeslevel") >= 1)
228 me.currentServerEncrypt = _("Requested (will encrypt)");
230 me.currentServerEncrypt = _("Requested (won't encrypt)");
233 if(cvar("crypto_aeslevel") <= 0)
234 me.currentServerEncrypt = _("Required (can't connect)");
236 me.currentServerEncrypt = _("Required (will encrypt)");
239 me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
241 s = crypto_getidfp(me.currentServerCName);
242 if not(s) { s = _("N/A"); }
243 me.currentServerID = strzone(s);
244 me.idLabel.setText(me.idLabel, me.currentServerID);
246 s = crypto_getkeyfp(me.currentServerCName);
247 if not(s) { s = _("N/A"); }
248 me.currentServerKey = strzone(s);
249 me.keyLabel.setText(me.keyLabel, me.currentServerKey);
252 void XonoticServerInfoDialog_fill(entity me)
256 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Hostname:")));
257 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
258 e.colorL = SKINCOLOR_SERVERINFO_NAME;
262 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Address:")));
263 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
264 e.colorL = SKINCOLOR_SERVERINFO_IP;
270 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
271 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
275 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
276 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
280 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
281 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
285 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
286 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
290 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
291 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
297 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
298 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
300 me.numPlayersLabel = e;
302 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
303 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
307 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
308 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
310 me.numFreeSlotsLabel = e;
312 me.gotoRC(me, me.rows - 5, 0);
313 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Encryption:")));
314 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
318 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
319 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
323 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
324 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
328 me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
329 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
331 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
332 me.rawPlayerList = e;
334 me.gotoRC(me, me.rows - 1, 0);
335 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Close"), '0 0 0'));
336 e.onClick = Dialog_Close;
337 e.onClickEntity = me;
338 //me.TD(me, 1, me.columns/3, e = makeXonoticButton("", '0 0 0')); // TODO: Add bookmark button here
339 // e.onClick = ServerList_Favorite_Click;
340 // e.onClickEntity = slist;
341 // slist.favoriteButton = e;
342 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Join!"), '0 0 0'));
343 e.onClick = Join_Click;
344 e.onClickEntity = me;
347 void Join_Click(entity btn, entity me)
349 localcmd("connect ", me.currentServerCName, "\n");