]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_join_serverinfo.c
Merge remote-tracking branch 'origin/zykure/playerstats_ladders' into samual/combined...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_join_serverinfo.c
1 #ifdef INTERFACE
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)
10
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)
25
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)
42
43 void Join_Click(entity btn, entity me);
44 #endif
45
46 #ifdef IMPLEMENTATION
47 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
48 {
49         float m, pure, freeslots, j, numh, maxp, numb, sflags;
50         string s, typestr, versionstr, k, v, modname;
51
52         // ====================================
53         //  First clear and unzone the strings
54         // ====================================
55         if(me.currentServerName)
56                 strunzone(me.currentServerName);
57         me.currentServerName = string_null;
58
59         if(me.currentServerCName)
60                 strunzone(me.currentServerCName);
61         me.currentServerCName = string_null;
62
63         if(me.currentServerType)
64                 strunzone(me.currentServerType);
65         me.currentServerType = string_null;
66
67         if(me.currentServerMap)
68                 strunzone(me.currentServerMap);
69         me.currentServerMap = string_null;
70
71         if(me.currentServerPlayers)
72                 strunzone(me.currentServerPlayers);
73         me.currentServerPlayers = string_null;
74
75         if(me.currentServerNumPlayers)
76                 strunzone(me.currentServerNumPlayers);
77         me.currentServerNumPlayers = string_null;
78
79         if(me.currentServerNumBots)
80                 strunzone(me.currentServerNumBots);
81         me.currentServerNumBots = string_null;
82
83         if(me.currentServerNumFreeSlots)
84                 strunzone(me.currentServerNumFreeSlots);
85         me.currentServerNumFreeSlots = string_null;
86
87         if(me.currentServerMod)
88                 strunzone(me.currentServerMod);
89         me.currentServerMod = string_null;
90
91         if(me.currentServerVersion)
92                 strunzone(me.currentServerVersion);
93         me.currentServerVersion = string_null;
94
95         // not zoned!
96         //if(me.currentServerEncrypt)
97         //      strunzone(me.currentServerEncrypt);
98         //me.currentServerEncrypt = string_null;
99         if(me.currentServerPure)
100                 strunzone(me.currentServerPure);
101         me.currentServerPure = string_null;
102
103         if(me.currentServerKey)
104                 strunzone(me.currentServerKey);
105         me.currentServerKey = string_null;
106
107         if(me.currentServerID)
108                 strunzone(me.currentServerID);
109         me.currentServerID = string_null;
110
111         // ==========================
112         //  Now, fill in the strings
113         // ==========================
114         me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
115         me.nameLabel.setText(me.nameLabel, me.currentServerName);
116
117         me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
118         me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
119
120         pure = -1;
121         typestr = _("N/A");
122         versionstr = _("N/A");
123
124         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
125         m = tokenizebyseparator(s, ":");
126         if(m >= 2)
127         {
128                 typestr = argv(0);
129                 versionstr = argv(1);
130         }
131         freeslots = -1;
132         sflags = -1;
133         modname = "";
134         for(j = 2; j < m; ++j)
135         {
136                 if(argv(j) == "")
137                         break;
138                 k = substring(argv(j), 0, 1);
139                 v = substring(argv(j), 1, -1);
140                 if(k == "P")
141                         pure = stof(v);
142                 else if(k == "S")
143                         freeslots = stof(v);
144                 else if(k == "F")
145                         sflags = stof(v);
146                 else if(k == "M")
147                         modname = v;
148         }
149
150 #ifdef COMPAT_NO_MOD_IS_XONOTIC
151         if(modname == "")
152                 modname = "Xonotic";
153 #endif
154
155         s = gethostcachestring(SLIST_FIELD_MOD, i);
156         if(s != "data")
157                 modname = sprintf(_("%s (%s)"), modname, s);
158
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
161
162         me.currentServerType = strzone(typestr);
163         me.typeLabel.setText(me.typeLabel, me.currentServerType);
164
165         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
166         me.mapLabel.setText(me.mapLabel, me.currentServerMap);
167
168         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
169         me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
170
171         numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
172         maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
173         numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
174         me.currentServerNumPlayers = strzone(sprintf(_("%d/%d"), numh, maxp));
175         me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
176
177         s = ftos(numb);
178         me.currentServerNumBots = strzone(s);
179         me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
180
181         if(freeslots < 0) { freeslots = maxp - numh - numb; }
182         s = ftos(freeslots);
183         me.currentServerNumFreeSlots = strzone(s);
184         me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
185
186         me.currentServerMod = ((modname == "Xonotic") ? _("Default") : modname);
187         me.currentServerMod = strzone(me.currentServerMod);
188         me.modLabel.setText(me.modLabel, me.currentServerMod);
189
190         me.currentServerVersion = strzone(versionstr);
191         me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
192
193         me.currentServerPure = ((pure < 0) ? "N/A" : (pure == 0) ? _("Official") : sprintf(_("%d modified"), pure));
194         me.currentServerPure = strzone(me.currentServerPure);
195         me.pureLabel.setText(me.pureLabel, me.currentServerPure);
196
197         s = crypto_getencryptlevel(me.currentServerCName);
198         if(s == "")
199         {
200                 if(cvar("crypto_aeslevel") >= 3)
201                         me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
202                 else
203                         me.currentServerEncrypt = _("N/A (auth library missing)");
204         }
205         else switch(stof(substring(s, 0, 1)))
206         {
207                 case 0:
208                         if(cvar("crypto_aeslevel") >= 3)
209                                 me.currentServerEncrypt = _("Not supported (can't connect)");
210                         else
211                                 me.currentServerEncrypt = _("Not supported (won't encrypt)");
212                         break;
213                 case 1:
214                         if(cvar("crypto_aeslevel") >= 2)
215                                 me.currentServerEncrypt = _("Supported (will encrypt)");
216                         else
217                                 me.currentServerEncrypt = _("Supported (won't encrypt)");
218                         break;
219                 case 2:
220                         if(cvar("crypto_aeslevel") >= 1)
221                                 me.currentServerEncrypt = _("Requested (will encrypt)");
222                         else
223                                 me.currentServerEncrypt = _("Requested (won't encrypt)");
224                         break;
225                 case 3:
226                         if(cvar("crypto_aeslevel") <= 0)
227                                 me.currentServerEncrypt = _("Required (can't connect)");
228                         else
229                                 me.currentServerEncrypt = _("Required (will encrypt)");
230                         break;
231         }
232         me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
233
234         s = crypto_getidfp(me.currentServerCName);
235         if (!s) { s = _("N/A"); }
236         me.currentServerID = strzone(s);
237         me.idLabel.setText(me.idLabel, me.currentServerID);
238
239         s = crypto_getkeyfp(me.currentServerCName);
240         if (!s) { s = _("N/A"); }
241         me.currentServerKey = strzone(s);
242         me.keyLabel.setText(me.keyLabel, me.currentServerKey);
243 }
244
245 void XonoticServerInfoDialog_fill(entity me)
246 {
247         entity e;
248         me.TR(me);
249                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Hostname:")));
250                 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
251                 e.colorL = SKINCOLOR_SERVERINFO_NAME;
252                 e.allowCut = 1;
253                 me.nameLabel = e;
254         me.TR(me);
255                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Address:")));
256                 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
257                 e.colorL = SKINCOLOR_SERVERINFO_IP;
258                 e.allowCut = 1;
259                 me.cnameLabel = e;
260
261         me.TR(me);
262         me.TR(me);
263                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
264                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
265                 e.allowCut = 1;
266                 me.typeLabel = e;
267         me.TR(me);
268                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
269                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
270                 e.allowCut = 1;
271                 me.mapLabel = e;
272         me.TR(me);
273                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
274                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
275                 e.allowCut = 1;
276                 me.modLabel = e;
277         me.TR(me);
278                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
279                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
280                 e.allowCut = 1;
281                 me.versionLabel = e;
282         me.TR(me);
283                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
284                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
285                 e.allowCut = 1;
286                 me.pureLabel = e;
287
288         me.TR(me);
289         me.TR(me);
290                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
291                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
292                 e.allowCut = 1;
293                 me.numPlayersLabel = e;
294         me.TR(me);
295                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
296                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
297                 e.allowCut = 1;
298                 me.numBotsLabel = e;
299         me.TR(me);
300                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
301                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
302                 e.allowCut = 1;
303                 me.numFreeSlotsLabel = e;
304
305         me.gotoRC(me, me.rows - 5, 0);
306                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Encryption:")));
307                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
308                         e.allowCut = 1;
309                         me.encryptLabel = e;
310         me.TR(me);
311                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
312                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
313                         e.allowCut = 1;
314                         me.keyLabel = e;
315         me.TR(me);
316                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
317                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
318                         e.allowCut = 1;
319                         me.idLabel = e;
320
321         me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
322                 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
323         me.TR(me);
324                 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
325                         me.rawPlayerList = e;
326
327         me.gotoRC(me, me.rows - 1, 0);
328                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Close"), '0 0 0'));
329                         e.onClick = Dialog_Close;
330                         e.onClickEntity = me;
331                 //me.TD(me, 1, me.columns/3, e = makeXonoticButton("", '0 0 0')); // TODO: Add bookmark button here
332                 //      e.onClick = ServerList_Favorite_Click;
333                 //      e.onClickEntity = slist;
334                 //      slist.favoriteButton = e;
335                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Join!"), '0 0 0'));
336                         e.onClick = Join_Click;
337                         e.onClickEntity = me;
338 }
339
340 void Join_Click(entity btn, entity me)
341 {
342         localcmd("connect ", me.currentServerCName, "\n");
343 }
344
345 #endif