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