Allow requesting reconnect when mods kick player (#14971)
Some checks failed
windows / VS 2019 ${{ matrix.config.arch }}-${{ matrix.type }} (map[arch:x64 generator:-G'Visual Studio 16 2019' -A x64 vcpkg_triplet:x64-windows], portable) (push) Has been cancelled
android / build (push) Has been cancelled
cpp_lint / clang_tidy (push) Has been cancelled
linux / gcc_7 (push) Has been cancelled
linux / gcc_14 (push) Has been cancelled
linux / clang_7 (push) Has been cancelled
linux / clang_18 (push) Has been cancelled
linux / clang_11 (PROMETHEUS=1) (push) Has been cancelled
lua_lint / Compile and run multiplayer tests (push) Has been cancelled
lua_lint / Builtin Luacheck and Unit Tests (push) Has been cancelled
lua_api_deploy / build (push) Has been cancelled
macos / build (push) Has been cancelled
whitespace_checks / trailing_whitespaces (push) Has been cancelled
whitespace_checks / tabs_lua_api_files (push) Has been cancelled
windows / MinGW cross-compiler (${{ matrix.bits }}-bit) (32) (push) Has been cancelled
windows / MinGW cross-compiler (${{ matrix.bits }}-bit) (64) (push) Has been cancelled
windows / VS 2019 ${{ matrix.config.arch }}-${{ matrix.type }} (map[arch:x86 generator:-G'Visual Studio 16 2019' -A Win32 vcpkg_triplet:x86-windows], portable) (push) Has been cancelled

This commit is contained in:
1F616EMO~nya 2024-09-13 05:42:46 +08:00 committed by GitHub
parent b12e67699a
commit 38b4505ad7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 28 additions and 37 deletions

View File

@ -6,14 +6,14 @@ local S = core.get_translator("__builtin")
-- Misc. API functions -- Misc. API functions
-- --
-- @spec core.kick_player(String, String) :: Boolean -- @spec core.kick_player(String, String, Boolean) :: Boolean
function core.kick_player(player_name, reason) function core.kick_player(player_name, reason, reconnect)
if type(reason) == "string" then if type(reason) == "string" then
reason = "Kicked: " .. reason reason = "Kicked: " .. reason
else else
reason = "Kicked." reason = "Kicked."
end end
return core.disconnect_player(player_name, reason) return core.disconnect_player(player_name, reason, reconnect)
end end
function core.check_player_privs(name, ...) function core.check_player_privs(name, ...)

View File

@ -6999,10 +6999,11 @@ Bans
* Returns boolean indicating success * Returns boolean indicating success
* `minetest.unban_player_or_ip(ip_or_name)`: remove ban record matching * `minetest.unban_player_or_ip(ip_or_name)`: remove ban record matching
IP address or name IP address or name
* `minetest.kick_player(name, [reason])`: disconnect a player with an optional * `minetest.kick_player(name[, reason[, reconnect]])`: disconnect a player with an optional
reason. reason.
* Returns boolean indicating success (false if player nonexistent) * Returns boolean indicating success (false if player nonexistent)
* `minetest.disconnect_player(name, [reason])`: disconnect a player with an * If `reconnect` is true, allow the user to reconnect.
* `minetest.disconnect_player(name[, reason[, reconnect]])`: disconnect a player with an
optional reason, this will not prefix with 'Kicked: ' like kick_player. optional reason, this will not prefix with 'Kicked: ' like kick_player.
If no reason is given, it will default to 'Disconnected.' If no reason is given, it will default to 'Disconnected.'
* Returns boolean indicating success (false if player nonexistent) * Returns boolean indicating success (false if player nonexistent)

View File

@ -204,7 +204,6 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
// to be processed even if the serialization format has // to be processed even if the serialization format has
// not been agreed yet, the same as TOCLIENT_INIT. // not been agreed yet, the same as TOCLIENT_INIT.
m_access_denied = true; m_access_denied = true;
m_access_denied_reason = "Unknown";
if (pkt->getCommand() != TOCLIENT_ACCESS_DENIED) { if (pkt->getCommand() != TOCLIENT_ACCESS_DENIED) {
// Legacy code from 0.4.12 and older but is still used // Legacy code from 0.4.12 and older but is still used
@ -223,29 +222,23 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
u8 denyCode; u8 denyCode;
*pkt >> denyCode; *pkt >> denyCode;
if (denyCode == SERVER_ACCESSDENIED_SHUTDOWN || if (pkt->getRemainingBytes() > 0)
denyCode == SERVER_ACCESSDENIED_CRASH) {
*pkt >> m_access_denied_reason; *pkt >> m_access_denied_reason;
if (m_access_denied_reason.empty())
if (m_access_denied_reason.empty()) {
if (denyCode >= SERVER_ACCESSDENIED_MAX) {
m_access_denied_reason = gettext("Unknown disconnect reason.");
} else if (denyCode != SERVER_ACCESSDENIED_CUSTOM_STRING) {
m_access_denied_reason = gettext(accessDeniedStrings[denyCode]); m_access_denied_reason = gettext(accessDeniedStrings[denyCode]);
}
}
if (denyCode == SERVER_ACCESSDENIED_TOO_MANY_USERS) {
m_access_denied_reconnect = true;
} else if (pkt->getRemainingBytes() > 0) {
u8 reconnect; u8 reconnect;
*pkt >> reconnect; *pkt >> reconnect;
m_access_denied_reconnect = reconnect & 1; m_access_denied_reconnect = reconnect & 1;
} else if (denyCode == SERVER_ACCESSDENIED_CUSTOM_STRING) {
*pkt >> m_access_denied_reason;
} else if (denyCode == SERVER_ACCESSDENIED_TOO_MANY_USERS) {
m_access_denied_reason = gettext(accessDeniedStrings[denyCode]);
m_access_denied_reconnect = true;
} else if (denyCode < SERVER_ACCESSDENIED_MAX) {
m_access_denied_reason = gettext(accessDeniedStrings[denyCode]);
} else {
// Allow us to add new error messages to the
// protocol without raising the protocol version, if we want to.
// Until then (which may be never), this is outside
// of the defined protocol.
*pkt >> m_access_denied_reason;
if (m_access_denied_reason.empty())
m_access_denied_reason = "Unknown";
} }
} }

View File

@ -365,7 +365,7 @@ int ModApiServer::l_ban_player(lua_State *L)
return 1; return 1;
} }
// disconnect_player(name, [reason]) -> success // disconnect_player(name[, reason[, reconnect]]) -> success
int ModApiServer::l_disconnect_player(lua_State *L) int ModApiServer::l_disconnect_player(lua_State *L)
{ {
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
@ -388,7 +388,9 @@ int ModApiServer::l_disconnect_player(lua_State *L)
return 1; return 1;
} }
server->DenyAccess(player->getPeerId(), SERVER_ACCESSDENIED_CUSTOM_STRING, message); bool reconnect = readParam<bool>(L, 3, false);
server->DenyAccess(player->getPeerId(), SERVER_ACCESSDENIED_CUSTOM_STRING, message, reconnect);
lua_pushboolean(L, true); lua_pushboolean(L, true);
return 1; return 1;
} }

