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