]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/serverlist.qc
Merge branch 'master' into DefaultUser/trigger_cleanup
[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.infoButton.disabled = (me.lockedSelectedItem || me.nItems == 0 || !owned);
550         me.favoriteButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == ""));
551
552         if(me.lockedSelectedItem)
553         {
554                 if(me.nItems > 0)
555                 {
556                         if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer)
557                         {
558                                 strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
559                         }
560                         found = true;
561                 }
562         }
563         else if(me.selectedServer)
564         {
565                 for(i = 0; i < me.nItems; ++i)
566                 {
567                         if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer)
568                         {
569                                 // don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i);
570                                 me.selectedItem = i;
571                                 found = true;
572                                 break;
573                         }
574                 }
575         }
576         if(!found)
577         {
578                 if(me.nItems > 0)
579                 {
580                         // selected server disappeared, select the last server (scrolling to it)
581                         if(me.selectedItem >= me.nItems)
582                                 SUPER(XonoticServerList).setSelected(me, me.nItems - 1);
583                         strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
584                 }
585         }
586
587         if(owned)
588         {
589                 if(me.selectedServer != me.ipAddressBox.text)
590                 {
591                         me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
592                         me.ipAddressBox.cursorPos = strlen(me.selectedServer);
593                         me.ipAddressBoxFocused = -1;
594                 }
595         }
596
597         if(me.ipAddressBoxFocused != me.ipAddressBox.focused)
598         {
599                 if(me.ipAddressBox.focused || me.ipAddressBoxFocused < 0)
600                         ServerList_Update_favoriteButton(NULL, me);
601                 me.ipAddressBoxFocused = me.ipAddressBox.focused;
602         }
603
604         SUPER(XonoticServerList).draw(me);
605 }
606 void ServerList_PingSort_Click(entity btn, entity me)
607 {
608         me.setSortOrder(me, SLIST_FIELD_PING, +1);
609 }
610 void ServerList_NameSort_Click(entity btn, entity me)
611 {
612         me.setSortOrder(me, SLIST_FIELD_NAME, -1); // why?
613 }
614 void ServerList_MapSort_Click(entity btn, entity me)
615 {
616         me.setSortOrder(me, SLIST_FIELD_MAP, -1); // why?
617 }
618 void ServerList_PlayerSort_Click(entity btn, entity me)
619 {
620         me.setSortOrder(me, SLIST_FIELD_NUMHUMANS, -1);
621 }
622 void ServerList_TypeSort_Click(entity btn, entity me)
623 {
624         string s = me.filterString;
625         int m = strstrofs(s, ":", 0);
626         if(m >= 0)
627         {
628                 s = substring(s, 0, m);
629                 while(substring(s, m+1, 1) == " ") // skip spaces
630                         ++m;
631         }
632         else
633                 s = "";
634
635         Gametype first = NULL; FOREACH(Gametypes, !first, first = it; break);
636         bool flag = false;
637         FOREACH(Gametypes, s == MapInfo_Type_ToString(it), {
638                 // the type was found
639                 // choose the next one
640                 flag = true;
641                 s = MapInfo_Type_ToString(Gametypes_from(it.m_id + 1));
642                 if (s == "") s = MapInfo_Type_ToString(first);
643                 break;
644         });
645         if (!flag) {
646                 // no type was found
647                 // choose the first one
648                 s = MapInfo_Type_ToString(first);
649         }
650
651         if(s != "") s = strcat(s, ":");
652         s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1));
653
654         me.controlledTextbox.setText(me.controlledTextbox, s);
655         me.controlledTextbox.keyDown(me.controlledTextbox, K_END, 0, 0);
656         me.controlledTextbox.keyUp(me.controlledTextbox, K_END, 0, 0);
657         //ServerList_Filter_Change(me.controlledTextbox, me);
658 }
659 void ServerList_Filter_Change(entity box, entity me)
660 {
661         strfree(me.filterString);
662         if(box.text != "")
663                 me.filterString = strzone(box.text);
664         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
665
666         me.ipAddressBox.setText(me.ipAddressBox, "");
667         me.ipAddressBox.cursorPos = 0;
668         me.ipAddressBoxFocused = -1;
669 }
670 void ServerList_Categories_Click(entity box, entity me)
671 {
672         box.setChecked(box, autocvar_menu_slist_categories = !autocvar_menu_slist_categories);
673         me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
674
675         me.ipAddressBox.setText(me.ipAddressBox, "");
676         me.ipAddressBox.cursorPos = 0;
677         me.ipAddressBoxFocused = -1;
678 }
679 void ServerList_ShowEmpty_Click(entity box, entity me)
680 {
681         box.setChecked(box, me.filterShowEmpty = !me.filterShowEmpty);
682         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
683
684         me.ipAddressBox.setText(me.ipAddressBox, "");
685         me.ipAddressBox.cursorPos = 0;
686         me.ipAddressBoxFocused = -1;
687 }
688 void ServerList_ShowFull_Click(entity box, entity me)
689 {
690         box.setChecked(box, me.filterShowFull = !me.filterShowFull);
691         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
692
693         me.ipAddressBox.setText(me.ipAddressBox, "");
694         me.ipAddressBox.cursorPos = 0;
695         me.ipAddressBoxFocused = -1;
696 }
697 void XonoticServerList_setSortOrder(entity me, int fld, int direction)
698 {
699         if(me.currentSortField == fld)
700                 direction = -me.currentSortOrder;
701         me.currentSortOrder = direction;
702         me.currentSortField = fld;
703         me.sortButton1.forcePressed = (fld == SLIST_FIELD_PING);
704         me.sortButton2.forcePressed = (fld == SLIST_FIELD_NAME);
705         me.sortButton3.forcePressed = (fld == SLIST_FIELD_MAP);
706         me.sortButton4.forcePressed = 0;
707         me.sortButton5.forcePressed = (fld == SLIST_FIELD_NUMHUMANS);
708         me.selectedItem = 0;
709         strfree(me.selectedServer);
710         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
711 }
712 void XonoticServerList_positionSortButton(entity me, entity btn, float theOrigin, float theSize, string theTitle, void(entity, entity) theFunc)
713 {
714         vector originInLBSpace, sizeInLBSpace;
715         originInLBSpace = eY * (-me.itemHeight);
716         sizeInLBSpace = eY * me.itemHeight + eX * (1 - me.controlWidth);
717
718         vector originInDialogSpace, sizeInDialogSpace;
719         originInDialogSpace = boxToGlobal(originInLBSpace, me.Container_origin, me.Container_size);
720         sizeInDialogSpace = boxToGlobalSize(sizeInLBSpace, me.Container_size);
721
722         btn.Container_origin_x = originInDialogSpace.x + sizeInDialogSpace.x * theOrigin;
723         btn.Container_size_x   =                         sizeInDialogSpace.x * theSize;
724         btn.setText(btn, theTitle);
725         btn.onClick = theFunc;
726         btn.onClickEntity = me;
727         btn.resized = 1;
728 }
729 void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
730 {
731         SUPER(XonoticServerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
732
733         me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
734         me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
735         me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
736
737         me.columnIconsOrigin = 0;
738         me.columnIconsSize = me.realFontSize.x * 4 * me.iconsSizeFactor;
739         me.columnPingSize = me.realFontSize.x * 3;
740         me.columnMapSize = me.realFontSize.x * 10;
741         me.columnTypeSize = me.realFontSize.x * 4;
742         me.columnPlayersSize = me.realFontSize.x * 5;
743         me.columnNameSize = 1 - me.columnPlayersSize - me.columnMapSize - me.columnPingSize - me.columnIconsSize - me.columnTypeSize - 5 * me.realFontSize.x;
744         me.columnPingOrigin = me.columnIconsOrigin + me.columnIconsSize + me.realFontSize.x;
745         me.columnNameOrigin = me.columnPingOrigin + me.columnPingSize + me.realFontSize.x;
746         me.columnMapOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
747         me.columnTypeOrigin = me.columnMapOrigin + me.columnMapSize + me.realFontSize.x;
748         me.columnPlayersOrigin = me.columnTypeOrigin + me.columnTypeSize + me.realFontSize.x;
749
750         me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, _("Ping"), ServerList_PingSort_Click);
751         me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Hostname"), ServerList_NameSort_Click);
752         me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, _("Map"), ServerList_MapSort_Click);
753         me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, _("Type"), ServerList_TypeSort_Click);
754         me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click);
755
756         int f = me.currentSortField;
757         if(f >= 0)
758         {
759                 me.currentSortField = -1;
760                 me.setSortOrder(me, f, me.currentSortOrder); // force resetting the sort order
761         }
762 }
763 void ServerList_Connect_Click(entity btn, entity me)
764 {
765         if (me.lockedSelectedItem)
766                 return;
767         string sv = (me.ipAddressBox.text != "") ? me.ipAddressBox.text : me.selectedServer;
768         localcmd(sprintf("connect %s\n", sv));
769 }
770 void ServerList_Favorite_Click(entity btn, entity this)
771 {
772         string addr = this.ipAddressBox.text;
773         string ipstr = netaddress_resolve(addr, 26000);
774         if (ipstr == "") return;
775         m_play_click_sound(MENU_SOUND_SELECT);
776         this.toggleFavorite(this, addr);
777         this.ipAddressBoxFocused = -1;
778 }
779 void ServerList_Info_Click(entity btn, entity me)
780 {
781         if (me.nItems != 0)
782                 main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
783
784         vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
785         vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
786         DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
787 }
788 void XonoticServerList_doubleClickListBoxItem(entity me, int i, vector where)
789 {
790         ServerList_Connect_Click(NULL, me);
791 }
792 void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
793 {
794         // layout: Ping, Server name, Map name, NP, TP, MP
795         float p;
796         int q;
797         bool isv4, isv6;
798         vector theColor;
799         float theAlpha;
800         bool pure = false, pure_available = false;
801         int freeslots = -1, sflags = -1, j, m;
802         string s, typestr, versionstr, k, v, modname;
803
804         //printf("time: %f, i: %d, item: %d, nitems: %d\n", time, i, item, me.nItems);
805
806         vector oldscale = draw_scale;
807         vector oldshift = draw_shift;
808 #define SET_YRANGE(start,end) \
809         draw_scale = boxToGlobalSize(eX * 1 + eY * (end - start), oldscale); \
810         draw_shift = boxToGlobal(eY * start, oldshift, oldscale);
811
812         for (j = 0; j < category_draw_count; ++j) {
813                 // Matches exactly the headings with increased height.
814                 if (i == category_item[j])
815                         break;
816         }
817
818         if (j < category_draw_count)
819         {
820                 entity catent = RetrieveCategoryEnt(category_name[j]);
821                 if(catent)
822                 {
823                         SET_YRANGE(
824                                 (me.categoriesHeight - 1) / (me.categoriesHeight + 1),
825                                 me.categoriesHeight / (me.categoriesHeight + 1)
826                         );
827                         draw_Text(
828                                 eY * me.realUpperMargin
829                                 +
830 #if 0
831                                 eX * (me.columnNameOrigin + (me.columnNameSize - draw_TextWidth(catent.cat_string, 0, me.realFontSize)) * 0.5),
832                                 catent.cat_string,
833 #else
834                                 eX * (me.columnNameOrigin),
835                                 strcat(catent.cat_string, ":"),
836 #endif
837                                 me.realFontSize,
838                                 SKINCOLOR_SERVERLIST_CATEGORY,
839                                 SKINALPHA_SERVERLIST_CATEGORY,
840                                 0
841                         );
842                         SET_YRANGE(me.categoriesHeight / (me.categoriesHeight + 1), 1);
843                 }
844         }
845
846         if(isSelected && !me.lockedSelectedItem)
847                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
848         else if(isFocused)
849         {
850                 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
851                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
852         }
853
854         s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
855         m = tokenizebyseparator(s, ":");
856         typestr = "";
857         if(m >= 2)
858         {
859                 typestr = argv(0);
860                 versionstr = argv(1);
861         }
862         freeslots = -1;
863         modname = "";
864         for(j = 2; j < m; ++j)
865         {
866                 if(argv(j) == "")
867                         break;
868                 k = substring(argv(j), 0, 1);
869                 v = substring(argv(j), 1, -1);
870                 if(k == "P")
871                 {
872                         pure = (stof(v) == 0);
873                         pure_available = true;
874                 }
875                 else if(k == "S")
876                         freeslots = stof(v);
877                 else if(k == "F")
878                         sflags = stoi(v);
879                 else if(k == "M")
880                         modname = v;
881         }
882
883 #ifdef COMPAT_NO_MOD_IS_XONOTIC
884         if(modname == "")
885                 modname = "Xonotic";
886 #endif
887
888         string original_modname = modname;
889         modname = strtolower(modname);
890
891         /*
892         SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
893         s = gethostcachestring(SLIST_FIELD_MOD, i);
894         if(s != "data")
895                 if(modname == "xonotic")
896                         modname = s;
897         */
898
899         // list the mods here on which the pure server check actually works
900         if(modname != "xonotic")
901         if(modname != "instagib" || modname != "minstagib")
902         if(modname != "cts")
903         if(modname != "nix")
904         if(modname != "newtoys")
905                 pure_available = false;
906
907         if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0)
908                 theAlpha = SKINALPHA_SERVERLIST_FULL;
909         else if(freeslots == 0)
910                 theAlpha = SKINALPHA_SERVERLIST_FULL; // g_maxplayers support
911         else if (!gethostcachenumber(SLIST_FIELD_NUMHUMANS, i))
912                 theAlpha = SKINALPHA_SERVERLIST_EMPTY;
913         else
914                 theAlpha = 1;
915
916         p = gethostcachenumber(SLIST_FIELD_PING, i);
917         const int PING_LOW = 75;
918         const int PING_MED = 200;
919         const int PING_HIGH = 500;
920         if(p < PING_LOW)
921                 theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (p / PING_LOW);
922         else if(p < PING_MED)
923                 theColor = SKINCOLOR_SERVERLIST_MEDPING + (SKINCOLOR_SERVERLIST_HIGHPING - SKINCOLOR_SERVERLIST_MEDPING) * ((p - PING_LOW) / (PING_MED - PING_LOW));
924         else if(p < PING_HIGH)
925         {
926                 theColor = SKINCOLOR_SERVERLIST_HIGHPING;
927                 theAlpha *= 1 + (SKINALPHA_SERVERLIST_HIGHPING - 1) * ((p - PING_MED) / (PING_HIGH - PING_MED));
928         }
929         else
930         {
931                 theColor = eX;
932                 theAlpha *= SKINALPHA_SERVERLIST_HIGHPING;
933         }
934
935         if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, i))
936         {
937                 theColor = theColor * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINCOLOR_SERVERLIST_FAVORITE * SKINALPHA_SERVERLIST_FAVORITE;
938                 theAlpha = theAlpha * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINALPHA_SERVERLIST_FAVORITE;
939         }
940
941         s = gethostcachestring(SLIST_FIELD_CNAME, i);
942
943         isv4 = isv6 = false;
944         if(substring(s, 0, 1) == "[")
945         {
946                 isv6 = true;
947                 me.seenIPv6 += 1;
948         }
949         else if(IS_DIGIT(substring(s, 0, 1)))
950         {
951                 isv4 = true;
952                 me.seenIPv4 += 1;
953         }
954
955         q = stof(substring(crypto_getencryptlevel(s), 0, 1));
956         if((q <= 0 && cvar("crypto_aeslevel") >= 3) || (q >= 3 && cvar("crypto_aeslevel") <= 0))
957         {
958                 theColor = SKINCOLOR_SERVERLIST_IMPOSSIBLE;
959                 theAlpha = SKINALPHA_SERVERLIST_IMPOSSIBLE;
960         }
961
962         if(q == 1)
963         {
964                 if(cvar("crypto_aeslevel") >= 2)
965                         q |= 4;
966         }
967         if(q == 2)
968         {
969                 if(cvar("crypto_aeslevel") >= 1)
970                         q |= 4;
971         }
972         if(q == 3)
973                 q = 5;
974         else if(q >= 3)
975                 q -= 2;
976         // possible status:
977         // 0: crypto off
978         // 1: AES possible
979         // 2: AES recommended but not available
980         // 3: AES possible and will be used
981         // 4: AES recommended and will be used
982         // 5: AES required
983
984         // --------------
985         //  RENDER ICONS
986         // --------------
987         vector iconSize = '0 0 0';
988         iconSize_y = me.realFontSize.y * me.iconsSizeFactor;
989         iconSize_x = me.realFontSize.x * me.iconsSizeFactor;
990
991         vector iconPos = '0 0 0';
992         iconPos_x = (me.columnIconsSize - 3 * iconSize.x) * 0.5;
993         iconPos_y = (1 - iconSize.y) * 0.5;
994
995         // IP
996         if(me.seenIPv4 && me.seenIPv6)
997         {
998                 if(isv6)
999                         draw_Picture(iconPos, "icon_ipv6", iconSize, '1 1 1', 1);
1000                 else if(isv4)
1001                         draw_Picture(iconPos, "icon_ipv4", iconSize, '1 1 1', 1);
1002         }
1003
1004         iconPos.x += iconSize.x;
1005
1006         // AES
1007         if(q > 0)
1008                 draw_Picture(iconPos, strcat("icon_aeslevel", ftos(q)), iconSize, '1 1 1', 1);
1009
1010         iconPos.x += iconSize.x;
1011
1012         // Mod
1013         if(modname == "xonotic")
1014         {
1015                 // Here, pure_available should always be set. If not, consider
1016                 // it an impurity.
1017                 if(pure_available && pure)
1018                         draw_Picture(iconPos, "icon_pure1", iconSize, '1 1 1', 1);
1019         }
1020         else
1021         {
1022                 string icon = strcat("icon_mod_", modname);
1023                 if(draw_PictureSize(icon) == '0 0 0')
1024                         icon = "icon_mod_";
1025
1026                 // In mods, pure_available not being present indicates
1027                 // non-support of the feature. Just show the mod icon as is
1028                 // then.
1029                 if(pure_available && !pure)
1030                         draw_Picture(iconPos, icon, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE);
1031                 else
1032                         draw_Picture(iconPos, icon, iconSize, '1 1 1', 1);
1033         }
1034
1035         iconPos.x += iconSize.x;
1036
1037         // Stats
1038         if(sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS))
1039                 draw_Picture(iconPos, "icon_stats1", iconSize, '1 1 1', 1);
1040
1041         if(isFocused && me.mouseOverIcons && !me.tooltip)
1042         {
1043                 string t = "";
1044                 if(me.seenIPv4 && me.seenIPv6)
1045                         t = strcat(t, (isv6) ? "IPv6, " : "IPv4, ");
1046                 t = strcat(t, _("encryption:"), " ", (q ? sprintf(_("AES level %d"), q) : ZCTX(_("ENC^none"))), ", ");
1047                 t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname)));
1048                 if(pure_available)
1049                         t = strcat(t, sprintf(" (%s)", (pure) ? _("official settings") : _("modified settings")));
1050                 t = strcat(t, ", ");
1051                 t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled")));
1052                 setZonedTooltip(me, t, string_null);
1053         }
1054         // --------------
1055         //  RENDER TEXT
1056         // --------------
1057
1058         // ping
1059         s = ftos(p);
1060         draw_Text(me.realUpperMargin * eY + (me.columnPingOrigin + me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1061
1062         // server name
1063         s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, i), me.columnNameSize, 0, me.realFontSize);
1064         draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
1065
1066         // server map
1067         s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, i), me.columnMapSize, 0, me.realFontSize);
1068         draw_Text(me.realUpperMargin * eY + (me.columnMapOrigin + (me.columnMapSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1069
1070         // server gametype
1071         s = draw_TextShortenToWidth(typestr, me.columnTypeSize, 0, me.realFontSize);
1072         draw_Text(me.realUpperMargin * eY + (me.columnTypeOrigin + (me.columnTypeSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1073
1074         // server playercount
1075         s = strcat(ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)), "/", ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i)));
1076         draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1077 }
1078
1079 void XonoticServerList_focusedItemChangeNotify(entity me)
1080 {
1081         clearTooltip(me);
1082 }
1083
1084 float XonoticServerList_mouseMove(entity me, vector pos)
1085 {
1086         if(!SUPER(XonoticServerList).mouseMove(me, pos))
1087         {
1088                 me.mouseOverIcons = false;
1089                 clearTooltip(me);
1090                 return 1;
1091         }
1092
1093         me.mouseOverIcons = (pos_x <= me.columnIconsSize);
1094         if(!me.mouseOverIcons)
1095                 clearTooltip(me);
1096         return 1;
1097 }
1098
1099 bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift)
1100 {
1101         vector org, sz;
1102
1103         org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
1104         sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
1105
1106         if(scan == K_ENTER || scan == K_KP_ENTER)
1107         {
1108                 ServerList_Connect_Click(NULL, me);
1109                 return true;
1110         }
1111         else if(scan == K_MOUSE2 || scan == K_SPACE)
1112         {
1113                 if(me.nItems != 0)
1114                 {
1115                         m_play_click_sound(MENU_SOUND_OPEN);
1116                         main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
1117                         DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
1118                         return true;
1119                 }
1120                 return false;
1121         }
1122         else if(scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS)
1123         {
1124                 if(me.nItems != 0)
1125                 {
1126                         me.toggleFavorite(me, me.selectedServer);
1127                         me.ipAddressBoxFocused = -1;
1128                         return true;
1129                 }
1130                 return false;
1131         }
1132         else if(SUPER(XonoticServerList).keyDown(me, scan, ascii, shift))
1133                 return true;
1134         else if(!me.controlledTextbox)
1135                 return false;
1136         else
1137                 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
1138 }
1139
1140 float XonoticServerList_getTotalHeight(entity me)
1141 {
1142         float num_normal_rows = me.nItems;
1143         int num_headers = category_draw_count;
1144         return me.itemHeight * (num_normal_rows + me.categoriesHeight * num_headers);
1145 }
1146 int XonoticServerList_getItemAtPos(entity me, float pos)
1147 {
1148         pos = pos / me.itemHeight;
1149         int i;
1150         for (i = category_draw_count - 1; i >= 0; --i) {
1151                 int itemidx = category_item[i];
1152                 float itempos = i * me.categoriesHeight + category_item[i];
1153                 if (pos >= itempos + me.categoriesHeight + 1)
1154                         return itemidx + 1 + floor(pos - (itempos + me.categoriesHeight + 1));
1155                 if (pos >= itempos)
1156                         return itemidx;
1157         }
1158         // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1159         return floor(pos);
1160 }
1161 float XonoticServerList_getItemStart(entity me, int item)
1162 {
1163         int i;
1164         for (i = category_draw_count - 1; i >= 0; --i) {
1165                 int itemidx = category_item[i];
1166                 float itempos = i * me.categoriesHeight + category_item[i];
1167                 if (item >= itemidx + 1)
1168                         return (itempos + me.categoriesHeight + 1 + item - (itemidx + 1)) * me.itemHeight;
1169                 if (item >= itemidx)
1170                         return itempos * me.itemHeight;
1171         }
1172         // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1173         return item * me.itemHeight;
1174 }
1175 float XonoticServerList_getItemHeight(entity me, int item)
1176 {
1177         int i;
1178         for (i = 0; i < category_draw_count; ++i) {
1179                 // Matches exactly the headings with increased height.
1180                 if (item == category_item[i])
1181                         return me.itemHeight * (me.categoriesHeight + 1);
1182         }
1183         return me.itemHeight;
1184 }