From 976e7249f02bcad2d730d45b2278d4a67ae28165 Mon Sep 17 00:00:00 2001 From: "erin.cena" Date: Mon, 2 Nov 2026 18:13:42 -0500 Subject: [PATCH 1/2] Add filters to the server browsers: full, empty and password games, ping, game types and a search The server browser and the local network's list get a Filters page (FILTERS in the footer, the left trigger, L on the keyboard; or Settings > Online > SERVER BROWSER FILTERS): SHOW FULL GAMES, SHOW EMPTY GAMES and SHOW PASSWORD GAMES (YES or NO), PING (ANY, or under 300, 250, 150, 100 or 50 ms), SEARCH (words a game's server name or map must have, in any case), and GAME TYPES, each of CTF, Slayer, Oddball, King of the Hill and Race shown or hidden, so any mix of them can be listed. The page is a page of Settings' (tools/port_settings.py's BROWSER_FILTERS, under the PC version's FILTERS title), so its OK keeps the choices in config.toml, the network.browser_* settings, and the browser reads them as it opens. Join by Link's list, whose games are the invites taken, is not filtered. A game whose ping is not known (a local network game, a dedicated server the masters list, one still being timed) stays listed under a ping limit. Co-op games have no game type and stay listed (the CO-OP tab is theirs). The counts over the list say how many games the filters hide, and a list they leave empty says so and where to change them. The counts line is wider for it. The full and empty filters, and their settings' names (network.browser_show_full, network.browser_show_empty), follow OpenCE's Filters screen (OpenCommunityEdition/OpenCE#490, by MrBruh), which our port of that change left out with its browser. The left trigger had no key in the menus: L presses it now, and the prompts draw it as L (ui_widget_port_menu_key). The README's paragraph on OpenCE's Filters screen, which this browser never had, is replaced by ours. Checked: the harness's browser_menu test has a filters case (each filter, the settings read, the list's order and hidden count) with negative controls, and the menu_keys test the L key. Co-authored-by: MrBruh <4706866+cybersecurity@users.noreply.github.com> --- ...menu.multiplayer_type_select.join_game.xml | 9 +- ...ile_edit.network_setup.browser_filters.xml | 179 +++++++++++ ...etup.player_profile_edit.network_setup.xml | 43 ++- port/assets/menus/menus.json | 1 + port/linux/README.md | 40 ++- port/linux/game/menu_functions.c | 296 +++++++++++++++++- port/linux/game/menu_tags.c | 3 + port/linux/src/port_config.c | 35 +++ port/linux/src/xinput_sdl.c | 2 + source/interface/ui_widget.c | 8 +- tools/harness/tests/browser_menu.c | 199 +++++++++++- tools/harness/tests/menu_keys.c | 2 + tools/harness/tests/test_browser_menu.py | 34 +- tools/harness/tests/test_menu_keys.py | 4 +- tools/port_settings.py | 51 ++- 15 files changed, 851 insertions(+), 55 deletions(-) create mode 100644 port/assets/menus/ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.browser_filters.xml diff --git a/port/assets/menus/ce/main_menu.multiplayer_type_select.join_game.xml b/port/assets/menus/ce/main_menu.multiplayer_type_select.join_game.xml index 796bac7f28..6ada21102f 100644 --- a/port/assets/menus/ce/main_menu.multiplayer_type_select.join_game.xml +++ b/port/assets/menus/ce/main_menu.multiplayer_type_select.join_game.xml @@ -11,6 +11,7 @@ + @@ -28,7 +29,7 @@ - + @@ -409,6 +410,7 @@ + @@ -431,6 +433,11 @@ + + + + + diff --git a/port/assets/menus/ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.browser_filters.xml b/port/assets/menus/ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.browser_filters.xml new file mode 100644 index 0000000000..6a595a3e62 --- /dev/null +++ b/port/assets/menus/ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.browser_filters.xml @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/port/assets/menus/ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.xml b/port/assets/menus/ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.xml index 790a4235e4..87cdba87a7 100644 --- a/port/assets/menus/ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.xml +++ b/port/assets/menus/ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.xml @@ -18,12 +18,13 @@ - - - - - - + + + + + + + @@ -128,16 +129,24 @@ - - + + + + + + + + + + - + - + @@ -146,7 +155,7 @@ - + @@ -155,21 +164,21 @@ - + - - + + - + - + @@ -180,6 +189,7 @@ + @@ -194,6 +204,7 @@ + diff --git a/port/assets/menus/menus.json b/port/assets/menus/menus.json index 864f6eb8b4..ec3fe43ad0 100644 --- a/port/assets/menus/menus.json +++ b/port/assets/menus/menus.json @@ -67,6 +67,7 @@ "ce/main_menu.settings_select.player_setup.player_profile_edit.interface_settings.xml", "ce/main_menu.settings_select.player_setup.player_profile_edit.mouse_settings.xml", "ce/main_menu.settings_select.player_setup.player_profile_edit.name_edit.xml", + "ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.browser_filters.xml", "ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.discord_account.xml", "ce/main_menu.settings_select.player_setup.player_profile_edit.network_setup.xml", "ce/main_menu.settings_select.player_setup.player_profile_edit.profile_settings.xml", diff --git a/port/linux/README.md b/port/linux/README.md index 19f82f2dac..e83573344f 100644 --- a/port/linux/README.md +++ b/port/linux/README.md @@ -1043,6 +1043,12 @@ the setting for one start of the game. It has priority over the file. | `network.tunnel_port` | `0` | `HALO_NET_TUNNEL_PORT` | The UDP port for internet play. `0`: the game selects a port. Refer to "Internet play". | | `network.allow_upnp` | `true` | `HALO_NET_ALLOW_UPNP` | `true`: internet play can ask the router to forward its port (UPnP). `false`: the game does not ask. Refer to "Internet play". | | `network.public_lobby` | `true` | `HALO_NET_PUBLIC_LOBBY` | `true`: the server browser. Public games are listed, and Join Game > Server Browser shows them. `false`: no games are listed or shown. Refer to "Server browser". | +| `network.browser_show_full` | `true` | `HALO_NET_BROWSER_SHOW_FULL` | `false`: the server browser and the local network's list hide full games. Their Filters page. Refer to "Server browser". | +| `network.browser_show_empty` | `true` | `HALO_NET_BROWSER_SHOW_EMPTY` | `false`: the server browser and the local network's list hide games with no player. Their Filters page. | +| `network.browser_show_password` | `true` | `HALO_NET_BROWSER_SHOW_PASSWORD` | `false`: the server browser hides games that need a password. Their Filters page. | +| `network.browser_ping` | `0` | `HALO_NET_BROWSER_PING` | The server browsers list only games whose ping is under this many milliseconds (300, 250, 150, 100 or 50); `0` lists every game. A game whose ping is not known (a local network game's, a dedicated server's, one still being timed) is listed. Their Filters page. | +| `network.browser_show_ctf`, `network.browser_show_slayer`, `network.browser_show_oddball`, `network.browser_show_king`, `network.browser_show_race` | `true` | `HALO_NET_BROWSER_SHOW_CTF`, `HALO_NET_BROWSER_SHOW_SLAYER`, `HALO_NET_BROWSER_SHOW_ODDBALL`, `HALO_NET_BROWSER_SHOW_KING`, `HALO_NET_BROWSER_SHOW_RACE` | `false`: the server browsers hide the games of that game type (OpenCE's kinds of it too: SWAT is Slayer). Co-op games have none (the CO-OP tab). Their Filters page. | +| `network.browser_search` | `""` | `HALO_NET_BROWSER_SEARCH` | The server browsers list only games whose server name or map (as shown, or its own name) has these words, in any case. Empty lists every game. Their Filters page's SEARCH. | | `friends.share_status` | `true` | `HALO_FRIENDS_SHARE_STATUS` | Show your friends that you are online, and where, and let them join you (Multiplayer > FRIENDS). Only your friends can read it. `false` appears offline: nothing is published, and you still see your friends. Refer to "Friends". | | `network.host_public` | `true` | `HALO_NET_HOST_PUBLIC` | `true`: a new game of Create Game > Internet starts as PUBLIC. `false`: it starts as PRIVATE. LISTING in Server Setup changes it for each game. Refer to "Server browser". | | `network.game_mode` | `"openh1"` | `HALO_NET_GAME_MODE` | When you host: `"openh1"`, an OpenH1 game ("OpenH1 60 Tick" and the like) at the tick rate `network.sim_rate` sets, which OpenCE players can join too, at 30 (`network.allow_opence`); `"legacy"`, OpenCE's netcode at 30 ticks a second for everyone. `"standard"` is the same as `"openh1"`. Server Setup's GAME row (OPENH1 30 TICK, OPENH1 60 TICK, OPENH1 120 TICK or LEGACY) writes it and `network.sim_rate`. Read when hosting starts, and again when the game is started from Server Setup if no one has joined yet. Refer to "OpenH1 and Legacy games" in NETCODE.md. | @@ -2408,6 +2414,28 @@ Sorting and the tabs, in all three lists, for this run of the game: - Favorites stay at the top, sorted the same way among themselves; those not found stay at the bottom of All and Favorites, grey. +Filters, in the server browser and the local network's list (not in Join +by Link, whose games are the invites you took): FILTERS in the footer (the +left trigger, L on the keyboard, or a click), or Settings > Online > SERVER +BROWSER FILTERS, opens the Filters page. Its OK keeps the choices in +`config.toml` (the `network.browser_*` settings), so they stay for the next +time the game starts; Cancel leaves them as they were. + +- SHOW FULL GAMES, SHOW EMPTY GAMES, SHOW PASSWORD GAMES: YES or NO. +- PING: ANY, or only games under 300, 250, 150, 100 or 50 ms. A game whose + ping is not known (a local network game's, a dedicated server's, one + still being timed) stays listed. +- SEARCH: words that a game's server name or map must have, in any case + ("gulch" finds Blood Gulch). Select the row, type, and press Enter. +- GAME TYPES: CAPTURE THE FLAG, SLAYER, ODDBALL, KING OF THE HILL and RACE, + each SHOW or HIDE, so that any mix of them is listed. OpenCE's kinds go + with their game type (SWAT, Infection and Gun Game with Slayer). Co-op + games have no game type: the CO-OP tab lists them. + +The filters apply on every tab, the favorites too. The counts above the +list say how many games they hide (`3 HIDDEN`), and a list that they leave +empty says so. + The browser lists two kinds of games: the dedicated servers that the master servers list (`masters.txt`, `network.masters_file`; the official master, `https://master.opencommunityedition.com`, built in, when the file @@ -2429,17 +2457,7 @@ master servers, or only the brokers. first, the dedicated servers first among them and among the Legacy games after them, then the games with the most players, then by name. The browser keeps the order in `network.browser_sort`. -- FILTERS opens the Filters screen of Custom Edition. It has SHOW EMPTY - SERVERS, SHOW FULL SERVERS, GAME TYPE (ANY or one game engine) and SHOW - MISSING MAPS (NO, YES, or IF DOWNLOADABLE, for a Custom Edition map that - Map Sharing can download when you join). OK writes the - `network.browser_*` settings. Settings > Network Setup > SERVER BROWSER - writes the same settings, and also shows LISTS, SORT BY (DEDICATED FIRST, - PLAYERS, NAME, MAP, GAME TYPE or LOCKED FIRST; an order that a title reversed - shows as the same choice) and MASTER SERVERS - (the number of master servers that answered the last request of the - browser, for example `2 OF 2`). The PING and TEAMPLAY OPTIONS rows of - Custom Edition are not on the Filters screen. +- FILTERS hides games from the list: refer to "Filters" above. - A dedicated server's row shows the dedicated icon of Custom Edition. Instead of a ping, a dedicated server shows its region (EU, NA-E), because the browser does not ping the servers that the master servers diff --git a/port/linux/game/menu_functions.c b/port/linux/game/menu_functions.c index 51c2b866f0..7ee32e350b 100644 --- a/port/linux/game/menu_functions.c +++ b/port/linux/game/menu_functions.c @@ -2577,6 +2577,10 @@ static boolean hdr_display_panel(struct widget_instance *row, wchar_t *value, wc return TRUE; } +/* (the server browsers' Filters page's SEARCH: below) */ +static void browser_search_show(struct widget_instance *list); +static boolean browser_search_panel(struct widget_instance *row, wchar_t *value); + /* the panel's name, value and words for a row of the page (the others': FALSE) */ static boolean discord_account_panel(struct widget_instance *row, wchar_t *name, wchar_t *value, @@ -2801,6 +2805,8 @@ static void settings_panel_show(struct widget_instance *list, short tab) discord_account_panel(row, name, value, &help); /* (the display's peak: its words of the display now) */ hdr_display_panel(row, value, &help); + /* (the browsers' SEARCH: its words) */ + browser_search_panel(row, value); /* (Button Remapping's: a button being taken, a replacement asked) */ if (pad_editor_page(screen_of(list))) pad_editor_panel(row, name, value, &help); @@ -2910,6 +2916,7 @@ static void settings_page_update(struct widget_instance *list) sim_rate_row_show(list); settings_each(screen, setting_stash); settings_sliders_show(list); + browser_search_show(list); settings_rows_pack(list, tab != NONE); settings_focus_shown(list); settings_tabs_show(list, tab); @@ -4698,6 +4705,109 @@ static void settings_sliders_default(struct widget_instance *screen) } } +/* ---- the server browsers' Filters page (tools/port_settings.py's +BROWSER_FILTERS, its rows the network.browser_* settings): opened by the +browsers' FILTERS (the left trigger; "port browser filters", which starts +it with no change kept: its OK writes its own, as a page of Settings' does) +or by Settings' Online. Its SEARCH row's words are typed into its value +("port browser search": A, Start or a click begins, Enter keeps, Escape +forgets), a change kept as a spinner's is. The browser reads them all again +as it opens (browser_filters_read) */ + +#define BROWSER_SEARCH_SETTING "network.browser_search" +#define BROWSER_SEARCH_TEXT 32 + +/* "port browser filters": not Join by Link's, whose games are not filtered */ +static boolean browser_filters_open(void) +{ + if (multiplayer.mode == _multiplayer_mode_direct_link) + return FALSE; + if (text_field_editing(NULL)) + text_field_end(FALSE); + settings_pending_clear(); + ui_play_audio_feedback_sound(SOUND_FORWARD); + return TRUE; +} + +/* (the words typed: a change kept, or none if they are the setting's) */ +static void browser_search_typed(char const *text) +{ + char current[BROWSER_SEARCH_TEXT] = ""; + + setting_text(BROWSER_SEARCH_SETTING, current, sizeof(current), FALSE); + if (!strcmp(current, text)) + settings_pending_remove(BROWSER_SEARCH_SETTING); + else + settings_pending_set(BROWSER_SEARCH_SETTING, text); +} + +/* "port browser search" (its row's A: begins, or ends) */ +static boolean browser_search_edit(struct widget_instance *row) +{ + char text[BROWSER_SEARCH_TEXT] = ""; + + if (text_field_editing(row)) + { + text_field_end(TRUE); + return TRUE; + } + if (text_field_editing(NULL)) + text_field_end(TRUE); + settings_value(BROWSER_SEARCH_SETTING, text, sizeof(text)); + text_field_begin(row, text, BROWSER_SEARCH_TEXT - 1, browser_search_typed); + return TRUE; +} + +/* SEARCH's value as its row and the panel show it: the words, or OFF */ +static void browser_search_text(char *text, unsigned int size) +{ + text[0] = 0; + settings_value(BROWSER_SEARCH_SETTING, text, size); + if (!text[0]) + snprintf(text, size, "OFF"); +} + +/* (each frame of a page) SEARCH's value, the words typed while they are; +typing whose row lost the focus keeps what was typed */ +static void browser_search_show(struct widget_instance *list) +{ + struct widget_instance *row = named(list, "op_browser_search", 0); + struct widget_instance *value = row ? named(row, "browser_search_value", 0) : NULL; + char text[BROWSER_SEARCH_TEXT]; + + if (!value) + return; + if (text_field_editing(row) && list->focused_child != row) + text_field_end(TRUE); + browser_search_text(text, sizeof(text)); + text_field_show(value, text, text_field_editing(row)); +} + +/* the SEARCH row's panel: its words (the others': FALSE) */ +static boolean browser_search_panel(struct widget_instance *row, wchar_t *value) +{ + char text[BROWSER_SEARCH_TEXT]; + short index; + + if (!row->name || strcmp(row->name, "op_browser_search")) + return FALSE; + browser_search_text(text, sizeof(text)); + for (index = 0; text[index] && index < ROW_TEXT_LENGTH - 1; index++) + value[index] = (wchar_t)(unsigned char)text[index]; + value[index] = 0; + return TRUE; +} + +/* "port settings defaults": no words searched for (what is typed forgotten) */ +static void browser_search_default(struct widget_instance *screen) +{ + if (!named(screen, "op_browser_search", 0)) + return; + if (text_field_editing(NULL)) + text_field_end(FALSE); + browser_search_typed(""); +} + /* ---- the menu */ /* "mp type set mode": the item's (by its name) */ @@ -5903,6 +6013,7 @@ static void lobby_browser_update(struct widget_instance *list); static boolean lobby_browser_select(struct widget_instance *widget, short controller, short row, boolean *widget_deleted); static void browser_prompts_show(struct widget_instance *list); +static void browser_filters_refresh(void); /* "gamespy screen init": the mode's title and parts; the games' client */ static boolean browser_initialize(struct widget_instance *screen, struct event_record *event, @@ -5915,6 +6026,8 @@ static boolean browser_initialize(struct widget_instance *screen, struct event_r short index; server_browser_initialize(screen); + /* (the filters as Filters left them: browser_filters_read, below) */ + browser_filters_refresh(); for (index = 0; index < NUMBEROF(titles); index++) visible_set(named(screen, titles[index], 0), !strcmp(titles[index], title)); /* (the tabs and their prompts, but for Join by Link's list, whose games @@ -6249,6 +6362,13 @@ struct browser_sort_entry boolean coop; /* a dedicated server's */ boolean dedicated; + /* what the filters see of it (browser_filters_show): its most players + (0: not known), its game engine (0: co-op's none), its password, and + its map's name as the rows show it */ + short maximum_players; + short engine_type; + boolean locked; + wchar_t map_shown[ROW_TEXT_LENGTH]; }; static short browser_sort_column = _browser_sort_players; @@ -6365,6 +6485,125 @@ static boolean browser_tab_lists_offline(void) return browser_tab == _browser_tab_all || browser_tab == _browser_tab_favorites; } +/* ---- the browsers' filters (the Filters page, tools/port_settings.py's +BROWSER_FILTERS: the network.browser_* settings, read as a list opens and +kept): full games, empty ones and those with a password listed or not, only +the games whose ping is under a limit (one whose ping is not known is +listed: a local network game's, a master server's dedicated server's, one +being timed), the gametypes listed (a co-op game has none: CO-OP is its +tab), and words a game's name or map must have. The server browser's and +the local network's lists are filtered, not Join by Link's, whose games are +the invites taken. Nothing is sent: the lists' own */ + +#define BROWSER_SEARCH_LENGTH 31 +#define BROWSER_ALL_ENGINES 0x3E + +struct browser_filters +{ + boolean show_full, show_empty, show_password; + /* milliseconds; 0: any */ + short maximum_ping; + /* a bit for each game engine listed (1 << 1 CTF to 1 << 5 Race) */ + short engines; + char search[BROWSER_SEARCH_LENGTH + 1]; +}; + +static struct browser_filters browser_filters = { TRUE, TRUE, TRUE, 0, BROWSER_ALL_ENGINES, "" }; +/* whether the list being ordered is filtered, and how many of the games its +tab lists the filters hid */ +static boolean browser_filtering; +static short browser_filtered_count; + +/* whether text has the words, in any case (ASCII's) */ +static boolean browser_text_has(wchar_t const *text, char const *words) +{ + short start, index; + + for (start = 0; text[start]; start++) + { + for (index = 0; words[index] && text[start + index]; index++) + { + int x = text[start + index] >= 'a' && text[start + index] <= 'z' ? text[start + index] - 32 : + text[start + index]; + int y = words[index] >= 'a' && words[index] <= 'z' ? words[index] - 32 : words[index]; + + if (x != y) + break; + } + if (!words[index]) + return TRUE; + } + return !words[0]; +} + +/* whether the filters list the game */ +static boolean browser_filters_show(struct browser_filters const *filters, struct browser_sort_entry const *entry) +{ + wchar_t text[ROW_TEXT_LENGTH]; + short index; + + if (!filters->show_full && entry->maximum_players > 0 && entry->players >= entry->maximum_players) + return FALSE; + if (!filters->show_empty && entry->players <= 0) + return FALSE; + if (!filters->show_password && entry->locked) + return FALSE; + if (filters->maximum_ping > 0 && entry->ping >= 0 && entry->ping >= filters->maximum_ping) + return FALSE; + if (entry->engine_type >= 1 && entry->engine_type <= 5 && !(filters->engines & (1 << entry->engine_type))) + return FALSE; + if (!filters->search[0]) + return TRUE; + /* (its name, its map as shown (Blood Gulch), and its map's own name + (bloodgulch)) */ + for (index = 0; entry->name[index] && index < ROW_TEXT_LENGTH - 1; index++) + text[index] = (wchar_t)(unsigned char)entry->name[index]; + text[index] = 0; + if (browser_text_has(text, filters->search) || browser_text_has(entry->map_shown, filters->search)) + return TRUE; + for (index = 0; entry->map[index] && index < ROW_TEXT_LENGTH - 1; index++) + text[index] = (wchar_t)(unsigned char)entry->map[index]; + text[index] = 0; + return browser_text_has(text, filters->search); +} + +/* the filters as the settings have them (the words without the spaces +around them) */ +static void browser_filters_read(struct browser_filters *filters) +{ + static char const *const engines[] = + { + NULL, "network.browser_show_ctf", "network.browser_show_slayer", "network.browser_show_oddball", + "network.browser_show_king", "network.browser_show_race", + }; + char text[BROWSER_SEARCH_LENGTH + 1]; + char const *search = config_string("network.browser_search"); + short index, length; + + filters->show_full = config_boolean("network.browser_show_full") != 0; + filters->show_empty = config_boolean("network.browser_show_empty") != 0; + filters->show_password = config_boolean("network.browser_show_password") != 0; + filters->maximum_ping = (short)PIN(config_integer("network.browser_ping"), 0, 9999); + filters->engines = 0; + for (index = 1; index < (short)NUMBEROF(engines); index++) + { + if (config_boolean(engines[index])) + filters->engines |= (short)(1 << index); + } + for (search = search ? search : ""; *search == ' '; search++) + { + } + snprintf(text, sizeof(text), "%s", search); + for (length = (short)strlen(text); length > 0 && text[length - 1] == ' '; length--) + text[length - 1] = 0; + snprintf(filters->search, sizeof(filters->search), "%s", text); +} + +static void browser_filters_refresh(void) +{ + browser_filters_read(&browser_filters); +} + /* the order of the games found: the favorites first, then the others, those the tab shows, each part sorted by the column chosen; into `order`, returning how many */ @@ -6375,6 +6614,7 @@ static short browser_favorites_order(short const *favorite_of, struct browser_so short written = 0; browser_found_favorites = 0; + browser_filtered_count = 0; for (pass = 0; pass < 2; pass++) { short start = written; @@ -6382,7 +6622,12 @@ static short browser_favorites_order(short const *favorite_of, struct browser_so for (index = 0; index < count; index++) { - if ((favorite_of[index] != NONE) == (pass == 0) && browser_tab_shows(&entries[index], pass == 0)) + if ((favorite_of[index] != NONE) != (pass == 0) || !browser_tab_shows(&entries[index], pass == 0)) + continue; + /* (those the filters hide counted, for the words over the list) */ + if (browser_filtering && !browser_filters_show(&browser_filters, &entries[index])) + browser_filtered_count++; + else order[written++] = index; } /* (each part sorted, alike ones kept in the order found) */ @@ -6498,9 +6743,9 @@ static boolean browser_tab_choose(short tab) /* the words in the list's place while it has no rows: what it shows, why there are none and what to do (the mode's, multiplayer.mode; the tab's; the server browser's: internet play off, or its list, still being looked -for, newer games it cannot join), into text */ +for, newer games it cannot join; the games its filters hid), into text */ static void browser_empty_text(short mode, short tab, boolean online, boolean public_lobby, boolean looking, - int newer, wchar_t *text, short size) + int newer, short filtered, wchar_t *text, short size) { static wchar_t const *const kinds[NUMBER_OF_BROWSER_TABS] = { @@ -6519,6 +6764,11 @@ static void browser_empty_text(short mode, short tab, boolean online, boolean pu usnprintf(text, size - 1, L"The server browser is off\r\n(network.public_lobby)."); else if (server_browser && looking) usnprintf(text, size - 1, L"Looking for public games..."); + else if (filtered > 0) + { + usnprintf(text, size - 1, L"%d %s hidden by your filters.\r\nChoose FILTERS to change them.", filtered, + filtered == 1 ? L"game is" : L"games are"); + } else if (tab == _browser_tab_favorites) { usnprintf(text, size - 1, server_browser ? L"None of your favorites is online.\r\n%s" : @@ -6991,13 +7241,14 @@ static void browser_status_text(struct browser_row const *row, wchar_t *text, sh } /* the footer's prompts for the list's mode: REFRESH the server browser's, -PASTE LINK Join by Link's in its place */ +PASTE LINK Join by Link's in its place; FILTERS but Join by Link's */ static void browser_prompts_show(struct widget_instance *list) { struct widget_instance *bar = named(list, "join_game_button_bar", 0); menu_prompts_show(bar, "prompt_refresh", multiplayer.mode == _multiplayer_mode_server_browser); menu_prompts_show(bar, "prompt_paste", multiplayer.mode == _multiplayer_mode_direct_link); + menu_prompts_show(bar, "prompt_filters", multiplayer.mode != _multiplayer_mode_direct_link); } /* what the list shows above its rows: its tabs, the sort, its games and @@ -7040,6 +7291,13 @@ static void browser_header_show(struct widget_instance *list, short games, long } usnprintf(text, NUMBEROF(text) - 1, L"%d %s %ld %s", games, games == 1 ? L"GAME" : L"GAMES", players, players == 1 ? L"PLAYER" : L"PLAYERS"); + /* (and how many the filters hide) */ + if (browser_filtering && browser_filtered_count > 0) + { + short length = (short)ustrlen(text); + + usnprintf(text + length, NUMBEROF(text) - 1 - length, L" %d HIDDEN", browser_filtered_count); + } text[NUMBEROF(text) - 1] = 0; text_set(named(screen, "browser_counts", 0), text); visible_set(named(screen, "browser_empty", 0), rows == 0); @@ -7441,8 +7699,16 @@ static short lobby_browser_favorites(short count) entries[index].dedicated = game->dedicated != 0; settings_wide_copy(entries[index].mode, game_kind_name(game->engine_type, game->kind, FALSE), BROWSER_MODE_LENGTH); + entries[index].maximum_players = game->maximum_player_count; + entries[index].engine_type = (short)game->engine_type; + entries[index].locked = game->locked != 0; + /* (the map's name as shown, for the words searched for alone) */ + entries[index].map_shown[0] = 0; + if (browser_filters.search[0]) + map_display_name(game->map, entries[index].map_shown); } browser_favorites_match(favorites, count, favorite_of, "net:"); + browser_filtering = TRUE; listed = browser_favorites_order(favorite_of, entries, count, order); for (index = 0; index < listed; index++) ordered[index] = lobby_browser.games[order[index]]; @@ -7697,7 +7963,7 @@ static void lobby_browser_update(struct widget_instance *list) players += lobby_browser.games[index].player_count; browser_empty_text(multiplayer.mode, browser_tab, config_boolean("network.online"), config_boolean("network.public_lobby"), now - lobby_browser.begin_time < LOBBY_BROWSER_LOOK_TIME, - p2p_lobby_newer_games(), text, NUMBEROF(text)); + p2p_lobby_newer_games(), browser_filtered_count, text, NUMBEROF(text)); browser_header_show(list, lobby_browser.count, players, rows, text); } browser_focus(list, browser_chosen_row()); @@ -7911,9 +8177,17 @@ static short local_browser_favorites(struct widget_instance *list) entries[index].dedicated = advertised_dedicated(game); settings_wide_copy(entries[index].mode, game_kind_name(game->engine_type, favorites[index].kind, FALSE), BROWSER_MODE_LENGTH); + entries[index].maximum_players = game->maximum_player_count; + entries[index].engine_type = (short)game->engine_type; + entries[index].locked = FALSE; + entries[index].map_shown[0] = 0; + if (browser_filters.search[0]) + game_map_name(game, entries[index].map_shown); } browser_favorites_match(favorites, multiplayer.game_count, favorite_of, multiplayer.mode == _multiplayer_mode_lan ? "lan:" : NULL); + /* (Join by Link's games are the invites taken: never hidden) */ + browser_filtering = multiplayer.mode != _multiplayer_mode_direct_link; multiplayer.game_count = browser_favorites_order(favorite_of, entries, multiplayer.game_count, order); for (index = 0; index < multiplayer.game_count; index++) multiplayer.games[index] = games[order[index]]; @@ -8019,7 +8293,8 @@ static void browser_update(struct widget_instance *list) multiplayer.mode == _multiplayer_mode_direct_link ? L"JOIN BY LINK" : L"LOCAL NETWORK", text); for (index = 0; index < multiplayer.game_count; index++) players += multiplayer.games[index]->player_count; - browser_empty_text(multiplayer.mode, browser_tab, TRUE, TRUE, FALSE, 0, text, NUMBEROF(text)); + browser_empty_text(multiplayer.mode, browser_tab, TRUE, TRUE, FALSE, 0, browser_filtered_count, text, + NUMBEROF(text)); browser_header_show(list, multiplayer.game_count, players, rows, text); browser_focus(list, browser_chosen_row()); } @@ -10485,6 +10760,14 @@ boolean pc_menu_event_function_invoke( { return browser_refresh(widget, controller, widget_deleted); } + else if (!strcmp(name, "port browser filters")) + { + return browser_filters_open(); + } + else if (!strcmp(name, "port browser search")) + { + return browser_search_edit(widget); + } else if (!strcmp(name, "gamespy back handler") && text_field_editing(NULL)) { text_field_end(FALSE); @@ -10659,6 +10942,7 @@ boolean pc_menu_event_function_invoke( { settings_each(screen_of(widget), setting_default_show); settings_sliders_default(screen_of(widget)); + browser_search_default(screen_of(widget)); pad_editor_defaults(screen_of(widget)); } else if (!strncmp(name, "port slider ", 12)) diff --git a/port/linux/game/menu_tags.c b/port/linux/game/menu_tags.c index a3f829275a..9fa908194b 100644 --- a/port/linux/game/menu_tags.c +++ b/port/linux/game/menu_tags.c @@ -496,6 +496,9 @@ static char const *const port_function_names[] = /* (the browsers' tabs and refresh: menu_functions.c's browser_tab_choose, browser_refresh) */ "port browser tab", "port browser tab next", "port browser tab previous", "port browser refresh", + /* (the browsers' Filters page and its SEARCH: menu_functions.c's + browser_filters_open, browser_search_edit) */ + "port browser filters", "port browser search", /* (Multiplayer's PARTY and its screen: party_menu.inc) */ "port party open", "port party button", "port party x", "port party y", /* (Multiplayer's MATCHMAKING and its screen: matchmaking_menu.inc) */ diff --git a/port/linux/src/port_config.c b/port/linux/src/port_config.c index 2167d64a2d..f49d122e81 100644 --- a/port/linux/src/port_config.c +++ b/port/linux/src/port_config.c @@ -1154,6 +1154,41 @@ static const struct config_setting config_settings[] = "The server browser: public games are listed through the signalling\n" "brokers, and Join Game > Server Browser shows them. False lists no\n" "game of this machine's and shows none." }, + /* (the server browsers' Filters: menu_functions.c's browser_filters_read; + the first two named as OpenCE names them) */ + { "network.browser_show_full", _config_boolean, "true", "HALO_NET_BROWSER_SHOW_FULL", _environment_value, + _platform_all, + "The server browsers list full games (their Filters page)." }, + { "network.browser_show_empty", _config_boolean, "true", "HALO_NET_BROWSER_SHOW_EMPTY", _environment_value, + _platform_all, + "The server browsers list games with no player (their Filters page)." }, + { "network.browser_show_password", _config_boolean, "true", "HALO_NET_BROWSER_SHOW_PASSWORD", + _environment_value, _platform_all, + "The server browsers list games that need a password (their Filters\n" + "page)." }, + { "network.browser_ping", _config_integer, "0", "HALO_NET_BROWSER_PING", _environment_value, _platform_all, + "The server browsers list only games whose ping is under this many\n" + "milliseconds (300, 250, 150, 100 or 50); 0 lists every game. A game\n" + "whose ping is not known (a local network game's, a dedicated\n" + "server's, one still being timed) is listed." }, + { "network.browser_show_ctf", _config_boolean, "true", "HALO_NET_BROWSER_SHOW_CTF", _environment_value, + _platform_all, + "The server browsers list Capture the Flag games (their Filters page)." }, + { "network.browser_show_slayer", _config_boolean, "true", "HALO_NET_BROWSER_SHOW_SLAYER", _environment_value, + _platform_all, + "The server browsers list Slayer games (their Filters page)." }, + { "network.browser_show_oddball", _config_boolean, "true", "HALO_NET_BROWSER_SHOW_ODDBALL", _environment_value, + _platform_all, + "The server browsers list Oddball games (their Filters page)." }, + { "network.browser_show_king", _config_boolean, "true", "HALO_NET_BROWSER_SHOW_KING", _environment_value, + _platform_all, + "The server browsers list King of the Hill games (their Filters page)." }, + { "network.browser_show_race", _config_boolean, "true", "HALO_NET_BROWSER_SHOW_RACE", _environment_value, + _platform_all, + "The server browsers list Race games (their Filters page)." }, + { "network.browser_search", _config_string, "\"\"", "HALO_NET_BROWSER_SEARCH", _environment_value, _platform_all, + "The server browsers list only games whose server name or map has\n" + "these words, in any case; empty lists every game (their Filters page)." }, { "friends.share_status", _config_boolean, "true", "HALO_FRIENDS_SHARE_STATUS", _environment_value, _platform_all, "Show your friends that you are online, and where (the menus, a party,\n" "a game), and let them join you (Multiplayer > FRIENDS). Only your\n" diff --git a/port/linux/src/xinput_sdl.c b/port/linux/src/xinput_sdl.c index 9aaf214a17..a465959f76 100644 --- a/port/linux/src/xinput_sdl.c +++ b/port/linux/src/xinput_sdl.c @@ -881,6 +881,8 @@ static void keyboard_gamepad(const struct platform_input_state *input, XINPUT_GA /* (R as the right trigger: Multiplayer's and the server browser's refresh, drawn as R) */ pad->bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER] |= analog(k[SDL_SCANCODE_R]); + /* (L as the left trigger: the server browsers' Filters, drawn as L) */ + pad->bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER] |= analog(k[SDL_SCANCODE_L]); } /* the keys held when the game and the menus switch, or typing or the diff --git a/source/interface/ui_widget.c b/source/interface/ui_widget.c index e1c1c3dff1..afc8a9f98a 100644 --- a/source/interface/ui_widget.c +++ b/source/interface/ui_widget.c @@ -4348,9 +4348,9 @@ X as E (the delete of Load Game, Profiles and the gametypes), or in a server browser as Tab (its sort: halo_keyboard_browser_keys_active), Y as F (their favorite), LB and RB (the white and black buttons, Settings' and the browsers' tabs) as Q and E, the right trigger (Multiplayer's and the -browsers' refresh) as R, back as F1; -NULL for the others (the D-pad, which the arrow keys press, Start, the left -trigger and the sticks), drawn as the controller's */ +browsers' refresh) as R, the left trigger (the browsers' Filters) as L, back +as F1; NULL for the others (the D-pad, which the arrow keys press, Start and +the sticks), drawn as the controller's */ static char const *ui_widget_port_menu_key( short icon_type) { @@ -4366,6 +4366,8 @@ static char const *ui_widget_port_menu_key( return "E"; case _icon_right_trigger: return "R"; + case _icon_left_trigger: + return "L"; case _icon_y_button: return "F"; case _icon_white_button: diff --git a/tools/harness/tests/browser_menu.c b/tools/harness/tests/browser_menu.c index 7cadb84a31..0b8e0cb5c7 100644 --- a/tools/harness/tests/browser_menu.c +++ b/tools/harness/tests/browser_menu.c @@ -49,6 +49,57 @@ static int usnprintf(wchar_t *text, size_t size, wchar_t const *format, ...) static short browser_found_favorites, browser_offline_count; static short browser_sort_column, browser_tab; static boolean browser_sort_descending; +static struct browser_filters browser_filters = { TRUE, TRUE, TRUE, 0, BROWSER_ALL_ENGINES, "" }; +static boolean browser_filtering; +static short browser_filtered_count; + +/* the fake settings (port_config.c's): the filters' own, by name */ +static struct +{ + char const *name; + char const *value; +} fake_settings[] = +{ + { "network.browser_show_full", "true" }, { "network.browser_show_empty", "true" }, + { "network.browser_show_password", "true" }, { "network.browser_ping", "0" }, + { "network.browser_show_ctf", "true" }, { "network.browser_show_slayer", "true" }, + { "network.browser_show_oddball", "true" }, { "network.browser_show_king", "true" }, + { "network.browser_show_race", "true" }, { "network.browser_search", "" }, +}; + +static char const *config_string(char const *name) +{ + size_t index; + + for (index = 0; index < sizeof(fake_settings) / sizeof(fake_settings[0]); index++) + { + if (!strcmp(fake_settings[index].name, name)) + return fake_settings[index].value; + } + CHECK(FALSE, "%s is not a setting", name); + return ""; +} + +static void config_set(char const *name, char const *value) +{ + size_t index; + + for (index = 0; index < sizeof(fake_settings) / sizeof(fake_settings[0]); index++) + { + if (!strcmp(fake_settings[index].name, name)) + fake_settings[index].value = value; + } +} + +static int config_boolean(char const *name) +{ + return !strcmp(config_string(name), "true"); +} + +static long config_integer(char const *name) +{ + return atol(config_string(name)); +} /* the fake font: each character 6 units wide, "." 2 */ static short settings_text_width(long font, wchar_t const *text) @@ -76,6 +127,8 @@ static struct browser_sort_entry entry(char const *name, boolean openh1, boolean result.dedicated = !strcmp(name, "coop") || !strcmp(name, "alpha"); result.players = players; result.rate = openh1 ? 60 : 30; + /* (12 players at most: delta's full) */ + result.maximum_players = 12; return result; } @@ -147,39 +200,165 @@ int main(int argc, char **argv) wchar_t text[256]; /* the local network's: what to do */ - browser_empty_text(_multiplayer_mode_lan, _browser_tab_all, TRUE, TRUE, FALSE, 0, text, NUMBEROF(text)); + browser_empty_text(_multiplayer_mode_lan, _browser_tab_all, TRUE, TRUE, FALSE, 0, 0, text, + NUMBEROF(text)); CHECK(contains(text, L"No games on your network yet.") && contains(text, L"Host one from Create Game."), "the local network's empty list says %ls", text); - browser_empty_text(_multiplayer_mode_lan, _browser_tab_openh1, TRUE, TRUE, FALSE, 0, text, NUMBEROF(text)); + browser_empty_text(_multiplayer_mode_lan, _browser_tab_openh1, TRUE, TRUE, FALSE, 0, 0, text, + NUMBEROF(text)); CHECK(contains(text, L"No OpenH1 games on your network."), "OPENH1's says %ls", text); - browser_empty_text(_multiplayer_mode_lan, _browser_tab_favorites, TRUE, TRUE, FALSE, 0, text, + browser_empty_text(_multiplayer_mode_lan, _browser_tab_favorites, TRUE, TRUE, FALSE, 0, 0, text, NUMBEROF(text)); CHECK(contains(text, L"favorites") && contains(text, L"FAVORITE on a game"), "FAVORITES' says %ls", text); /* the server browser's: still looking, off, none of a kind, newer */ - browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_all, TRUE, TRUE, TRUE, 0, text, + browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_all, TRUE, TRUE, TRUE, 0, 0, text, NUMBEROF(text)); CHECK(contains(text, L"Looking for public games"), "looking says %ls", text); - browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_all, FALSE, TRUE, FALSE, 0, text, + browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_all, FALSE, TRUE, FALSE, 0, 0, text, NUMBEROF(text)); CHECK(contains(text, L"Internet play is off"), "offline says %ls", text); - browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_coop, TRUE, TRUE, FALSE, 0, text, + browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_coop, TRUE, TRUE, FALSE, 0, 0, text, NUMBEROF(text)); CHECK(contains(text, L"No co-op games"), "CO-OP's says %ls", text); - browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_dedicated, TRUE, TRUE, FALSE, 0, text, + browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_dedicated, TRUE, TRUE, FALSE, 0, 0, text, NUMBEROF(text)); CHECK(contains(text, L"No dedicated server games"), "DEDICATED's says %ls", text); - browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_all, TRUE, TRUE, FALSE, 3, text, + browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_all, TRUE, TRUE, FALSE, 3, 0, text, NUMBEROF(text)); CHECK(contains(text, L"3 games are on a newer version"), "newer says %ls", text); - browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_all, TRUE, TRUE, FALSE, 0, text, + /* (the filters' hidden games: how many, and where to change them; + on a tab too, and before the newer games) */ + browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_openh1, TRUE, TRUE, FALSE, 3, 2, text, + NUMBEROF(text)); + CHECK(contains(text, L"2 games are hidden by your filters") && contains(text, L"FILTERS"), + "filtered says %ls", text); + browser_empty_text(_multiplayer_mode_lan, _browser_tab_all, TRUE, TRUE, FALSE, 0, 1, text, NUMBEROF(text)); + CHECK(contains(text, L"1 game is hidden by your filters"), "one filtered says %ls", text); + browser_empty_text(_multiplayer_mode_server_browser, _browser_tab_all, TRUE, TRUE, FALSE, 0, 0, text, NUMBEROF(text)); CHECK(contains(text, L"No public games found"), "none says %ls", text); /* Join by Link's: how to paste a link (its footer's prompt) */ - browser_empty_text(_multiplayer_mode_direct_link, _browser_tab_all, TRUE, TRUE, FALSE, 0, text, + browser_empty_text(_multiplayer_mode_direct_link, _browser_tab_all, TRUE, TRUE, FALSE, 0, 0, text, NUMBEROF(text)); CHECK(contains(text, L"PASTE LINK"), "Join by Link's says %ls", text); return 0; } + CASE("filters") + { + struct browser_filters filters; + struct browser_sort_entry game = entry("Foozy BG Snipers", TRUE, FALSE, 4); + char names[128]; + short offline; + + /* (a Slayer game of 4 of 16 on Blood Gulch, a ping of 120, no password) */ + game.maximum_players = 16; + game.engine_type = 2; + game.ping = 120; + snprintf(game.map, sizeof(game.map), "bloodgulch"); + wcscpy(game.map_shown, L"Blood Gulch"); + /* the settings' defaults list every game */ + browser_filters_read(&filters); + CHECK(filters.show_full && filters.show_empty && filters.show_password && filters.maximum_ping == 0 && + filters.engines == BROWSER_ALL_ENGINES && !filters.search[0], "the defaults filter games"); + CHECK(browser_filters_show(&filters, &game), "the defaults hide a game"); + /* full and empty games */ + game.players = 16; + CHECK(browser_filters_show(&filters, &game), "SHOW FULL GAMES: YES hides a full game"); + filters.show_full = FALSE; + CHECK(!browser_filters_show(&filters, &game), "SHOW FULL GAMES: NO lists a full game"); + game.players = 15; + CHECK(browser_filters_show(&filters, &game), "SHOW FULL GAMES: NO hides a game with room"); + game.maximum_players = 0; + game.players = 40; + CHECK(browser_filters_show(&filters, &game), "a game whose most players is not known hidden as full"); + game.maximum_players = 16; + game.players = 0; + filters.show_empty = FALSE; + CHECK(!browser_filters_show(&filters, &game), "SHOW EMPTY GAMES: NO lists an empty game"); + game.players = 1; + CHECK(browser_filters_show(&filters, &game), "SHOW EMPTY GAMES: NO hides a game of one player"); + /* a password */ + game.locked = TRUE; + CHECK(browser_filters_show(&filters, &game), "SHOW PASSWORD GAMES: YES hides a locked game"); + filters.show_password = FALSE; + CHECK(!browser_filters_show(&filters, &game), "SHOW PASSWORD GAMES: NO lists a locked game"); + game.locked = FALSE; + /* the ping: under the limit, a ping not known listed */ + filters.maximum_ping = 150; + CHECK(browser_filters_show(&filters, &game), "PING UNDER 150 hides 120 ms"); + filters.maximum_ping = 100; + CHECK(!browser_filters_show(&filters, &game), "PING UNDER 100 lists 120 ms"); + game.ping = 100; + CHECK(!browser_filters_show(&filters, &game), "PING UNDER 100 lists 100 ms"); + game.ping = 99; + CHECK(browser_filters_show(&filters, &game), "PING UNDER 100 hides 99 ms"); + game.ping = NONE; + CHECK(browser_filters_show(&filters, &game), "a ping not known hidden by PING"); + /* the game types, more than one at once; a co-op game has none */ + filters.engines = (short)(1 << 1 | 1 << 3); + CHECK(!browser_filters_show(&filters, &game), "CTF and ODDBALL alone list Slayer"); + game.engine_type = 3; + CHECK(browser_filters_show(&filters, &game), "CTF and ODDBALL alone hide Oddball"); + game.engine_type = 1; + CHECK(browser_filters_show(&filters, &game), "CTF and ODDBALL alone hide CTF"); + game.engine_type = 0; + CHECK(browser_filters_show(&filters, &game), "the game types hide a co-op game"); + filters.engines = 0; + CHECK(browser_filters_show(&filters, &game), "no game type hides a co-op game"); + game.engine_type = 5; + CHECK(!browser_filters_show(&filters, &game), "no game type lists Race"); + filters.engines = BROWSER_ALL_ENGINES; + /* the words: the name's or the map's (shown or its own), in any case */ + snprintf(filters.search, sizeof(filters.search), "snip"); + CHECK(browser_filters_show(&filters, &game), "\"snip\" hides Foozy BG Snipers"); + snprintf(filters.search, sizeof(filters.search), "BLOOD GULCH"); + CHECK(browser_filters_show(&filters, &game), "\"BLOOD GULCH\" hides a game on Blood Gulch"); + snprintf(filters.search, sizeof(filters.search), "bloodg"); + CHECK(browser_filters_show(&filters, &game), "\"bloodg\" hides a game on bloodgulch"); + snprintf(filters.search, sizeof(filters.search), "hang em"); + CHECK(!browser_filters_show(&filters, &game), "\"hang em\" lists a game on Blood Gulch"); + snprintf(filters.search, sizeof(filters.search), "Snipers!"); + CHECK(!browser_filters_show(&filters, &game), "\"Snipers!\" lists Foozy BG Snipers"); + /* the settings read: the game types in the engines' order, the + ping, the words without the spaces around them */ + config_set("network.browser_show_full", "false"); + config_set("network.browser_show_password", "false"); + config_set("network.browser_ping", "250"); + config_set("network.browser_show_slayer", "false"); + config_set("network.browser_show_race", "false"); + config_set("network.browser_search", " gulch "); + browser_filters_read(&filters); + CHECK(!filters.show_full && filters.show_empty && !filters.show_password, "the settings' YES and NO"); + CHECK(filters.maximum_ping == 250, "network.browser_ping 250 read as %d", filters.maximum_ping); + CHECK(filters.engines == (1 << 1 | 1 << 3 | 1 << 4), "the game types read as %#x", filters.engines); + CHECK(!strcmp(filters.search, "gulch"), "the words read as \"%s\"", filters.search); + /* the list: the filters hide games from every tab, counted; the + favorites too. Off (Join by Link's), they hide none */ + browser_filters = filters; + browser_filters.engines = BROWSER_ALL_ENGINES; + browser_filters.search[0] = 0; + browser_filters.show_empty = FALSE; + browser_filters.maximum_ping = 0; + browser_filtering = TRUE; + /* (bravo's 9 and delta's 12 of 12 players: delta full) */ + listed(_browser_tab_all, names, sizeof(names), &offline); + CHECK(!strcmp(names, "echo* bravo* alpha coop "), "ALL filtered lists %s", names); + CHECK(browser_filtered_count == 1, "ALL filtered counts %d hidden", browser_filtered_count); + listed(_browser_tab_openh1, names, sizeof(names), &offline); + CHECK(!strcmp(names, "echo* alpha "), "OPENH1 filtered lists %s", names); + CHECK(browser_filtered_count == 1, "OPENH1 filtered counts %d hidden", browser_filtered_count); + listed(_browser_tab_legacy, names, sizeof(names), &offline); + CHECK(browser_filtered_count == 0, "LEGACY counts %d hidden of another tab's", browser_filtered_count); + snprintf(browser_filters.search, sizeof(browser_filters.search), "ECHO"); + listed(_browser_tab_all, names, sizeof(names), &offline); + CHECK(!strcmp(names, "echo* "), "\"ECHO\" lists %s", names); + CHECK(browser_filtered_count == 4, "\"ECHO\" counts %d hidden", browser_filtered_count); + browser_filtering = FALSE; + listed(_browser_tab_all, names, sizeof(names), &offline); + CHECK(!strcmp(names, "echo* bravo* alpha delta coop "), "unfiltered lists %s", names); + CHECK(browser_filtered_count == 0, "unfiltered counts %d hidden", browser_filtered_count); + return 0; + } CASE("ping") { wchar_t text[16]; diff --git a/tools/harness/tests/menu_keys.c b/tools/harness/tests/menu_keys.c index ef9be3bd17..cf49de52a8 100644 --- a/tools/harness/tests/menu_keys.c +++ b/tools/harness/tests/menu_keys.c @@ -51,6 +51,7 @@ static int scancode(char const *name) { "F1", SDL_SCANCODE_F1 }, { "Tab", SDL_SCANCODE_TAB }, { "R", SDL_SCANCODE_R }, + { "L", SDL_SCANCODE_L }, }; size_t index; @@ -74,6 +75,7 @@ static boolean pressed(XINPUT_GAMEPAD const *pad, short icon) case _icon_black_button: return pad->bAnalogButtons[XINPUT_GAMEPAD_BLACK] != 0; case _icon_white_button: return pad->bAnalogButtons[XINPUT_GAMEPAD_WHITE] != 0; case _icon_right_trigger: return pad->bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER] != 0; + case _icon_left_trigger: return pad->bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER] != 0; case _icon_back_button: return (pad->wButtons & XINPUT_GAMEPAD_BACK) != 0; case _icon_start_button: return (pad->wButtons & XINPUT_GAMEPAD_START) != 0; default: return FALSE; diff --git a/tools/harness/tests/test_browser_menu.py b/tools/harness/tests/test_browser_menu.py index 02f95d790b..8978b3d82f 100644 --- a/tools/harness/tests/test_browser_menu.py +++ b/tools/harness/tests/test_browser_menu.py @@ -15,7 +15,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[2])) from harness import CHECK_FAILED, ROOT, build, enum_with, function, mutated, read, run, structure # noqa: E402 -CASES = ["tabs", "empty", "ellipsis", "ping"] +CASES = ["tabs", "empty", "ellipsis", "ping", "filters"] NEGATIVE_CONTROLS = { "favorites-on-every-tab": (("\tcase _browser_tab_favorites:\n\t\treturn favorite;\n", ""), "tabs"), @@ -30,6 +30,23 @@ "L\"No games.\""), "empty"), "never-cut": (("if (font == NONE || width <= 0 || settings_text_width(font, fitted) <= width)", "if (TRUE)"), "ellipsis"), + "full-never-hidden": (("entry->maximum_players > 0 && entry->players >= entry->maximum_players)", + "entry->maximum_players > 0 && entry->players > entry->maximum_players)"), "filters"), + "empty-never-hidden": (("if (!filters->show_empty && entry->players <= 0)", "if (FALSE)"), "filters"), + "password-never-hidden": (("if (!filters->show_password && entry->locked)", "if (FALSE)"), "filters"), + "ping-at-limit-listed": (("entry->ping >= filters->maximum_ping)", "entry->ping > filters->maximum_ping)"), + "filters"), + "ping-unknown-hidden": (("filters->maximum_ping > 0 && entry->ping >= 0 &&", "filters->maximum_ping > 0 &&"), + "filters"), + "coop-hidden-by-types": (("entry->engine_type >= 1 && entry->engine_type <= 5 &&", ""), "filters"), + "search-name-only": (("browser_text_has(text, filters->search) || browser_text_has(entry->map_shown, " + "filters->search)", "browser_text_has(text, filters->search)"), "filters"), + "search-case-kept": (("int y = words[index] >= 'a' && words[index] <= 'z' ? words[index] - 32 : words[index];", + "int y = words[index];"), "filters"), + "search-spaces-kept": (("; *search == ' '; search++)", "; 0; search++)"), "filters"), + "types-read-shifted": (("(short)(1 << index);", "(short)(1 << (index - 1));"), "filters"), + "hidden-not-counted": (("\t\t\t\tbrowser_filtered_count++;", "\t\t\t\t;"), "filters"), + "filtered-says-nothing": (("\telse if (filtered > 0)", "\telse if (FALSE)"), "empty"), "ping-unknown-as-measuring": (("\telse if (ping_state == _browser_ping_measuring)", "\telse if (ping_state != _browser_ping_measured)"), "ping"), "ping-bars-one-off": (("ping < PING_GOOD ? 3", "ping <= PING_GOOD ? 3"), "ping"), @@ -47,14 +64,17 @@ def generated(fault=None): enum_with(menus, "_multiplayer_mode_server_browser"), enum_with(menus, "_browser_sort_players"), enum_with(menus, "_browser_tab_all"), enum_with(menus, "_browser_ping_measured"), enum_with(menus, "PING_GOOD = 80"), + "#define BROWSER_SEARCH_LENGTH %s" % re.search(r"#define BROWSER_SEARCH_LENGTH (\d+)", menus).group(1), + "#define BROWSER_ALL_ENGINES %s" % re.search(r"#define BROWSER_ALL_ENGINES (\w+)", menus).group(1), "\n".join(re.findall(r"^#define BROWSER_PING_\w+ L[^\n]+", menus, re.M)), "#define BROWSER_MODE_LENGTH %s" % re.search(r"#define BROWSER_MODE_LENGTH (\d+)", menus).group(1), "#define MENU_TEXT_ELLIPSIS_LENGTH %s" % re.search(r"#define MENU_TEXT_ELLIPSIS_LENGTH (\d+)", menus).group(1), - structure(menus, "browser_sort_entry")]) + "\n" + structure(menus, "browser_sort_entry"), structure(menus, "browser_filters")]) + "\n" code = "\n\n".join(function(menus, name) for name in ( "settings_wide_copy", "browser_text_compare", "browser_wide_compare", "browser_sort_before", - "browser_tab_shows", "browser_tab_lists_offline", "browser_favorites_order", "browser_empty_text", + "browser_tab_shows", "browser_tab_lists_offline", "browser_text_has", "browser_filters_show", + "browser_filters_read", "browser_favorites_order", "browser_empty_text", "menu_text_cut", "menu_text_fit", "browser_ping_cell", "browser_ping_bars")) if fault: code = mutated(code, *fault) @@ -169,7 +189,13 @@ def test_browser_layout(): icon = re.match(r"%([a-z-]+) ", words).group(1).replace("-", "_") assert f"case _icon_{icon}:" in keys, f"{name}'s {icon} has no key" assert [words.split(" ", 1)[1] for _, words, *_ in port_settings.BROWSER_PROMPTS] == \ - ["FAVORITE", "REFRESH", "PASTE LINK", "SORT", "BACK"] + ["FAVORITE", "REFRESH", "PASTE LINK", "SORT", "FILTERS", "BACK"] + # (FILTERS, and the left trigger, open the Filters page, Settings' Online's too) + filters = f"{port_settings.PE}/network_setup/browser_filters/browser_filters_screen" + assert f'' in screen + assert f'' in text + assert f'open="{filters}"' in (CE / "main_menu.settings_select.player_setup.player_profile_edit." + "network_setup.xml").read_text() # (the sort is the column titles': each sorts by its column, X the next of them; the title sorted by # brighter, its arrow its way; no sort of its own by the tabs) sorts = re.findall(r'\{ "(op_sort_header_\w+)", L"(\w+)", (?:TRUE|FALSE) \}', menus) diff --git a/tools/harness/tests/test_menu_keys.py b/tools/harness/tests/test_menu_keys.py index 2fda424dcf..0dd5ca6c48 100644 --- a/tools/harness/tests/test_menu_keys.py +++ b/tools/harness/tests/test_menu_keys.py @@ -23,6 +23,8 @@ # Tab as X (delete) in the Profiles screen, as the browsers' "tab-deletes": ("keyboard", ("(browser ? k[SDL_SCANCODE_TAB] : k[SDL_SCANCODE_E])", "k[SDL_SCANCODE_TAB]"), "browser"), + # the browsers' Filters (the left trigger) drawn as L, which presses nothing + "l-not-left-trigger": ("keyboard", ("analog(k[SDL_SCANCODE_L])", "analog(0)"), "keys"), "escape-not-b": ("keyboard", ("k[SDL_SCANCODE_ESCAPE] || k[SDL_SCANCODE_BACKSPACE]", "k[SDL_SCANCODE_BACKSPACE]"), "keys"), } @@ -41,7 +43,7 @@ def generated(fault=None): keyboard = mutated(keyboard, *change) names = set(re.findall(r"SDL_SCANCODE_\w+", keyboard + function(inputs, "typing_gamepad"))) names |= {"SDL_SCANCODE_RETURN", "SDL_SCANCODE_ESCAPE", "SDL_SCANCODE_E", "SDL_SCANCODE_F", "SDL_SCANCODE_Q", - "SDL_SCANCODE_F1"} + "SDL_SCANCODE_L", "SDL_SCANCODE_F1"} config = "\n".join(re.findall(r"^#define XINPUT_GAMEPAD_\w+ [^\n]+", read("port/include/xdk/xdk_xbox.h"), re.M)) config += "\nenum {" + ", ".join(sorted(names)) + ", TEST_SCANCODE_COUNT};\n" config += enum_with(widgets, "_icon_a_button") + "\n" diff --git a/tools/port_settings.py b/tools/port_settings.py index f50102c4c9..8c7cfb2a26 100644 --- a/tools/port_settings.py +++ b/tools/port_settings.py @@ -447,6 +447,12 @@ def _page_screen(folder: str, screen: str) -> str: STREAMER = ("interface_settings/streamer_mode", "streamer_mode_screen") # (Online's Discord account: port/linux/src/player_link.c) DISCORD_ACCOUNT = ("network_setup/discord_account", "discord_account_screen") +# (the server browsers' Filters, which their FILTERS opens too: menu_functions.c's +# browser_filters_read; its title the PC version's Filters') +BROWSER_FILTERS = ("network_setup/browser_filters", "browser_filters_screen") +BROWSER_FILTERS_TITLE = "main_menu/multiplayer_type_select/join_game/filters/header_filters" +SHOW_HIDE = [("SHOW", "true"), ("HIDE", "false")] +BROWSER_PINGS = [("ANY", "0")] + [(f"UNDER {ms} MS", str(ms)) for ms in (300, 250, 150, 100, 50)] # Button Remapping's rows for a group's actions (the most a group has: # controller_remap_menu.inl's pad_action_groups), and what each row does: A # (or a click) takes the next button pressed, left and right step through @@ -460,7 +466,7 @@ def _page_screen(folder: str, screen: str) -> str: # menu_functions.c's discord_account_show fills in each frame: a link's (what # the page it opens is at), an action's (what it does, its state); and # hdr_display_show's, the display's peak -SETTINGS_STATUS_ROWS = {"discord_account", "link_status", "link_unlink", +SETTINGS_STATUS_ROWS = {"discord_account", "link_status", "link_unlink", "browser_search", *(f"link_master_{n}" for n in range(1, 5)), "hdr_display", "remap_player", "remap_group", *(f"pad_{n}" for n in range(1, REMAP_ROWS + 1))} # the rows whose labels menu_functions.c writes (a master server's host): the @@ -662,6 +668,9 @@ def _page_screen(folder: str, screen: str) -> str: ("DISCORD ACCOUNT ›", None, _page_screen(*DISCORD_ACCOUNT), "Link your Discord account, so that servers that block VPNs let you in while you use one.", None, "discord_account"), + ("SERVER BROWSER FILTERS ›", None, _page_screen(*BROWSER_FILTERS), + "Which games the server browser and the local network's list show: full and empty games, a " + "password, the ping, the game types, and words to search for.", None), # (port/linux/game/map_share.c: this machine's part in another's # game) (SECTION, "MAP SHARING"), @@ -945,6 +954,37 @@ def _page_screen(folder: str, screen: str) -> str: "Name-calling and insults that are not slurs.", None), ], }, + BROWSER_FILTERS[0]: { + "screen": BROWSER_FILTERS[1], "header": BROWSER_FILTERS_TITLE, + "rows": [ + # (the network.browser_* settings, which the server browser and + # the local network's list read as they open, not Join by + # Link's: menu_functions.c's browser_filters_show) + (SECTION, "GAMES"), + ("SHOW FULL GAMES", "network.browser_show_full", YES_NO, + "Lists the games that have no room left.", None), + ("SHOW EMPTY GAMES", "network.browser_show_empty", YES_NO, + "Lists the games that no one is playing yet.", None), + ("SHOW PASSWORD GAMES", "network.browser_show_password", YES_NO, + "Lists the games that need a password to join.", None), + ("PING", "network.browser_ping", BROWSER_PINGS, + "Lists only the games whose ping is under this.|A game whose ping is not known is listed: a local " + "network game's, a dedicated server's, one still being timed.", None), + # (the search's words typed into its value: menu_functions.c's + # browser_search_edit) + ("SEARCH", None, None, + "Lists only the games whose server name or map has these words. Select it and type; Enter keeps " + "them. Empty them to list every game.", None, "browser_search", "port browser search"), + (SECTION, "GAME TYPES"), + ("CAPTURE THE FLAG", "network.browser_show_ctf", SHOW_HIDE, + "Lists Capture the Flag games, OpenCE's kinds of it too.", None), + ("SLAYER", "network.browser_show_slayer", SHOW_HIDE, + "Lists Slayer games, OpenCE's kinds of it too (SWAT, Infection, Gun Game).", None), + ("ODDBALL", "network.browser_show_oddball", SHOW_HIDE, "Lists Oddball games.", None), + ("KING OF THE HILL", "network.browser_show_king", SHOW_HIDE, "Lists King of the Hill games.", None), + ("RACE", "network.browser_show_race", SHOW_HIDE, "Lists Race games.", None), + ], + }, DISCORD_ACCOUNT[0]: { "screen": DISCORD_ACCOUNT[1], "title": "DISCORD ACCOUNT", "rows": [ @@ -1474,8 +1514,9 @@ def _settings_page(folder: str, page: dict) -> list: f'y="{SETTINGS_TABS_TOP}"/>'] if tab else []), f'']) if not tab: + # (its title's picture its own, or one the PC version has: "header") lines += _widget(header, [("controller", 1), ("left", 35), ("top", 11), ("width", 605), ("height", 59), - ("bitmap", header), ("wide", WIDE_LEFT)], []) + ("bitmap", page.get("header", header)), ("wide", WIDE_LEFT)], []) # (the tabs last: up from the first row, down from the buttons) lines += _widget(f"{base}/options_menu", [("type", "column_list"), ("width", 640), ("height", 480), @@ -3659,6 +3700,9 @@ def part_dot(size: int) -> str: ("prompt_paste", "%right-trigger PASTE LINK", 156, 144, ''), # (the next column's title sorts: menu_functions.c's browser_sort_choose) ("prompt_sort", "%x-button SORT", 304, 100, ''), + # (the Filters page, but Join by Link's: menu_functions.c's browser_filters_open) + ("prompt_filters", "%left-trigger FILTERS", 408, 100, + f''), ("prompt_back", "%b-button BACK", 516, 96, ''), ] # Multiplayer's: its list's items (and its two pages': CREATE GAME's and @@ -3931,6 +3975,7 @@ def _browser() -> list: '', '', '', '', + f'', f'', f'', f' list: [f'' for name in ("header_server_browser", "header_lan", "header_direct_link")]) lines += _header(f"{base}/header_lan", f"{base}/header_local_network") - lines += _part_text(f"{base}/browser_counts", [("left", 420), ("top", 46), ("width", 192), ("height", 18), + lines += _part_text(f"{base}/browser_counts", [("left", 372), ("top", 46), ("width", 240), ("height", 18), ("font", "ui\\small_ui"), ("color", PART_DIM), ("align", "right"), ("wide", WIDE_RIGHT)]) lines += _widget(f"{base}/browser_columns_line", [("controller", 1), ("left", BROWSER_LIST_X), From d843c9b578a5ffa814fd45184837945b1086355e Mon Sep 17 00:00:00 2001 From: "erin.cena" Date: Mon, 2 Nov 2026 18:14:57 -0500 Subject: [PATCH 2/2] Let the ping filter's unknown pings pass by their value, and the menu keys test name the left trigger (#452) --- port/linux/game/menu_functions.c | 3 ++- tools/harness/tests/menu_keys.c | 5 ++--- tools/harness/tests/test_browser_menu.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/port/linux/game/menu_functions.c b/port/linux/game/menu_functions.c index 7ee32e350b..353b5fab0d 100644 --- a/port/linux/game/menu_functions.c +++ b/port/linux/game/menu_functions.c @@ -6548,7 +6548,8 @@ static boolean browser_filters_show(struct browser_filters const *filters, struc return FALSE; if (!filters->show_password && entry->locked) return FALSE; - if (filters->maximum_ping > 0 && entry->ping >= 0 && entry->ping >= filters->maximum_ping) + /* (a ping not known, NONE, under any limit) */ + if (filters->maximum_ping > 0 && entry->ping >= filters->maximum_ping) return FALSE; if (entry->engine_type >= 1 && entry->engine_type <= 5 && !(filters->engines & (1 << entry->engine_type))) return FALSE; diff --git a/tools/harness/tests/menu_keys.c b/tools/harness/tests/menu_keys.c index cf49de52a8..87f9f59edf 100644 --- a/tools/harness/tests/menu_keys.c +++ b/tools/harness/tests/menu_keys.c @@ -160,10 +160,9 @@ int main(int argc, char **argv) } CASE("unnamed") { - /* (the D-pad, Start, the triggers and the sticks keep the - controller's) */ + /* (the D-pad, Start and the sticks keep the controller's) */ CHECK(!ui_widget_port_menu_key(_icon_dpad_up) && !ui_widget_port_menu_key(_icon_start_button) && - !ui_widget_port_menu_key(_icon_left_trigger) && !ui_widget_port_menu_key(_icon_left_thumb), + !ui_widget_port_menu_key(_icon_left_thumb), "a button the keyboard has no menu key for named one"); return 0; } diff --git a/tools/harness/tests/test_browser_menu.py b/tools/harness/tests/test_browser_menu.py index 8978b3d82f..14c883294c 100644 --- a/tools/harness/tests/test_browser_menu.py +++ b/tools/harness/tests/test_browser_menu.py @@ -36,8 +36,8 @@ "password-never-hidden": (("if (!filters->show_password && entry->locked)", "if (FALSE)"), "filters"), "ping-at-limit-listed": (("entry->ping >= filters->maximum_ping)", "entry->ping > filters->maximum_ping)"), "filters"), - "ping-unknown-hidden": (("filters->maximum_ping > 0 && entry->ping >= 0 &&", "filters->maximum_ping > 0 &&"), - "filters"), + "ping-unknown-hidden": (("entry->ping >= filters->maximum_ping)", + "(entry->ping < 0 || entry->ping >= filters->maximum_ping))"), "filters"), "coop-hidden-by-types": (("entry->engine_type >= 1 && entry->engine_type <= 5 &&", ""), "filters"), "search-name-only": (("browser_text_has(text, filters->search) || browser_text_has(entry->map_shown, " "filters->search)", "browser_text_has(text, filters->search)"), "filters"),