1 #include "serverlist.qh"
5 #include "mainwindow.qh"
6 #include "dialog_multiplayer_join_serverinfo.qh"
7 #include <common/mapinfo.qh>
9 void RegisterSLCategories()
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);
26 #define PROCESS_OVERRIDE(override_string,override_field) \
27 for(i = 0; i < category_ent_count; ++i) \
29 s = categories[i].override_string; \
30 if(s != "" && s != categories[i].cat_name) \
33 for(x = 0; x < category_ent_count; ++x) \
35 if(categories[x].cat_name == s) \
43 strfree(categories[i].override_string); \
44 categories[i].override_field = catnum; \
50 "RegisterSLCategories(): Improper override '%s' for category '%s'!", \
52 categories[i].cat_name \
56 strfree(categories[i].override_string); \
57 categories[i].override_field = 0; \
59 PROCESS_OVERRIDE(cat_enoverride_string, cat_enoverride)
60 PROCESS_OVERRIDE(cat_dioverride_string, cat_dioverride)
61 #undef PROCESS_OVERRIDE
64 // Supporting Functions
65 entity RetrieveCategoryEnt(int catnum)
67 if((catnum > 0) && (catnum <= category_ent_count))
69 return categories[catnum - 1];
73 error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum));
78 bool IsServerInList(string list, string srv)
84 srv = netaddress_resolve(srv, 26000);
87 p = crypto_getidfp(srv);
88 n = tokenize_console(list);
89 for(i = 0; i < n; ++i)
91 if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0)
99 if(srv == netaddress_resolve(argv(i), 26000))
106 int CheckCategoryOverride(int cat)
108 entity catent = RetrieveCategoryEnt(cat);
111 int override = (autocvar_menu_slist_categories ? catent.cat_enoverride : catent.cat_dioverride);
112 if(override) { return override; }
117 error(sprintf("CheckCategoryOverride(%d): Improper category number!\n", cat));
122 int CheckCategoryForEntry(int entry)
124 string s, k, v, modtype = "";
125 int j, m, impure = 0, freeslots = 0, sflags = 0;
126 s = gethostcachestring(SLIST_FIELD_QCSTATUS, entry);
127 m = tokenizebyseparator(s, ":");
129 for(j = 2; j < m; ++j)
131 if(argv(j) == "") { break; }
132 k = substring(argv(j), 0, 1);
133 v = substring(argv(j), 1, -1);
136 case "P": { impure = stof(v); break; }
137 case "S": { freeslots = stof(v); break; }
138 case "F": { sflags = stof(v); break; }
139 case "M": { modtype = strtolower(v); break; }
143 if(modtype != "xonotic") { impure += autocvar_menu_slist_modimpurity; }
145 // check if this server is favorited
146 if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, entry)) { return CAT_FAVORITED; }
148 // now check if it's recommended
149 if(autocvar_menu_slist_recommendations)
151 string cname = gethostcachestring(SLIST_FIELD_CNAME, entry);
153 if(IsPromoted(cname)) { return CAT_RECOMMENDED; }
156 float recommended = 0;
157 if(autocvar_menu_slist_recommendations & 1)
159 if(IsRecommended(cname)) { ++recommended; }
160 else { --recommended; }
162 if(autocvar_menu_slist_recommendations & 2)
165 ///// check for minimum free slots
166 (freeslots >= autocvar_menu_slist_recommendations_minfreeslots)
168 && // check for purity requirement
170 (autocvar_menu_slist_recommendations_purethreshold < 0)
172 (impure <= autocvar_menu_slist_recommendations_purethreshold)
175 && // check for minimum amount of humans
177 gethostcachenumber(SLIST_FIELD_NUMHUMANS, entry)
179 autocvar_menu_slist_recommendations_minhumans
182 && // check for maximum latency
184 gethostcachenumber(SLIST_FIELD_PING, entry)
186 autocvar_menu_slist_recommendations_maxping
193 if(recommended > 0) { return CAT_RECOMMENDED; }
197 // if not favorited or recommended, check modname
198 if(modtype != "xonotic")
202 // old servers which don't report their mod name are considered modified now
203 case "": { return CAT_MODIFIED; }
205 case "xpm": { return CAT_XPM; }
207 case "instagib": { return CAT_INSTAGIB; }
208 case "overkill": { return CAT_OVERKILL; }
209 //case "nix": { return CAT_NIX; }
210 //case "newtoys": { return CAT_NEWTOYS; }
212 // "cts" is allowed as compat, xdf is replacement
214 case "xdf": { return CAT_DEFRAG; }
216 default: { LOG_TRACEF("Found strange mod type: %s", modtype); return CAT_MODIFIED; }
220 // must be normal or impure server
221 return ((impure > autocvar_menu_slist_purethreshold) ? CAT_MODIFIED : CAT_NORMAL);
224 METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string srv))
227 string srv_resolved = netaddress_resolve(srv, 26000);
228 string p = crypto_getidfp(srv_resolved);
229 string s = cvar_string("net_slist_favorites");
231 for (int i = 0, n = tokenize_console(s); i < n; ++i)
234 if (substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0)
236 // it's a pubkey hash
237 match = (p && p == argv(i));
242 match = (srv_resolved == netaddress_resolve(argv(i), 26000));
244 if (!match) continue;
247 string before = (i > 0) ? substring(s, 0, argv_end_index(i - 1)) : "";
248 string after = (i < n - 1) ? substring(s, argv_start_index(i + 1), -1) : "";
249 s = strcat(before, (before != "" && after != "" ? " " : ""), after);
252 // TODO: why not break here?
253 n = tokenize_console(s);
254 --i; // offset the increment that is about to happen
258 ret = strcat(s, (s != "" ? " " : ""), p ? p : srv);
260 cvar_set("net_slist_favorites", ret);
261 this.refreshServerList(this, REFRESHSERVERLIST_RESORT);
264 void ServerList_Update_favoriteButton(entity btn, entity me)
266 entity e = me.favoriteButton;
267 if(IsFavorite(me.ipAddressBox.text))
269 e.setText(e, _("Remove"));
274 e.setText(e, _("Favorite"));
275 setZonedTooltip(e, _("Bookmark the currently highlighted server so that it's faster to find in the future"), string_null);
279 entity makeXonoticServerList()
282 me = NEW(XonoticServerList);
283 me.configureXonoticServerList(me);
286 void XonoticServerList_configureXonoticServerList(entity me)
288 me.configureXonoticListBox(me);
291 #define SLIST_FIELD(suffix,name) SLIST_FIELD_##suffix = gethostcacheindexforkey(name);
298 void XonoticServerList_setSelected(entity me, int i)
300 me.lockedSelectedItem = false;
301 //int save = me.selectedItem;
302 SUPER(XonoticServerList).setSelected(me, i);
304 if(me.selectedItem == save)
309 if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems)
310 return; // sorry, it would be wrong
312 strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
314 me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
315 me.ipAddressBox.cursorPos = strlen(me.selectedServer);
316 me.ipAddressBoxFocused = -1;
318 void XonoticServerList_refreshServerList(entity me, int mode)
320 //print("refresh of type ", ftos(mode), "\n");
322 if(mode >= REFRESHSERVERLIST_REFILTER)
327 string s, typestr, modstr;
331 m = strstrofs(s, ":", 0);
334 typestr = substring(s, 0, m);
335 s = substring(s, m + 1, strlen(s) - m - 1);
336 while(substring(s, 0, 1) == " ")
337 s = substring(s, 1, strlen(s) - 1);
342 modstr = cvar_string("menu_slist_modfilter");
344 m = SLIST_MASK_AND - 1;
345 resethostcachemasks();
347 // ping: reject negative ping (no idea why this happens in the first place, engine bug)
348 sethostcachemasknumber(++m, SLIST_FIELD_PING, 0, SLIST_TEST_GREATEREQUAL);
351 if(!me.filterShowFull)
353 sethostcachemasknumber(++m, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); // legacy
354 sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, ":S0:", SLIST_TEST_NOTCONTAIN); // g_maxplayers support
358 if(!me.filterShowEmpty)
359 sethostcachemasknumber(++m, SLIST_FIELD_NUMHUMANS, 1, SLIST_TEST_GREATEREQUAL);
361 // gametype filtering
363 sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(typestr, ":"), SLIST_TEST_STARTSWITH);
368 if(substring(modstr, 0, 1) == "!")
369 sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(substring(modstr, 1, strlen(modstr) - 1)), SLIST_TEST_NOTEQUAL);
371 sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(modstr), SLIST_TEST_EQUAL);
375 n = tokenizebyseparator(_Nex_ExtResponseSystem_BannedServers, " ");
376 for(i = 0; i < n; ++i)
378 sethostcachemaskstring(++m, SLIST_FIELD_CNAME, argv(i), SLIST_TEST_NOTSTARTSWITH);
380 m = SLIST_MASK_OR - 1;
383 sethostcachemaskstring(++m, SLIST_FIELD_NAME, s, SLIST_TEST_CONTAINS);
384 sethostcachemaskstring(++m, SLIST_FIELD_MAP, s, SLIST_TEST_CONTAINS);
385 sethostcachemaskstring(++m, SLIST_FIELD_PLAYERS, s, SLIST_TEST_CONTAINS);
386 sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(s, ":"), SLIST_TEST_STARTSWITH);
390 //listflags |= SLSF_FAVORITES;
391 listflags |= SLSF_CATEGORIES;
392 if(me.currentSortOrder < 0) { listflags |= SLSF_DESCENDING; }
393 sethostcachesort(me.currentSortField, listflags);
397 if(mode >= REFRESHSERVERLIST_ASK)
398 refreshhostcache(mode >= REFRESHSERVERLIST_RESET);
400 void XonoticServerList_focusEnter(entity me)
402 SUPER(XonoticServerList).focusEnter(me);
403 if(time < me.nextRefreshTime)
405 //print("sorry, no refresh yet\n");
408 me.nextRefreshTime = time + 10;
409 me.refreshServerList(me, REFRESHSERVERLIST_ASK);
412 void XonoticServerList_draw(entity me)
415 bool found = false, owned;
417 if(_Nex_ExtResponseSystem_BannedServersNeedsRefresh)
421 _Nex_ExtResponseSystem_BannedServersNeedsRefresh = 0;
424 if(_Nex_ExtResponseSystem_PromotedServersNeedsRefresh)
428 _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 0;
431 if(_Nex_ExtResponseSystem_RecommendedServersNeedsRefresh)
435 _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 0;
438 if(me.currentSortField == -1)
440 me.setSortOrder(me, SLIST_FIELD_PING, +1);
441 me.refreshServerList(me, REFRESHSERVERLIST_RESET);
443 else if(me.needsRefresh == 1)
445 me.needsRefresh = 2; // delay by one frame to make sure "slist" has been executed
447 else if(me.needsRefresh == 2)
450 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
452 else if(me.needsRefresh == 3)
455 me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
458 owned = ((me.selectedServer == me.ipAddressBox.text) && (me.ipAddressBox.text != ""));
460 for(i = 0; i < category_draw_count; ++i) { category_name[i] = -1; category_item[i] = -1; }
461 category_draw_count = 0;
463 if(autocvar_menu_slist_categories >= 0) // if less than 0, don't even draw a category heading for favorites
465 float itemcount = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT);
466 me.nItems = itemcount;
468 //float visible = floor(me.scrollPos / me.itemHeight);
469 // ^ unfortunately no such optimization can be made-- we must process through the
470 // entire list, otherwise there is no way to know which item is first in its category.
472 // binary search method suggested by div
474 for(int j = 1; j <= category_ent_count; ++j) {
476 float last = (itemcount - 1);
481 float catf = gethostcachenumber(SLIST_FIELD_CATEGORY, first);
482 float catl = gethostcachenumber(SLIST_FIELD_CATEGORY, last);
484 // The first one is already > j.
485 // Therefore, category j does not exist.
486 // Higher numbered categories do exist though.
487 } else if (catl < j) {
488 // The last one is < j.
489 // Thus this category - and any following -
492 } else if (catf == j) {
493 // Starts at first. This breaks the loop
494 // invariant in the binary search and thus has
495 // to be handled separately.
496 if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != j)
497 error("Category mismatch I");
499 if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == j)
500 error("Category mismatch II");
501 category_name[category_draw_count] = j;
502 category_item[category_draw_count] = first;
503 ++category_draw_count;
506 // At this point, catf <= j < catl, thus
507 // catf < catl, thus first < last.
510 // catf == gethostcachenumber(SLIST_FIELD_CATEGORY(first)
511 // catl == gethostcachenumber(SLIST_FIELD_CATEGORY(last)
514 while (last - first > 1) {
515 float middle = floor((first + last) / 2);
516 // By loop condition, middle != first && middle != last.
517 float cat = gethostcachenumber(SLIST_FIELD_CATEGORY, middle);
527 if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != j)
528 error("Category mismatch III");
530 if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == j)
531 error("Category mismatch IV");
532 category_name[category_draw_count] = j;
533 category_item[category_draw_count] = last;
534 ++category_draw_count;
535 begin = last + 1; // already scanned through these, skip 'em
538 begin = last; // already scanned through these, skip 'em
541 if(autocvar_menu_slist_categories_onlyifmultiple && (category_draw_count == 1))
543 category_name[0] = -1;
544 category_item[0] = -1;
545 category_draw_count = 0;
546 me.nItems = itemcount;
549 else { me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); }
551 me.connectButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == ""));
552 me.disconnectButton.disabled = (!(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)));
553 me.infoButton.disabled = (me.lockedSelectedItem || me.nItems == 0 || !owned);
554 me.favoriteButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == ""));
556 if(me.lockedSelectedItem)
560 if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer)
562 strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
567 else if(me.selectedServer)
569 for(i = 0; i < me.nItems; ++i)
571 if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer)
573 // don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i);
584 // selected server disappeared, select the last server (scrolling to it)
585 if(me.selectedItem >= me.nItems)
586 SUPER(XonoticServerList).setSelected(me, me.nItems - 1);
587 strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
593 if(me.selectedServer != me.ipAddressBox.text)
595 me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
596 me.ipAddressBox.cursorPos = strlen(me.selectedServer);
597 me.ipAddressBoxFocused = -1;
601 if(me.ipAddressBoxFocused != me.ipAddressBox.focused)
603 if(me.ipAddressBox.focused || me.ipAddressBoxFocused < 0)
604 ServerList_Update_favoriteButton(NULL, me);
605 me.ipAddressBoxFocused = me.ipAddressBox.focused;
608 SUPER(XonoticServerList).draw(me);
610 void ServerList_PingSort_Click(entity btn, entity me)
612 me.setSortOrder(me, SLIST_FIELD_PING, +1);
614 void ServerList_NameSort_Click(entity btn, entity me)
616 me.setSortOrder(me, SLIST_FIELD_NAME, -1); // why?
618 void ServerList_MapSort_Click(entity btn, entity me)
620 me.setSortOrder(me, SLIST_FIELD_MAP, -1); // why?
622 void ServerList_PlayerSort_Click(entity btn, entity me)
624 me.setSortOrder(me, SLIST_FIELD_NUMHUMANS, -1);
626 void ServerList_TypeSort_Click(entity btn, entity me)
628 string s = me.filterString;
629 int m = strstrofs(s, ":", 0);
632 s = substring(s, 0, m);
633 while(substring(s, m+1, 1) == " ") // skip spaces
639 Gametype first = NULL; FOREACH(Gametypes, !first, first = it; break);
641 FOREACH(Gametypes, s == MapInfo_Type_ToString(it), {
642 // the type was found
643 // choose the next one
645 s = MapInfo_Type_ToString(Gametypes_from(it.m_id + 1));
646 if (s == "") s = MapInfo_Type_ToString(first);
651 // choose the first one
652 s = MapInfo_Type_ToString(first);
655 if(s != "") s = strcat(s, ":");
656 s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1));
658 me.controlledTextbox.setText(me.controlledTextbox, s);
659 me.controlledTextbox.keyDown(me.controlledTextbox, K_END, 0, 0);
660 me.controlledTextbox.keyUp(me.controlledTextbox, K_END, 0, 0);
661 //ServerList_Filter_Change(me.controlledTextbox, me);
663 void ServerList_Filter_Change(entity box, entity me)
665 strfree(me.filterString);
667 me.filterString = strzone(box.text);
668 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
670 me.ipAddressBox.setText(me.ipAddressBox, "");
671 me.ipAddressBox.cursorPos = 0;
672 me.ipAddressBoxFocused = -1;
674 void ServerList_Categories_Click(entity box, entity me)
676 box.setChecked(box, autocvar_menu_slist_categories = !autocvar_menu_slist_categories);
677 me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
679 me.ipAddressBox.setText(me.ipAddressBox, "");
680 me.ipAddressBox.cursorPos = 0;
681 me.ipAddressBoxFocused = -1;
683 void ServerList_ShowEmpty_Click(entity box, entity me)
685 box.setChecked(box, me.filterShowEmpty = !me.filterShowEmpty);
686 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
688 me.ipAddressBox.setText(me.ipAddressBox, "");
689 me.ipAddressBox.cursorPos = 0;
690 me.ipAddressBoxFocused = -1;
692 void ServerList_ShowFull_Click(entity box, entity me)
694 box.setChecked(box, me.filterShowFull = !me.filterShowFull);
695 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
697 me.ipAddressBox.setText(me.ipAddressBox, "");
698 me.ipAddressBox.cursorPos = 0;
699 me.ipAddressBoxFocused = -1;
701 void XonoticServerList_setSortOrder(entity me, int fld, int direction)
703 if(me.currentSortField == fld)
704 direction = -me.currentSortOrder;
705 me.currentSortOrder = direction;
706 me.currentSortField = fld;
707 me.sortButton1.forcePressed = (fld == SLIST_FIELD_PING);
708 me.sortButton2.forcePressed = (fld == SLIST_FIELD_NAME);
709 me.sortButton3.forcePressed = (fld == SLIST_FIELD_MAP);
710 me.sortButton4.forcePressed = 0;
711 me.sortButton5.forcePressed = (fld == SLIST_FIELD_NUMHUMANS);
713 strfree(me.selectedServer);
714 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
716 void XonoticServerList_positionSortButton(entity me, entity btn, float theOrigin, float theSize, string theTitle, void(entity, entity) theFunc)
718 vector originInLBSpace, sizeInLBSpace;
719 originInLBSpace = eY * (-me.itemHeight);
720 sizeInLBSpace = eY * me.itemHeight + eX * (1 - me.controlWidth);
722 vector originInDialogSpace, sizeInDialogSpace;
723 originInDialogSpace = boxToGlobal(originInLBSpace, me.Container_origin, me.Container_size);
724 sizeInDialogSpace = boxToGlobalSize(sizeInLBSpace, me.Container_size);
726 btn.Container_origin_x = originInDialogSpace.x + sizeInDialogSpace.x * theOrigin;
727 btn.Container_size_x = sizeInDialogSpace.x * theSize;
728 btn.setText(btn, theTitle);
729 btn.onClick = theFunc;
730 btn.onClickEntity = me;
733 void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
735 SUPER(XonoticServerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
737 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
738 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
739 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
741 me.columnIconsOrigin = 0;
742 me.columnIconsSize = me.realFontSize.x * 4 * me.iconsSizeFactor;
743 me.columnPingSize = me.realFontSize.x * 3;
744 me.columnMapSize = me.realFontSize.x * 10;
745 me.columnTypeSize = me.realFontSize.x * 4;
746 me.columnPlayersSize = me.realFontSize.x * 5;
747 me.columnNameSize = 1 - me.columnPlayersSize - me.columnMapSize - me.columnPingSize - me.columnIconsSize - me.columnTypeSize - 5 * me.realFontSize.x;
748 me.columnPingOrigin = me.columnIconsOrigin + me.columnIconsSize + me.realFontSize.x;
749 me.columnNameOrigin = me.columnPingOrigin + me.columnPingSize + me.realFontSize.x;
750 me.columnMapOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
751 me.columnTypeOrigin = me.columnMapOrigin + me.columnMapSize + me.realFontSize.x;
752 me.columnPlayersOrigin = me.columnTypeOrigin + me.columnTypeSize + me.realFontSize.x;
754 me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, _("Ping"), ServerList_PingSort_Click);
755 me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Hostname"), ServerList_NameSort_Click);
756 me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, _("Map"), ServerList_MapSort_Click);
757 me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, _("Type"), ServerList_TypeSort_Click);
758 me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click);
760 int f = me.currentSortField;
763 me.currentSortField = -1;
764 me.setSortOrder(me, f, me.currentSortOrder); // force resetting the sort order
767 void ServerList_Connect_Click(entity btn, entity me)
769 if (me.lockedSelectedItem)
771 string sv = (me.ipAddressBox.text != "") ? me.ipAddressBox.text : me.selectedServer;
772 localcmd(sprintf("connect %s\n", sv));
774 void ServerList_Favorite_Click(entity btn, entity this)
776 string addr = this.ipAddressBox.text;
777 string ipstr = netaddress_resolve(addr, 26000);
778 if (ipstr == "") return;
779 m_play_click_sound(MENU_SOUND_SELECT);
780 this.toggleFavorite(this, addr);
781 this.ipAddressBoxFocused = -1;
783 void ServerList_Info_Click(entity btn, entity me)
786 main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
788 vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
789 vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
790 DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
792 void XonoticServerList_doubleClickListBoxItem(entity me, int i, vector where)
794 ServerList_Connect_Click(NULL, me);
796 void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
798 // layout: Ping, Server name, Map name, NP, TP, MP
804 bool pure = false, pure_available = false;
805 int freeslots = -1, sflags = -1, j, m;
806 string s, typestr, versionstr, k, v, modname;
808 //printf("time: %f, i: %d, item: %d, nitems: %d\n", time, i, item, me.nItems);
810 vector oldscale = draw_scale;
811 vector oldshift = draw_shift;
812 #define SET_YRANGE(start,end) \
813 draw_scale = boxToGlobalSize(eX * 1 + eY * (end - start), oldscale); \
814 draw_shift = boxToGlobal(eY * start, oldshift, oldscale);
816 for (j = 0; j < category_draw_count; ++j) {
817 // Matches exactly the headings with increased height.
818 if (i == category_item[j])
822 if (j < category_draw_count)
824 entity catent = RetrieveCategoryEnt(category_name[j]);
828 (me.categoriesHeight - 1) / (me.categoriesHeight + 1),
829 me.categoriesHeight / (me.categoriesHeight + 1)
832 eY * me.realUpperMargin
835 eX * (me.columnNameOrigin + (me.columnNameSize - draw_TextWidth(catent.cat_string, 0, me.realFontSize)) * 0.5),
838 eX * (me.columnNameOrigin),
839 strcat(catent.cat_string, ":"),
842 SKINCOLOR_SERVERLIST_CATEGORY,
843 SKINALPHA_SERVERLIST_CATEGORY,
846 SET_YRANGE(me.categoriesHeight / (me.categoriesHeight + 1), 1);
850 if(isSelected && !me.lockedSelectedItem)
851 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
854 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
855 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
858 s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
859 m = tokenizebyseparator(s, ":");
864 versionstr = argv(1);
868 for(j = 2; j < m; ++j)
872 k = substring(argv(j), 0, 1);
873 v = substring(argv(j), 1, -1);
876 pure = (stof(v) == 0);
877 pure_available = true;
887 #ifdef COMPAT_NO_MOD_IS_XONOTIC
892 string original_modname = modname;
893 modname = strtolower(modname);
896 SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
897 s = gethostcachestring(SLIST_FIELD_MOD, i);
899 if(modname == "xonotic")
903 // list the mods here on which the pure server check actually works
904 if(modname != "xonotic")
905 if(modname != "instagib" || modname != "minstagib")
908 if(modname != "newtoys")
909 pure_available = false;
911 if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0)
912 theAlpha = SKINALPHA_SERVERLIST_FULL;
913 else if(freeslots == 0)
914 theAlpha = SKINALPHA_SERVERLIST_FULL; // g_maxplayers support
915 else if (!gethostcachenumber(SLIST_FIELD_NUMHUMANS, i))
916 theAlpha = SKINALPHA_SERVERLIST_EMPTY;
920 p = gethostcachenumber(SLIST_FIELD_PING, i);
921 const int PING_LOW = 75;
922 const int PING_MED = 200;
923 const int PING_HIGH = 500;
925 theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (p / PING_LOW);
926 else if(p < PING_MED)
927 theColor = SKINCOLOR_SERVERLIST_MEDPING + (SKINCOLOR_SERVERLIST_HIGHPING - SKINCOLOR_SERVERLIST_MEDPING) * ((p - PING_LOW) / (PING_MED - PING_LOW));
928 else if(p < PING_HIGH)
930 theColor = SKINCOLOR_SERVERLIST_HIGHPING;
931 theAlpha *= 1 + (SKINALPHA_SERVERLIST_HIGHPING - 1) * ((p - PING_MED) / (PING_HIGH - PING_MED));
936 theAlpha *= SKINALPHA_SERVERLIST_HIGHPING;
939 if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, i))
941 theColor = theColor * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINCOLOR_SERVERLIST_FAVORITE * SKINALPHA_SERVERLIST_FAVORITE;
942 theAlpha = theAlpha * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINALPHA_SERVERLIST_FAVORITE;
945 s = gethostcachestring(SLIST_FIELD_CNAME, i);
948 if(substring(s, 0, 1) == "[")
953 else if(IS_DIGIT(substring(s, 0, 1)))
959 q = stof(substring(crypto_getencryptlevel(s), 0, 1));
960 if((q <= 0 && cvar("crypto_aeslevel") >= 3) || (q >= 3 && cvar("crypto_aeslevel") <= 0))
962 theColor = SKINCOLOR_SERVERLIST_IMPOSSIBLE;
963 theAlpha = SKINALPHA_SERVERLIST_IMPOSSIBLE;
968 if(cvar("crypto_aeslevel") >= 2)
973 if(cvar("crypto_aeslevel") >= 1)
983 // 2: AES recommended but not available
984 // 3: AES possible and will be used
985 // 4: AES recommended and will be used
991 vector iconSize = '0 0 0';
992 iconSize_y = me.realFontSize.y * me.iconsSizeFactor;
993 iconSize_x = me.realFontSize.x * me.iconsSizeFactor;
995 vector iconPos = '0 0 0';
996 iconPos_x = (me.columnIconsSize - 3 * iconSize.x) * 0.5;
997 iconPos_y = (1 - iconSize.y) * 0.5;
1000 if(me.seenIPv4 && me.seenIPv6)
1003 draw_Picture(iconPos, "icon_ipv6", iconSize, '1 1 1', 1);
1005 draw_Picture(iconPos, "icon_ipv4", iconSize, '1 1 1', 1);
1008 iconPos.x += iconSize.x;
1012 draw_Picture(iconPos, strcat("icon_aeslevel", ftos(q)), iconSize, '1 1 1', 1);
1014 iconPos.x += iconSize.x;
1017 if(modname == "xonotic")
1019 // Here, pure_available should always be set. If not, consider
1021 if(pure_available && pure)
1022 draw_Picture(iconPos, "icon_pure1", iconSize, '1 1 1', 1);
1026 string icon = strcat("icon_mod_", modname);
1027 if(draw_PictureSize(icon) == '0 0 0')
1030 // In mods, pure_available not being present indicates
1031 // non-support of the feature. Just show the mod icon as is
1033 if(pure_available && !pure)
1034 draw_Picture(iconPos, icon, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE);
1036 draw_Picture(iconPos, icon, iconSize, '1 1 1', 1);
1039 iconPos.x += iconSize.x;
1042 if(sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS))
1043 draw_Picture(iconPos, "icon_stats1", iconSize, '1 1 1', 1);
1045 if(isFocused && me.mouseOverIcons && !me.tooltip)
1048 if(me.seenIPv4 && me.seenIPv6)
1049 t = strcat(t, (isv6) ? "IPv6, " : "IPv4, ");
1050 t = strcat(t, _("encryption:"), " ", (q ? sprintf(_("AES level %d"), q) : ZCTX(_("ENC^none"))), ", ");
1051 t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname)));
1053 t = strcat(t, sprintf(" (%s)", (pure) ? _("official settings") : _("modified settings")));
1054 t = strcat(t, ", ");
1055 t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled")));
1056 setZonedTooltip(me, t, string_null);
1064 draw_Text(me.realUpperMargin * eY + (me.columnPingOrigin + me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1067 s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, i), me.columnNameSize, 0, me.realFontSize);
1068 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
1071 s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, i), me.columnMapSize, 0, me.realFontSize);
1072 draw_Text(me.realUpperMargin * eY + (me.columnMapOrigin + (me.columnMapSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1075 s = draw_TextShortenToWidth(typestr, me.columnTypeSize, 0, me.realFontSize);
1076 draw_Text(me.realUpperMargin * eY + (me.columnTypeOrigin + (me.columnTypeSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1078 // server playercount
1079 s = strcat(ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)), "/", ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i)));
1080 draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1083 void XonoticServerList_focusedItemChangeNotify(entity me)
1088 float XonoticServerList_mouseMove(entity me, vector pos)
1090 if(!SUPER(XonoticServerList).mouseMove(me, pos))
1092 me.mouseOverIcons = false;
1097 me.mouseOverIcons = (pos_x <= me.columnIconsSize);
1098 if(!me.mouseOverIcons)
1103 bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift)
1107 org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
1108 sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
1110 if(scan == K_ENTER || scan == K_KP_ENTER)
1112 ServerList_Connect_Click(NULL, me);
1115 else if(scan == K_MOUSE2 || scan == K_SPACE)
1119 m_play_click_sound(MENU_SOUND_OPEN);
1120 main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
1121 DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
1126 else if(scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS)
1130 me.toggleFavorite(me, me.selectedServer);
1131 me.ipAddressBoxFocused = -1;
1136 else if(SUPER(XonoticServerList).keyDown(me, scan, ascii, shift))
1138 else if(!me.controlledTextbox)
1141 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
1144 float XonoticServerList_getTotalHeight(entity me)
1146 float num_normal_rows = me.nItems;
1147 int num_headers = category_draw_count;
1148 return me.itemHeight * (num_normal_rows + me.categoriesHeight * num_headers);
1150 int XonoticServerList_getItemAtPos(entity me, float pos)
1152 pos = pos / me.itemHeight;
1154 for (i = category_draw_count - 1; i >= 0; --i) {
1155 int itemidx = category_item[i];
1156 float itempos = i * me.categoriesHeight + category_item[i];
1157 if (pos >= itempos + me.categoriesHeight + 1)
1158 return itemidx + 1 + floor(pos - (itempos + me.categoriesHeight + 1));
1162 // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1165 float XonoticServerList_getItemStart(entity me, int item)
1168 for (i = category_draw_count - 1; i >= 0; --i) {
1169 int itemidx = category_item[i];
1170 float itempos = i * me.categoriesHeight + category_item[i];
1171 if (item >= itemidx + 1)
1172 return (itempos + me.categoriesHeight + 1 + item - (itemidx + 1)) * me.itemHeight;
1173 if (item >= itemidx)
1174 return itempos * me.itemHeight;
1176 // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1177 return item * me.itemHeight;
1179 float XonoticServerList_getItemHeight(entity me, int item)
1182 for (i = 0; i < category_draw_count; ++i) {
1183 // Matches exactly the headings with increased height.
1184 if (item == category_item[i])
1185 return me.itemHeight * (me.categoriesHeight + 1);
1187 return me.itemHeight;