Skip to content

Commit 413be76

Browse files
IceDragon200rubenwardy
andauthoredNov 26, 2021
Implemented disconnect_player (#10492)
Co-authored-by: rubenwardy <rw@rubenwardy.com>
1 parent c85aa00 commit 413be76

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed
 

‎builtin/game/misc.lua

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ local S = core.get_translator("__builtin")
66
-- Misc. API functions
77
--
88

9+
-- @spec core.kick_player(String, String) :: Boolean
10+
function core.kick_player(player_name, reason)
11+
if type(reason) == "string" then
12+
reason = "Kicked: " .. reason
13+
else
14+
reason = "Kicked."
15+
end
16+
return core.disconnect_player(player_name, reason)
17+
end
18+
919
function core.check_player_privs(name, ...)
1020
if core.is_player(name) then
1121
name = name:get_player_name()

‎doc/lua_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -5741,6 +5741,10 @@ Bans
57415741
* `minetest.kick_player(name, [reason])`: disconnect a player with an optional
57425742
reason.
57435743
* Returns boolean indicating success (false if player nonexistant)
5744+
* `minetest.disconnect_player(name, [reason])`: disconnect a player with an
5745+
optional reason, this will not prefix with 'Kicked: ' like kick_player.
5746+
If no reason is given, it will default to 'Disconnected.'
5747+
* Returns boolean indicating success (false if player nonexistant)
57445748

57455749
Particles
57465750
---------

‎src/script/lua_api/l_server.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,20 @@ int ModApiServer::l_ban_player(lua_State *L)
310310
return 1;
311311
}
312312

313-
// kick_player(name, [reason]) -> success
314-
int ModApiServer::l_kick_player(lua_State *L)
313+
// disconnect_player(name, [reason]) -> success
314+
int ModApiServer::l_disconnect_player(lua_State *L)
315315
{
316316
NO_MAP_LOCK_REQUIRED;
317317

318318
if (!getEnv(L))
319319
throw LuaError("Can't kick player before server has started up");
320320

321321
const char *name = luaL_checkstring(L, 1);
322-
std::string message("Kicked");
322+
std::string message;
323323
if (lua_isstring(L, 2))
324-
message.append(": ").append(readParam<std::string>(L, 2));
324+
message.append(readParam<std::string>(L, 2));
325325
else
326-
message.append(".");
326+
message.append("Disconnected.");
327327

328328
RemotePlayer *player = dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name);
329329
if (player == NULL) {
@@ -554,7 +554,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
554554
API_FCT(get_ban_list);
555555
API_FCT(get_ban_description);
556556
API_FCT(ban_player);
557-
API_FCT(kick_player);
557+
API_FCT(disconnect_player);
558558
API_FCT(remove_player);
559559
API_FCT(unban_player_or_ip);
560560
API_FCT(notify_authentication_modified);

‎src/script/lua_api/l_server.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class ModApiServer : public ModApiBase
9797
// unban_player_or_ip()
9898
static int l_unban_player_or_ip(lua_State *L);
9999

100-
// kick_player(name, [message]) -> success
101-
static int l_kick_player(lua_State *L);
100+
// disconnect_player(name, [reason]) -> success
101+
static int l_disconnect_player(lua_State *L);
102102

103103
// remove_player(name)
104104
static int l_remove_player(lua_State *L);

0 commit comments

Comments
 (0)