View File

@ -106,7 +106,7 @@ private:
// unban_player_or_ip() // unban_player_or_ip()
static int l_unban_player_or_ip(lua_State *L); static int l_unban_player_or_ip(lua_State *L);
// disconnect_player(name, [reason]) -> success // disconnect_player(name[, reason[, reconnect]]) -> success
static int l_disconnect_player(lua_State *L); static int l_disconnect_player(lua_State *L);
// remove_player(name) // remove_player(name)

View File

@ -1383,17 +1383,12 @@ void Server::SendBreath(session_t peer_id, u16 breath)
} }
void Server::SendAccessDenied(session_t peer_id, AccessDeniedCode reason, void Server::SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
const std::string &custom_reason, bool reconnect) std::string_view custom_reason, bool reconnect)
{ {
assert(reason < SERVER_ACCESSDENIED_MAX); assert(reason < SERVER_ACCESSDENIED_MAX);
NetworkPacket pkt(TOCLIENT_ACCESS_DENIED, 1, peer_id); NetworkPacket pkt(TOCLIENT_ACCESS_DENIED, 1, peer_id);
pkt << (u8)reason; pkt << (u8)reason << custom_reason << (u8)reconnect;
if (reason == SERVER_ACCESSDENIED_CUSTOM_STRING)
pkt << custom_reason;
else if (reason == SERVER_ACCESSDENIED_SHUTDOWN ||
reason == SERVER_ACCESSDENIED_CRASH)
pkt << custom_reason << (u8)reconnect;
Send(&pkt); Send(&pkt);
} }
@ -2829,7 +2824,7 @@ void Server::DenySudoAccess(session_t peer_id)
void Server::DenyAccess(session_t peer_id, AccessDeniedCode reason, void Server::DenyAccess(session_t peer_id, AccessDeniedCode reason,
const std::string &custom_reason, bool reconnect) std::string_view custom_reason, bool reconnect)
{ {
SendAccessDenied(peer_id, reason, custom_reason, reconnect); SendAccessDenied(peer_id, reason, custom_reason, reconnect);
m_clients.event(peer_id, CSE_SetDenied); m_clients.event(peer_id, CSE_SetDenied);

View File

@ -364,7 +364,7 @@ public:
void DenySudoAccess(session_t peer_id); void DenySudoAccess(session_t peer_id);
void DenyAccess(session_t peer_id, AccessDeniedCode reason, void DenyAccess(session_t peer_id, AccessDeniedCode reason,
const std::string &custom_reason = "", bool reconnect = false); std::string_view custom_reason = "", bool reconnect = false);
void kickAllPlayers(AccessDeniedCode reason, void kickAllPlayers(AccessDeniedCode reason,
const std::string &str_reason, bool reconnect); const std::string &str_reason, bool reconnect);
void acceptAuth(session_t peer_id, bool forSudoMode); void acceptAuth(session_t peer_id, bool forSudoMode);
@ -485,7 +485,7 @@ private:
void SendHP(session_t peer_id, u16 hp, bool effect); void SendHP(session_t peer_id, u16 hp, bool effect);
void SendBreath(session_t peer_id, u16 breath); void SendBreath(session_t peer_id, u16 breath);
void SendAccessDenied(session_t peer_id, AccessDeniedCode reason, void SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
const std::string &custom_reason, bool reconnect = false); std::string_view custom_reason, bool reconnect = false);
void SendDeathscreen(session_t peer_id, bool set_camera_point_target, void SendDeathscreen(session_t peer_id, bool set_camera_point_target,
v3f camera_point_target); v3f camera_point_target);
void SendItemDef(session_t peer_id, IItemDefManager *itemdef, u16 protocol_version); void SendItemDef(session_t peer_id, IItemDefManager *itemdef, u16 protocol_version);