From a957ce2aa026dbd397d22deff334dff4af5fd848 Mon Sep 17 00:00:00 2001 From: Beyley Thomas Date: Fri, 25 Feb 2022 22:39:03 -0800 Subject: [PATCH 1/3] Allow binding to ports <1024 on non-linux builds (#136) * Allow binding to ports <1024 on non-linux builds This seems to be only a restriction on Linux and Mac versions older then Mojave * Fix port check on djui_panel_join_ip_parse_port --- src/pc/djui/djui_panel_host.c | 4 ++++ src/pc/djui/djui_panel_join.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pc/djui/djui_panel_host.c b/src/pc/djui/djui_panel_host.c index 582427c33..f49987d30 100644 --- a/src/pc/djui/djui_panel_host.c +++ b/src/pc/djui/djui_panel_host.c @@ -27,7 +27,11 @@ static bool djui_panel_host_port_valid(void) { port += (*buffer - '0'); buffer++; } +#if __linux__ return port >= 1024 && port <= 65535; +#else + return port <= 65535; +#endif } static void djui_panel_host_port_text_change(struct DjuiBase* caller) { diff --git a/src/pc/djui/djui_panel_join.c b/src/pc/djui/djui_panel_join.c index a5cb57520..c15d7ac8d 100644 --- a/src/pc/djui/djui_panel_join.c +++ b/src/pc/djui/djui_panel_join.c @@ -52,13 +52,13 @@ static bool djui_panel_join_ip_parse_spacer(char** msg) { } static bool djui_panel_join_ip_parse_port(char** msg) { - int num = 0; + int port = 0; for (int i = 0; i < 5; i++) { char c = **msg; if (c >= '0' && c <= '9') { // is number - num *= 10; - num += (c - '0'); + port *= 10; + port += (c - '0'); *msg = *msg + 1; } else if (i == 0) { return false; @@ -67,7 +67,7 @@ static bool djui_panel_join_ip_parse_port(char** msg) { } } - return num >= 1024 && num <= 65535; + return port <= 65535; } static bool djui_panel_join_ip_valid(char* buffer) { From 1c36ea979faad812c01c0e1cc841beee0f949ceb Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 25 Feb 2022 22:44:23 -0800 Subject: [PATCH 2/3] Fix crash on invalid domain --- src/pc/network/socket/domain_res.c | 38 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/pc/network/socket/domain_res.c b/src/pc/network/socket/domain_res.c index fb57c4865..264eb08ed 100644 --- a/src/pc/network/socket/domain_res.c +++ b/src/pc/network/socket/domain_res.c @@ -12,23 +12,27 @@ void domain_resolution(void) { - struct in_addr addr; - char *host_name; - struct hostent *remoteHost; - char* domainname = ""; - host_name = configJoinIp; - if (host_name == NULL) { - return; - } - int i = 0; - remoteHost = gethostbyname(host_name); - i = 0; - if (remoteHost->h_addrtype == AF_INET) { + struct in_addr addr; + char *host_name = configJoinIp; + struct hostent *remoteHost; + char* domainname = ""; + host_name = configJoinIp; - while (remoteHost->h_addr_list[i] != 0) { - addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++]; - domainname = inet_ntoa(addr); - snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", domainname); + if (host_name == NULL) { + return; + } + + int i = 0; + remoteHost = gethostbyname(host_name); + if (remoteHost == NULL) { + return; + } + + if (remoteHost->h_addrtype == AF_INET) { + while (remoteHost->h_addr_list[i] != 0) { + addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++]; + domainname = inet_ntoa(addr); + snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", domainname); + } } - } } From a83ce7d946c3185d370ad4e7fa575a8ac44a3d37 Mon Sep 17 00:00:00 2001 From: Amy54Desu <69287652+Amy54Desu@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:11:50 -0500 Subject: [PATCH 3/3] Settable Player Limit (#135) Allow a configurable maximum number of players --- src/pc/configfile.c | 2 + src/pc/configfile.h | 1 + src/pc/djui/djui_panel_host.c | 6 +++ src/pc/djui/djui_panel_host_settings.c | 52 ++++++++++++++++++++++++-- src/pc/network/discord/lobby.c | 3 +- src/pc/network/packets/packet_join.c | 3 +- 6 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 9334dab7b..f95645a6c 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -103,6 +103,7 @@ bool configSkipIntro = 0; bool configShareLives = 0; bool configEnableCheats = 0; bool configBubbleDeath = true; +unsigned int configAmountofPlayers = 16; bool configHUD = true; #ifdef DISCORDRPC bool configDiscordRPC = true; @@ -175,6 +176,7 @@ static const struct ConfigOption options[] = { {.name = "share_lives", .type = CONFIG_TYPE_BOOL, .boolValue = &configShareLives}, {.name = "enable_cheats", .type = CONFIG_TYPE_BOOL, .boolValue = &configEnableCheats}, {.name = "bubble_death", .type = CONFIG_TYPE_BOOL, .boolValue = &configBubbleDeath}, + {.name = "amount_of_players", .type = CONFIG_TYPE_UINT, .uintValue = &configAmountofPlayers}, #ifdef DISCORDRPC {.name = "discordrpc_enable", .type = CONFIG_TYPE_BOOL, .boolValue = &configDiscordRPC}, #endif diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 425f572a6..e3c69d1a3 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -70,6 +70,7 @@ extern bool configSkipIntro; extern bool configShareLives; extern bool configEnableCheats; extern bool configBubbleDeath; +extern unsigned int configAmountofPlayers; #ifdef DISCORDRPC extern bool configDiscordRPC; #endif diff --git a/src/pc/djui/djui_panel_host.c b/src/pc/djui/djui_panel_host.c index f49987d30..b185c63dd 100644 --- a/src/pc/djui/djui_panel_host.c +++ b/src/pc/djui/djui_panel_host.c @@ -49,6 +49,12 @@ static void djui_panel_host_do_host(struct DjuiBase* caller) { djui_inputbox_select_all(sInputboxPort); return; } + + // Doesn't let you host if the player limit is not good + if (configAmountofPlayers < 2 || configAmountofPlayers > 16) { + return; + } + configHostPort = atoi(sInputboxPort->buffer); djui_panel_host_message_create(caller); } diff --git a/src/pc/djui/djui_panel_host_settings.c b/src/pc/djui/djui_panel_host_settings.c index e770d57e8..a2748366b 100644 --- a/src/pc/djui/djui_panel_host_settings.c +++ b/src/pc/djui/djui_panel_host_settings.c @@ -5,8 +5,11 @@ #include "pc/utils/misc.h" #include "pc/configfile.h" #include "pc/cheats.h" +#include "pc/network/discord/lobby.h" +#include "djui_inputbox.h" static unsigned int sKnockbackIndex = 0; +struct DjuiInputbox* sPlayerAmount = NULL; static void djui_panel_host_settings_knockback_change(UNUSED struct DjuiBase* caller) { switch (sKnockbackIndex) { @@ -16,8 +19,31 @@ static void djui_panel_host_settings_knockback_change(UNUSED struct DjuiBase* ca } } +static bool djui_panel_host_limit_valid(void) { + char* buffer = sPlayerAmount->buffer; + int limit = 0; + while (*buffer != '\0') { + if (*buffer < '0' || *buffer > '9') { return false; } + limit *= 10; + limit += (*buffer - '0'); + buffer++; + } + return limit >= 2 && limit <= 16; +} + +static void djui_panel_host_player_text_change(struct DjuiBase* caller) { + struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller; + if (djui_panel_host_limit_valid()) { + djui_inputbox_set_text_color(inputbox1, 0, 0, 0, 255); + } else { + djui_inputbox_set_text_color(inputbox1, 255, 0, 0, 255); + return; + } + configAmountofPlayers = atoi(sPlayerAmount->buffer); +} + void djui_panel_host_settings_create(struct DjuiBase* caller) { - f32 bodyHeight = 32 * 7 + 64 * 1 + 16 * 7; + f32 bodyHeight = 32 * 8 + 64 * 1 + 16 * 8; struct DjuiBase* defaultBase = NULL; struct DjuiThreePanel* panel = djui_panel_menu_create(bodyHeight, "\\#ff0800\\S\\#1be700\\E\\#00b3ff\\T\\#ffef00\\T\\#ff0800\\I\\#1be700\\N\\#00b3ff\\G\\#ffef00\\S"); @@ -56,14 +82,34 @@ void djui_panel_host_settings_create(struct DjuiBase* caller) { struct DjuiCheckbox* checkbox5 = djui_checkbox_create(&body->base, "Bubble on death", &configBubbleDeath); djui_base_set_size_type(&checkbox5->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); djui_base_set_size(&checkbox5->base, 1.0f, 32); + + struct DjuiRect* rect1 = djui_rect_create(&body->base); + djui_base_set_size_type(&rect1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&rect1->base, 1.0f, 32); + djui_base_set_color(&rect1->base, 0, 0, 0, 0); + { + struct DjuiText* text1 = djui_text_create(&rect1->base, "Amount of players"); + djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_color(&text1->base, 200, 200, 200, 255); + djui_base_set_size(&text1->base, 0.485f, 64); + djui_base_set_alignment(&text1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP); + struct DjuiInputbox* inputbox1 = djui_inputbox_create(&rect1->base, 32); + djui_base_set_size_type(&inputbox1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&inputbox1->base, 0.5f, 32); + djui_base_set_alignment(&inputbox1->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP); + char limitString[32] = { 0 }; + snprintf(limitString, 32, "%d", configAmountofPlayers); + djui_inputbox_set_text(inputbox1, limitString); + djui_interactable_hook_value_change(&inputbox1->base, djui_panel_host_player_text_change); + sPlayerAmount = inputbox1; + } + struct DjuiButton* button1 = djui_button_create(&body->base, "Back"); djui_base_set_size_type(&button1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); djui_base_set_size(&button1->base, 1.0f, 64); djui_button_set_style(button1, 1); djui_interactable_hook_click(&button1->base, djui_panel_menu_back); - defaultBase = &button1->base; } - djui_panel_add(caller, &panel->base, defaultBase); } diff --git a/src/pc/network/discord/lobby.c b/src/pc/network/discord/lobby.c index c7ea022e3..2565cf3ee 100644 --- a/src/pc/network/discord/lobby.c +++ b/src/pc/network/discord/lobby.c @@ -3,6 +3,7 @@ #include "discord_network.h" #include "pc/logfile.h" #include "pc/utils/misc.h" +#include "pc/configfile.h" #define MAX_LOBBY_RETRY 5 #define MAX_LOBBY_RETRY_WAIT_TIME 6 @@ -45,7 +46,7 @@ static void on_lobby_create_callback(UNUSED void* data, enum EDiscordResult resu gCurActivity.type = DiscordActivityType_Playing; snprintf(gCurActivity.party.id, 128, DISCORD_ID_FORMAT, lobby->id); gCurActivity.party.size.current_size = 1; - gCurActivity.party.size.max_size = MAX_PLAYERS; + gCurActivity.party.size.max_size = configAmountofPlayers; char secretJoin[128] = ""; snprintf(secretJoin, 128, DISCORD_ID_FORMAT ":%s", lobby->id, lobby->secret); diff --git a/src/pc/network/packets/packet_join.c b/src/pc/network/packets/packet_join.c index e55fade76..81c4b911e 100644 --- a/src/pc/network/packets/packet_join.c +++ b/src/pc/network/packets/packet_join.c @@ -18,6 +18,7 @@ #include "pc/debuglog.h" #include "pc/utils/misc.h" #include "pc/lua/smlua.h" +#include "pc/configfile.h" extern u8* gOverrideEeprom; static u8 eeprom[512] = { 0 }; @@ -66,7 +67,7 @@ void network_send_join(struct Packet* joinRequestPacket) { // figure out id u8 globalIndex = joinRequestPacket->localIndex; if (globalIndex == UNKNOWN_LOCAL_INDEX) { - for (int i = 1; i < MAX_PLAYERS; i++) { + for (int i = 1; i < configAmountofPlayers; i++) { if (!gNetworkPlayers[i].connected) { globalIndex = i; break;