]> 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 mirceakitsune/preview_images
[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, sflags;
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         sflags = -1;
128         for(j = 2; j < m; ++j)
129         {
130                 if(argv(j) == "")
131                         break;
132                 k = substring(argv(j), 0, 1);
133                 v = substring(argv(j), 1, -1);
134                 if(k == "P")
135                         pure = stof(v);
136                 else if(k == "S")
137                         freeslots = stof(v);
138                 else if(k == "F")
139                         sflags = stof(v);
140         }
141
142         me.currentServerType = strzone(typestr);
143         me.typeLabel.setText(me.typeLabel, me.currentServerType);
144
145         SLIST_FIELD_MAP = gethostcacheindexforkey("map");
146         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
147         me.mapLabel.setText(me.mapLabel, me.currentServerMap);
148
149         SLIST_FIELD_PLAYERS = gethostcacheindexforkey("players");
150         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
151         me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
152
153         SLIST_FIELD_NUMHUMANS = gethostcacheindexforkey("numhumans");
154         numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
155         SLIST_FIELD_MAXPLAYERS = gethostcacheindexforkey("maxplayers");
156         maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
157         SLIST_FIELD_NUMBOTS = gethostcacheindexforkey("numbots");
158         numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
159         if(freeslots < 0)
160                 freeslots = maxp - numh - numb;
161         me.currentServerNumPlayers = strzone(sprintf(_("%d/%d, %d free player slots"), numh, maxp, freeslots));
162         me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
163
164         s = ftos(numb);
165         me.currentServerNumBots = strzone(s);
166         me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
167
168         SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
169         me.currentServerMod = strzone(gethostcachestring(SLIST_FIELD_MOD, i));
170         me.modLabel.setText(me.modLabel, me.currentServerMod);
171
172         me.currentServerVersion = strzone(versionstr);
173         me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
174
175         me.currentServerPure = ((pure < 0) ? "N/A" : (pure == 0) ? _("Official settings") : sprintf(_("%d modified settings"), pure));
176         me.currentServerPure = strzone(me.currentServerPure);
177         me.pureLabel.setText(me.pureLabel, me.currentServerPure);
178
179         SLIST_FIELD_PING = gethostcacheindexforkey("ping");
180         s = ftos(gethostcachenumber(SLIST_FIELD_PING, i));
181         me.currentServerPing = strzone(s);
182         me.pingLabel.setText(me.pingLabel, me.currentServerPing);
183
184         s = crypto_getidfp(me.currentServerCName);
185         if not(s)
186                 s = _("N/A");
187         me.currentServerID = strzone(s);
188         me.idLabel.setText(me.idLabel, me.currentServerID);
189
190         s = crypto_getkeyfp(me.currentServerCName);
191         if not(s)
192                 s = _("N/A");
193         me.currentServerKey = strzone(s);
194         me.keyLabel.setText(me.keyLabel, me.currentServerKey);
195
196         s = crypto_getencryptlevel(me.currentServerCName);
197         if(s == "")
198         {
199                 if(cvar("crypto_aeslevel") >= 3)
200                         me.currentServerEncrypt = _("N/A (can't connect)");
201                 else
202                         me.currentServerEncrypt = _("N/A");
203         }
204         else switch(stof(substring(s, 0, 1)))
205         {
206                 case 0:
207                         if(cvar("crypto_aeslevel") >= 3)
208                                 me.currentServerEncrypt = _("not supported (can't connect)");
209                         else
210                                 me.currentServerEncrypt = _("not supported (won't encrypt)");
211                         break;
212                 case 1:
213                         if(cvar("crypto_aeslevel") >= 2)
214                                 me.currentServerEncrypt = _("supported (will encrypt)");
215                         else
216                                 me.currentServerEncrypt = _("supported (won't encrypt)");
217                         break;
218                 case 2:
219                         if(cvar("crypto_aeslevel") >= 1)
220                                 me.currentServerEncrypt = _("requested (will encrypt)");
221                         else
222                                 me.currentServerEncrypt = _("requested (won't encrypt)");
223                         break;
224                 case 3:
225                         if(cvar("crypto_aeslevel") <= 0)
226                                 me.currentServerEncrypt = _("required (can't connect)");
227                         else
228                                 me.currentServerEncrypt = _("required (will encrypt)");
229                         break;
230         }
231         me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
232 }
233
234 void XonoticServerInfoDialog_fill(entity me)
235 {
236         entity e;
237         me.TR(me);
238                 me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, ""));
239                         e.colorL = SKINCOLOR_SERVERINFO_NAME;
240                         e.allowCut = 1;
241                         me.nameLabel = e;
242         me.TR(me);
243                 me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, ""));
244                         e.colorL = SKINCOLOR_SERVERINFO_IP;
245                         e.allowCut = 1;
246                         me.cnameLabel = e;
247
248         me.TR(me);
249                 me.TD(me, 1, 5.5, e = makeXonoticTextLabel(0, _("Players:")));
250         me.TR(me);
251                 me.TD(me, me.rows - 4, 6, e = makeXonoticPlayerList());
252                         me.rawPlayerList = e;
253
254         me.gotoRC(me, 1, 6.25); me.setFirstColumn(me, me.currentColumn);
255
256         me.TR(me);
257                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Type:")));
258                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
259                         e.allowCut = 1;
260                         me.typeLabel = e;
261         me.TR(me);
262                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Map:")));
263                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
264                         e.allowCut = 1;
265                         me.mapLabel = e;
266         me.TR(me);
267                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Gameplay:")));
268                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
269                         e.allowCut = 1;
270                         me.pureLabel = e;
271         me.TR(me);
272                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Players:")));
273                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
274                         e.allowCut = 1;
275                         me.numPlayersLabel = e;
276         me.TR(me);
277                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Bots:")));
278                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
279                         e.allowCut = 1;
280                         me.numBotsLabel = e;
281         me.TR(me);
282                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Mod:")));
283                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
284                         e.allowCut = 1;
285                         me.modLabel = e;
286         me.TR(me);
287                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Version:")));
288                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
289                         e.allowCut = 1;
290                         me.versionLabel = e;
291         me.TR(me);
292                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Ping:")));
293                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
294                         e.allowCut = 1;
295                         me.pingLabel = e;
296
297         me.TR(me);
298                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("CA:")));
299                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
300                         e.allowCut = 1;
301                         me.keyLabel = e;
302
303         me.TR(me);
304                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Key:")));
305                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
306                         e.allowCut = 1;
307                         me.idLabel = e;
308
309         me.TR(me);
310                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, _("Encryption:")));
311                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
312                         e.allowCut = 1;
313                         me.encryptLabel = e;
314
315         me.gotoRC(me, me.rows - 1, 0);
316
317                 me.TD(me, 1, me.columns - 6, e = makeXonoticButton(_("Close"), '0 0 0'));
318                         e.onClick = Dialog_Close;
319                         e.onClickEntity = me;
320                 me.TD(me, 1, me.columns - 6, e = makeXonoticButton(_("Join!"), '0 0 0'));
321                         e.onClick = Join_Click;
322                         e.onClickEntity = me;
323 }
324
325 void Join_Click(entity btn, entity me)
326 {
327         localcmd("connect ", me.currentServerCName, "\n");
328 }
329
330 #endif