]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_join_serverinfo.c
Merge remote branch 'refs/remotes/origin/terencehill/crosshair_fix'
[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         SLIST_FIELD_NAME = gethostcacheindexforkey("name");
64         me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
65         me.nameLabel.setText(me.nameLabel, me.currentServerName);
66
67         SLIST_FIELD_CNAME = gethostcacheindexforkey("cname");
68         me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
69         me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
70
71         pure = -1;
72         typestr = "N/A";
73         versionstr = "N/A";
74
75         SLIST_FIELD_QCSTATUS = gethostcacheindexforkey("qcstatus");
76         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
77         m = tokenizebyseparator(s, ":");
78         if(m >= 2)
79         {
80                 typestr = argv(0);
81                 versionstr = argv(1);
82         }
83         for(j = 2; j < m; ++j)
84         {
85                 if(argv(j) == "")
86                         break;
87                 k = substring(argv(j), 0, 1);
88                 v = substring(argv(j), 1, -1);
89                 if(k == "P")
90                         pure = stof(v);
91         }
92
93         me.currentServerType = strzone(typestr);
94         me.typeLabel.setText(me.typeLabel, me.currentServerType);
95
96         SLIST_FIELD_MAP = gethostcacheindexforkey("map");
97         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
98         me.mapLabel.setText(me.mapLabel, me.currentServerMap);
99
100         SLIST_FIELD_PLAYERS = gethostcacheindexforkey("players");
101         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
102         me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
103
104         SLIST_FIELD_NUMHUMANS = gethostcacheindexforkey("numhumans");
105         numh = ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i));
106         SLIST_FIELD_MAXPLAYERS = gethostcacheindexforkey("maxplayers");
107         maxp = ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i));
108         me.currentServerNumPlayers = strzone(strcat(numh,"/",maxp));
109         me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
110
111         SLIST_FIELD_NUMBOTS = gethostcacheindexforkey("numbots");
112         s = ftos(gethostcachenumber(SLIST_FIELD_NUMBOTS, i));
113         me.currentServerNumBots = strzone(s);
114         me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
115
116         SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
117         me.currentServerMod = strzone(gethostcachestring(SLIST_FIELD_MOD, i));
118         me.modLabel.setText(me.modLabel, me.currentServerMod);
119
120         me.currentServerVersion = strzone(versionstr);
121         me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
122
123         me.currentServerPure = ((pure < 0) ? "N/A" : (pure == 0) ? "Official settings" : sprintf("%d modified settings", pure));
124         me.pureLabel.setText(me.pureLabel, me.currentServerPure);
125
126         SLIST_FIELD_PING = gethostcacheindexforkey("ping");
127         s = ftos(gethostcachenumber(SLIST_FIELD_PING, i));
128         me.currentServerPing = strzone(s);
129         me.pingLabel.setText(me.pingLabel, me.currentServerPing);
130
131         print(me.currentServerCName, "\n");
132
133         s = crypto_getidfp(me.currentServerCName);
134         if not(s)
135                 s = "N/A";
136         me.currentServerID = strzone(s);
137         me.idLabel.setText(me.idLabel, me.currentServerID);
138
139         s = crypto_getkeyfp(me.currentServerCName);
140         if not(s)
141                 s = "N/A";
142         me.currentServerKey = strzone(s);
143         me.keyLabel.setText(me.keyLabel, me.currentServerKey);
144
145         s = crypto_getencryptlevel(me.currentServerCName);
146         if(s == "")
147         {
148                 if(cvar("crypto_aeslevel") >= 3)
149                         me.currentServerEncrypt = "N/A (can't connect)";
150                 else
151                         me.currentServerEncrypt = "N/A";
152         }
153         else switch(stof(substring(s, 0, 1)))
154         {
155                 case 0:
156                         if(cvar("crypto_aeslevel") >= 3)
157                                 me.currentServerEncrypt = "not supported (can't connect)";
158                         else
159                                 me.currentServerEncrypt = "not supported";
160                         break;
161                 case 1:
162                         me.currentServerEncrypt = "supported";
163                         break;
164                 case 2:
165                         me.currentServerEncrypt = "requested";
166                         break;
167                 case 3:
168                         if(cvar("crypto_aeslevel") <= 0)
169                                 me.currentServerEncrypt = "required (can't connect)";
170                         else
171                                 me.currentServerEncrypt = "required";
172                         break;
173         }
174         me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
175 }
176
177 void XonoticServerInfoDialog_fill(entity me)
178 {
179         entity e;
180         me.TR(me);
181                 me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, ""));
182                         e.colorL = SKINCOLOR_SERVERINFO_NAME;
183                         e.allowCut = 1;
184                         me.nameLabel = e;
185         me.TR(me);
186                 me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, ""));
187                         e.colorL = SKINCOLOR_SERVERINFO_IP;
188                         e.allowCut = 1;
189                         me.cnameLabel = e;
190
191         me.TR(me);
192                 me.TD(me, 1, 5.5, e = makeXonoticTextLabel(0, "Players:"));
193         me.TR(me);
194                 me.TD(me, me.rows - 4, 6, e = makeXonoticPlayerList());
195                         me.rawPlayerList = e;
196
197         me.gotoRC(me, 1, 6.25); me.setFirstColumn(me, me.currentColumn);
198
199         me.TR(me);
200                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Type:"));
201                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
202                         e.allowCut = 1;
203                         me.typeLabel = e;
204         me.TR(me);
205                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Map:"));
206                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
207                         e.allowCut = 1;
208                         me.mapLabel = e;
209         me.TR(me);
210                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Gameplay:"));
211                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
212                         e.allowCut = 1;
213                         me.pureLabel = e;
214         me.TR(me);
215                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Players:"));
216                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
217                         e.allowCut = 1;
218                         me.numPlayersLabel = e;
219         me.TR(me);
220                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Bots:"));
221                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
222                         e.allowCut = 1;
223                         me.numBotsLabel = e;
224         me.TR(me);
225                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Mod:"));
226                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
227                         e.allowCut = 1;
228                         me.modLabel = e;
229         me.TR(me);
230                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Version:"));
231                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
232                         e.allowCut = 1;
233                         me.versionLabel = e;
234         me.TR(me);
235                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Ping:"));
236                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
237                         e.allowCut = 1;
238                         me.pingLabel = e;
239
240         me.TR(me);
241                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "CA:"));
242                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
243                         e.allowCut = 1;
244                         me.keyLabel = e;
245
246         me.TR(me);
247                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Key:"));
248                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
249                         e.allowCut = 1;
250                         me.idLabel = e;
251
252         me.TR(me);
253                 me.TD(me, 1, 1.75, e = makeXonoticTextLabel(0, "Encryption:"));
254                 me.TD(me, 1, 4.0, e = makeXonoticTextLabel(0, ""));
255                         e.allowCut = 1;
256                         me.encryptLabel = e;
257
258         me.gotoRC(me, me.rows - 1, 0);
259
260                 me.TD(me, 1, me.columns - 6, e = makeXonoticButton("Close", '0 0 0'));
261                         e.onClick = Dialog_Close;
262                         e.onClickEntity = me;
263                 me.TD(me, 1, me.columns - 6, e = makeXonoticButton("Join!", '0 0 0'));
264                         e.onClick = Join_Click;
265                         e.onClickEntity = me;
266 }
267
268 void Join_Click(entity btn, entity me)
269 {
270         localcmd("connect ", me.currentServerCName, "\n");
271 }
272
273 #endif