]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_join_serverinfo.qc
Merge branch 'master' into terencehill/quickmenu
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_join_serverinfo.qc
1 #include "../../common/mapinfo.qh"
2
3 #ifndef DIALOG_MULTIPLAYER_JOIN_SERVERINFO_H
4 #define DIALOG_MULTIPLAYER_JOIN_SERVERINFO_H
5 #include "dialog.qc"
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)
14
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)
29
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)
46
47 void Join_Click(entity btn, entity me);
48 #endif
49
50 #ifdef IMPLEMENTATION
51 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
52 {
53         float m, pure, freeslots, j, numh, maxp, numb, sflags;
54         string s, typestr, versionstr, k, v, modname;
55
56         // ====================================
57         //  First clear and unzone the strings
58         // ====================================
59         if(me.currentServerName)
60                 strunzone(me.currentServerName);
61         me.currentServerName = string_null;
62
63         if(me.currentServerCName)
64                 strunzone(me.currentServerCName);
65         me.currentServerCName = string_null;
66
67         if(me.currentServerType)
68                 strunzone(me.currentServerType);
69         me.currentServerType = string_null;
70
71         if(me.currentServerMap)
72                 strunzone(me.currentServerMap);
73         me.currentServerMap = string_null;
74
75         if(me.currentServerPlayers)
76                 strunzone(me.currentServerPlayers);
77         me.currentServerPlayers = string_null;
78
79         if(me.currentServerNumPlayers)
80                 strunzone(me.currentServerNumPlayers);
81         me.currentServerNumPlayers = string_null;
82
83         if(me.currentServerNumBots)
84                 strunzone(me.currentServerNumBots);
85         me.currentServerNumBots = string_null;
86
87         if(me.currentServerNumFreeSlots)
88                 strunzone(me.currentServerNumFreeSlots);
89         me.currentServerNumFreeSlots = string_null;
90
91         if(me.currentServerMod)
92                 strunzone(me.currentServerMod);
93         me.currentServerMod = string_null;
94
95         if(me.currentServerVersion)
96                 strunzone(me.currentServerVersion);
97         me.currentServerVersion = string_null;
98
99         // not zoned!
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;
106
107         if(me.currentServerKey)
108                 strunzone(me.currentServerKey);
109         me.currentServerKey = string_null;
110
111         if(me.currentServerID)
112                 strunzone(me.currentServerID);
113         me.currentServerID = string_null;
114
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);
120
121         me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
122         me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
123
124         pure = -1;
125         typestr = _("N/A");
126         versionstr = _("N/A");
127
128         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
129         m = tokenizebyseparator(s, ":");
130         if(m >= 2)
131         {
132                 typestr = argv(0);
133                 versionstr = argv(1);
134         }
135         freeslots = -1;
136         sflags = -1;
137         modname = "";
138         for(j = 2; j < m; ++j)
139         {
140                 if(argv(j) == "")
141                         break;
142                 k = substring(argv(j), 0, 1);
143                 v = substring(argv(j), 1, -1);
144                 if(k == "P")
145                         pure = stof(v);
146                 else if(k == "S")
147                         freeslots = stof(v);
148                 else if(k == "F")
149                         sflags = stof(v);
150                 else if(k == "M")
151                         modname = v;
152         }
153
154 #ifdef COMPAT_NO_MOD_IS_XONOTIC
155         if(modname == "")
156                 modname = "Xonotic";
157 #endif
158
159         s = gethostcachestring(SLIST_FIELD_MOD, i);
160         if(s != "data")
161                 modname = sprintf("%s (%s)", modname, s);
162
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
165
166         me.currentServerType = strzone(typestr);
167         me.typeLabel.setText(me.typeLabel, me.currentServerType);
168
169         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
170         me.mapLabel.setText(me.mapLabel, me.currentServerMap);
171
172         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
173         me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
174
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);
180
181         s = ftos(numb);
182         me.currentServerNumBots = strzone(s);
183         me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
184
185         if(freeslots < 0) { freeslots = maxp - numh - numb; }
186         s = ftos(freeslots);
187         me.currentServerNumFreeSlots = strzone(s);
188         me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
189
190         me.currentServerMod = ((modname == "Xonotic") ? _("Default") : modname);
191         me.currentServerMod = strzone(me.currentServerMod);
192         me.modLabel.setText(me.modLabel, me.currentServerMod);
193
194         me.currentServerVersion = strzone(versionstr);
195         me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
196
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);
200
201         s = crypto_getencryptlevel(me.currentServerCName);
202         if(s == "")
203         {
204                 if(cvar("crypto_aeslevel") >= 3)
205                         me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
206                 else
207                         me.currentServerEncrypt = _("N/A (auth library missing)");
208         }
209         else switch(stof(substring(s, 0, 1)))
210         {
211                 case 0:
212                         if(cvar("crypto_aeslevel") >= 3)
213                                 me.currentServerEncrypt = _("Not supported (can't connect)");
214                         else
215                                 me.currentServerEncrypt = _("Not supported (won't encrypt)");
216                         break;
217                 case 1:
218                         if(cvar("crypto_aeslevel") >= 2)
219                                 me.currentServerEncrypt = _("Supported (will encrypt)");
220                         else
221                                 me.currentServerEncrypt = _("Supported (won't encrypt)");
222                         break;
223                 case 2:
224                         if(cvar("crypto_aeslevel") >= 1)
225                                 me.currentServerEncrypt = _("Requested (will encrypt)");
226                         else
227                                 me.currentServerEncrypt = _("Requested (won't encrypt)");
228                         break;
229                 case 3:
230                         if(cvar("crypto_aeslevel") <= 0)
231                                 me.currentServerEncrypt = _("Required (can't connect)");
232                         else
233                                 me.currentServerEncrypt = _("Required (will encrypt)");
234                         break;
235         }
236         me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
237
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);
242
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);
247 }
248
249 void XonoticServerInfoDialog_fill(entity me)
250 {
251         entity e;
252         me.TR(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;
256                 e.allowCut = 1;
257                 me.nameLabel = e;
258         me.TR(me);
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;
262                 e.allowCut = 1;
263                 me.cnameLabel = e;
264
265         me.TR(me);
266         me.TR(me);
267                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
268                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
269                 e.allowCut = 1;
270                 me.typeLabel = e;
271         me.TR(me);
272                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
273                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
274                 e.allowCut = 1;
275                 me.mapLabel = e;
276         me.TR(me);
277                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
278                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
279                 e.allowCut = 1;
280                 me.modLabel = e;
281         me.TR(me);
282                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
283                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
284                 e.allowCut = 1;
285                 me.versionLabel = e;
286         me.TR(me);
287                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
288                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
289                 e.allowCut = 1;
290                 me.pureLabel = e;
291
292         me.TR(me);
293         me.TR(me);
294                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
295                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
296                 e.allowCut = 1;
297                 me.numPlayersLabel = e;
298         me.TR(me);
299                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
300                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
301                 e.allowCut = 1;
302                 me.numBotsLabel = e;
303         me.TR(me);
304                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
305                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
306                 e.allowCut = 1;
307                 me.numFreeSlotsLabel = e;
308
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, ""));
312                         e.allowCut = 1;
313                         me.encryptLabel = e;
314         me.TR(me);
315                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
316                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
317                         e.allowCut = 1;
318                         me.keyLabel = e;
319         me.TR(me);
320                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
321                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
322                         e.allowCut = 1;
323                         me.idLabel = e;
324
325         me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
326                 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
327         me.TR(me);
328                 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
329                         me.rawPlayerList = e;
330
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;
342 }
343
344 void Join_Click(entity btn, entity me)
345 {
346         localcmd("connect ", me.currentServerCName, "\n");
347 }
348
349 #endif