mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
Add ban management routines to Lua API
Those functions are: * minetest.get_ban_list() * minetest.get_ban_description(ip_or_name) * minetest.ban_player(name) * minetest.unban_player_or_ip(ip_or_name)
This commit is contained in:
parent
548da26ddc
commit
8a3c777c40
@ -932,6 +932,12 @@ Server:
|
||||
minetest.request_shutdown() -> request for server shutdown
|
||||
minetest.get_server_status() -> server status string
|
||||
|
||||
Bans:
|
||||
minetest.get_ban_list() -> ban list (same as minetest.get_ban_description(""))
|
||||
minetest.get_ban_description(ip_or_name) -> ban description (string)
|
||||
minetest.ban_player(name) -> ban a player
|
||||
minetest.unban_player_or_ip(name) -> unban player or IP address
|
||||
|
||||
Random:
|
||||
minetest.get_connected_players() -> list of ObjectRefs
|
||||
minetest.hash_node_position({x=,y=,z=}) -> 48-bit integer
|
||||
|
@ -4584,6 +4584,56 @@ static int l_get_player_privs(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get_ban_list()
|
||||
static int l_get_ban_list(lua_State *L)
|
||||
{
|
||||
lua_pushstring(L, get_server(L)->getBanDescription("").c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get_ban_description()
|
||||
static int l_get_ban_description(lua_State *L)
|
||||
{
|
||||
const char * ip_or_name = luaL_checkstring(L, 1);
|
||||
lua_pushstring(L, get_server(L)->getBanDescription(std::string(ip_or_name)).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ban_player()
|
||||
static int l_ban_player(lua_State *L)
|
||||
{
|
||||
const char * name = luaL_checkstring(L, 1);
|
||||
Player *player = get_env(L)->getPlayer(name);
|
||||
if(player == NULL)
|
||||
{
|
||||
lua_pushboolean(L, false); // no such player
|
||||
return 1;
|
||||
}
|
||||
try
|
||||
{
|
||||
Address addr = get_server(L)->getPeerAddress(get_env(L)->getPlayer(name)->peer_id);
|
||||
std::string ip_str = addr.serializeString();
|
||||
get_server(L)->setIpBanned(ip_str, name);
|
||||
}
|
||||
catch(con::PeerNotFoundException) // unlikely
|
||||
{
|
||||
dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
|
||||
lua_pushboolean(L, false); // error
|
||||
return 1;
|
||||
}
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// unban_player_or_ip()
|
||||
static int l_unban_player_of_ip(lua_State *L)
|
||||
{
|
||||
const char * ip_or_name = luaL_checkstring(L, 1);
|
||||
get_server(L)->unsetIpBanned(ip_or_name);
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get_inventory(location)
|
||||
static int l_get_inventory(lua_State *L)
|
||||
{
|
||||
@ -4946,6 +4996,10 @@ static const struct luaL_Reg minetest_f [] = {
|
||||
{"chat_send_all", l_chat_send_all},
|
||||
{"chat_send_player", l_chat_send_player},
|
||||
{"get_player_privs", l_get_player_privs},
|
||||
{"get_ban_list", l_get_ban_list},
|
||||
{"get_ban_description", l_get_ban_description},
|
||||
{"ban_player", l_ban_player},
|
||||
{"unban_player_or_ip", l_unban_player_of_ip},
|
||||
{"get_inventory", l_get_inventory},
|
||||
{"create_detached_inventory_raw", l_create_detached_inventory_raw},
|
||||
{"get_dig_params", l_get_dig_params},
|
||||
|
Loading…
Reference in New Issue
Block a user