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