Move network_disconnect to network.h

This commit is contained in:
EmeraldLockdown 2026-03-11 18:54:32 -05:00
parent fbf3280f09
commit f1b3917adc
12 changed files with 92 additions and 111 deletions

View file

@ -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

View file

@ -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()

View file

@ -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 |
| :--------- | :---- |

View file

@ -2825,6 +2825,30 @@ Gets a Discord ID corresponding to the network player with `localIndex`
<br />
## [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:](#)
<br />
---
# functions from obj_behaviors.c

View file

@ -1840,30 +1840,6 @@ Gets the CoopNet ID of a player with `localIndex` if CoopNet is being used and t
<br />
## [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:](#)
<br />
## [get_volume_master](#get_volume_master)
### Description

View file

@ -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)
<br />
@ -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)

View file

@ -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"

View file

@ -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);

View file

@ -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;
}

View file

@ -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| */

View file

@ -1,9 +1,12 @@
#include <stdio.h>
#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;
}
}

View file

@ -4,6 +4,12 @@
#include <stdbool.h>
#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