1 #include "../../common/mapinfo.qh"
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)
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)
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)
46 void Join_Click(entity btn, entity me);
50 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
52 float m, pure, freeslots, j, numh, maxp, numb, sflags;
53 string s, typestr, versionstr, k, v, modname;
55 // ====================================
56 // First clear and unzone the strings
57 // ====================================
58 if(me.currentServerName)
59 strunzone(me.currentServerName);
60 me.currentServerName = string_null;
62 if(me.currentServerCName)
63 strunzone(me.currentServerCName);
64 me.currentServerCName = string_null;
66 if(me.currentServerType)
67 strunzone(me.currentServerType);
68 me.currentServerType = string_null;
70 if(me.currentServerMap)
71 strunzone(me.currentServerMap);
72 me.currentServerMap = string_null;
74 if(me.currentServerPlayers)
75 strunzone(me.currentServerPlayers);
76 me.currentServerPlayers = string_null;
78 if(me.currentServerNumPlayers)
79 strunzone(me.currentServerNumPlayers);
80 me.currentServerNumPlayers = string_null;
82 if(me.currentServerNumBots)
83 strunzone(me.currentServerNumBots);
84 me.currentServerNumBots = string_null;
86 if(me.currentServerNumFreeSlots)
87 strunzone(me.currentServerNumFreeSlots);
88 me.currentServerNumFreeSlots = string_null;
90 if(me.currentServerMod)
91 strunzone(me.currentServerMod);
92 me.currentServerMod = string_null;
94 if(me.currentServerVersion)
95 strunzone(me.currentServerVersion);
96 me.currentServerVersion = string_null;
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;
106 if(me.currentServerKey)
107 strunzone(me.currentServerKey);
108 me.currentServerKey = string_null;
110 if(me.currentServerID)
111 strunzone(me.currentServerID);
112 me.currentServerID = string_null;
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);
120 me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
121 me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
125 versionstr = _("N/A");
127 s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
128 m = tokenizebyseparator(s, ":");
132 versionstr = argv(1);
137 for(j = 2; j < m; ++j)
141 k = substring(argv(j), 0, 1);
142 v = substring(argv(j), 1, -1);
153 #ifdef COMPAT_NO_MOD_IS_XONOTIC
158 s = gethostcachestring(SLIST_FIELD_MOD, i);
160 modname = sprintf("%s (%s)", modname, s);
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
165 me.currentServerType = strzone(typestr);
166 me.typeLabel.setText(me.typeLabel, me.currentServerType);
168 me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
169 me.mapLabel.setText(me.mapLabel, me.currentServerMap);
171 me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
172 me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
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);
181 me.currentServerNumBots = strzone(s);
182 me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
184 if(freeslots < 0) { freeslots = maxp - numh - numb; }
186 me.currentServerNumFreeSlots = strzone(s);
187 me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
189 me.currentServerMod = ((modname == "Xonotic") ? _("Default") : modname);
190 me.currentServerMod = strzone(me.currentServerMod);
191 me.modLabel.setText(me.modLabel, me.currentServerMod);
193 me.currentServerVersion = strzone(versionstr);
194 me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
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);
200 s = crypto_getencryptlevel(me.currentServerCName);
203 if(cvar("crypto_aeslevel") >= 3)
204 me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
206 me.currentServerEncrypt = _("N/A (auth library missing)");
208 else switch(stof(substring(s, 0, 1)))
211 if(cvar("crypto_aeslevel") >= 3)
212 me.currentServerEncrypt = _("Not supported (can't connect)");
214 me.currentServerEncrypt = _("Not supported (won't encrypt)");
217 if(cvar("crypto_aeslevel") >= 2)
218 me.currentServerEncrypt = _("Supported (will encrypt)");
220 me.currentServerEncrypt = _("Supported (won't encrypt)");
223 if(cvar("crypto_aeslevel") >= 1)
224 me.currentServerEncrypt = _("Requested (will encrypt)");
226 me.currentServerEncrypt = _("Requested (won't encrypt)");
229 if(cvar("crypto_aeslevel") <= 0)
230 me.currentServerEncrypt = _("Required (can't connect)");
232 me.currentServerEncrypt = _("Required (will encrypt)");
235 me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
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);
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);
248 void XonoticServerInfoDialog_fill(entity 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;
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;
266 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
267 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
271 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
272 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
276 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
277 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
281 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
282 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
286 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
287 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
293 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
294 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
296 me.numPlayersLabel = e;
298 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
299 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
303 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
304 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
306 me.numFreeSlotsLabel = e;
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, ""));
314 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
315 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
319 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
320 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
324 me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
325 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
327 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
328 me.rawPlayerList = e;
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;
343 void Join_Click(entity btn, entity me)
345 localcmd("connect ", me.currentServerCName, "\n");