]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/serverlist.qc
Merge branch 'master' into DefaultUser/func_button_relay
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / serverlist.qc
1 #include "serverlist.qh"
2
3 #include "checkbox.qh"
4 #include "inputbox.qh"
5 #include "mainwindow.qh"
6 #include "dialog_multiplayer_join_serverinfo.qh"
7 #include <common/mapinfo.qh>
8
9 void RegisterSLCategories()
10 {
11         entity cat;
12         #define SLIST_CATEGORY(name,enoverride,dioverride,str) \
13                 SET_FIELD_COUNT(name, CATEGORY_FIRST, category_ent_count) \
14                 CHECK_MAX_COUNT(name, MAX_CATEGORIES, category_ent_count, "SLIST_CATEGORY") \
15                 cat = categories[name - 1] = new(slist_category); \
16                 cat.cat_name = #name; \
17                 cat.cat_enoverride_string = strzone(SLIST_CATEGORY_AUTOCVAR(name)); \
18                 cat.cat_dioverride_string = strzone(dioverride); \
19                 cat.cat_string = strzone(str);
20         SLIST_CATEGORIES
21         #undef SLIST_CATEGORY
22
23         int i, x, catnum;
24         string s;
25
26         #define PROCESS_OVERRIDE(override_string,override_field) \
27                 for(i = 0; i < category_ent_count; ++i) \
28                 { \
29                         s = categories[i].override_string; \
30                         if((s != "") && (s != categories[i].cat_name)) \
31                         { \
32                                 catnum = 0; \
33                                 for(x = 0; x < category_ent_count; ++x) \
34                                 { if(categories[x].cat_name == s) { \
35                                         catnum = (x+1); \
36                                         break; \
37                                 } } \
38                                 if(catnum) \
39                                 { \
40                                         strfree(categories[i].override_string); \
41                                         categories[i].override_field = catnum; \
42                                         continue; \
43                                 } \
44                                 else \
45                                 { \
46                                         LOG_INFOF( \
47                                                 "RegisterSLCategories(): Improper override '%s' for category '%s'!", \
48                                                 s, \
49                                                 categories[i].cat_name \
50                                         ); \
51                                 } \
52                         } \
53                         strfree(categories[i].override_string); \
54                         categories[i].override_field = 0; \
55                 }
56         PROCESS_OVERRIDE(cat_enoverride_string, cat_enoverride)
57         PROCESS_OVERRIDE(cat_dioverride_string, cat_dioverride)
58         #undef PROCESS_OVERRIDE
59 }
60
61 // Supporting Functions
62 entity RetrieveCategoryEnt(int catnum)
63 {
64         if((catnum > 0) && (catnum <= category_ent_count))
65         {
66                 return categories[catnum - 1];
67         }
68         else
69         {
70                 error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum));
71                 return NULL;
72         }
73 }
74
75 bool IsServerInList(string list, string srv)
76 {
77         string p;
78         int i, n;
79         if(srv == "")
80                 return false;
81         srv = netaddress_resolve(srv, 26000);
82         if(srv == "")
83                 return false;
84         p = crypto_getidfp(srv);
85         n = tokenize_console(list);
86         for(i = 0; i < n; ++i)
87         {
88                 if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0)
89                 {
90                         if(p)
91                                 if(argv(i) == p)
92                                         return true;
93                 }
94                 else
95                 {
96                         if(srv == netaddress_resolve(argv(i), 26000))
97                                 return true;
98                 }
99         }
100         return false;
101 }
102
103 int CheckCategoryOverride(int cat)
104 {
105         entity catent = RetrieveCategoryEnt(cat);
106         if(catent)
107         {
108                 int override = (autocvar_menu_slist_categories ? catent.cat_enoverride : catent.cat_dioverride);
109                 if(override) { return override; }
110                 else { return cat; }
111         }
112         else
113         {
114                 error(sprintf("CheckCategoryOverride(%d): Improper category number!\n", cat));
115                 return cat;
116         }
117 }
118
119 int CheckCategoryForEntry(int entry)
120 {
121         string s, k, v, modtype = "";
122         int j, m, impure = 0, freeslots = 0, sflags = 0;
123         s = gethostcachestring(SLIST_FIELD_QCSTATUS, entry);
124         m = tokenizebyseparator(s, ":");
125
126         for(j = 2; j < m; ++j)
127         {
128                 if(argv(j) == "") { break; }
129                 k = substring(argv(j), 0, 1);
130                 v = substring(argv(j), 1, -1);
131                 switch(k)
132                 {
133                         case "P": { impure = stof(v); break; }
134                         case "S": { freeslots = stof(v); break; }
135                         case "F": { sflags = stof(v); break; }
136                         case "M": { modtype = strtolower(v); break; }
137                 }
138         }
139
140         if(modtype != "xonotic") { impure += autocvar_menu_slist_modimpurity; }
141
142         // check if this server is favorited
143         if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, entry)) { return CAT_FAVORITED; }
144
145         // now check if it's recommended
146         if(autocvar_menu_slist_recommendations)
147         {
148                 string cname = gethostcachestring(SLIST_FIELD_CNAME, entry);
149
150                 if(IsPromoted(cname)) { return CAT_RECOMMENDED; }
151                 else
152                 {
153                         float recommended = 0;
154                         if(autocvar_menu_slist_recommendations & 1)
155                         {
156                                 if(IsRecommended(cname)) { ++recommended; }
157                                 else { --recommended; }
158                         }
159                         if(autocvar_menu_slist_recommendations & 2)
160                         {
161                                 if(
162                                         ///// check for minimum free slots
163                                         (freeslots >= autocvar_menu_slist_recommendations_minfreeslots)
164
165                                         && // check for purity requirement
166                                         (
167                                                 (autocvar_menu_slist_recommendations_purethreshold < 0)
168                                                 ||
169                                                 (impure <= autocvar_menu_slist_recommendations_purethreshold)
170                                         )
171
172                                         && // check for minimum amount of humans
173                                         (
174                                                 gethostcachenumber(SLIST_FIELD_NUMHUMANS, entry)
175                                                 >=
176                                                 autocvar_menu_slist_recommendations_minhumans
177                                         )
178
179                                         && // check for maximum latency
180                                         (
181                                                 gethostcachenumber(SLIST_FIELD_PING, entry)
182                                                 <=
183                                                 autocvar_menu_slist_recommendations_maxping
184                                         )
185                                 )
186                                         { ++recommended; }
187                                 else
188                                         { --recommended; }
189                         }
190                         if(recommended > 0) { return CAT_RECOMMENDED; }
191                 }
192         }
193
194         // if not favorited or recommended, check modname
195         if(modtype != "xonotic")
196         {
197                 switch(modtype)
198                 {
199                         // old servers which don't report their mod name are considered modified now
200                         case "": { return CAT_MODIFIED; }
201
202                         case "xpm": { return CAT_XPM; }
203                         case "minstagib":
204                         case "instagib": { return CAT_INSTAGIB; }
205                         case "overkill": { return CAT_OVERKILL; }
206                         //case "nix": { return CAT_NIX; }
207                         //case "newtoys": { return CAT_NEWTOYS; }
208
209                         // "cts" is allowed as compat, xdf is replacement
210                         case "cts":
211                         case "xdf": { return CAT_DEFRAG; }
212
213                         default: { LOG_TRACEF("Found strange mod type: %s", modtype); return CAT_MODIFIED; }
214                 }
215         }
216
217         // must be normal or impure server
218         return ((impure > autocvar_menu_slist_purethreshold) ? CAT_MODIFIED : CAT_NORMAL);
219 }
220
221 METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string srv))
222 {
223         bool adding = true;
224         string srv_resolved = netaddress_resolve(srv, 26000);
225         string p = crypto_getidfp(srv_resolved);
226         string s = cvar_string("net_slist_favorites");
227         string ret = s;
228         for (int i = 0, n = tokenize_console(s); i < n; ++i)
229         {
230                 bool match;
231                 if (substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0)
232                 {
233                         // it's a pubkey hash
234                         match = (p && p == argv(i));
235                 }
236                 else
237                 {
238                         // it's an ip
239                         match = (srv_resolved == netaddress_resolve(argv(i), 26000));
240                 }
241                 if (!match) continue;
242                 // on match: remove
243                 adding = false;
244                 string before = (i > 0) ? substring(s, 0, argv_end_index(i - 1)) : "";
245                 string after = (i < n - 1) ? substring(s, argv_start_index(i + 1), -1) : "";
246                 s = strcat(before, (before != "" && after != "" ? " " : ""), after);
247                 ret = s;
248                 // keep searching
249                 // TODO: why not break here?
250                 n = tokenize_console(s);
251                 --i; // offset the increment that is about to happen
252         }
253         if (adding)
254         {
255                 ret = strcat(s, (s != "" ? " " : ""), p ? p : srv);
256         }
257         cvar_set("net_slist_favorites", ret);
258         this.refreshServerList(this, REFRESHSERVERLIST_RESORT);
259 }
260
261 void ServerList_Update_favoriteButton(entity btn, entity me)
262 {
263         entity e = me.favoriteButton;
264         if(IsFavorite(me.ipAddressBox.text))
265         {
266                 e.setText(e, _("Remove"));
267                 clearTooltip(e);
268         }
269         else
270         {
271                 e.setText(e, _("Favorite"));
272                 setZonedTooltip(e, _("Bookmark the currently highlighted server so that it's faster to find in the future"), string_null);
273         }
274 }
275
276 entity makeXonoticServerList()
277 {
278         entity me;
279         me = NEW(XonoticServerList);
280         me.configureXonoticServerList(me);
281         return me;
282 }
283 void XonoticServerList_configureXonoticServerList(entity me)
284 {
285         me.configureXonoticListBox(me);
286
287         // update field ID's
288         #define SLIST_FIELD(suffix,name) SLIST_FIELD_##suffix = gethostcacheindexforkey(name);
289         SLIST_FIELDS
290         #undef SLIST_FIELD
291
292         // clear list
293         me.nItems = 0;
294 }
295 void XonoticServerList_setSelected(entity me, int i)
296 {
297         me.lockedSelectedItem = false;
298         //int save = me.selectedItem;
299         SUPER(XonoticServerList).setSelected(me, i);
300         /*
301         if(me.selectedItem == save)
302                 return;
303         */
304         if(me.nItems == 0)
305                 return;
306         if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems)
307                 return; // sorry, it would be wrong
308
309         strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
310
311         me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
312         me.ipAddressBox.cursorPos = strlen(me.selectedServer);
313         me.ipAddressBoxFocused = -1;
314 }
315 void XonoticServerList_refreshServerList(entity me, int mode)
316 {
317         //print("refresh of type ", ftos(mode), "\n");
318
319         if(mode >= REFRESHSERVERLIST_REFILTER)
320         {
321                 float m;
322                 int i, n;
323                 int listflags = 0;
324                 string s, typestr, modstr;
325
326                 s = me.filterString;
327
328                 m = strstrofs(s, ":", 0);
329                 if(m >= 0)
330                 {
331                         typestr = substring(s, 0, m);
332                         s = substring(s, m + 1, strlen(s) - m - 1);
333                         while(substring(s, 0, 1) == " ")
334                                 s = substring(s, 1, strlen(s) - 1);
335                 }
336                 else
337                         typestr = "";
338
339                 modstr = cvar_string("menu_slist_modfilter");
340
341                 m = SLIST_MASK_AND - 1;
342                 resethostcachemasks();
343
344                 // ping: reject negative ping (no idea why this happens in the first place, engine bug)
345                 sethostcachemasknumber(++m, SLIST_FIELD_PING, 0, SLIST_TEST_GREATEREQUAL);
346
347                 // show full button
348                 if(!me.filterShowFull)
349                 {
350                         sethostcachemasknumber(++m, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); // legacy
351                         sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, ":S0:", SLIST_TEST_NOTCONTAIN); // g_maxplayers support
352                 }
353
354                 // show empty button
355                 if(!me.filterShowEmpty)
356                         sethostcachemasknumber(++m, SLIST_FIELD_NUMHUMANS, 1, SLIST_TEST_GREATEREQUAL);
357
358                 // gametype filtering
359                 if(typestr != "")
360                         sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(typestr, ":"), SLIST_TEST_STARTSWITH);
361
362                 // mod filtering
363                 if(modstr != "")
364                 {
365                         if(substring(modstr, 0, 1) == "!")
366                                 sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(substring(modstr, 1, strlen(modstr) - 1)), SLIST_TEST_NOTEQUAL);
367                         else
368                                 sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(modstr), SLIST_TEST_EQUAL);
369                 }
370
371                 // server banning
372                 n = tokenizebyseparator(_Nex_ExtResponseSystem_BannedServers, " ");
373                 for(i = 0; i < n; ++i)
374                         if(argv(i) != "")
375                                 sethostcachemaskstring(++m, SLIST_FIELD_CNAME, argv(i), SLIST_TEST_NOTSTARTSWITH);
376
377                 m = SLIST_MASK_OR - 1;
378                 if(s != "")
379                 {
380                         sethostcachemaskstring(++m, SLIST_FIELD_NAME, s, SLIST_TEST_CONTAINS);
381                         sethostcachemaskstring(++m, SLIST_FIELD_MAP, s, SLIST_TEST_CONTAINS);
382                         sethostcachemaskstring(++m, SLIST_FIELD_PLAYERS, s, SLIST_TEST_CONTAINS);
383                         sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(s, ":"), SLIST_TEST_STARTSWITH);
384                 }
385
386                 // sorting flags
387                 //listflags |= SLSF_FAVORITES;
388                 listflags |= SLSF_CATEGORIES;
389                 if(me.currentSortOrder < 0) { listflags |= SLSF_DESCENDING; }
390                 sethostcachesort(me.currentSortField, listflags);
391         }
392
393         resorthostcache();
394         if(mode >= REFRESHSERVERLIST_ASK)
395                 refreshhostcache(mode >= REFRESHSERVERLIST_RESET);
396 }
397 void XonoticServerList_focusEnter(entity me)
398 {
399         SUPER(XonoticServerList).focusEnter(me);
400         if(time < me.nextRefreshTime)
401         {
402                 //print("sorry, no refresh yet\n");
403                 return;
404         }
405         me.nextRefreshTime = time + 10;
406         me.refreshServerList(me, REFRESHSERVERLIST_ASK);
407 }
408
409 void XonoticServerList_draw(entity me)
410 {
411         int i;
412         bool found = false, owned;
413
414         if(_Nex_ExtResponseSystem_BannedServersNeedsRefresh)
415         {
416                 if(!me.needsRefresh)
417                         me.needsRefresh = 2;
418                 _Nex_ExtResponseSystem_BannedServersNeedsRefresh = 0;
419         }
420
421         if(_Nex_ExtResponseSystem_PromotedServersNeedsRefresh)
422         {
423                 if(!me.needsRefresh)
424                         me.needsRefresh = 3;
425                 _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 0;
426         }
427
428         if(_Nex_ExtResponseSystem_RecommendedServersNeedsRefresh)
429         {
430                 if(!me.needsRefresh)
431                         me.needsRefresh = 3;
432                 _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 0;
433         }
434
435         if(me.currentSortField == -1)
436         {
437                 me.setSortOrder(me, SLIST_FIELD_PING, +1);
438                 me.refreshServerList(me, REFRESHSERVERLIST_RESET);
439         }
440         else if(me.needsRefresh == 1)
441         {
442                 me.needsRefresh = 2; // delay by one frame to make sure "slist" has been executed
443         }
444         else if(me.needsRefresh == 2)
445         {
446                 me.needsRefresh = 0;
447                 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
448         }
449         else if(me.needsRefresh == 3)
450         {
451                 me.needsRefresh = 0;
452                 me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
453         }
454
455         owned = ((me.selectedServer == me.ipAddressBox.text) && (me.ipAddressBox.text != ""));
456
457         for(i = 0; i < category_draw_count; ++i) { category_name[i] = -1; category_item[i] = -1; }
458         category_draw_count = 0;
459
460         if(autocvar_menu_slist_categories >= 0) // if less than 0, don't even draw a category heading for favorites
461         {
462                 float itemcount = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT);
463                 me.nItems = itemcount;
464
465                 //float visible = floor(me.scrollPos / me.itemHeight);
466                 // ^ unfortunately no such optimization can be made-- we must process through the
467                 // entire list, otherwise there is no way to know which item is first in its category.
468
469                 // binary search method suggested by div
470                 float begin = 0;
471                 for(int j = 1; j <= category_ent_count; ++j) {
472                         float first = begin;
473                         float last = (itemcount - 1);
474                         if (first > last) {
475                                 // List is empty.
476                                 break;
477                         }
478                         float catf = gethostcachenumber(SLIST_FIELD_CATEGORY, first);
479                         float catl = gethostcachenumber(SLIST_FIELD_CATEGORY, last);
480                         if (catf > j) {
481                                 // The first one is already > j.
482                                 // Therefore, category j does not exist.
483                                 // Higher numbered categories do exist though.
484                         } else if (catl < j) {
485                                 // The last one is < j.
486                                 // Thus this category - and any following -
487                                 // don't exist.
488                                 break;
489                         } else if (catf == j) {
490                                 // Starts at first. This breaks the loop
491                                 // invariant in the binary search and thus has
492                                 // to be handled separately.
493                                 if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != j)
494                                         error("Category mismatch I");
495                                 if(first > 0)
496                                         if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == j)
497                                                 error("Category mismatch II");
498                                 category_name[category_draw_count] = j;
499                                 category_item[category_draw_count] = first;
500                                 ++category_draw_count;
501                                 begin = first + 1;
502                         } else {
503                                 // At this point, catf <= j < catl, thus
504                                 // catf < catl, thus first < last.
505                                 // INVARIANTS:
506                                 // last - first >= 1
507                                 // catf == gethostcachenumber(SLIST_FIELD_CATEGORY(first)
508                                 // catl == gethostcachenumber(SLIST_FIELD_CATEGORY(last)
509                                 // catf < j
510                                 // catl >= j
511                                 while (last - first > 1) {
512                                         float middle = floor((first + last) / 2);
513                                         // By loop condition, middle != first && middle != last.
514                                         float cat = gethostcachenumber(SLIST_FIELD_CATEGORY, middle);
515                                         if (cat >= j) {
516                                                 last = middle;
517                                                 catl = cat;
518                                         } else {
519                                                 first = middle;
520                                                 catf = cat;
521                                         }
522                                 }
523                                 if (catl == j) {
524                                         if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != j)
525                                                 error("Category mismatch III");
526                                         if(last > 0)
527                                                 if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == j)
528                                                         error("Category mismatch IV");
529                                         category_name[category_draw_count] = j;
530                                         category_item[category_draw_count] = last;
531                                         ++category_draw_count;
532                                         begin = last + 1; // already scanned through these, skip 'em
533                                 }
534                                 else
535                                         begin = last; // already scanned through these, skip 'em
536                         }
537                 }
538                 if(autocvar_menu_slist_categories_onlyifmultiple && (category_draw_count == 1))
539                 {
540                         category_name[0] = -1;
541                         category_item[0] = -1;
542                         category_draw_count = 0;
543                         me.nItems = itemcount;
544                 }
545         }
546         else { me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); }
547
548         me.connectButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == ""));
549         me.disconnectButton.disabled = (!(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)));
550         me.infoButton.disabled = (me.lockedSelectedItem || me.nItems == 0 || !owned);
551         me.favoriteButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == ""));
552
553         if(me.lockedSelectedItem)
554         {
555                 if(me.nItems > 0)
556                 {
557                         if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer)
558                         {
559                                 strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
560                         }
561                         found = true;
562                 }
563         }
564         else if(me.selectedServer)
565         {
566                 for(i = 0; i < me.nItems; ++i)
567                 {
568                         if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer)
569                         {
570                                 // don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i);
571                                 me.selectedItem = i;
572                                 found = true;
573                                 break;
574                         }
575                 }
576         }
577         if(!found)
578         {
579                 if(me.nItems > 0)
580                 {
581                         // selected server disappeared, select the last server (scrolling to it)
582                         if(me.selectedItem >= me.nItems)
583                                 SUPER(XonoticServerList).setSelected(me, me.nItems - 1);
584                         strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
585                 }
586         }
587
588         if(owned)
589         {
590                 if(me.selectedServer != me.ipAddressBox.text)
591                 {
592                         me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
593                         me.ipAddressBox.cursorPos = strlen(me.selectedServer);
594                         me.ipAddressBoxFocused = -1;
595                 }
596         }
597
598         if(me.ipAddressBoxFocused != me.ipAddressBox.focused)
599         {
600                 if(me.ipAddressBox.focused || me.ipAddressBoxFocused < 0)
601                         ServerList_Update_favoriteButton(NULL, me);
602                 me.ipAddressBoxFocused = me.ipAddressBox.focused;
603         }
604
605         SUPER(XonoticServerList).draw(me);
606 }
607 void ServerList_PingSort_Click(entity btn, entity me)
608 {
609         me.setSortOrder(me, SLIST_FIELD_PING, +1);
610 }
611 void ServerList_NameSort_Click(entity btn, entity me)
612 {
613         me.setSortOrder(me, SLIST_FIELD_NAME, -1); // why?
614 }
615 void ServerList_MapSort_Click(entity btn, entity me)
616 {
617         me.setSortOrder(me, SLIST_FIELD_MAP, -1); // why?
618 }
619 void ServerList_PlayerSort_Click(entity btn, entity me)
620 {
621         me.setSortOrder(me, SLIST_FIELD_NUMHUMANS, -1);
622 }
623 void ServerList_TypeSort_Click(entity btn, entity me)
624 {
625         string s = me.filterString;
626         int m = strstrofs(s, ":", 0);
627         if(m >= 0)
628         {
629                 s = substring(s, 0, m);
630                 while(substring(s, m+1, 1) == " ") // skip spaces
631                         ++m;
632         }
633         else
634                 s = "";
635
636         Gametype first = NULL; FOREACH(Gametypes, !first, first = it; break);
637         bool flag = false;
638         FOREACH(Gametypes, s == MapInfo_Type_ToString(it), {
639                 // the type was found
640                 // choose the next one
641                 flag = true;
642                 s = MapInfo_Type_ToString(Gametypes_from(it.m_id + 1));
643                 if (s == "") s = MapInfo_Type_ToString(first);
644                 break;
645         });
646         if (!flag) {
647                 // no type was found
648                 // choose the first one
649                 s = MapInfo_Type_ToString(first);
650         }
651
652         if(s != "") s = strcat(s, ":");
653         s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1));
654
655         me.controlledTextbox.setText(me.controlledTextbox, s);
656         me.controlledTextbox.keyDown(me.controlledTextbox, K_END, 0, 0);
657         me.controlledTextbox.keyUp(me.controlledTextbox, K_END, 0, 0);
658         //ServerList_Filter_Change(me.controlledTextbox, me);
659 }
660 void ServerList_Filter_Change(entity box, entity me)
661 {
662         strfree(me.filterString);
663         if(box.text != "")
664                 me.filterString = strzone(box.text);
665         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
666
667         me.ipAddressBox.setText(me.ipAddressBox, "");
668         me.ipAddressBox.cursorPos = 0;
669         me.ipAddressBoxFocused = -1;
670 }
671 void ServerList_Categories_Click(entity box, entity me)
672 {
673         box.setChecked(box, autocvar_menu_slist_categories = !autocvar_menu_slist_categories);
674         me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
675
676         me.ipAddressBox.setText(me.ipAddressBox, "");
677         me.ipAddressBox.cursorPos = 0;
678         me.ipAddressBoxFocused = -1;
679 }
680 void ServerList_ShowEmpty_Click(entity box, entity me)
681 {
682         box.setChecked(box, me.filterShowEmpty = !me.filterShowEmpty);
683         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
684
685         me.ipAddressBox.setText(me.ipAddressBox, "");
686         me.ipAddressBox.cursorPos = 0;
687         me.ipAddressBoxFocused = -1;
688 }
689 void ServerList_ShowFull_Click(entity box, entity me)
690 {
691         box.setChecked(box, me.filterShowFull = !me.filterShowFull);
692         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
693
694         me.ipAddressBox.setText(me.ipAddressBox, "");
695         me.ipAddressBox.cursorPos = 0;
696         me.ipAddressBoxFocused = -1;
697 }
698 void XonoticServerList_setSortOrder(entity me, int fld, int direction)
699 {
700         if(me.currentSortField == fld)
701                 direction = -me.currentSortOrder;
702         me.currentSortOrder = direction;
703         me.currentSortField = fld;
704         me.sortButton1.forcePressed = (fld == SLIST_FIELD_PING);
705         me.sortButton2.forcePressed = (fld == SLIST_FIELD_NAME);
706         me.sortButton3.forcePressed = (fld == SLIST_FIELD_MAP);
707         me.sortButton4.forcePressed = 0;
708         me.sortButton5.forcePressed = (fld == SLIST_FIELD_NUMHUMANS);
709         me.selectedItem = 0;
710         strfree(me.selectedServer);
711         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
712 }
713 void XonoticServerList_positionSortButton(entity me, entity btn, float theOrigin, float theSize, string theTitle, void(entity, entity) theFunc)
714 {
715         vector originInLBSpace, sizeInLBSpace;
716         originInLBSpace = eY * (-me.itemHeight);
717         sizeInLBSpace = eY * me.itemHeight + eX * (1 - me.controlWidth);
718
719         vector originInDialogSpace, sizeInDialogSpace;
720         originInDialogSpace = boxToGlobal(originInLBSpace, me.Container_origin, me.Container_size);
721         sizeInDialogSpace = boxToGlobalSize(sizeInLBSpace, me.Container_size);
722
723         btn.Container_origin_x = originInDialogSpace.x + sizeInDialogSpace.x * theOrigin;
724         btn.Container_size_x   =                         sizeInDialogSpace.x * theSize;
725         btn.setText(btn, theTitle);
726         btn.onClick = theFunc;
727         btn.onClickEntity = me;
728         btn.resized = 1;
729 }
730 void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
731 {
732         SUPER(XonoticServerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
733
734         me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
735         me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
736         me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
737
738         me.columnIconsOrigin = 0;
739         me.columnIconsSize = me.realFontSize.x * 4 * me.iconsSizeFactor;
740         me.columnPingSize = me.realFontSize.x * 3;
741         me.columnMapSize = me.realFontSize.x * 10;
742         me.columnTypeSize = me.realFontSize.x * 4;
743         me.columnPlayersSize = me.realFontSize.x * 5;
744         me.columnNameSize = 1 - me.columnPlayersSize - me.columnMapSize - me.columnPingSize - me.columnIconsSize - me.columnTypeSize - 5 * me.realFontSize.x;
745         me.columnPingOrigin = me.columnIconsOrigin + me.columnIconsSize + me.realFontSize.x;
746         me.columnNameOrigin = me.columnPingOrigin + me.columnPingSize + me.realFontSize.x;
747         me.columnMapOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
748         me.columnTypeOrigin = me.columnMapOrigin + me.columnMapSize + me.realFontSize.x;
749         me.columnPlayersOrigin = me.columnTypeOrigin + me.columnTypeSize + me.realFontSize.x;
750
751         me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, _("Ping"), ServerList_PingSort_Click);
752         me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Hostname"), ServerList_NameSort_Click);
753         me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, _("Map"), ServerList_MapSort_Click);
754         me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, _("Type"), ServerList_TypeSort_Click);
755         me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click);
756
757         int f = me.currentSortField;
758         if(f >= 0)
759         {
760                 me.currentSortField = -1;
761                 me.setSortOrder(me, f, me.currentSortOrder); // force resetting the sort order
762         }
763 }
764 void ServerList_Connect_Click(entity btn, entity me)
765 {
766         if (me.lockedSelectedItem)
767                 return;
768         string sv = (me.ipAddressBox.text != "") ? me.ipAddressBox.text : me.selectedServer;
769         localcmd(sprintf("connect %s\n", sv));
770 }
771 void ServerList_Favorite_Click(entity btn, entity this)
772 {
773         string addr = this.ipAddressBox.text;
774         string ipstr = netaddress_resolve(addr, 26000);
775         if (ipstr == "") return;
776         m_play_click_sound(MENU_SOUND_SELECT);
777         this.toggleFavorite(this, addr);
778         this.ipAddressBoxFocused = -1;
779 }
780 void ServerList_Info_Click(entity btn, entity me)
781 {
782         if (me.nItems != 0)
783                 main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
784
785         vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
786         vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
787         DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
788 }
789 void XonoticServerList_doubleClickListBoxItem(entity me, int i, vector where)
790 {
791         ServerList_Connect_Click(NULL, me);
792 }
793 void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
794 {
795         // layout: Ping, Server name, Map name, NP, TP, MP
796         float p;
797         int q;
798         bool isv4, isv6;
799         vector theColor;
800         float theAlpha;
801         bool pure = false, pure_available = false;
802         int freeslots = -1, sflags = -1, j, m;
803         string s, typestr, versionstr, k, v, modname;
804
805         //printf("time: %f, i: %d, item: %d, nitems: %d\n", time, i, item, me.nItems);
806
807         vector oldscale = draw_scale;
808         vector oldshift = draw_shift;
809 #define SET_YRANGE(start,end) \
810         draw_scale = boxToGlobalSize(eX * 1 + eY * (end - start), oldscale); \
811         draw_shift = boxToGlobal(eY * start, oldshift, oldscale);
812
813         for (j = 0; j < category_draw_count; ++j) {
814                 // Matches exactly the headings with increased height.
815                 if (i == category_item[j])
816                         break;
817         }
818
819         if (j < category_draw_count)
820         {
821                 entity catent = RetrieveCategoryEnt(category_name[j]);
822                 if(catent)
823                 {
824                         SET_YRANGE(
825                                 (me.categoriesHeight - 1) / (me.categoriesHeight + 1),
826                                 me.categoriesHeight / (me.categoriesHeight + 1)
827                         );
828                         draw_Text(
829                                 eY * me.realUpperMargin
830                                 +
831 #if 0
832                                 eX * (me.columnNameOrigin + (me.columnNameSize - draw_TextWidth(catent.cat_string, 0, me.realFontSize)) * 0.5),
833                                 catent.cat_string,
834 #else
835                                 eX * (me.columnNameOrigin),
836                                 strcat(catent.cat_string, ":"),
837 #endif
838                                 me.realFontSize,
839                                 SKINCOLOR_SERVERLIST_CATEGORY,
840                                 SKINALPHA_SERVERLIST_CATEGORY,
841                                 0
842                         );
843                         SET_YRANGE(me.categoriesHeight / (me.categoriesHeight + 1), 1);
844                 }
845         }
846
847         if(isSelected && !me.lockedSelectedItem)
848                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
849         else if(isFocused)
850         {
851                 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
852                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
853         }
854
855         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
856         m = tokenizebyseparator(s, ":");
857         typestr = "";
858         if(m >= 2)
859         {
860                 typestr = argv(0);
861                 versionstr = argv(1);
862         }
863         freeslots = -1;
864         modname = "";
865         for(j = 2; j < m; ++j)
866         {
867                 if(argv(j) == "")
868                         break;
869                 k = substring(argv(j), 0, 1);
870                 v = substring(argv(j), 1, -1);
871                 if(k == "P")
872                 {
873                         pure = (stof(v) == 0);
874                         pure_available = true;
875                 }
876                 else if(k == "S")
877                         freeslots = stof(v);
878                 else if(k == "F")
879                         sflags = stoi(v);
880                 else if(k == "M")
881                         modname = v;
882         }
883
884 #ifdef COMPAT_NO_MOD_IS_XONOTIC
885         if(modname == "")
886                 modname = "Xonotic";
887 #endif
888
889         string original_modname = modname;
890         modname = strtolower(modname);
891
892         /*
893         SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
894         s = gethostcachestring(SLIST_FIELD_MOD, i);
895         if(s != "data")
896                 if(modname == "xonotic")
897                         modname = s;
898         */
899
900         // list the mods here on which the pure server check actually works
901         if(modname != "xonotic")
902         if(modname != "instagib" || modname != "minstagib")
903         if(modname != "cts")
904         if(modname != "nix")
905         if(modname != "newtoys")
906                 pure_available = false;
907
908         if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0)
909                 theAlpha = SKINALPHA_SERVERLIST_FULL;
910         else if(freeslots == 0)
911                 theAlpha = SKINALPHA_SERVERLIST_FULL; // g_maxplayers support
912         else if (!gethostcachenumber(SLIST_FIELD_NUMHUMANS, i))
913                 theAlpha = SKINALPHA_SERVERLIST_EMPTY;
914         else
915                 theAlpha = 1;
916
917         p = gethostcachenumber(SLIST_FIELD_PING, i);
918         const int PING_LOW = 75;
919         const int PING_MED = 200;
920         const int PING_HIGH = 500;
921         if(p < PING_LOW)
922                 theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (p / PING_LOW);
923         else if(p < PING_MED)
924                 theColor = SKINCOLOR_SERVERLIST_MEDPING + (SKINCOLOR_SERVERLIST_HIGHPING - SKINCOLOR_SERVERLIST_MEDPING) * ((p - PING_LOW) / (PING_MED - PING_LOW));
925         else if(p < PING_HIGH)
926         {
927                 theColor = SKINCOLOR_SERVERLIST_HIGHPING;
928                 theAlpha *= 1 + (SKINALPHA_SERVERLIST_HIGHPING - 1) * ((p - PING_MED) / (PING_HIGH - PING_MED));
929         }
930         else
931         {
932                 theColor = eX;
933                 theAlpha *= SKINALPHA_SERVERLIST_HIGHPING;
934         }
935
936         if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, i))
937         {
938                 theColor = theColor * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINCOLOR_SERVERLIST_FAVORITE * SKINALPHA_SERVERLIST_FAVORITE;
939                 theAlpha = theAlpha * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINALPHA_SERVERLIST_FAVORITE;
940         }
941
942         s = gethostcachestring(SLIST_FIELD_CNAME, i);
943
944         isv4 = isv6 = false;
945         if(substring(s, 0, 1) == "[")
946         {
947                 isv6 = true;
948                 me.seenIPv6 += 1;
949         }
950         else if(IS_DIGIT(substring(s, 0, 1)))
951         {
952                 isv4 = true;
953                 me.seenIPv4 += 1;
954         }
955
956         q = stof(substring(crypto_getencryptlevel(s), 0, 1));
957         if((q <= 0 && cvar("crypto_aeslevel") >= 3) || (q >= 3 && cvar("crypto_aeslevel") <= 0))
958         {
959                 theColor = SKINCOLOR_SERVERLIST_IMPOSSIBLE;
960                 theAlpha = SKINALPHA_SERVERLIST_IMPOSSIBLE;
961         }
962
963         if(q == 1)
964         {
965                 if(cvar("crypto_aeslevel") >= 2)
966                         q |= 4;
967         }
968         if(q == 2)
969         {
970                 if(cvar("crypto_aeslevel") >= 1)
971                         q |= 4;
972         }
973         if(q == 3)
974                 q = 5;
975         else if(q >= 3)
976                 q -= 2;
977         // possible status:
978         // 0: crypto off
979         // 1: AES possible
980         // 2: AES recommended but not available
981         // 3: AES possible and will be used
982         // 4: AES recommended and will be used
983         // 5: AES required
984
985         // --------------
986         //  RENDER ICONS
987         // --------------
988         vector iconSize = '0 0 0';
989         iconSize_y = me.realFontSize.y * me.iconsSizeFactor;
990         iconSize_x = me.realFontSize.x * me.iconsSizeFactor;
991
992         vector iconPos = '0 0 0';
993         iconPos_x = (me.columnIconsSize - 3 * iconSize.x) * 0.5;
994         iconPos_y = (1 - iconSize.y) * 0.5;
995
996         // IP
997         if(me.seenIPv4 && me.seenIPv6)
998         {
999                 if(isv6)
1000                         draw_Picture(iconPos, "icon_ipv6", iconSize, '1 1 1', 1);
1001                 else if(isv4)
1002                         draw_Picture(iconPos, "icon_ipv4", iconSize, '1 1 1', 1);
1003         }
1004
1005         iconPos.x += iconSize.x;
1006
1007         // AES
1008         if(q > 0)
1009                 draw_Picture(iconPos, strcat("icon_aeslevel", ftos(q)), iconSize, '1 1 1', 1);
1010
1011         iconPos.x += iconSize.x;
1012
1013         // Mod
1014         if(modname == "xonotic")
1015         {
1016                 // Here, pure_available should always be set. If not, consider
1017                 // it an impurity.
1018                 if(pure_available && pure)
1019                         draw_Picture(iconPos, "icon_pure1", iconSize, '1 1 1', 1);
1020         }
1021         else
1022         {
1023                 string icon = strcat("icon_mod_", modname);
1024                 if(draw_PictureSize(icon) == '0 0 0')
1025                         icon = "icon_mod_";
1026
1027                 // In mods, pure_available not being present indicates
1028                 // non-support of the feature. Just show the mod icon as is
1029                 // then.
1030                 if(pure_available && !pure)
1031                         draw_Picture(iconPos, icon, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE);
1032                 else
1033                         draw_Picture(iconPos, icon, iconSize, '1 1 1', 1);
1034         }
1035
1036         iconPos.x += iconSize.x;
1037
1038         // Stats
1039         if(sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS))
1040                 draw_Picture(iconPos, "icon_stats1", iconSize, '1 1 1', 1);
1041
1042         if(isFocused && me.mouseOverIcons && !me.tooltip)
1043         {
1044                 string t = "";
1045                 if(me.seenIPv4 && me.seenIPv6)
1046                         t = strcat(t, (isv6) ? "IPv6, " : "IPv4, ");
1047                 t = strcat(t, _("encryption:"), " ", (q ? sprintf(_("AES level %d"), q) : ZCTX(_("ENC^none"))), ", ");
1048                 t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname)));
1049                 if(pure_available)
1050                         t = strcat(t, sprintf(" (%s)", (pure) ? _("official settings") : _("modified settings")));
1051                 t = strcat(t, ", ");
1052                 t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled")));
1053                 setZonedTooltip(me, t, string_null);
1054         }
1055         // --------------
1056         //  RENDER TEXT
1057         // --------------
1058
1059         // ping
1060         s = ftos(p);
1061         draw_Text(me.realUpperMargin * eY + (me.columnPingOrigin + me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1062
1063         // server name
1064         s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, i), me.columnNameSize, 0, me.realFontSize);
1065         draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
1066
1067         // server map
1068         s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, i), me.columnMapSize, 0, me.realFontSize);
1069         draw_Text(me.realUpperMargin * eY + (me.columnMapOrigin + (me.columnMapSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1070
1071         // server gametype
1072         s = draw_TextShortenToWidth(typestr, me.columnTypeSize, 0, me.realFontSize);
1073         draw_Text(me.realUpperMargin * eY + (me.columnTypeOrigin + (me.columnTypeSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1074
1075         // server playercount
1076         s = strcat(ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)), "/", ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i)));
1077         draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1078 }
1079
1080 void XonoticServerList_focusedItemChangeNotify(entity me)
1081 {
1082         clearTooltip(me);
1083 }
1084
1085 float XonoticServerList_mouseMove(entity me, vector pos)
1086 {
1087         if(!SUPER(XonoticServerList).mouseMove(me, pos))
1088         {
1089                 me.mouseOverIcons = false;
1090                 clearTooltip(me);
1091                 return 1;
1092         }
1093
1094         me.mouseOverIcons = (pos_x <= me.columnIconsSize);
1095         if(!me.mouseOverIcons)
1096                 clearTooltip(me);
1097         return 1;
1098 }
1099
1100 bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift)
1101 {
1102         vector org, sz;
1103
1104         org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
1105         sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
1106
1107         if(scan == K_ENTER || scan == K_KP_ENTER)
1108         {
1109                 ServerList_Connect_Click(NULL, me);
1110                 return true;
1111         }
1112         else if(scan == K_MOUSE2 || scan == K_SPACE)
1113         {
1114                 if(me.nItems != 0)
1115                 {
1116                         m_play_click_sound(MENU_SOUND_OPEN);
1117                         main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
1118                         DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
1119                         return true;
1120                 }
1121                 return false;
1122         }
1123         else if(scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS)
1124         {
1125                 if(me.nItems != 0)
1126                 {
1127                         me.toggleFavorite(me, me.selectedServer);
1128                         me.ipAddressBoxFocused = -1;
1129                         return true;
1130                 }
1131                 return false;
1132         }
1133         else if(SUPER(XonoticServerList).keyDown(me, scan, ascii, shift))
1134                 return true;
1135         else if(!me.controlledTextbox)
1136                 return false;
1137         else
1138                 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
1139 }
1140
1141 float XonoticServerList_getTotalHeight(entity me)
1142 {
1143         float num_normal_rows = me.nItems;
1144         int num_headers = category_draw_count;
1145         return me.itemHeight * (num_normal_rows + me.categoriesHeight * num_headers);
1146 }
1147 int XonoticServerList_getItemAtPos(entity me, float pos)
1148 {
1149         pos = pos / me.itemHeight;
1150         int i;
1151         for (i = category_draw_count - 1; i >= 0; --i) {
1152                 int itemidx = category_item[i];
1153                 float itempos = i * me.categoriesHeight + category_item[i];
1154                 if (pos >= itempos + me.categoriesHeight + 1)
1155                         return itemidx + 1 + floor(pos - (itempos + me.categoriesHeight + 1));
1156                 if (pos >= itempos)
1157                         return itemidx;
1158         }
1159         // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1160         return floor(pos);
1161 }
1162 float XonoticServerList_getItemStart(entity me, int item)
1163 {
1164         int i;
1165         for (i = category_draw_count - 1; i >= 0; --i) {
1166                 int itemidx = category_item[i];
1167                 float itempos = i * me.categoriesHeight + category_item[i];
1168                 if (item >= itemidx + 1)
1169                         return (itempos + me.categoriesHeight + 1 + item - (itemidx + 1)) * me.itemHeight;
1170                 if (item >= itemidx)
1171                         return itempos * me.itemHeight;
1172         }
1173         // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1174         return item * me.itemHeight;
1175 }
1176 float XonoticServerList_getItemHeight(entity me, int item)
1177 {
1178         int i;
1179         for (i = 0; i < category_draw_count; ++i) {
1180                 // Matches exactly the headings with increased height.
1181                 if (item == category_item[i])
1182                         return me.itemHeight * (me.categoriesHeight + 1);
1183         }
1184         return me.itemHeight;
1185 }