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