mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
Update screwdriver and xban
- Suppression de xban premier du nom, xban2 prend le relai, - Supression de screwdriver(base_game) - Ajout de Screwdriver(redo)
This commit is contained in:
parent
51b43de231
commit
bd3d29e8d8
136
minetestforfun_game/mods/screwdriver/init.lua
Executable file → Normal file
136
minetestforfun_game/mods/screwdriver/init.lua
Executable file → Normal file
@ -1,52 +1,3 @@
|
||||
|
||||
local mode_text = {
|
||||
{"Change rotation, Don't change axisdir."},
|
||||
{"Keep choosen face in front then rotate it."},
|
||||
{"Change axis dir, Reset rotation."},
|
||||
{"Bring top in front then rotate it."},
|
||||
}
|
||||
|
||||
local opposite_faces = {
|
||||
[0] = 5,
|
||||
[1] = 2,
|
||||
[2] = 1,
|
||||
[3] = 4,
|
||||
[4] = 3,
|
||||
[5] = 0,
|
||||
}
|
||||
|
||||
local function screwdriver_setmode(user,itemstack)
|
||||
local player_name = user:get_player_name()
|
||||
local item = itemstack:to_table()
|
||||
local mode = tonumber(itemstack:get_metadata())
|
||||
if not mode then
|
||||
minetest.chat_send_player(player_name, "Use while sneaking to change screwdriwer modes.")
|
||||
mode = 0
|
||||
end
|
||||
mode = mode + 1
|
||||
if mode == 5 then
|
||||
mode = 1
|
||||
end
|
||||
minetest.chat_send_player(player_name, "Screwdriver mode : "..mode.." - "..mode_text[mode][1] )
|
||||
itemstack:set_name("screwdriver:screwdriver"..mode)
|
||||
itemstack:set_metadata(mode)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local function get_node_face(pointed_thing)
|
||||
local ax, ay, az = pointed_thing.above.x, pointed_thing.above.y, pointed_thing.above.z
|
||||
local ux, uy, uz = pointed_thing.under.x, pointed_thing.under.y, pointed_thing.under.z
|
||||
if ay > uy then return 0 -- Top
|
||||
elseif az > uz then return 1 -- Z+ side
|
||||
elseif az < uz then return 2 -- Z- side
|
||||
elseif ax > ux then return 3 -- X+ side
|
||||
elseif ax < ux then return 4 -- X- side
|
||||
elseif ay < uy then return 5 -- Bottom
|
||||
else
|
||||
error("pointed_thing.above and under are the same!")
|
||||
end
|
||||
end
|
||||
|
||||
local function nextrange(x, max)
|
||||
x = x + 1
|
||||
if x > max then
|
||||
@ -55,21 +6,21 @@ local function nextrange(x, max)
|
||||
return x
|
||||
end
|
||||
|
||||
local function screwdriver_handler(itemstack, user, pointed_thing)
|
||||
-- Handles rotation
|
||||
local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = pointed_thing.under
|
||||
local keys = user:get_player_control()
|
||||
local player_name = user:get_player_name()
|
||||
local mode = tonumber(itemstack:get_metadata())
|
||||
if not mode or keys["sneak"] == true then
|
||||
return screwdriver_setmode(user, itemstack)
|
||||
end
|
||||
|
||||
if minetest.is_protected(pos, user:get_player_name()) then
|
||||
minetest.record_protection_violation(pos, user:get_player_name())
|
||||
return
|
||||
end
|
||||
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
if not ndef or not ndef.paramtype2 == "facedir" or
|
||||
@ -78,47 +29,22 @@ local function screwdriver_handler(itemstack, user, pointed_thing)
|
||||
node.param2 == nil then
|
||||
return
|
||||
end
|
||||
-- Get ready to set the param2
|
||||
|
||||
-- Set param2
|
||||
local n = node.param2
|
||||
local axisdir = math.floor(n / 4)
|
||||
local rotation = n - axisdir * 4
|
||||
if mode == 1 then
|
||||
n = axisdir * 4 + nextrange(rotation, 3)
|
||||
elseif mode == 2 then
|
||||
-- If you are pointing at the axisdir face or the
|
||||
-- opposite one then you can just rotate the node.
|
||||
-- Otherwise change the axisdir, avoiding the facing
|
||||
-- and opposite axes.
|
||||
local face = get_node_face(pointed_thing)
|
||||
if axisdir == face or axisdir == opposite_faces[face] then
|
||||
n = axisdir * 4 + nextrange(rotation, 3)
|
||||
else
|
||||
axisdir = nextrange(axisdir, 5)
|
||||
-- This is repeated because switching from the face
|
||||
-- can move to to the opposite and vice-versa
|
||||
if axisdir == face or axisdir == opposite_faces[face] then
|
||||
axisdir = nextrange(axisdir, 5)
|
||||
end
|
||||
if axisdir == face or axisdir == opposite_faces[face] then
|
||||
axisdir = nextrange(axisdir, 5)
|
||||
end
|
||||
n = axisdir * 4
|
||||
end
|
||||
elseif mode == 3 then
|
||||
n = nextrange(axisdir, 5) * 4
|
||||
elseif mode == 4 then
|
||||
local face = get_node_face(pointed_thing)
|
||||
if axisdir == face then
|
||||
n = axisdir * 4 + nextrange(rotation, 3)
|
||||
else
|
||||
n = face * 4
|
||||
end
|
||||
end
|
||||
--print (dump(axisdir..", "..rotation))
|
||||
|
||||
node.param2 = n
|
||||
minetest.swap_node(pos, node)
|
||||
|
||||
local item_wear = tonumber(itemstack:get_wear())
|
||||
item_wear = item_wear + 327
|
||||
item_wear = item_wear + 300 -- was 327
|
||||
if item_wear > 65535 then
|
||||
itemstack:clear()
|
||||
return itemstack
|
||||
@ -127,6 +53,21 @@ local function screwdriver_handler(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Screwdriver
|
||||
minetest.register_tool("screwdriver:screwdriver", {
|
||||
description = "Screwdriver (left-click rotates face, right-click rotates axis)",
|
||||
inventory_image = "screwdriver.png",
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
screwdriver_handler(itemstack, user, pointed_thing, 1)
|
||||
return itemstack
|
||||
end,
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
screwdriver_handler(itemstack, user, pointed_thing, 3)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "screwdriver:screwdriver",
|
||||
recipe = {
|
||||
@ -135,25 +76,8 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_tool("screwdriver:screwdriver", {
|
||||
description = "Screwdriver",
|
||||
inventory_image = "screwdriver.png",
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
screwdriver_handler(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
for i = 1, 4 do
|
||||
minetest.register_tool("screwdriver:screwdriver"..i, {
|
||||
description = "Screwdriver in Mode "..i,
|
||||
inventory_image = "screwdriver.png^tool_mode"..i..".png",
|
||||
wield_image = "screwdriver.png",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
screwdriver_handler(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
-- Compatibility with original mod
|
||||
minetest.register_alias("screwdriver:screwdriver1", "screwdriver:screwdriver")
|
||||
minetest.register_alias("screwdriver:screwdriver2", "screwdriver:screwdriver")
|
||||
minetest.register_alias("screwdriver:screwdriver3", "screwdriver:screwdriver")
|
||||
minetest.register_alias("screwdriver:screwdriver4", "screwdriver:screwdriver")
|
||||
|
3
minetestforfun_game/mods/screwdriver/readme.txt
Executable file → Normal file
3
minetestforfun_game/mods/screwdriver/readme.txt
Executable file → Normal file
@ -1,5 +1,6 @@
|
||||
Minetest mod: screwdriver
|
||||
=========================
|
||||
Edited by TenPlus1 on 2nd Sep 2014
|
||||
==================================
|
||||
|
||||
License of source code:
|
||||
-----------------------
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 769 B |
Binary file not shown.
Before Width: | Height: | Size: 211 B |
Binary file not shown.
Before Width: | Height: | Size: 360 B |
Binary file not shown.
Before Width: | Height: | Size: 367 B |
Binary file not shown.
Before Width: | Height: | Size: 268 B |
@ -1,25 +0,0 @@
|
||||
|
||||
Copyright (c) 2013, Diego Martínez
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
@ -1,115 +0,0 @@
|
||||
|
||||
Extended Ban Mod for Minetest
|
||||
-----------------------------
|
||||
|
||||
This mod registers all the IPs used by individual players, and can ban the
|
||||
player when using any of them, even if he is not online at the moment.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
See file 'LICENSE.txt'.
|
||||
|
||||
Chat Commands
|
||||
-------------
|
||||
|
||||
/xban <player> [<reason>]
|
||||
Ban given player and all his IPs. If reason not given, it defaults to
|
||||
"because random". If player is online at the moment, he/she is shown it. If
|
||||
user is not online, it saves it in a list, and next time he connects from any
|
||||
IP, or connects from a banned IP with different name, it gets banned again,
|
||||
and new IP/username recorded.
|
||||
|
||||
/xtempban <player> <time> [<reason>]
|
||||
Same as /xban, except it specifies a temporary ban.
|
||||
<time> must be prefixed by a colon (':'), and can be in any of the
|
||||
following formats:
|
||||
123m - Ban for 123 minutes.
|
||||
12h - Ban for 12 hours.
|
||||
1d - Ban for 1 day.
|
||||
1W - Ban for 1 week.
|
||||
1M - Ban for 1 month (30 days).
|
||||
If not specified, the ban is permanent and must be manually removed.
|
||||
|
||||
/xunban <player>
|
||||
Unban given player and all his IPs.
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The following options can be used to change the behavior of `xban'. They
|
||||
must be set in your server's `minetest.conf'.
|
||||
|
||||
xban.kick_guests = <bool>
|
||||
Whether to kick "Guest" users (automatically generated player names).
|
||||
Default is false.
|
||||
|
||||
xban.ban_message = <string>
|
||||
The default ban message when not specified.
|
||||
Default is "Because random.".
|
||||
|
||||
xban.guest_kick_message = <string>
|
||||
Message sent before kicking guests. Not applicable if the option
|
||||
`xban.kick_guests' is false.
|
||||
Default is "Guest accounts are not allowed. Please choose a proper name.".
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
Other mods can make use of xban functionality if desired. You just need
|
||||
to (opt)depend on xban.
|
||||
|
||||
xban.ban_player(name, time, reason)
|
||||
|
||||
Bans a given player <name> for <time> seconds with specified <reason>.
|
||||
If <time> is nil, it acts as a permanent ban.
|
||||
If <reason> is nil, the default reason "because random" is used.
|
||||
|
||||
xban.unban_player(name)
|
||||
--> (true) or (nil, error)
|
||||
|
||||
Removes a player from the ban list.
|
||||
Returns true on success, or nil plus error message on error.
|
||||
|
||||
xban.find_entry(name_or_ip)
|
||||
--> (entry, index) or (nil)
|
||||
|
||||
Returns the database entry for the given player or IP. Please note that a
|
||||
single entry is shared by several IPs and several user names at the same
|
||||
time. See below for the format of entries. Also note that the table is not
|
||||
copied, so modifications will be saved to disk.
|
||||
|
||||
xban.entries
|
||||
|
||||
This is the list of entries in the database. See below for format.
|
||||
|
||||
Files
|
||||
-----
|
||||
|
||||
This mod only modifies a single file named 'players.iplist.v2' in the world
|
||||
directory (and indirectly, 'ipban.txt'). The format is a serialized Lua table.
|
||||
|
||||
Each item in the table is in the following format:
|
||||
|
||||
{
|
||||
names = {
|
||||
["foo"] = true, -- To ban by name.
|
||||
["123.45.67.89"] = true, -- To ban by IP.
|
||||
...
|
||||
},
|
||||
banned = "Because random.", -- If nil, user is not banned.
|
||||
expires = 123456, -- In time_t. If nil, user is permabanned.
|
||||
privs = { ... }, -- Player privileges before the ban.
|
||||
record = { -- Record of previous bans.
|
||||
{
|
||||
date = 123456, -- Date when the ban was issued.
|
||||
time = 4123, -- Ban time. This is nil if permabanned.
|
||||
reason = "asdf", -- Duh.
|
||||
},
|
||||
...
|
||||
},
|
||||
}
|
||||
|
||||
The old `players.iplist' DB format is still read at startup, and converted
|
||||
to the new format. In this case, `banned' is set to the default ban reason,
|
||||
and `expires' is unset.
|
@ -1,94 +0,0 @@
|
||||
|
||||
-- Extended Ban Mod for Minetest
|
||||
-- (C) 2013 Diego Martínez <kaeza>
|
||||
-- See `LICENSE.txt' for details.
|
||||
|
||||
-- chat.lua: Chat commands.
|
||||
|
||||
minetest.register_chatcommand("ban", {
|
||||
params = "<player> [reason]",
|
||||
description = "Ban all IPs for a given player",
|
||||
privs = { ban=true, },
|
||||
func = function(name, param)
|
||||
param = param:trim()
|
||||
local player_name, reason = param:match("([^ ]+)( *.*)")
|
||||
if not player_name then
|
||||
xban._.send(name, "Usage: /ban <player> [reason]")
|
||||
return
|
||||
end
|
||||
reason = reason:trim()
|
||||
xban._.ACTION("%s bans %s. Reason: %s", name, player_name, reason)
|
||||
if reason == "" then reason = nil end
|
||||
local r, e = xban.ban_player(player_name, nil, reason)
|
||||
if r then
|
||||
xban._.send(name, "Banning %s.", player_name)
|
||||
else
|
||||
xban._.send(name, "ERROR: %s.", e)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local mul = { [""]=1, s=1, m=60, h=3600, H=3600, d=3600*24, D=86400, w=86400*7, W=86400*7, M=86400*30 }
|
||||
|
||||
local function parse_time(t)
|
||||
local total = 0
|
||||
for count, suffix in t:gmatch("(%d+)([mhHdDwWM]?)") do
|
||||
count = count and tonumber(count)
|
||||
if count and suffix then
|
||||
total = (total or 0) + (count * mul[suffix])
|
||||
end
|
||||
end
|
||||
if total then return total end
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("tempban", {
|
||||
params = "<player> <time> [<reason>]",
|
||||
description = "Future ban all IPs for a given player, temporarily",
|
||||
privs = { ban=true, },
|
||||
func = function(name, param)
|
||||
param = param:trim()
|
||||
local player_name, time, reason = param:match("([^ ]+) *([^ ]+)( *.*)")
|
||||
if not (player_name and time) then
|
||||
xban._.send(name, "Usage: /tempban <player> <time> [<reason>]")
|
||||
return
|
||||
end
|
||||
time = parse_time(time)
|
||||
if not time then
|
||||
xban._.send(name, "Invalid time format. Syntax is: [0-9]+[mhdWM] with no space between the number and the time unit. A month is 30 days.")
|
||||
return
|
||||
elseif time < 60 then
|
||||
xban._.send(name, "Ban time must be at least 60 seconds.")
|
||||
return
|
||||
end
|
||||
reason = reason:trim()
|
||||
xban._.ACTION("%s bans %s for %d seconds. Reason: %s.",
|
||||
name, player_name, time, reason
|
||||
)
|
||||
if reason == "" then reason = nil end
|
||||
local r, e = xban.ban_player(player_name, time, reason)
|
||||
if r then
|
||||
xban._.send(name, "Banning %s for %d seconds.", player_name, time)
|
||||
else
|
||||
xban._.send(name, "ERROR: %s", e)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("unban", {
|
||||
params = "<player>",
|
||||
description = "Unban all IPs for a given player",
|
||||
privs = { ban=true, },
|
||||
func = function(name, param)
|
||||
param = param:trim()
|
||||
if param == "" then
|
||||
xban._.send(name, "Usage: /unban <player>")
|
||||
return
|
||||
end
|
||||
local r, e = xban.unban_player(param)
|
||||
if r then
|
||||
xban._.send(name, "Unbanning %s.", param)
|
||||
else
|
||||
xban._.send(name, "ERROR: %s.", e)
|
||||
end
|
||||
end,
|
||||
})
|
@ -1,26 +0,0 @@
|
||||
|
||||
-- Extended Ban Mod for Minetest
|
||||
-- (C) 2013 Diego Martínez <kaeza>
|
||||
-- See `LICENSE.txt' for details.
|
||||
|
||||
-- conf.lua: Config routines.
|
||||
|
||||
xban.conf = { }
|
||||
|
||||
local conf = Settings(minetest.get_worldpath().."/xban.conf")
|
||||
|
||||
function xban.conf.get(k)
|
||||
local v
|
||||
v = conf:get(k)
|
||||
if v and (v ~= "") then return v end
|
||||
v = minetest.setting_get("xban."..k)
|
||||
if v and (v ~= "") then return v end
|
||||
end
|
||||
|
||||
function xban.conf.get_bool(k)
|
||||
local v
|
||||
v = conf:get(k)
|
||||
if v and (v ~= "") then return conf:get_bool(k) end
|
||||
v = minetest.setting_get("xban."..k)
|
||||
if v and (v ~= "") then return minetest.setting_getbool("xban."..k) end
|
||||
end
|
@ -1,20 +0,0 @@
|
||||
|
||||
-- Extended Ban Mod for Minetest
|
||||
-- (C) 2013 Diego Martínez <kaeza>
|
||||
-- See `LICENSE.txt' for details.
|
||||
|
||||
-- init.lua: Initialization script.
|
||||
|
||||
xban = { }
|
||||
xban._ = { } -- Internal functions.
|
||||
|
||||
local MP = minetest.get_modpath("xban")
|
||||
|
||||
dofile(MP.."/conf.lua")
|
||||
dofile(MP.."/intr.lua")
|
||||
dofile(MP.."/xban.lua")
|
||||
dofile(MP.."/chat.lua")
|
||||
|
||||
if minetest.setting_getbool("log_mods") then
|
||||
minetest.log("action", "Carbone: [xban] loaded.")
|
||||
end
|
@ -1,20 +0,0 @@
|
||||
|
||||
-- Extended Ban Mod for Minetest
|
||||
-- (C) 2013 Diego Martínez <kaeza>
|
||||
-- See `LICENSE.txt' for details.
|
||||
|
||||
-- intr.lua: Internal functions.
|
||||
|
||||
-- NOTE: Do not use these from other mods; they may change without notice.
|
||||
|
||||
local function mklogger(type)
|
||||
return function(fmt, ...) minetest.log(type, fmt:format(...)) end
|
||||
end
|
||||
|
||||
xban._.INFO = mklogger("info")
|
||||
xban._.WARN = mklogger("warning")
|
||||
xban._.ACTION = mklogger("action")
|
||||
|
||||
function xban._.send(name, fmt, ...)
|
||||
minetest.chat_send_player(name, (fmt:format(...)))
|
||||
end
|
@ -1,13 +0,0 @@
|
||||
|
||||
#
|
||||
# Sample configuration file for xban mod.
|
||||
#
|
||||
|
||||
# Whether guest accounts are disallowed.
|
||||
#kick_guests = false
|
||||
|
||||
# Default ban message.
|
||||
#ban_message = Because random.
|
||||
|
||||
# Default kick message for guests.
|
||||
#guest_kick_message = Guest accounts are not allowed in this server. Please choose a proper username and try again in a few minutes.
|
@ -1,110 +0,0 @@
|
||||
|
||||
-- Extended Ban Mod for Minetest
|
||||
-- (C) 2013 Diego Martínez <kaeza>
|
||||
-- See `LICENSE.txt' for details.
|
||||
|
||||
-- xban.lua: Core functions.
|
||||
|
||||
local DEF_BAN_MESSAGE = (xban.conf.get("ban_message")
|
||||
or "(no reason given)")
|
||||
|
||||
local DB_FILE = minetest.get_worldpath().."/players.iplist"
|
||||
|
||||
local unpack = unpack or table.unpack
|
||||
|
||||
local iplist = { }
|
||||
|
||||
local function get_ip(name)
|
||||
if minetest.get_player_by_name(name) then
|
||||
return minetest.get_player_ip(name)
|
||||
end
|
||||
end
|
||||
|
||||
function xban.find_entry(name_or_ip, create)
|
||||
|
||||
for index, data in ipairs(iplist) do
|
||||
for k, v in pairs(data.names) do
|
||||
if v and (k == name_or_ip) then
|
||||
return data, index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if create then
|
||||
local data = { names={} }
|
||||
table.insert(iplist, data)
|
||||
return data
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local function load_db()
|
||||
local f = io.open(DB_FILE, "r")
|
||||
if not f then return end
|
||||
xban._.INFO("Loading IP database...")
|
||||
local db = minetest.deserialize(f:read("*a"))
|
||||
f:close()
|
||||
iplist = db
|
||||
xban._.INFO("IP database loaded.")
|
||||
end
|
||||
|
||||
function xban.save_db()
|
||||
local f, e = io.open(DB_FILE, "w")
|
||||
if not f then
|
||||
xban._.WARN("Error saving IP database: %s.", (e or ""))
|
||||
return
|
||||
end
|
||||
xban._.INFO("Saving IP database...")
|
||||
f:write(minetest.serialize(iplist))
|
||||
f:close()
|
||||
xban._.INFO("IP database saved.")
|
||||
end
|
||||
|
||||
function xban.ban_player(name, time, reason)
|
||||
local data = xban.find_entry(name, true)
|
||||
local ip = get_ip(name)
|
||||
data.names[name] = true
|
||||
if ip then data.names[ip] = true end
|
||||
reason = reason or DEF_BAN_REASON
|
||||
data.banned = reason
|
||||
if not data.record then data.record = { } end
|
||||
table.insert(data.record, { date=os.time(), time=time, reason=reason })
|
||||
data.privs = data.privs or minetest.get_player_privs(name)
|
||||
minetest.after(1, function()
|
||||
xban._.send(name,
|
||||
"-x- You have been banned from this server: %s.",
|
||||
(reason or DEF_BAN_MESSAGE)
|
||||
)
|
||||
if time then
|
||||
data.expires = os.time() + time
|
||||
xban._.send(name, "-x- Your ban will expire on %s.", os.date("%c", data.expires))
|
||||
end
|
||||
xban._.send(name, "-x- Disconnection will follow shortly...")
|
||||
end)
|
||||
if minetest.auth_table[name] then
|
||||
minetest.set_player_privs(name, { })
|
||||
end
|
||||
minetest.after(5, minetest.ban_player, name)
|
||||
xban._.ACTION("Banned names/IPs: %s", table.concat(data.names, ", "))
|
||||
xban._.INFO("Revoked all privileges.")
|
||||
xban.save_db()
|
||||
return true
|
||||
end
|
||||
|
||||
function xban.unban_player(name)
|
||||
local data = xban.find_entry(name)
|
||||
if not data then return nil, "No such player." end
|
||||
if data.privs and next(data.privs) then
|
||||
minetest.set_player_privs(name, data.privs)
|
||||
end
|
||||
for _, nm in ipairs(data.names) do
|
||||
minetest.unban_player_or_ip(nm)
|
||||
end
|
||||
data.banned = nil
|
||||
xban.save_db()
|
||||
return true
|
||||
end
|
||||
|
||||
load_db()
|
||||
|
||||
xban.db = iplist
|
Loading…
Reference in New Issue
Block a user