]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_join_serverinfo.c
indicate mod in menu HUD if sent by the server; detect minstagib and CTS and send...
[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                 if(modname == "Xonotic")
158                         modname = s;
159
160         j = MapInfo_Type_FromString(typestr); // try and get the real name of the game type
161         if(j) { typestr = MapInfo_Type_ToText(j); } // only set it if we actually found it
162         
163         me.currentServerType = strzone(typestr);
164         me.typeLabel.setText(me.typeLabel, me.currentServerType);
165
166         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
167         me.mapLabel.setText(me.mapLabel, me.currentServerMap);
168
169         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
170         me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
171
172         numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
173         maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
174         numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
175         me.currentServerNumPlayers = strzone(sprintf(_("%d/%d"), numh, maxp));
176         me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
177
178         s = ftos(numb);
179         me.currentServerNumBots = strzone(s);
180         me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
181         
182         if(freeslots < 0) { freeslots = maxp - numh - numb; }
183         s = ftos(freeslots);
184         me.currentServerNumFreeSlots = strzone(s);
185         me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
186
187         me.currentServerMod = ((modname == "Xonotic") ? _("Default") : modname);
188         me.currentServerMod = strzone(modname);
189         me.modLabel.setText(me.modLabel, me.currentServerMod);
190
191         me.currentServerVersion = strzone(versionstr);
192         me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
193
194         me.currentServerPure = ((pure < 0) ? "N/A" : (pure == 0) ? _("Official") : sprintf(_("%d modified"), pure));
195         me.currentServerPure = strzone(me.currentServerPure);
196         me.pureLabel.setText(me.pureLabel, me.currentServerPure);
197
198         s = crypto_getencryptlevel(me.currentServerCName);
199         if(s == "")
200         {
201                 if(cvar("crypto_aeslevel") >= 3)
202                         me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
203                 else
204                         me.currentServerEncrypt = _("N/A (auth library missing)");
205         }
206         else switch(stof(substring(s, 0, 1)))
207         {
208                 case 0:
209                         if(cvar("crypto_aeslevel") >= 3)
210                                 me.currentServerEncrypt = _("Not supported (can't connect)");
211                         else
212                                 me.currentServerEncrypt = _("Not supported (won't encrypt)");
213                         break;
214                 case 1:
215                         if(cvar("crypto_aeslevel") >= 2)
216                                 me.currentServerEncrypt = _("Supported (will encrypt)");
217                         else
218                                 me.currentServerEncrypt = _("Supported (won't encrypt)");
219                         break;
220                 case 2:
221                         if(cvar("crypto_aeslevel") >= 1)
222                                 me.currentServerEncrypt = _("Requested (will encrypt)");
223                         else
224                                 me.currentServerEncrypt = _("Requested (won't encrypt)");
225                         break;
226                 case 3:
227                         if(cvar("crypto_aeslevel") <= 0)
228                                 me.currentServerEncrypt = _("Required (can't connect)");
229                         else
230                                 me.currentServerEncrypt = _("Required (will encrypt)");
231                         break;
232         }
233         me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
234         
235         s = crypto_getidfp(me.currentServerCName);
236         if not(s) { s = _("N/A"); }
237         me.currentServerID = strzone(s);
238         me.idLabel.setText(me.idLabel, me.currentServerID);
239
240         s = crypto_getkeyfp(me.currentServerCName);
241         if not(s) { s = _("N/A"); }
242         me.currentServerKey = strzone(s);
243         me.keyLabel.setText(me.keyLabel, me.currentServerKey);
244 }
245
246 void XonoticServerInfoDialog_fill(entity me)
247 {
248         entity e;
249         me.TR(me);
250                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Hostname:")));
251                 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
252                 e.colorL = SKINCOLOR_SERVERINFO_NAME;
253                 e.allowCut = 1;
254                 me.nameLabel = e;
255         me.TR(me);
256                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Address:")));
257                 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
258                 e.colorL = SKINCOLOR_SERVERINFO_IP;
259                 e.allowCut = 1;
260                 me.cnameLabel = e;
261                 
262         me.TR(me);
263         me.TR(me);
264                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
265                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
266                 e.allowCut = 1;
267                 me.typeLabel = e;
268         me.TR(me);
269                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
270                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
271                 e.allowCut = 1;
272                 me.mapLabel = e;
273         me.TR(me);
274                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
275                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
276                 e.allowCut = 1;
277                 me.modLabel = e;
278         me.TR(me);
279                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
280                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
281                 e.allowCut = 1;
282                 me.versionLabel = e;
283         me.TR(me);
284                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
285                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
286                 e.allowCut = 1;
287                 me.pureLabel = e;
288                 
289         me.TR(me);
290         me.TR(me);
291                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
292                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
293                 e.allowCut = 1;
294                 me.numPlayersLabel = e;
295         me.TR(me);
296                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
297                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
298                 e.allowCut = 1;
299                 me.numBotsLabel = e;
300         me.TR(me);
301                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
302                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
303                 e.allowCut = 1;
304                 me.numFreeSlotsLabel = e;
305                 
306         me.gotoRC(me, me.rows - 5, 0);
307                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Encryption:")));
308                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
309                         e.allowCut = 1;
310                         me.encryptLabel = e;
311         me.TR(me);
312                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
313                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
314                         e.allowCut = 1;
315                         me.keyLabel = e;
316         me.TR(me);
317                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
318                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
319                         e.allowCut = 1;
320                         me.idLabel = e;
321
322         me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
323                 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
324         me.TR(me);
325                 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
326                         me.rawPlayerList = e;
327
328         me.gotoRC(me, me.rows - 1, 0);
329                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Close"), '0 0 0'));
330                         e.onClick = Dialog_Close;
331                         e.onClickEntity = me;
332                 //me.TD(me, 1, me.columns/3, e = makeXonoticButton("", '0 0 0')); // TODO: Add bookmark button here
333                 //      e.onClick = ServerList_Favorite_Click;
334                 //      e.onClickEntity = slist;
335                 //      slist.favoriteButton = e;
336                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Join!"), '0 0 0'));
337                         e.onClick = Join_Click;
338                         e.onClickEntity = me;
339 }
340
341 void Join_Click(entity btn, entity me)
342 {
343         localcmd("connect ", me.currentServerCName, "\n");
344 }
345
346 #endif