#include "serverlist.qh"
-#ifndef SERVERLIST_H
-#define SERVERLIST_H
-#include "listbox.qc"
-CLASS(XonoticServerList, XonoticListBox)
- METHOD(XonoticServerList, configureXonoticServerList, void(entity));
- ATTRIB(XonoticServerList, rowsPerItem, float, 1)
- METHOD(XonoticServerList, draw, void(entity));
- METHOD(XonoticServerList, drawListBoxItem, void(entity, int, vector, bool, bool));
- METHOD(XonoticServerList, doubleClickListBoxItem, void(entity, float, vector));
- METHOD(XonoticServerList, resizeNotify, void(entity, vector, vector, vector, vector));
- METHOD(XonoticServerList, keyDown, float(entity, float, float, float));
- METHOD(XonoticServerList, toggleFavorite, void(entity, string));
-
- ATTRIB(XonoticServerList, iconsSizeFactor, float, 0.85)
- METHOD(XonoticServerList, mouseMove, float(entity, vector));
- ATTRIB(XonoticServerList, mouseOverIcons, bool, false)
- METHOD(XonoticServerList, focusedItemChangeNotify, void(entity));
-
- ATTRIB(XonoticServerList, realFontSize, vector, '0 0 0')
- ATTRIB(XonoticServerList, realUpperMargin, float, 0)
- ATTRIB(XonoticServerList, columnIconsOrigin, float, 0)
- ATTRIB(XonoticServerList, columnIconsSize, float, 0)
- ATTRIB(XonoticServerList, columnPingOrigin, float, 0)
- ATTRIB(XonoticServerList, columnPingSize, float, 0)
- ATTRIB(XonoticServerList, columnNameOrigin, float, 0)
- ATTRIB(XonoticServerList, columnNameSize, float, 0)
- ATTRIB(XonoticServerList, columnMapOrigin, float, 0)
- ATTRIB(XonoticServerList, columnMapSize, float, 0)
- ATTRIB(XonoticServerList, columnTypeOrigin, float, 0)
- ATTRIB(XonoticServerList, columnTypeSize, float, 0)
- ATTRIB(XonoticServerList, columnPlayersOrigin, float, 0)
- ATTRIB(XonoticServerList, columnPlayersSize, float, 0)
- ATTRIB(XonoticServerList, lockedSelectedItem, bool, true) // initially keep selected the first item of the list, avoiding an unwanted scrolling
-
- ATTRIB(XonoticServerList, selectedServer, string, string_null) // to restore selected server when needed
- METHOD(XonoticServerList, setSelected, void(entity, float));
- METHOD(XonoticServerList, setSortOrder, void(entity, float, float));
- ATTRIB(XonoticServerList, filterShowEmpty, float, 1)
- ATTRIB(XonoticServerList, filterShowFull, float, 1)
- ATTRIB(XonoticServerList, filterString, string, string_null)
- ATTRIB(XonoticServerList, controlledTextbox, entity, NULL)
- ATTRIB(XonoticServerList, ipAddressBox, entity, NULL)
- ATTRIB(XonoticServerList, favoriteButton, entity, NULL)
- ATTRIB(XonoticServerList, nextRefreshTime, float, 0)
- METHOD(XonoticServerList, refreshServerList, void(entity, float)); // refresh mode: REFRESHSERVERLIST_*
- ATTRIB(XonoticServerList, needsRefresh, float, 1)
- METHOD(XonoticServerList, focusEnter, void(entity));
- METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity)));
- ATTRIB(XonoticServerList, sortButton1, entity, NULL)
- ATTRIB(XonoticServerList, sortButton2, entity, NULL)
- ATTRIB(XonoticServerList, sortButton3, entity, NULL)
- ATTRIB(XonoticServerList, sortButton4, entity, NULL)
- ATTRIB(XonoticServerList, sortButton5, entity, NULL)
- ATTRIB(XonoticServerList, connectButton, entity, NULL)
- ATTRIB(XonoticServerList, infoButton, entity, NULL)
- ATTRIB(XonoticServerList, currentSortOrder, float, 0)
- ATTRIB(XonoticServerList, currentSortField, float, -1)
-
- ATTRIB(XonoticServerList, ipAddressBoxFocused, float, -1)
-
- ATTRIB(XonoticServerList, seenIPv4, float, 0)
- ATTRIB(XonoticServerList, seenIPv6, float, 0)
- ATTRIB(XonoticServerList, categoriesHeight, float, 1.25)
-
- METHOD(XonoticServerList, getTotalHeight, float(entity));
- METHOD(XonoticServerList, getItemAtPos, float(entity, float));
- METHOD(XonoticServerList, getItemStart, float(entity, float));
- METHOD(XonoticServerList, getItemHeight, float(entity, float));
-ENDCLASS(XonoticServerList)
-entity makeXonoticServerList();
-
-#ifndef IMPLEMENTATION
-float autocvar_menu_slist_categories;
-float autocvar_menu_slist_categories_onlyifmultiple;
-float autocvar_menu_slist_purethreshold;
-float autocvar_menu_slist_modimpurity;
-float autocvar_menu_slist_recommendations;
-float autocvar_menu_slist_recommendations_maxping;
-float autocvar_menu_slist_recommendations_minfreeslots;
-float autocvar_menu_slist_recommendations_minhumans;
-float autocvar_menu_slist_recommendations_purethreshold;
-
-// server cache fields
-#define SLIST_FIELDS \
- SLIST_FIELD(CNAME, "cname") \
- SLIST_FIELD(PING, "ping") \
- SLIST_FIELD(GAME, "game") \
- SLIST_FIELD(MOD, "mod") \
- SLIST_FIELD(MAP, "map") \
- SLIST_FIELD(NAME, "name") \
- SLIST_FIELD(MAXPLAYERS, "maxplayers") \
- SLIST_FIELD(NUMPLAYERS, "numplayers") \
- SLIST_FIELD(NUMHUMANS, "numhumans") \
- SLIST_FIELD(NUMBOTS, "numbots") \
- SLIST_FIELD(PROTOCOL, "protocol") \
- SLIST_FIELD(FREESLOTS, "freeslots") \
- SLIST_FIELD(PLAYERS, "players") \
- SLIST_FIELD(QCSTATUS, "qcstatus") \
- SLIST_FIELD(CATEGORY, "category") \
- SLIST_FIELD(ISFAVORITE, "isfavorite")
-
-#define SLIST_FIELD(suffix,name) float SLIST_FIELD_##suffix;
-SLIST_FIELDS
-#undef SLIST_FIELD
-
-const float REFRESHSERVERLIST_RESORT = 0; // sort the server list again to update for changes to e.g. favorite status, categories
-const float REFRESHSERVERLIST_REFILTER = 1; // ..., also update filter and sort criteria
-const float REFRESHSERVERLIST_ASK = 2; // ..., also suggest querying servers now
-const float REFRESHSERVERLIST_RESET = 3; // ..., also clear the list first
-
-// function declarations
-float IsServerInList(string list, string srv);
-#define IsFavorite(srv) IsServerInList(cvar_string("net_slist_favorites"), srv)
-#define IsPromoted(srv) IsServerInList(_Nex_ExtResponseSystem_PromotedServers, srv)
-#define IsRecommended(srv) IsServerInList(_Nex_ExtResponseSystem_RecommendedServers, srv)
-
-entity RetrieveCategoryEnt(float catnum);
-
-float CheckCategoryOverride(float cat);
-float CheckCategoryForEntry(float entry);
-float m_gethostcachecategory(float entry) { return CheckCategoryOverride(CheckCategoryForEntry(entry)); }
-
-void RegisterSLCategories();
-
-void ServerList_Connect_Click(entity btn, entity me);
-void ServerList_Categories_Click(entity box, entity me);
-void ServerList_ShowEmpty_Click(entity box, entity me);
-void ServerList_ShowFull_Click(entity box, entity me);
-void ServerList_Filter_Change(entity box, entity me);
-void ServerList_Favorite_Click(entity btn, entity me);
-void ServerList_Info_Click(entity btn, entity me);
-void ServerList_Update_favoriteButton(entity btn, entity me);
-
-// fields for category entities
-const int MAX_CATEGORIES = 9;
-const int CATEGORY_FIRST = 1;
-entity categories[MAX_CATEGORIES];
-int category_ent_count;
-.string cat_name;
-.string cat_string;
-.string cat_enoverride_string;
-.string cat_dioverride_string;
-.float cat_enoverride;
-.float cat_dioverride;
-
-// fields for drawing categories
-int category_name[MAX_CATEGORIES];
-int category_item[MAX_CATEGORIES];
-int category_draw_count;
-
-#define SLIST_CATEGORIES \
- SLIST_CATEGORY(CAT_FAVORITED, "", "", CTX(_("SLCAT^Favorites"))) \
- SLIST_CATEGORY(CAT_RECOMMENDED, "", "", CTX(_("SLCAT^Recommended"))) \
- SLIST_CATEGORY(CAT_NORMAL, "", "CAT_SERVERS", CTX(_("SLCAT^Normal Servers"))) \
- SLIST_CATEGORY(CAT_SERVERS, "CAT_NORMAL", "CAT_SERVERS", CTX(_("SLCAT^Servers"))) \
- SLIST_CATEGORY(CAT_XPM, "CAT_NORMAL", "CAT_SERVERS", CTX(_("SLCAT^Competitive Mode"))) \
- SLIST_CATEGORY(CAT_MODIFIED, "", "CAT_SERVERS", CTX(_("SLCAT^Modified Servers"))) \
- SLIST_CATEGORY(CAT_OVERKILL, "", "CAT_SERVERS", CTX(_("SLCAT^Overkill Mode"))) \
- SLIST_CATEGORY(CAT_INSTAGIB, "", "CAT_SERVERS", CTX(_("SLCAT^InstaGib Mode"))) \
- SLIST_CATEGORY(CAT_DEFRAG, "", "CAT_SERVERS", CTX(_("SLCAT^Defrag Mode")))
-
-#define SLIST_CATEGORY_AUTOCVAR(name) autocvar_menu_slist_categories_##name##_override
-#define SLIST_CATEGORY(name,enoverride,dioverride,str) \
- int name; \
- string SLIST_CATEGORY_AUTOCVAR(name) = enoverride;
-SLIST_CATEGORIES
-#undef SLIST_CATEGORY
-#endif
-#endif
-#ifdef IMPLEMENTATION
+#include "checkbox.qh"
+#include "inputbox.qh"
+#include "mainwindow.qh"
+#include "dialog_multiplayer_join_serverinfo.qh"
+#include <common/mapinfo.qh>
void RegisterSLCategories()
{
else \
{ \
LOG_INFOF( \
- "RegisterSLCategories(): Improper override '%s' for category '%s'!\n", \
+ "RegisterSLCategories(): Improper override '%s' for category '%s'!", \
s, \
categories[i].cat_name \
); \
case "cts":
case "xdf": { return CAT_DEFRAG; }
- default: { LOG_TRACEF("Found strange mod type: %s\n", modtype); return CAT_MODIFIED; }
+ default: { LOG_TRACEF("Found strange mod type: %s", modtype); return CAT_MODIFIED; }
}
}
// entire list, otherwise there is no way to know which item is first in its category.
// binary search method suggested by div
- float x;
float begin = 0;
- for(x = 1; x <= category_ent_count; ++x) {
+ for(int j = 1; j <= category_ent_count; ++j) {
float first = begin;
float last = (itemcount - 1);
if (first > last) {
}
float catf = gethostcachenumber(SLIST_FIELD_CATEGORY, first);
float catl = gethostcachenumber(SLIST_FIELD_CATEGORY, last);
- if (catf > x) {
- // The first one is already > x.
- // Therefore, category x does not exist.
+ if (catf > j) {
+ // The first one is already > j.
+ // Therefore, category j does not exist.
// Higher numbered categories do exist though.
- } else if (catl < x) {
- // The last one is < x.
+ } else if (catl < j) {
+ // The last one is < j.
// Thus this category - and any following -
// don't exist.
break;
- } else if (catf == x) {
+ } else if (catf == j) {
// Starts at first. This breaks the loop
// invariant in the binary search and thus has
// to be handled separately.
- if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != x)
+ if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != j)
error("Category mismatch I");
if(first > 0)
- if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == x)
+ if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == j)
error("Category mismatch II");
- category_name[category_draw_count] = x;
+ category_name[category_draw_count] = j;
category_item[category_draw_count] = first;
++category_draw_count;
begin = first + 1;
} else {
- // At this point, catf <= x < catl, thus
+ // At this point, catf <= j < catl, thus
// catf < catl, thus first < last.
// INVARIANTS:
// last - first >= 1
// catf == gethostcachenumber(SLIST_FIELD_CATEGORY(first)
// catl == gethostcachenumber(SLIST_FIELD_CATEGORY(last)
- // catf < x
- // catl >= x
+ // catf < j
+ // catl >= j
while (last - first > 1) {
float middle = floor((first + last) / 2);
// By loop condition, middle != first && middle != last.
float cat = gethostcachenumber(SLIST_FIELD_CATEGORY, middle);
- if (cat >= x) {
+ if (cat >= j) {
last = middle;
catl = cat;
} else {
catf = cat;
}
}
- if (catl == x) {
- if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != x)
+ if (catl == j) {
+ if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != j)
error("Category mismatch III");
if(last > 0)
- if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == x)
+ if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == j)
error("Category mismatch IV");
- category_name[category_draw_count] = x;
+ category_name[category_draw_count] = j;
category_item[category_draw_count] = last;
++category_draw_count;
begin = last + 1; // already scanned through these, skip 'em
}
void ServerList_TypeSort_Click(entity btn, entity me)
{
- string s, t;
- float i, m;
- s = me.filterString;
- m = strstrofs(s, ":", 0);
+ string s = me.filterString;
+ int m = strstrofs(s, ":", 0);
if(m >= 0)
{
s = substring(s, 0, m);
else
s = "";
- for(i = 1; ; i *= 2) // 20 modes ought to be enough for anyone
- {
- t = MapInfo_Type_ToString(i);
- if(i > 1)
- if(t == "") // it repeats (default case)
- {
- // no type was found
- // choose the first one
- s = MapInfo_Type_ToString(1);
- break;
- }
- if(s == t)
- {
- // the type was found
- // choose the next one
- s = MapInfo_Type_ToString(i * 2);
- if(s == "")
- s = MapInfo_Type_ToString(1);
- break;
- }
+ Gametype first = NULL; FOREACH(Gametypes, !first, first = it; break);
+ bool flag = false;
+ FOREACH(Gametypes, s == MapInfo_Type_ToString(it), {
+ // the type was found
+ // choose the next one
+ flag = true;
+ s = MapInfo_Type_ToString(Gametypes_from(it.m_id + 1));
+ if (s == "") s = MapInfo_Type_ToString(first);
+ break;
+ });
+ if (!flag) {
+ // no type was found
+ // choose the first one
+ s = MapInfo_Type_ToString(first);
}
- if(s != "")
- s = strcat(s, ":");
+ if(s != "") s = strcat(s, ":");
s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1));
me.controlledTextbox.setText(me.controlledTextbox, s);
me.columnPlayersOrigin = me.columnTypeOrigin + me.columnTypeSize + me.realFontSize.x;
me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, _("Ping"), ServerList_PingSort_Click);
- me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Host name"), ServerList_NameSort_Click);
+ me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Hostname"), ServerList_NameSort_Click);
me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, _("Map"), ServerList_MapSort_Click);
me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, _("Type"), ServerList_TypeSort_Click);
me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click);
isv6 = true;
me.seenIPv6 += 1;
}
- else if(strstrofs("0123456789", substring(s, 0, 1), 0) >= 0)
+ else if(IS_DIGIT(substring(s, 0, 1)))
{
isv4 = true;
me.seenIPv4 += 1;
t = strcat(t, _("encryption:"), " ", (q ? sprintf(_("AES level %d"), q) : ZCTX(_("ENC^none"))), ", ");
t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname)));
if(pure_available)
- t = strcat(t, sprintf(_(" (%s)"), (pure) ? _("official settings") : _("modified settings")));
+ t = strcat(t, sprintf(" (%s)", (pure) ? _("official settings") : _("modified settings")));
t = strcat(t, ", ");
t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled")));
setZonedTooltip(me, t, string_null);
}
return me.itemHeight;
}
-
-#endif