]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_join_serverinfo.qc
baeb9a51bcbf127d14f8dc89acb36b6814ab5901
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_join_serverinfo.qc
1 #include "dialog_multiplayer_join_serverinfo.qh"
2 #include <common/mapinfo.qh>
3
4 #include "serverlist.qh"
5 #include "playerlist.qh"
6 #include "inputbox.qh"
7 #include "textlabel.qh"
8 #include "button.qh"
9
10 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
11 {
12         bool pure_available;
13         float m, pure_violations, freeslots, numh, maxp, numb, sflags;
14         string s, typestr, versionstr, k, v, modname;
15
16         // ====================================
17         //  First clear and unzone the strings
18         // ====================================
19         if(me.currentServerName)
20                 strunzone(me.currentServerName);
21         me.currentServerName = string_null;
22
23         if(me.currentServerCName)
24                 strunzone(me.currentServerCName);
25         me.currentServerCName = string_null;
26
27         if(me.currentServerType)
28                 strunzone(me.currentServerType);
29         me.currentServerType = string_null;
30
31         if(me.currentServerMap)
32                 strunzone(me.currentServerMap);
33         me.currentServerMap = string_null;
34
35         if(me.currentServerPlayers)
36                 strunzone(me.currentServerPlayers);
37         me.currentServerPlayers = string_null;
38
39         if(me.currentServerNumPlayers)
40                 strunzone(me.currentServerNumPlayers);
41         me.currentServerNumPlayers = string_null;
42
43         if(me.currentServerNumBots)
44                 strunzone(me.currentServerNumBots);
45         me.currentServerNumBots = string_null;
46
47         if(me.currentServerNumFreeSlots)
48                 strunzone(me.currentServerNumFreeSlots);
49         me.currentServerNumFreeSlots = string_null;
50
51         if(me.currentServerMod)
52                 strunzone(me.currentServerMod);
53         me.currentServerMod = string_null;
54
55         if(me.currentServerVersion)
56                 strunzone(me.currentServerVersion);
57         me.currentServerVersion = string_null;
58
59         // not zoned!
60         //if(me.currentServerEncrypt)
61         //      strunzone(me.currentServerEncrypt);
62         //me.currentServerEncrypt = string_null;
63         if(me.currentServerPure)
64                 strunzone(me.currentServerPure);
65         me.currentServerPure = string_null;
66
67         if(me.currentServerKey)
68                 strunzone(me.currentServerKey);
69         me.currentServerKey = string_null;
70
71         if(me.currentServerID)
72                 strunzone(me.currentServerID);
73         me.currentServerID = string_null;
74
75         // ==========================
76         //  Now, fill in the strings
77         // ==========================
78         me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
79         me.nameLabel.setText(me.nameLabel, me.currentServerName);
80
81         me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
82         me.cnameLabel.setText(me.cnameLabel, me.currentServerCName);
83
84         pure_available = false;
85         pure_violations = -1;
86         typestr = _("N/A");
87         versionstr = _("N/A");
88
89         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
90         m = tokenizebyseparator(s, ":");
91         if(m >= 2)
92         {
93                 typestr = argv(0);
94                 versionstr = argv(1);
95         }
96         freeslots = -1;
97         sflags = -1;
98         modname = "";
99         for(int j = 2; j < m; ++j)
100         {
101                 if(argv(j) == "")
102                         break;
103                 k = substring(argv(j), 0, 1);
104                 v = substring(argv(j), 1, -1);
105                 if(k == "P")
106                 {
107                         pure_available = true;
108                         pure_violations = stof(v);
109                 }
110                 else if(k == "S")
111                         freeslots = stof(v);
112                 else if(k == "F")
113                         sflags = stof(v);
114                 else if(k == "M")
115                         modname = v;
116         }
117
118 #ifdef COMPAT_NO_MOD_IS_XONOTIC
119         if(modname == "")
120                 modname = "Xonotic";
121 #endif
122
123         s = gethostcachestring(SLIST_FIELD_MOD, i);
124         if(s != "data")
125                 modname = sprintf("%s (%s)", modname, s);
126
127         Gametype j = MapInfo_Type_FromString(typestr); // try and get the real name of the game type
128         if(j) { typestr = MapInfo_Type_ToText(j); } // only set it if we actually found it
129
130         me.currentServerType = strzone(typestr);
131         me.typeLabel.setText(me.typeLabel, me.currentServerType);
132
133         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
134         me.mapLabel.setText(me.mapLabel, me.currentServerMap);
135
136         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
137         me.rawPlayerList.setPlayerList(me.rawPlayerList, me.currentServerPlayers);
138
139         numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
140         maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
141         numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
142         me.currentServerNumPlayers = strzone(sprintf("%d/%d", numh, maxp));
143         me.numPlayersLabel.setText(me.numPlayersLabel, me.currentServerNumPlayers);
144
145         s = ftos(numb);
146         me.currentServerNumBots = strzone(s);
147         me.numBotsLabel.setText(me.numBotsLabel, me.currentServerNumBots);
148
149         if(freeslots < 0) { freeslots = maxp - numh - numb; }
150         s = ftos(freeslots);
151         me.currentServerNumFreeSlots = strzone(s);
152         me.numFreeSlotsLabel.setText(me.numFreeSlotsLabel, me.currentServerNumFreeSlots);
153
154         me.currentServerMod = ((modname == "Xonotic") ? ZCTX(_("MOD^Default")) : modname);
155         me.currentServerMod = strzone(me.currentServerMod);
156         me.modLabel.setText(me.modLabel, me.currentServerMod);
157
158         me.currentServerVersion = strzone(versionstr);
159         me.versionLabel.setText(me.versionLabel, me.currentServerVersion);
160
161         me.currentServerPure = ((!pure_available) ? _("N/A") : (pure_violations == 0) ? _("Official") : sprintf(_("%d modified"), pure_violations));
162         me.currentServerPure = strzone(me.currentServerPure);
163         me.pureLabel.setText(me.pureLabel, me.currentServerPure);
164
165         s = crypto_getencryptlevel(me.currentServerCName);
166         if(s == "")
167         {
168                 if(cvar("crypto_aeslevel") >= 3)
169                         me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
170                 else
171                         me.currentServerEncrypt = _("N/A (auth library missing)");
172         }
173         else switch(stof(substring(s, 0, 1)))
174         {
175                 case 0:
176                         if(cvar("crypto_aeslevel") >= 3)
177                                 me.currentServerEncrypt = _("Not supported (can't connect)");
178                         else
179                                 me.currentServerEncrypt = _("Not supported (won't encrypt)");
180                         break;
181                 case 1:
182                         if(cvar("crypto_aeslevel") >= 2)
183                                 me.currentServerEncrypt = _("Supported (will encrypt)");
184                         else
185                                 me.currentServerEncrypt = _("Supported (won't encrypt)");
186                         break;
187                 case 2:
188                         if(cvar("crypto_aeslevel") >= 1)
189                                 me.currentServerEncrypt = _("Requested (will encrypt)");
190                         else
191                                 me.currentServerEncrypt = _("Requested (won't encrypt)");
192                         break;
193                 case 3:
194                         if(cvar("crypto_aeslevel") <= 0)
195                                 me.currentServerEncrypt = _("Required (can't connect)");
196                         else
197                                 me.currentServerEncrypt = _("Required (will encrypt)");
198                         break;
199         }
200         me.encryptLabel.setText(me.encryptLabel, me.currentServerEncrypt);
201         setZonedTooltip(me.encryptLabel, _("Use the `crypto_aeslevel` cvar to change your preferences"), string_null);
202
203         s = crypto_getidfp(me.currentServerCName);
204         if (!s) { s = _("N/A"); }
205         me.currentServerID = strzone(s);
206         me.idLabel.setText(me.idLabel, me.currentServerID);
207
208         s = crypto_getkeyfp(me.currentServerCName);
209         if (!s) { s = _("N/A"); }
210         me.currentServerKey = strzone(s);
211         me.keyLabel.setText(me.keyLabel, me.currentServerKey);
212 }
213
214 void XonoticServerInfoDialog_fill(entity me)
215 {
216         entity e;
217         me.TR(me);
218                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Hostname:")));
219                 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
220                 e.colorL = SKINCOLOR_SERVERINFO_NAME;
221                 e.allowCut = 1;
222                 me.nameLabel = e;
223         me.TR(me);
224                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Address:")));
225                 me.TD(me, 1, 4.6, e = makeXonoticTextLabel(0.5, ""));
226                 e.colorL = SKINCOLOR_SERVERINFO_IP;
227                 e.allowCut = 1;
228                 me.cnameLabel = e;
229
230         me.TR(me);
231         me.TR(me);
232                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Gametype:")));
233                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
234                 e.allowCut = 1;
235                 me.typeLabel = e;
236         me.TR(me);
237                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Map:")));
238                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
239                 e.allowCut = 1;
240                 me.mapLabel = e;
241         me.TR(me);
242                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Mod:")));
243                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
244                 e.allowCut = 1;
245                 me.modLabel = e;
246         me.TR(me);
247                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Version:")));
248                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
249                 e.allowCut = 1;
250                 me.versionLabel = e;
251         me.TR(me);
252                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Settings:")));
253                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
254                 e.allowCut = 1;
255                 me.pureLabel = e;
256
257         me.TR(me);
258         me.TR(me);
259                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Players:")));
260                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
261                 e.allowCut = 1;
262                 me.numPlayersLabel = e;
263         me.TR(me);
264                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Bots:")));
265                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
266                 e.allowCut = 1;
267                 me.numBotsLabel = e;
268         me.TR(me);
269                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Free slots:")));
270                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, ""));
271                 e.allowCut = 1;
272                 me.numFreeSlotsLabel = e;
273
274         me.gotoRC(me, me.rows - 5, 0);
275                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Encryption:")));
276                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
277                         e.allowCut = 1;
278                         me.encryptLabel = e;
279         me.TR(me);
280                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("ID:")));
281                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
282                         e.allowCut = 1;
283                         me.keyLabel = e;
284         me.TR(me);
285                 me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Key:")));
286                 me.TD(me, 1, 5.4, e = makeXonoticTextLabel(0, ""));
287                         e.allowCut = 1;
288                         me.idLabel = e;
289
290         me.gotoRC(me, 2, 2.2); me.setFirstColumn(me, me.currentColumn);
291                 me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Players:")));
292         me.TR(me);
293                 me.TD(me, me.rows - 8, 4, e = makeXonoticPlayerList());
294                         me.rawPlayerList = e;
295
296         me.gotoRC(me, me.rows - 1, 0);
297                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Close"), '0 0 0'));
298                         e.onClick = Dialog_Close;
299                         e.onClickEntity = me;
300                 //me.TD(me, 1, me.columns/3, e = makeXonoticButton("", '0 0 0')); // TODO: Add bookmark button here
301                 //      e.onClick = ServerList_Favorite_Click;
302                 //      e.onClickEntity = slist;
303                 //      slist.favoriteButton = e;
304                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Join!"), '0 0 0'));
305                         e.onClick = Join_Click;
306                         e.onClickEntity = me;
307 }
308
309 void Join_Click(entity btn, entity me)
310 {
311         localcmd("connect ", me.currentServerCName, "\n");
312 }