From f1b3917adca27be916832ff0c2c3cc8e1b5144a1 Mon Sep 17 00:00:00 2001 From: EmeraldLockdown <86802223+EmeraldLoc@users.noreply.github.com> Date: Wed, 11 Mar 2026 18:54:32 -0500 Subject: [PATCH] Move `network_disconnect` to `network.h` --- autogen/lua_definitions/constants.lua | 9 ----- autogen/lua_definitions/functions.lua | 14 ++++---- docs/lua/constants.md | 8 ----- docs/lua/functions-5.md | 24 +++++++++++++ docs/lua/functions-7.md | 24 ------------- docs/lua/functions.md | 2 +- src/pc/lua/smlua_constants_autogen.c | 3 -- src/pc/lua/smlua_functions_autogen.c | 52 +++++++++++++-------------- src/pc/lua/utils/smlua_misc_utils.c | 24 ------------- src/pc/lua/utils/smlua_misc_utils.h | 9 ----- src/pc/network/network_utils.c | 25 +++++++++++++ src/pc/network/network_utils.h | 9 +++++ 12 files changed, 92 insertions(+), 111 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 011e6a73d..8e160c5d4 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -8275,15 +8275,6 @@ HOOK_MAX = 60 --- @type LuaHookedEventType --- @type integer MAX_HOOKED_BEHAVIORS = 1024 -DC_LEAVE = 0 --- @type DisconnectType -DC_KICK = 1 --- @type DisconnectType -DC_BAN = 2 --- @type DisconnectType - ---- @alias DisconnectType ---- | `DC_LEAVE` ---- | `DC_KICK` ---- | `DC_BAN` - HUD_DISPLAY_LIVES = 0 --- @type HudDisplayValue HUD_DISPLAY_COINS = 1 --- @type HudDisplayValue HUD_DISPLAY_STARS = 2 --- @type HudDisplayValue diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 9984b61ce..9e982734e 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -7962,6 +7962,13 @@ function network_discord_id_from_local_index(localIndex) -- ... end +--- @param dcType? DisconnectType +--- @param reason? string +--- Disconnects the local player with DisconnectType `dcType` (default is DC_LEAVE) because of `reason` (optional). +function network_disconnect(dcType, reason) + -- ... +end + --- Resets Yoshi as being alive function set_yoshi_as_not_dead() -- ... @@ -11586,13 +11593,6 @@ function get_coopnet_id(localIndex) -- ... end ---- @param dcType? DisconnectType ---- @param reason? string ---- Disconnects the local player with DisconnectType `dcType` (default is DC_LEAVE) because of `reason` (optional). -function network_disconnect(dcType, reason) - -- ... -end - --- @return number --- Gets the master volume level function get_volume_master() diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 2b82d0596..0c92edac9 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -84,7 +84,6 @@ - [enum LuaActionHookType](#enum-LuaActionHookType) - [enum LuaModMenuElementType](#enum-LuaModMenuElementType) - [smlua_misc_utils.h](#smlua_misc_utilsh) - - [enum DisconnectType](#enum-DisconnectType) - [enum HudDisplayValue](#enum-HudDisplayValue) - [enum HudDisplayFlags](#enum-HudDisplayFlags) - [enum ActSelectHudPart](#enum-ActSelectHudPart) @@ -3547,13 +3546,6 @@ ## [smlua_misc_utils.h](#smlua_misc_utils.h) -### [enum DisconnectType](#DisconnectType) -| Identifier | Value | -| :--------- | :---- | -| DC_LEAVE | 0 | -| DC_KICK | 1 | -| DC_BAN | 2 | - ### [enum HudDisplayValue](#HudDisplayValue) | Identifier | Value | | :--------- | :---- | diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md index d7d4a8757..b6ac6cd85 100644 --- a/docs/lua/functions-5.md +++ b/docs/lua/functions-5.md @@ -2825,6 +2825,30 @@ Gets a Discord ID corresponding to the network player with `localIndex`
+## [network_disconnect](#network_disconnect) + +### Description +Disconnects the local player with DisconnectType `dcType` (default is DC_LEAVE) because of `reason` (optional). + +### Lua Example +`network_disconnect(dcType, reason)` + +### Parameters +| Field | Type | +| ----- | ---- | +| dcType | [enum DisconnectType](constants.md#enum-DisconnectType) | +| reason | `string` | + +### Returns +- None + +### C Prototype +`void network_disconnect(OPTIONAL enum DisconnectType dcType, OPTIONAL const char* reason);` + +[:arrow_up_small:](#) + +
+ --- # functions from obj_behaviors.c diff --git a/docs/lua/functions-7.md b/docs/lua/functions-7.md index 46446ddf5..207edbb6f 100644 --- a/docs/lua/functions-7.md +++ b/docs/lua/functions-7.md @@ -1840,30 +1840,6 @@ Gets the CoopNet ID of a player with `localIndex` if CoopNet is being used and t
-## [network_disconnect](#network_disconnect) - -### Description -Disconnects the local player with DisconnectType `dcType` (default is DC_LEAVE) because of `reason` (optional). - -### Lua Example -`network_disconnect(dcType, reason)` - -### Parameters -| Field | Type | -| ----- | ---- | -| dcType | [enum DisconnectType](constants.md#enum-DisconnectType) | -| reason | `string` | - -### Returns -- None - -### C Prototype -`void network_disconnect(OPTIONAL enum DisconnectType dcType, OPTIONAL const char* reason);` - -[:arrow_up_small:](#) - -
- ## [get_volume_master](#get_volume_master) ### Description diff --git a/docs/lua/functions.md b/docs/lua/functions.md index cd6fc83a9..b3af65380 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1439,6 +1439,7 @@ - [network_get_complete_player_name](functions-5.md#network_get_complete_player_name) - [network_check_singleplayer_pause](functions-5.md#network_check_singleplayer_pause) - [network_discord_id_from_local_index](functions-5.md#network_discord_id_from_local_index) + - [network_disconnect](functions-5.md#network_disconnect)
@@ -2061,7 +2062,6 @@ - [get_time_stop_flags](functions-7.md#get_time_stop_flags) - [get_local_discord_id](functions-7.md#get_local_discord_id) - [get_coopnet_id](functions-7.md#get_coopnet_id) - - [network_disconnect](functions-7.md#network_disconnect) - [get_volume_master](functions-7.md#get_volume_master) - [get_volume_level](functions-7.md#get_volume_level) - [get_volume_sfx](functions-7.md#get_volume_sfx) diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index dbd9b83cd..d7ca5a882 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3549,9 +3549,6 @@ char gSmluaConstants[] = "" "HOOK_ON_PACKET_BYTESTRING_RECEIVE=59\n" "HOOK_MAX=60\n" "MAX_HOOKED_BEHAVIORS=1024\n" -"DC_LEAVE=0\n" -"DC_KICK=1\n" -"DC_BAN=2\n" "HUD_DISPLAY_LIVES=0\n" "HUD_DISPLAY_COINS=1\n" "HUD_DISPLAY_STARS=2\n" diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 9e0d645e8..ebc32f885 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -23591,6 +23591,31 @@ int smlua_func_network_discord_id_from_local_index(lua_State* L) { return 1; } +int smlua_func_network_disconnect(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top < 0 || top > 2) { + LOG_LUA_LINE("Improper param count for '%s': Expected between %u and %u, Received %u", "network_disconnect", 0, 2, top); + return 0; + } + + int dcType = (int) 0; + if (top >= 1) { + dcType = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "network_disconnect"); return 0; } + } + const char* reason = (const char*) NULL; + if (top >= 2) { + reason = smlua_to_string(L, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "network_disconnect"); return 0; } + } + + network_disconnect(dcType, reason); + + return 1; +} + ///////////////////// // obj_behaviors.c // ///////////////////// @@ -34141,31 +34166,6 @@ int smlua_func_get_coopnet_id(lua_State* L) { return 1; } -int smlua_func_network_disconnect(lua_State* L) { - if (L == NULL) { return 0; } - - int top = lua_gettop(L); - if (top < 0 || top > 2) { - LOG_LUA_LINE("Improper param count for '%s': Expected between %u and %u, Received %u", "network_disconnect", 0, 2, top); - return 0; - } - - int dcType = (int) 0; - if (top >= 1) { - dcType = smlua_to_integer(L, 1); - if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "network_disconnect"); return 0; } - } - const char* reason = (const char*) NULL; - if (top >= 2) { - reason = smlua_to_string(L, 2); - if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "network_disconnect"); return 0; } - } - - network_disconnect(dcType, reason); - - return 1; -} - int smlua_func_get_volume_master(UNUSED lua_State* L) { if (L == NULL) { return 0; } @@ -38136,6 +38136,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "network_get_complete_player_name", smlua_func_network_get_complete_player_name); smlua_bind_function(L, "network_check_singleplayer_pause", smlua_func_network_check_singleplayer_pause); smlua_bind_function(L, "network_discord_id_from_local_index", smlua_func_network_discord_id_from_local_index); + smlua_bind_function(L, "network_disconnect", smlua_func_network_disconnect); // obj_behaviors.c smlua_bind_function(L, "set_yoshi_as_not_dead", smlua_func_set_yoshi_as_not_dead); @@ -38736,7 +38737,6 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "get_time_stop_flags", smlua_func_get_time_stop_flags); smlua_bind_function(L, "get_local_discord_id", smlua_func_get_local_discord_id); smlua_bind_function(L, "get_coopnet_id", smlua_func_get_coopnet_id); - smlua_bind_function(L, "network_disconnect", smlua_func_network_disconnect); smlua_bind_function(L, "get_volume_master", smlua_func_get_volume_master); smlua_bind_function(L, "get_volume_level", smlua_func_get_volume_level); smlua_bind_function(L, "get_volume_sfx", smlua_func_get_volume_sfx); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index cab62e76d..7c1064e40 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -525,30 +525,6 @@ const char* get_coopnet_id(UNUSED s8 localIndex) { /// -void network_disconnect(OPTIONAL enum DisconnectType dcType, OPTIONAL const char* reason) { - switch (dcType) { - case DC_KICK: - if (gNetworkType == NT_SERVER) { - LOG_LUA("network_disconnect: Cannot kick the server!"); - return; - } - network_send_moderation_action(MODERATION_ACTION_KICK, 0, (char*)reason, false); - break; - case DC_BAN: - if (gNetworkType == NT_SERVER) { - LOG_LUA("network_disconnect: Cannot ban the server!"); - return; - } - network_send_moderation_action(MODERATION_ACTION_BAN, 0, (char*)reason, false); - break; - default: - gQueuedDisconnect = dcType; - break; - } -} - -/// - f32 get_volume_master(void) { return gLuaVolumeMaster; } diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index 28cdd528f..c9f07b98b 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -5,12 +5,6 @@ #include "game/camera.h" #include "pc/lua/smlua_utils.h" -enum DisconnectType { - DC_LEAVE, - DC_KICK, - DC_BAN -}; - enum HudDisplayValue { HUD_DISPLAY_LIVES, HUD_DISPLAY_COINS, @@ -225,9 +219,6 @@ const char* get_local_discord_id(void); /* |description|Gets the CoopNet ID of a player with `localIndex` if CoopNet is being used and the player is connected, otherwise "-1" is returned|descriptionEnd| */ const char* get_coopnet_id(s8 localIndex); -/* |description|Disconnects the local player with DisconnectType `dcType` (default is DC_LEAVE) because of `reason` (optional).|descriptionEnd| */ -void network_disconnect(OPTIONAL enum DisconnectType dcType, OPTIONAL const char* reason); - /* |description|Gets the master volume level|descriptionEnd| */ f32 get_volume_master(void); /* |description|Gets the volume level of music|descriptionEnd| */ diff --git a/src/pc/network/network_utils.c b/src/pc/network/network_utils.c index bbfc7f5fd..0b279a485 100644 --- a/src/pc/network/network_utils.c +++ b/src/pc/network/network_utils.c @@ -1,9 +1,12 @@ #include #include "network_utils.h" +#include "moderation.h" #include "game/camera.h" #include "game/level_update.h" #include "game/mario_misc.h" #include "pc/mods/mods.h" +#include "pc/debuglog.h" +#include "pc/lua/smlua.h" u8 network_global_index_from_local(u8 localIndex) { if (gNetworkType == NT_SERVER) { return localIndex; } @@ -71,3 +74,25 @@ const char* network_discord_id_from_local_index(u8 localIndex) { if (localIndex >= MAX_PLAYERS) { return "0"; } return gNetworkPlayers[localIndex].discordId; } + +void network_disconnect(OPTIONAL enum DisconnectType dcType, OPTIONAL const char* reason) { + switch (dcType) { + case DC_KICK: + if (gNetworkType == NT_SERVER) { + LOG_LUA("network_disconnect: Cannot kick the server!"); + return; + } + network_send_moderation_action(MODERATION_ACTION_KICK, 0, (char*)reason, false); + break; + case DC_BAN: + if (gNetworkType == NT_SERVER) { + LOG_LUA("network_disconnect: Cannot ban the server!"); + return; + } + network_send_moderation_action(MODERATION_ACTION_BAN, 0, (char*)reason, false); + break; + default: + gQueuedDisconnect = dcType; + break; + } +} diff --git a/src/pc/network/network_utils.h b/src/pc/network/network_utils.h index d33658520..4b0ef0c05 100644 --- a/src/pc/network/network_utils.h +++ b/src/pc/network/network_utils.h @@ -4,6 +4,12 @@ #include #include "network.h" +enum DisconnectType { + DC_LEAVE, + DC_KICK, + DC_BAN +}; + /* |description|Gets a player's global index from their local index|descriptionEnd| */ u8 network_global_index_from_local(u8 localIndex); /* |description|Gets a player's local index from their global index|descriptionEnd| */ @@ -26,4 +32,7 @@ bool network_check_singleplayer_pause(void); /* |description|Gets a Discord ID corresponding to the network player with `localIndex`|descriptionEnd| */ const char* network_discord_id_from_local_index(u8 localIndex); +/* |description|Disconnects the local player with DisconnectType `dcType` (default is DC_LEAVE) because of `reason` (optional).|descriptionEnd| */ +void network_disconnect(OPTIONAL enum DisconnectType dcType, OPTIONAL const char* reason); + #endif \ No newline at end of file