]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_join_serverinfo.c
Merge remote branch 'origin/master' into morphed/hpitems
[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, 15)
9         ATTRIB(XonoticServerInfoDialog, columns, float, 12)
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, currentServerMod, string, string_null)
19         ATTRIB(XonoticServerInfoDialog, currentServerVersion, string, string_null)
20         ATTRIB(XonoticServerInfoDialog, currentServerPing, 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, modLabel, entity, NULL)
34         ATTRIB(XonoticServerInfoDialog, versionLabel, entity, NULL)
35         ATTRIB(XonoticServerInfoDialog, pingLabel, 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 float SLIST_FIELD_PING;
53 void Join_Click(entity btn, entity me);
54 #endif
55
56 #ifdef IMPLEMENTATION
57 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
58 {
59         float m, pure, freeslots, j, numh, maxp, numb;
60         string s, typestr, versionstr, k, v;
61
62         if(me.currentServerName)
63                 strunzone(me.currentServerName);
64         me.currentServerName = string_null;
65         if(me.currentServerCName)
66                 strunzone(me.currentServerCName);
67         me.currentServerCName = string_null;
68         if(me.currentServerType)
69                 strunzone(me.currentServerType);
70         me.currentServerType = string_null;
71         if(me.currentServerMap)
72                 strunzone(me.currentServerMap);
73         me.currentServerMap = string_null;
74         if(me.currentServerPlayers)
75                 strunzone(me.currentServerPlayers);
76         me.currentServerPlayers = string_null;
77         if(me.currentServerNumPlayers)
78                 strunzone(me.currentServerNumPlayers);
79         me.currentServerNumPlayers = string_null;
80         if(me.currentServerNumBots)
81                 strunzone(me.currentServerNumBots);
82         me.currentServerNumBots = string_null;
83         if(me.currentServerMod)
84                 strunzone(me.currentServerMod);
85         me.currentServerMod = string_null;
86         if(me.currentServerVersion)
87                 strunzone(me.currentServerVersion);
88         me.currentServerVersion = string_null;
89         if(me.currentServerPing)
90                 strunzone(me.currentServerPing);
91         me.currentServerPing = string_null;
92         if(me.currentServerKey)
93                 strunzone(me.currentServerKey);
94         me.currentServerKey = string_null;
95         if(me.currentServerID)
96                 strunzone(me.currentServerID);
97         me.currentServerID = string_null;
98         // not zoned!
99         //if(me.currentServerEncrypt)
100         //      strunzone(me.currentServerEncrypt);
101         //me.currentServerEncrypt = string_null;
102         if(me.currentServerPure)
103                 strunzone(me.currentServerPure);
104         me.currentServerPure = string_null;
105
106         SLIST_FIELD_NAME = gethostcacheindexforkey("name");
107         me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
108         me.nameLabel.setText(me.nameLabel, me.currentServerName);
109
110         SLIST_FIELD_CNAME = gethostcacheindexforkey("cname");
111         me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
112         me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
113
114         pure = -1;
115         typestr = _("N/A");
116         versionstr = _("N/A");
117
118         SLIST_FIELD_QCSTATUS = gethostcacheindexforkey("qcstatus");
119         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
120         m = tokenizebyseparator(s, ":");
121         if(m >= 2)
122         {
123                 typestr = argv(0);
124                 versionstr = argv(1);
125         }
126         freeslots = -1;
127         for(j = 2; j < m; ++j)
128         {
129                 if(argv(j) == "")
130                         break;
131                 k = substring(argv(j), 0, 1);
132                 v = substring(argv(j), 1, -1);
133                 if(k == "P")
134                         pure = stof(v);
135                 else if(k == "S")
136                         freeslots = stof(v);
137         }
138
139         me.currentServerType = strzone(typestr);
140         me.typeLabel.setText(me.typeLabel, me.currentServerType);
141
142         SLIST_FIELD_MAP = gethostcacheindexforkey("map");
143         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
144         me.mapLabel.setText(me.mapLabel, me.currentServerMap);
145
146         SLIST_FIELD_PLAYERS = gethostcacheindexforkey("players");
147         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
148         me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
149
150         SLIST_FIELD_NUMHUMANS = gethostcacheindexforkey("numhumans");
151         numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
152         SLIST_FIELD_MAXPLAYERS = gethostcacheindexforkey("maxplayers");
153         maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
154         SLIST_FIELD_NUMBOTS = gethostcacheindexforkey("numbots");
155         numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
156         if(freeslots < 0)
157                 freeslots = maxp - numh - numb;
158         me.currentServerNumPlayers = strzone(sprintf(_("%d/%d, %d free player slots"), numh, maxp, freeslots));
159         me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
160
161         s = ftos(numb);
162         me.currentServerNumBots = strzone(s);
163         me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
164
165         SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
166         me.currentServerMod = strzone(gethostcachestring(SLIST_FIELD_MOD, i));
167         me.modLabel.setText(me.modLabel, me.currentServerMod);
168
169         me.currentServerVersion = strzone(versionstr);
170         me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
171
172         me.currentServerPure = ((pure < 0) ? "N/A" : (pure == 0) ? _("Official settings") : sprintf(_("%d modified settings"), pure));
173         me.currentServerPure = strzone(me.currentServerPure);
174         me.pureLabel.setText(me.pureLabel, me.currentServerPure);
175
176         SLIST_FIELD_PING = gethostcacheindexforkey("ping");
177         s = ftos(gethostcachenumber(SLIST_FIELD_PING, i));
178         me.currentServerPing = strzone(s);
179         me.pingLabel.setText(me.pingLabel, me.currentServerPing);
180
181         s = crypto_getidfp(me.currentServerCName);
182         if not(s)
183                 s = _("N/A");
184         me.currentServerID = strzone(s);
185         me.idLabel.setText(me.idLabel, me.currentServerID);
186
187         s = crypto_getkeyfp(me.currentServerCName);
188         if not(s)
189                 s = _("N/A");
190         me.currentServerKey = strzone(s);
191         me.keyLabel.setText(me.keyLabel, me.currentServerKey);
192
193         s = crypto_getencryptlevel(me.currentServerCName);
194         if(s == "")
195         {
196                 if(cvar("crypto_aeslevel") >= 3)
197                         me.currentServerEncrypt = _("N/A (can't connect)");
198                 else
199                         me.currentServerEncrypt = _("N/A");
200         }
201         else switch(stof(substring(s, 0, 1)))
202         {
203                 case 0:
204                         if(cvar("crypto_aeslevel") >= 3)
205                                 me.currentServerEncrypt = _("not supported (can't connect)");
206                         else
207                                 me.currentServerEncrypt = _("not supported (won't encrypt)");
208                         break;
209                 case 1:
210                         if(cvar("crypto_aeslevel") >= 2)
211                                 me.currentServerEncrypt = _("supported (will encrypt)");
212                         else
213                                 me.currentServerEncrypt = _("supported (won't encrypt)");
214                         break;
215                 case 2:
216                         if(cvar("crypto_aeslevel") >= 1)
217                                 me.currentServerEncrypt = _("requested (will encrypt)");
218                         else
219                                 me.currentServerEncrypt = _("requested (won't encrypt)");
220                         break;
221                 case 3:
222                         if(cvar("crypto_aeslevel") <= 0)
223                                 me.currentServerEncrypt = _("required (can't connect)");
224                         else
225                                 me.currentServerEncrypt = _("required (will encrypt)");
226                         break;
227         }
228         me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
229 }
230
231 void XonoticServerInfoDialog_fill(entity me)
232 {
233         entity e;
234         me.TR(me);
235                 me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, ""));
236                         e.colorL = SKINCOLOR_SERVERINFO_NAME;
237                         e.allowCut = 1;
238                         me.nameLabel = e;
239         me.TR(me);
240                 me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, ""));
241                         e.colorL = SKINCOLOR_SERVERINFO_IP;
242                         e.allowCut = 1;
243                         me.cnameLabel = e;
244
245         me.TR(me);
246                 me.TD(me, 1, 5.5, e = makeXonoticTextLabel(0, _("Players:")));
247         me.TR(me);
248                 me.TD(me, me.rows - 4, 6, e = makeXonoticPlayerList());
249                         me.rawPlayerList = e;
250
251         me.gotoRC(me, 1, 6.25); me.setFirstColumn(me, me.currentColumn);
252
253         me.TR(me);
254                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Type:")));
255                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
256                         e.allowCut = 1;
257                         me.typeLabel = e;
258         me.TR(me);
259                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Map:")));
260                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
261                         e.allowCut = 1;
262                         me.mapLabel = e;
263         me.TR(me);
264                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Gameplay:")));
265                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
266                         e.allowCut = 1;
267                         me.pureLabel = e;
268         me.TR(me);
269                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Players:")));
270                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
271                         e.allowCut = 1;
272                         me.numPlayersLabel = e;
273         me.TR(me);
274                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Bots:")));
275                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
276                         e.allowCut = 1;
277                         me.numBotsLabel = e;
278         me.TR(me);
279                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Mod:")));
280                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
281                         e.allowCut = 1;
282                         me.modLabel = e;
283         me.TR(me);
284                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Version:")));
285                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
286                         e.allowCut = 1;
287                         me.versionLabel = e;
288         me.TR(me);
289                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Ping:")));
290                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
291                         e.allowCut = 1;
292                         me.pingLabel = e;
293
294         me.TR(me);
295                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("CA:")));
296                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
297                         e.allowCut = 1;
298                         me.keyLabel = e;
299
300         me.TR(me);
301                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Key:")));
302                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
303                         e.allowCut = 1;
304                         me.idLabel = e;
305
306         me.TR(me);
307                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Encryption:")));
308                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
309                         e.allowCut = 1;
310                         me.encryptLabel = e;
311
312         me.gotoRC(me, me.rows - 1, 0);
313
314                 me.TD(me, 1, me.columns - 6, e = makeXonoticButton(_("Close"), '0 0 0'));
315                         e.onClick = Dialog_Close;
316                         e.onClickEntity = me;
317                 me.TD(me, 1, me.columns - 6, e = makeXonoticButton(_("Join!"), '0 0 0'));
318                         e.onClick = Join_Click;
319                         e.onClickEntity = me;
320 }
321
322 void Join_Click(entity btn, entity me)
323 {
324         localcmd("connect ", me.currentServerCName, "\n");
325 }
326
327 #endif