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