]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_join_serverinfo.qc
Merge branch 'Juhu/lmsrot' into 'master'
[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 "tabcontroller.qh"
5 #include "serverlist.qh"
6 #include "playerlist.qh"
7 #include "inputbox.qh"
8 #include "textlabel.qh"
9 #include "button.qh"
10 #include "dialog_multiplayer_join_serverinfotab.qh"
11 #include "dialog_multiplayer_join_termsofservice.qh"
12
13
14 void XonoticServerInfoDialog_loadServerInfo(entity me, float i)
15 {
16         bool pure_available;
17         float m, pure_violations, freeslots, numh, maxp, numb, sflags;
18         string s, typestr, versionstr, k, v, modname;
19
20         // ====================================
21         //  First clear and unzone the strings
22         // ====================================
23         strfree(me.currentServerName);
24         strfree(me.currentServerCName);
25         strfree(me.currentServerType);
26         strfree(me.currentServerMap);
27         strfree(me.currentServerPlayers);
28         strfree(me.currentServerNumPlayers);
29         strfree(me.currentServerNumBots);
30         strfree(me.currentServerNumFreeSlots);
31         strfree(me.currentServerMod);
32         strfree(me.currentServerVersion);
33         // not zoned!
34         //      strfree(me.currentServerEncrypt);
35         strfree(me.currentServerPure);
36         strfree(me.currentServerKey);
37         strfree(me.currentServerID);
38
39         // ==========================
40         //  Now, fill in the strings
41         // ==========================
42         me.currentServerName = strzone(gethostcachestring(SLIST_FIELD_NAME, i));
43         me.infoTab.nameLabel.setText(me.infoTab.nameLabel, me.currentServerName);
44
45         me.currentServerCName = strzone(gethostcachestring(SLIST_FIELD_CNAME, i));
46         me.infoTab.cnameLabel.setText(me.infoTab.cnameLabel, me.currentServerCName);
47
48         pure_available = false;
49         pure_violations = -1;
50         typestr = _("N/A");
51         versionstr = _("N/A");
52
53         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
54         m = tokenizebyseparator(s, ":");
55         if(m >= 2)
56         {
57                 typestr = argv(0);
58                 versionstr = argv(1);
59         }
60         freeslots = -1;
61         sflags = -1;
62         modname = "";
63         bool ToSSpecified = false;
64         for(int j = 2; j < m; ++j)
65         {
66                 if(argv(j) == "")
67                         break;
68                 k = substring(argv(j), 0, 1);
69                 v = substring(argv(j), 1, -1);
70                 if(k == "P")
71                 {
72                         pure_available = true;
73                         pure_violations = stof(v);
74                 }
75                 else if(k == "S")
76                 {
77                         freeslots = stof(v);
78                 }
79                 else if(k == "F")
80                 {
81                         sflags = stof(v);
82                 }
83                 else if(k == "M")
84                 {
85                         modname = v;
86                 }
87                 else if(k == "T")
88                 {
89                         ToSSpecified = true;
90                         string downloadurl = v;
91                         LOG_INFOF("SERVERTOS DOWNLOADURL: %s", downloadurl);
92                         if (downloadurl == "INVALID")
93                         {
94                                 me.ToSTab.textBox.setText(me.ToSTab.textBox, _("No Terms of Service specified"));
95                         }
96                         else
97                         {
98                                 downloadurl = strreplace("|", ":", downloadurl);
99                                 me.ToSTab.loadToS(me.ToSTab, downloadurl);
100                         }
101                 }
102         }
103
104         if (!ToSSpecified)
105         {
106                 me.ToSTab.textBox.setText(me.ToSTab.textBox, _("No Terms of Service specified"));
107         }
108
109 #ifdef COMPAT_NO_MOD_IS_XONOTIC
110         if(modname == "")
111                 modname = "Xonotic";
112 #endif
113
114         s = gethostcachestring(SLIST_FIELD_MOD, i);
115         if(s != "data")
116                 modname = sprintf("%s (%s)", modname, s);
117
118         Gametype j = MapInfo_Type_FromString(typestr, false); // try and get the real name of the game type
119         if(j) { typestr = MapInfo_Type_ToText(j); } // only set it if we actually found it
120
121         me.currentServerType = strzone(typestr);
122         me.infoTab.typeLabel.setText(me.infoTab.typeLabel, me.currentServerType);
123
124         me.currentServerMap = strzone(gethostcachestring(SLIST_FIELD_MAP, i));
125         me.infoTab.mapLabel.setText(me.infoTab.mapLabel, me.currentServerMap);
126
127         me.currentServerPlayers = strzone(gethostcachestring(SLIST_FIELD_PLAYERS, i));
128         me.infoTab.rawPlayerList.setPlayerList(me.infoTab.rawPlayerList, me.currentServerPlayers);
129
130         numh = gethostcachenumber(SLIST_FIELD_NUMHUMANS, i);
131         maxp = gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i);
132         numb = gethostcachenumber(SLIST_FIELD_NUMBOTS, i);
133         me.currentServerNumPlayers = strzone(sprintf("%d/%d", numh, maxp));
134         me.infoTab.numPlayersLabel.setText(me.infoTab.numPlayersLabel, me.currentServerNumPlayers);
135
136         s = ftos(numb);
137         me.currentServerNumBots = strzone(s);
138         me.infoTab.numBotsLabel.setText(me.infoTab.numBotsLabel, me.currentServerNumBots);
139
140         if(freeslots < 0) { freeslots = maxp - numh - numb; }
141         s = ftos(freeslots);
142         me.currentServerNumFreeSlots = strzone(s);
143         me.infoTab.numFreeSlotsLabel.setText(me.infoTab.numFreeSlotsLabel, me.currentServerNumFreeSlots);
144
145         me.currentServerMod = ((modname == "Xonotic") ? ZCTX(_("MOD^Default")) : modname);
146         me.currentServerMod = strzone(me.currentServerMod);
147         me.infoTab.modLabel.setText(me.infoTab.modLabel, me.currentServerMod);
148
149         me.currentServerVersion = strzone(versionstr);
150         me.infoTab.versionLabel.setText(me.infoTab.versionLabel, me.currentServerVersion);
151
152         me.currentServerPure = ((!pure_available) ? _("N/A") : (pure_violations == 0) ? _("Official") : sprintf(_("%d modified"), pure_violations));
153         me.currentServerPure = strzone(me.currentServerPure);
154         me.infoTab.pureLabel.setText(me.infoTab.pureLabel, me.currentServerPure);
155
156         s = crypto_getencryptlevel(me.currentServerCName);
157         if(s == "")
158         {
159                 if(cvar("crypto_aeslevel") >= 3)
160                         me.currentServerEncrypt = _("N/A (auth library missing, can't connect)");
161                 else
162                         me.currentServerEncrypt = _("N/A (auth library missing)");
163         }
164         else switch(stof(substring(s, 0, 1)))
165         {
166                 case 0:
167                         if(cvar("crypto_aeslevel") >= 3)
168                                 me.currentServerEncrypt = _("Not supported (can't connect)");
169                         else
170                                 me.currentServerEncrypt = _("Not supported (won't encrypt)");
171                         break;
172                 case 1:
173                         if(cvar("crypto_aeslevel") >= 2)
174                                 me.currentServerEncrypt = _("Supported (will encrypt)");
175                         else
176                                 me.currentServerEncrypt = _("Supported (won't encrypt)");
177                         break;
178                 case 2:
179                         if(cvar("crypto_aeslevel") >= 1)
180                                 me.currentServerEncrypt = _("Requested (will encrypt)");
181                         else
182                                 me.currentServerEncrypt = _("Requested (won't encrypt)");
183                         break;
184                 case 3:
185                         if(cvar("crypto_aeslevel") <= 0)
186                                 me.currentServerEncrypt = _("Required (can't connect)");
187                         else
188                                 me.currentServerEncrypt = _("Required (will encrypt)");
189                         break;
190         }
191         me.infoTab.encryptLabel.setText(me.infoTab.encryptLabel, me.currentServerEncrypt);
192         setZonedTooltip(me.infoTab.encryptLabel, _("Use the `crypto_aeslevel` cvar to change your preferences"), string_null);
193
194         s = crypto_getidfp(me.currentServerCName);
195         if (!s) { s = _("N/A"); }
196         me.currentServerID = strzone(s);
197         me.infoTab.idLabel.setText(me.infoTab.idLabel, me.currentServerID);
198
199         s = crypto_getkeyfp(me.currentServerCName);
200         if (!s) { s = _("N/A"); }
201         me.currentServerKey = strzone(s);
202         me.infoTab.keyLabel.setText(me.infoTab.keyLabel, me.currentServerKey);
203
204         me.currentServerStatsStatus = ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? ((sflags & SERVERFLAG_PLAYERSTATS_CUSTOM) ? _("custom stats server") : _("stats enabled")) : _("stats disabled"));
205         me.currentServerStatsStatus = strzone(me.currentServerStatsStatus);
206         me.infoTab.statsLabel.setText(me.infoTab.statsLabel, me.currentServerStatsStatus);
207 }
208
209 void XonoticServerInfoDialog_fill(entity me)
210 {
211         entity mc, e;
212         mc = makeXonoticTabController(me.rows - 2);
213         me.TR(me);
214                 me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Status"), me.infoTab = makeXonoticServerInfoTab()));
215                 me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Terms of Service"), me.ToSTab = makeXonoticServerToSTab()));
216
217         me.TR(me);
218                 me.TD(me, me.rows - 2, me.columns, mc);
219
220         me.gotoRC(me, me.rows - 1, 0);
221                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Close"), '0 0 0'));
222                         e.onClick = Dialog_Close;
223                         e.onClickEntity = me;
224                 //me.TD(me, 1, me.columns/3, e = makeXonoticButton("", '0 0 0')); // TODO: Add bookmark button here
225                 //      e.onClick = ServerList_Favorite_Click;
226                 //      e.onClickEntity = slist;
227                 //      slist.favoriteButton = e;
228                 me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Join!"), '0 0 0'));
229                         e.onClick = Join_Click;
230                         e.onClickEntity = me;
231 }
232
233 void Join_Click(entity btn, entity me)
234 {
235         localcmd("connect ", me.currentServerCName, "\n");
236 }
237