Skip to content

Commit 857a49e

Browse files
sapierShadowNinja
sapier
authored andcommittedFeb 3, 2014
Add minetest.kick_player(name, reason)
1 parent ea0def3 commit 857a49e

File tree

6 files changed

+67
-17
lines changed

6 files changed

+67
-17
lines changed
 

‎builtin/chatcommands.lua

+20-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ minetest.register_chatcommand("grant", {
107107
description = "Give privilege to player",
108108
privs = {},
109109
func = function(name, param)
110-
if not minetest.check_player_privs(name, {privs=true}) and
110+
if not minetest.check_player_privs(name, {privs=true}) and
111111
not minetest.check_player_privs(name, {basic_privs=true}) then
112112
minetest.chat_send_player(name, "Your privileges are insufficient.")
113113
return
@@ -153,7 +153,7 @@ minetest.register_chatcommand("revoke", {
153153
description = "Remove privilege from player",
154154
privs = {},
155155
func = function(name, param)
156-
if not minetest.check_player_privs(name, {privs=true}) and
156+
if not minetest.check_player_privs(name, {privs=true}) and
157157
not minetest.check_player_privs(name, {basic_privs=true}) then
158158
minetest.chat_send_player(name, "Your privileges are insufficient.")
159159
return
@@ -670,6 +670,24 @@ minetest.register_chatcommand("unban", {
670670
end,
671671
})
672672

673+
minetest.register_chatcommand("kick", {
674+
params = "<name> [reason]",
675+
description = "kick a player",
676+
privs = {kick=true},
677+
func = function(name, param)
678+
local tokick, reason = string.match(param, "([^ ]+) (.+)")
679+
if not tokick then
680+
tokick = param
681+
end
682+
if not minetest.kick_player(tokick, reason) then
683+
minetest.chat_send_player(name, "Failed to kick player " .. tokick)
684+
else
685+
minetest.chat_send_player(name, "kicked " .. tokick)
686+
minetest.log("action", name .. " kicked " .. tokick)
687+
end
688+
end,
689+
})
690+
673691
minetest.register_chatcommand("clearobjects", {
674692
params = "",
675693
description = "clear all objects in world",

‎builtin/privileges.lua

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ minetest.register_privilege("basic_privs", "Can modify 'shout' and 'interact' pr
3434
minetest.register_privilege("server", "Can do server maintenance stuff")
3535
minetest.register_privilege("shout", "Can speak in chat")
3636
minetest.register_privilege("ban", "Can ban and unban players")
37+
minetest.register_privilege("kick", "Can kick players")
3738
minetest.register_privilege("give", "Can use /give and /giveme")
3839
minetest.register_privilege("password", "Can use /setpassword and /clearpassword")
3940
minetest.register_privilege("fly", {

‎doc/lua_api.txt

+15-14
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ All default ores are of the uniformly-distributed scatter type.
393393

394394
- scatter
395395
Randomly chooses a location and generates a cluster of ore.
396-
If noise_params is specified, the ore will be placed if the 3d perlin noise at
396+
If noise_params is specified, the ore will be placed if the 3d perlin noise at
397397
that point is greater than the noise_threshhold, giving the ability to create a non-equal
398398
distribution of ore.
399399
- sheet
@@ -439,7 +439,7 @@ or through raw data supplied through Lua, in the form of a table. This table mu
439439
- The 'data' field is a flat table of MapNodes making up the schematic, in the order of [z [y [x]]].
440440
Important: The default value for param1 in MapNodes here is 255, which represents "always place".
441441

442-
In the bulk MapNode data, param1, instead of the typical light values, instead represents the
442+
In the bulk MapNode data, param1, instead of the typical light values, instead represents the
443443
probability of that node appearing in the structure.
444444
When passed to minetest.create_schematic, probability is an integer value ranging from 0 to 255:
445445
- A probability value of 0 means that node will never appear (0% chance).
@@ -542,7 +542,7 @@ eg. 'default:pick_wood 21323'
542542
eg. 'default:apple'
543543

544544
Table format:
545-
eg. {name="default:dirt", count=5, wear=0, metadata=""}
545+
eg. {name="default:dirt", count=5, wear=0, metadata=""}
546546
^ 5 dirt nodes
547547
eg. {name="default:pick_wood", count=1, wear=21323, metadata=""}
548548
^ a wooden pick about 1/3 weared out
@@ -1102,7 +1102,7 @@ tablecolumns[<type 1>,<opt 1a>,<opt 1b>,...;<type 2>,<opt 2a>,<opt 2b>;...]
11021102
^^ span=<value> number of following columns to affect (default infinite)
11031103

11041104
Note: do NOT use a element name starting with "key_" those names are reserved to
1105-
pass key press events to formspec!
1105+
pass key press events to formspec!
11061106

11071107
Inventory location:
11081108

@@ -1458,7 +1458,7 @@ minetest.get_all_craft_recipes(query item) -> table or nil
14581458
^ returns indexed table with all registered recipes for query item (node)
14591459
or nil if no recipe was found
14601460
recipe entry table:
1461-
{
1461+
{
14621462
method = 'normal' or 'cooking' or 'fuel'
14631463
width = 0-3, 0 means shapeless recipe
14641464
items = indexed [1-9] table with recipe items
@@ -1532,6 +1532,7 @@ minetest.get_ban_list() -> ban list (same as minetest.get_ban_description(""))
15321532
minetest.get_ban_description(ip_or_name) -> ban description (string)
15331533
minetest.ban_player(name) -> ban a player
15341534
minetest.unban_player_or_ip(name) -> unban player or IP address
1535+
minetest.kick_player(name, [reason]) -> disconnect a player with a optional reason
15351536

15361537
Particles:
15371538
minetest.add_particle(particle definition)
@@ -1918,7 +1919,7 @@ methods:
19181919
^ returns raw node data is in the form of an array of node content ids
19191920
- set_data(data): Sets the data contents of the VoxelManip object
19201921
- update_map(): Update map after writing chunk back to map.
1921-
^ To be used only by VoxelManip objects created by the mod itself; not a VoxelManip that was
1922+
^ To be used only by VoxelManip objects created by the mod itself; not a VoxelManip that was
19221923
^ retrieved from minetest.get_mapgen_object
19231924
- set_lighting(light, p1, p2): Set the lighting within the VoxelManip to a uniform value
19241925
^ light is a table, {day=<0...15>, night=<0...15>}
@@ -1968,31 +1969,31 @@ methods:
19681969

19691970
Mapgen objects
19701971
---------------
1971-
A mapgen object is a construct used in map generation. Mapgen objects can be used by an on_generate
1972-
callback to speed up operations by avoiding unnecessary recalculations; these can be retrieved using the
1973-
minetest.get_mapgen_object() function. If the requested Mapgen object is unavailable, or
1972+
A mapgen object is a construct used in map generation. Mapgen objects can be used by an on_generate
1973+
callback to speed up operations by avoiding unnecessary recalculations; these can be retrieved using the
1974+
minetest.get_mapgen_object() function. If the requested Mapgen object is unavailable, or
19741975
get_mapgen_object() was called outside of an on_generate() callback, nil is returned.
19751976

19761977
The following Mapgen objects are currently available:
19771978

19781979
- voxelmanip
1979-
This returns three values; the VoxelManip object to be used, minimum and maximum emerged position, in that
1980+
This returns three values; the VoxelManip object to be used, minimum and maximum emerged position, in that
19801981
order. All mapgens support this object.
19811982

19821983
- heightmap
1983-
Returns an array containing the y coordinates of the ground levels of nodes in the most recently
1984+
Returns an array containing the y coordinates of the ground levels of nodes in the most recently
19841985
generated chunk by the current mapgen.
19851986

19861987
- biomemap
1987-
Returns an array containing the biome IDs of nodes in the most recently generated chunk by the
1988+
Returns an array containing the biome IDs of nodes in the most recently generated chunk by the
19881989
current mapgen.
19891990

19901991
- heatmap
1991-
Returns an array containing the temperature values of nodes in the most recently generated chunk by
1992+
Returns an array containing the temperature values of nodes in the most recently generated chunk by
19921993
the current mapgen.
19931994

19941995
- humiditymap
1995-
Returns an array containing the humidity values of nodes in the most recently generated chunk by the
1996+
Returns an array containing the humidity values of nodes in the most recently generated chunk by the
19961997
current mapgen.
19971998

19981999
- gennotify

‎src/script/lua_api/l_server.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,31 @@ int ModApiServer::l_ban_player(lua_State *L)
160160
return 1;
161161
}
162162

163+
// kick_player(name, [reason]) -> success
164+
int ModApiServer::l_kick_player(lua_State *L)
165+
{
166+
NO_MAP_LOCK_REQUIRED;
167+
const char *name = luaL_checkstring(L, 1);
168+
std::string message;
169+
if (lua_isstring(L, 2))
170+
{
171+
message = std::string("Kicked: ") + lua_tostring(L, 2);
172+
}
173+
else
174+
{
175+
message = "Kicked.";
176+
}
177+
Player *player = getEnv(L)->getPlayer(name);
178+
if (player == NULL)
179+
{
180+
lua_pushboolean(L, false); // No such player
181+
return 1;
182+
}
183+
getServer(L)->DenyAccess(player->peer_id, narrow_to_wide(message));
184+
lua_pushboolean(L, true);
185+
return 1;
186+
}
187+
163188
// unban_player_or_ip()
164189
int ModApiServer::l_unban_player_or_ip(lua_State *L)
165190
{
@@ -327,6 +352,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
327352
API_FCT(get_ban_list);
328353
API_FCT(get_ban_description);
329354
API_FCT(ban_player);
355+
API_FCT(kick_player);
330356
API_FCT(unban_player_or_ip);
331357
API_FCT(notify_authentication_modified);
332358
}

‎src/script/lua_api/l_server.h

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class ModApiServer : public ModApiBase {
7979
// unban_player_or_ip()
8080
static int l_unban_player_or_ip(lua_State *L);
8181

82+
// kick_player(name, [message]) -> success
83+
static int l_kick_player(lua_State *L);
84+
8285
// notify_authentication_modified(name)
8386
static int l_notify_authentication_modified(lua_State *L);
8487

‎src/server.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
330330
void peerAdded(con::Peer *peer);
331331
void deletingPeer(con::Peer *peer, bool timeout);
332332

333+
void DenyAccess(u16 peer_id, const std::wstring &reason);
334+
333335
private:
334336

335337
friend class EmergeThread;
@@ -415,7 +417,6 @@ class Server : public con::PeerHandler, public MapEventReceiver,
415417

416418
void DiePlayer(u16 peer_id);
417419
void RespawnPlayer(u16 peer_id);
418-
void DenyAccess(u16 peer_id, const std::wstring &reason);
419420
void DeleteClient(u16 peer_id, ClientDeletionReason reason);
420421
void UpdateCrafting(u16 peer_id);
421422

0 commit comments

Comments
 (0)
Please sign in to comment.