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)
53 float m, pure, freeslots, j, numh, maxp, numb, sflags;
54 string s, typestr, versionstr, k, v, modname;
56 // ====================================
57 // First clear and unzone the strings
58 // ====================================
59 if(me.currentServerName)
60 strunzone(me.currentServerName);
61 me.currentServerName = string_null;
63 if(me.currentServerCName)
64 strunzone(me.currentServerCName);
65 me.currentServerCName = string_null;
67 if(me.currentServerType)
68 strunzone(me.currentServerType);
69 me.currentServerType = string_null;
71 if(me.currentServerMap)
72 strunzone(me.currentServerMap);
73 me.currentServerMap = string_null;
75 if(me.currentServerPlayers)
76 strunzone(me.currentServerPlayers);
77 me.currentServerPlayers = string_null;
79 if(me.currentServerNumPlayers)
80 strunzone(me.currentServerNumPlayers);
81 me.currentServerNumPlayers = string_null;
83 if(me.currentServerNumBots)
84 strunzone(me.currentServerNumBots);
85 me.currentServerNumBots = string_null;
87 if(me.currentServerNumFreeSlots)
88 strunzone(me.currentServerNumFreeSlots);
89 me.currentServerNumFreeSlots = string_null;
91 if(me.currentServerMod)
92 strunzone(me.currentServerMod);
93 me.currentServerMod = string_null;
95 if(me.currentServerVersion)
96 strunzone(me.currentServerVersion);
97 me.currentServerVersion = string_null;
100 //if(me.currentServerEncrypt)
101 // strunzone(me.currentServerEncrypt);
102 //me.currentServerEncrypt = string_null;
103 if(me.currentServerPure)
104 strunzone(me.currentServerPure);
105 me.currentServerPure = string_null;
107 if(me.currentServerKey)
108 strunzone(me.currentServerKey);
109 me.currentServerKey = string_null;
111 if(me.currentServerID)
112 strunzone(me.currentServerID);
113 me.currentServerID = string_null;
115 // ==========================
116 // Now, fill in the strings
117 // ==========================
118 me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
119 me.nameLabel.setText(me.nameLabel, me.currentServerName);
121 me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
122 me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
126 versionstr = _("N/A");
128 s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
129 m = tokenizebyseparator(s, ":");
133 versionstr = argv(1);
138 for(j = 2; j < m; ++j)
142 k = substring(argv(j), 0, 1);
143 v = substring(argv(j), 1, -1);
154 #ifdef COMPAT_NO_MOD_IS_XONOTIC
159 s = gethostcachestring(SLIST_FIELD_MOD, i);
161 modname = sprintf("%s (%s)", modname, s);
163 j = MapInfo_Type_FromString(typestr); // try and get the real name of the game type
164 if(j) { typestr = MapInfo_Type_ToText(j); } // only set it if we actually found it
166 me.currentServerType = strzone(typestr);
167 me.typeLabel.setText(me.typeLabel, me.currentServerType);
169 me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
170 me.mapLabel.setText(me.mapLabel, me.currentServerMap);
172 me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
173 me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
175 numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
176 maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
177 numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
178 me.currentServerNumPlayers = strzone(sprintf("%d/%d", numh, maxp));
179 me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
182 me.currentServerNumBots = strzone(s);
183 me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
185 if(freeslots < 0) { freeslots = maxp - numh - numb; }
187 me.currentServerNumFreeSlots = strzone(s);
188 me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
190 me.currentServerMod = ((modname == "Xonotic") ? _("Default") : modname);
191 me.currentServerMod = strzone(me.currentServerMod);
192 me.modLabel.setText(me.modLabel, me.currentServerMod);
194 me.currentServerVersion = strzone(versionstr);
195 me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
197 me.currentServerPure = ((pure < 0) ? _("N/A") : (pure == 0) ? _("Official") : sprintf(_("%d modified"), pure));
198 me.currentServerPure = strzone(me.currentServerPure);
199 me.pureLabel.setText(me.pureLabel, me.currentServerPure);
201 s = crypto_getencryptlevel(me.currentServerCName);
204 if(cvar("crypto_aeslevel") >= 3)
205 me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
207 me.currentServerEncrypt = _("N/A (auth library missing)");
209 else switch(stof(substring(s, 0, 1)))
212 if(cvar("crypto_aeslevel") >= 3)
213 me.currentServerEncrypt = _("Not supported (can't connect)");
215 me.currentServerEncrypt = _("Not supported (won't encrypt)");
218 if(cvar("crypto_aeslevel") >= 2)
219 me.currentServerEncrypt = _("Supported (will encrypt)");
221 me.currentServerEncrypt = _("Supported (won't encrypt)");
224 if(cvar("crypto_aeslevel") >= 1)
225 me.currentServerEncrypt = _("Requested (will encrypt)");
227 me.currentServerEncrypt = _("Requested (won't encrypt)");
230 if(cvar("crypto_aeslevel") <= 0)
231 me.currentServerEncrypt = _("Required (can't connect)");
233 me.currentServerEncrypt = _("Required (will encrypt)");
236 me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
238 s = crypto_getidfp(me.currentServerCName);
239 if (!s) { s = _("N/A"); }
240 me.currentServerID = strzone(s);
241 me.idLabel.setText(me.idLabel, me.currentServerID);
243 s = crypto_getkeyfp(me.currentServerCName);
244 if (!s) { s = _("N/A"); }
245 me.currentServerKey = strzone(s);
246 me.keyLabel.setText(me.keyLabel, me.currentServerKey);
249 void XonoticServerInfoDialog_fill(entity me)
253 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Hostname:")));
254 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
255 e.colorL = SKINCOLOR_SERVERINFO_NAME;
259 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Address:")));
260 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
261 e.colorL = SKINCOLOR_SERVERINFO_IP;
267 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
268 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
272 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
273 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
277 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
278 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
282 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
283 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
287 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
288 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
294 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
295 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
297 me.numPlayersLabel = e;
299 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
300 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
304 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
305 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
307 me.numFreeSlotsLabel = e;
309 me.gotoRC(me, me.rows - 5, 0);
310 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Encryption:")));
311 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
315 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
316 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
320 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
321 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
325 me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
326 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
328 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
329 me.rawPlayerList = e;
331 me.gotoRC(me, me.rows - 1, 0);
332 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Close"), '0 0 0'));
333 e.onClick = Dialog_Close;
334 e.onClickEntity = me;
335 //me.TD(me, 1, me.columns/3, e = makeXonoticButton("", '0 0 0')); // TODO: Add bookmark button here
336 // e.onClick = ServerList_Favorite_Click;
337 // e.onClickEntity = slist;
338 // slist.favoriteButton = e;
339 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Join!"), '0 0 0'));
340 e.onClick = Join_Click;
341 e.onClickEntity = me;
344 void Join_Click(entity btn, entity me)
346 localcmd("connect ", me.currentServerCName, "\n");