X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fserverlist.qc;h=fc2ba573bbaa7448addcd648cde86d9a2ae421e2;hp=6b3cea416de0158dfed3fa2ab2b24783d64ff26d;hb=f72821fdcebe3ca01181a99727a06198de65ea08;hpb=6603ee5ff104719d3d4b9dad7ae4bf66f46706e5 diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index 6b3cea416..fc2ba573b 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -1,174 +1,10 @@ -#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, "", "", ZCTX(_("SLCAT^Favorites"))) \ - SLIST_CATEGORY(CAT_RECOMMENDED, "", "", ZCTX(_("SLCAT^Recommended"))) \ - SLIST_CATEGORY(CAT_NORMAL, "", "CAT_SERVERS", ZCTX(_("SLCAT^Normal Servers"))) \ - SLIST_CATEGORY(CAT_SERVERS, "CAT_NORMAL", "CAT_SERVERS", ZCTX(_("SLCAT^Servers"))) \ - SLIST_CATEGORY(CAT_XPM, "CAT_NORMAL", "CAT_SERVERS", ZCTX(_("SLCAT^Competitive Mode"))) \ - SLIST_CATEGORY(CAT_MODIFIED, "", "CAT_SERVERS", ZCTX(_("SLCAT^Modified Servers"))) \ - SLIST_CATEGORY(CAT_OVERKILL, "", "CAT_SERVERS", ZCTX(_("SLCAT^Overkill Mode"))) \ - SLIST_CATEGORY(CAT_INSTAGIB, "", "CAT_SERVERS", ZCTX(_("SLCAT^InstaGib Mode"))) \ - SLIST_CATEGORY(CAT_DEFRAG, "", "CAT_SERVERS", ZCTX(_("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 +#include "serverlist.qh" -#endif -#endif -#ifdef IMPLEMENTATION +#include "checkbox.qh" +#include "inputbox.qh" +#include "mainwindow.qh" +#include "dialog_multiplayer_join_serverinfo.qh" +#include void RegisterSLCategories() { @@ -177,7 +13,7 @@ void RegisterSLCategories() SET_FIELD_COUNT(name, CATEGORY_FIRST, category_ent_count) \ CHECK_MAX_COUNT(name, MAX_CATEGORIES, category_ent_count, "SLIST_CATEGORY") \ cat = categories[name - 1] = new(slist_category); \ - cat.cat_name = strzone(#name); \ + cat.cat_name = #name; \ cat.cat_enoverride_string = strzone(SLIST_CATEGORY_AUTOCVAR(name)); \ cat.cat_dioverride_string = strzone(dioverride); \ cat.cat_string = strzone(str); @@ -202,6 +38,7 @@ void RegisterSLCategories() if(catnum) \ { \ strunzone(categories[i].override_string); \ + categories[i].override_string = string_null; \ categories[i].override_field = catnum; \ continue; \ } \ @@ -215,6 +52,7 @@ void RegisterSLCategories() } \ } \ strunzone(categories[i].override_string); \ + categories[i].override_string = string_null; \ categories[i].override_field = 0; \ } PROCESS_OVERRIDE(cat_enoverride_string, cat_enoverride) @@ -382,54 +220,44 @@ int CheckCategoryForEntry(int entry) return ((impure > autocvar_menu_slist_purethreshold) ? CAT_MODIFIED : CAT_NORMAL); } -void XonoticServerList_toggleFavorite(entity me, string srv) +METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string srv)) { - string s, s0, s1, s2, srv_resolved, p; - int i, n; - bool f = false; - srv_resolved = netaddress_resolve(srv, 26000); - p = crypto_getidfp(srv_resolved); - s = cvar_string("net_slist_favorites"); - n = tokenize_console(s); - for(i = 0; i < n; ++i) + bool adding = true; + string srv_resolved = netaddress_resolve(srv, 26000); + string p = crypto_getidfp(srv_resolved); + string s = cvar_string("net_slist_favorites"); + string ret = s; + for (int i = 0, n = tokenize_console(s); i < n; ++i) { - if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) + bool match; + if (substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) { - if(p) - if(argv(i) != p) - continue; + // it's a pubkey hash + match = (p && p == argv(i)); } else { - if(srv_resolved != netaddress_resolve(argv(i), 26000)) - continue; + // it's an ip + match = (srv_resolved == netaddress_resolve(argv(i), 26000)); } - s0 = s1 = s2 = ""; - if(i > 0) - s0 = substring(s, 0, argv_end_index(i - 1)); - if(i < n-1) - s2 = substring(s, argv_start_index(i + 1), -1); - if(s0 != "" && s2 != "") - s1 = " "; - cvar_set("net_slist_favorites", strcat(s0, s1, s2)); - s = cvar_string("net_slist_favorites"); + if (!match) continue; + // on match: remove + adding = false; + string before = (i > 0) ? substring(s, 0, argv_end_index(i - 1)) : ""; + string after = (i < n - 1) ? substring(s, argv_start_index(i + 1), -1) : ""; + s = strcat(before, (before != "" && after != "" ? " " : ""), after); + ret = s; + // keep searching + // TODO: why not break here? n = tokenize_console(s); - f = true; - --i; + --i; // offset the increment that is about to happen } - - if(!f) + if (adding) { - s1 = ""; - if(s != "") - s1 = " "; - if(p) - cvar_set("net_slist_favorites", strcat(s, s1, p)); - else - cvar_set("net_slist_favorites", strcat(s, s1, srv)); + ret = strcat(s, (s != "" ? " " : ""), p ? p : srv); } - - me.refreshServerList(me, REFRESHSERVERLIST_RESORT); + cvar_set("net_slist_favorites", ret); + this.refreshServerList(this, REFRESHSERVERLIST_RESORT); } void ServerList_Update_favoriteButton(entity btn, entity me) @@ -963,16 +791,14 @@ void ServerList_Connect_Click(entity btn, entity me) ) )); } -void ServerList_Favorite_Click(entity btn, entity me) +void ServerList_Favorite_Click(entity btn, entity this) { - string ipstr; - ipstr = netaddress_resolve(me.ipAddressBox.text, 26000); - if(ipstr != "") - { - m_play_click_sound(MENU_SOUND_SELECT); - me.toggleFavorite(me, me.ipAddressBox.text); - me.ipAddressBoxFocused = -1; - } + string addr = this.ipAddressBox.text; + string ipstr = netaddress_resolve(addr, 26000); + if (ipstr == "") return; + m_play_click_sound(MENU_SOUND_SELECT); + this.toggleFavorite(this, addr); + this.ipAddressBoxFocused = -1; } void ServerList_Info_Click(entity btn, entity me) { @@ -1380,5 +1206,3 @@ float XonoticServerList_getItemHeight(entity me, int item) } return me.itemHeight; } - -#endif