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