diff --git a/README.md b/README.md index d9693f2..fd0280e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This mod is based on the concepts introduced by xban2, and expands on them by using an sql database instead of a serialised table file. This approach to ban management: -* Offers API access to useful functions +* Offers API access to core functions that can be disabled if reqd * Improves the robustness of the data. * Grants an enhanced view of player accounts and ban records. * Provides tiered access to player record information. @@ -19,7 +19,7 @@ favourite database management gui. Transactions are coded without locks so it's not recommended to write to the database whilst Minetest is using it. Reading the database shouldn't be an issue. -Existing users please note: sban will not allow minetest to run if your db version doesn't match the current version required, if that happens and only if, you need to apply sban/tools/sban_update.sql to the database by copying the file into the world folder, then you can use sqlite3 in a terminal after navigating to the world folder using the commands: +Existing users please note: sban will not allow minetest to run if your db version doesn't match the current version required, if that happens and only if, you need to apply sban/tools/sban_update.sql to the database by copying the file into the world folder, then you can use sqlite3 in a terminal, after navigating to the world folder, using the commands: sqlite3 sban.sqlite .read sban_update.sql @@ -47,7 +47,7 @@ The mod provides the following chat console commands. These commands require the ban privilege. The ban_admin and server privileges extend the functionality of some commands. -#### bang +bang Launches a GUI. Comprehensive management of bans via a user interface for in-game convenience. On launch the interface shows a hotlist containing the last 10 players to join. Use search @@ -56,7 +56,7 @@ accessible via the arrows. ``` Usage: /bang ``` -#### ban +ban Bans a player permanently. @@ -67,7 +67,7 @@ Example: /ban Steve Some reason. The server privilege enables the pre-emptive banning of player names or IP addresses for which the server has no current record. -#### tempban +tempban Bans a player temporarily. @@ -82,7 +82,7 @@ assumed to mean seconds. For example, 42 means 42 seconds, 1337m means 1337 minu and so on. You can chain more than one such group and they will add up. For example, 1Y3M3D7h will ban for 1 year, 3 months, 3 days and 7 hours. -#### unban +unban Unbans a player. @@ -92,7 +92,7 @@ Example: /unban Steve Some reason. Note that this command requires a reason. -#### ban_record +ban_record Displays player record and ban record. @@ -115,7 +115,7 @@ the expiration time (if applicable), the reason, and the source of the ban. Note that the records of players with the server privilege can only be viewed by other players with the server privilege. -#### ban_wl +ban_wl Manages the whitelist. @@ -140,7 +140,7 @@ This is an intensive process that will cause lag, so it's recommended you perform this on a local instance and copy the database to the server before starting with the sban mod installed. -#### ban_dbi +ban_dbi Imports bans from xban.db or ipban.txt files into an existing sban.sqlite file. @@ -158,7 +158,7 @@ command on each file. For example: Each record is checked against the database by player name to prevent duplicate entries. -#### ban_dbe +ban_dbe Extracts all valid player records from an xban.db file and saves them in xban.sql. @@ -175,7 +175,7 @@ from the sqlite prompt using: The time of the import operation is dependant on the size of the .sql file. -#### ban_dbx +ban_dbx Dumps the database back to xban2 file format. Use it before you uninstall this mod if you intend using xban2 and wish to retain the data. @@ -184,7 +184,7 @@ if you intend using xban2 and wish to retain the data. Do this before enabling xban2 mod otherwise it will be overwritten by the currently loaded data. -#### whois +whois ```Usage: //whois ``` @@ -192,29 +192,31 @@ Example: //whois sadie Returns all known accounts and ip addresses associated with a player name. -#### CONFIG +#### CONFIG SETTINGS You can add these optional settings to minetest.conf to adjust the sban mod's -behaviour. +behaviour. Deleting them removes the modification and sban will revert back to +the default behaviour. Minetest config file can only be changed when the server +isn't running! -#### sban.api +sban.api -Controls loading of the API functions. Default is false. +Controls loading of the API functions. Default: true - sban.api = true + sban.api = false -This would load the API functions and allow other mods access via the global sban table. +This would disable the API functions and prevent other mods access via the global sban table. -#### sban.display_max +sban.display_max Changes the maximum number of player records displayed when using the /ban_record command. sban.display_max = 12 -This would increase the number of records shown from the default 10 records to 12. +This would increase the number of records shown from the default: 10 records to 12. -#### sban.ban_max +sban.ban_max Allows server owners to set an expiry date for bans. It uses the same format for durations as the /tempban command. @@ -225,11 +227,10 @@ In this example all permanent player bans created after the setting has been add to minetest.conf, and after a server restart, will expire 90 days after the ban was set. If required, longer ban durations can still be set with the tempban command. -Please note: if you delete or adjust the setting, after restarting the server, bans -created while the setting was active will not change and will retain their original -expiry date. +Please note: existing ban expiry dates are not affected by changing this setting, + including permanent bans but they will be applied to any subsequent new bans. -#### sban.accounts_per_id +sban.accounts_per_id Restricts how many accounts an id can have. @@ -237,7 +238,7 @@ Restricts how many accounts an id can have. Please note this setting is optional and the default behaviour is unrestricted. -#### sban.ip_limit +sban.ip_limit Restricts how many ip addresses an id can have. @@ -245,16 +246,16 @@ Restricts how many ip addresses an id can have. Please note this setting is optional and the default behaviour is unrestricted. -#### sban.import_enabled +sban.import_enabled Disables the import/export sections of code. sban.import_enabled = false -The default is true, this setting allows you to save memory by disabling the code and commands associated with -importing & exporting data and should only be set to false once you have imported any ban sources. +The default is true, this setting allows you to disable the code and commands associated with +importing & exporting data and should only be set to false once you have imported your ban sources. -#### sban.cache.max +sban.cache.max Maximum cached name records. @@ -262,7 +263,7 @@ Maximum cached name records. If you don't add this setting sban will use the value above as the default. -#### sban.cache.ttl +sban.cache.ttl Time in seconds to deduct from the last player to login as the cutoff point for pre caching names. diff --git a/init.lua b/init.lua index 8a5206b..55dba8e 100644 --- a/init.lua +++ b/init.lua @@ -44,7 +44,7 @@ local db_version = '0.2.1' local db = _sql.open(DB) -- connection local mod_version = '0.2.0' local expiry, owner, owner_id, def_duration, display_max, names_per_id -local importer, ID, HL_Max, max_cache_records, ttl, cap, ip_limit +local importer, ID, HL_Max, max_cache_records, ttl, cap, ip_limit, api local formstate = {} local t_units = { s = 1, S=1, m = 60, h = 3600, H = 3600, @@ -71,10 +71,11 @@ if minetest.settings then display_max = tonumber(minetest.settings:get("sban.display_max")) or 10 names_per_id = tonumber(minetest.settings:get("sban.accounts_per_id")) ip_limit = tonumber(minetest.settings:get("sban.ip_limit")) - importer = minetest.settings:get("sban.import_enabled") or true + importer = minetest.settings:get_bool("sban.import_enabled", true) HL_Max = tonumber(minetest.settings:get("sban.hotlist_max")) or 15 max_cache_records = tonumber(minetest.settings:get("sban.cache.max")) or 1000 ttl = tonumber(minetest.settings:get("sban.cache.ttl")) or 86400 + api = minetest.settings:get_bool("sban.api", true) else -- old api method expiry = minetest.setting_get("sban.ban_max") @@ -87,6 +88,7 @@ else HL_Max = tonumber(minetest.setting_get("sban.hotlist_max")) or 15 max_cache_records = tonumber(minetest.setting_get("sban.cache_max")) or 1000 ttl = tonumber(minetest.setting_get("sban.cache_ttl")) or 86400 + api = minetest.setting_getbool("sban.api") or true end --[[ @@ -2031,90 +2033,92 @@ minetest.register_chatcommand("/whois", { ####################### ]] --- Ban function --- @param name string --- @param source string --- @param reason string --- @param expires alphanumerical duration string or integer --- @return bool --- @return msg string -sban.ban = function(name, source, reason, expires) - -- check params are valid - assert(type(name) == 'string') - assert(type(source) == 'string') - assert(type(reason) == 'string') - if expires and type(expires) == 'string' then - expires = parse_time(expires) - elseif expires and type(expires) == "integer" then - local ts = os.time() - if expires < ts then - expires = ts + expires +if api then + -- Ban function + -- @param name string + -- @param source string + -- @param reason string + -- @param expires alphanumerical duration string or integer + -- @return bool + -- @return msg string + sban.ban = function(name, source, reason, expires) + -- check params are valid + assert(type(name) == 'string') + assert(type(source) == 'string') + assert(type(reason) == 'string') + if expires and type(expires) == 'string' then + expires = parse_time(expires) + elseif expires and type(expires) == "integer" then + local ts = os.time() + if expires < ts then + expires = ts + expires + end + end + if name == owner then + return false, 'insufficient privileges!' + end + local id = get_id(name) + if not id then + return false, ("No records exist for %s"):format(name) + elseif bans[id] then + -- only one active ban per id is reqd! + return false, ("An active ban already exist for %s"):format(name) + end + -- ban player + create_ban_record(name, source, reason, expires) + return true, ("Banned %s."):format(name) + end + + -- Unban function + -- @param name string + -- @param source name string + -- @param reason string + -- @return bool and msg string or nil + sban.unban = function(name, source, reason) + -- check params are valid + assert(type(name) == 'string') + assert(type(source) == 'string') + assert(type(reason) == 'string') + -- look for records by id + local id = get_id(name) + if id then + if not bans[id] then + return false, ("No active ban record for "..name) + end + update_ban_record(id, name, reason, name) + return true, ("Unbanned %s."):format(name) + else + return false, ("No records exist for %s"):format(name) end end - if name == owner then - return false, 'insufficient privileges!' - end - local id = get_id(name) - if not id then - return false, ("No records exist for %s"):format(name) - elseif bans[id] then - -- only one active ban per id is reqd! - return false, ("An active ban already exist for %s"):format(name) - end - -- ban player - create_ban_record(name, source, reason, expires) - return true, ("Banned %s."):format(name) -end --- Unban function --- @param name string --- @param source name string --- @param reason string --- @return bool and msg string or nil -sban.unban = function(name, source, reason) - -- check params are valid - assert(type(name) == 'string') - assert(type(source) == 'string') - assert(type(reason) == 'string') - -- look for records by id - local id = get_id(name) - if id then - if not bans[id] then - return false, ("No active ban record for "..name) + -- Fetch ban status for a player name or ip address + -- @param name_or_ip string + -- @return bool + sban.ban_status = function(name_or_ip) + assert(type(name_or_ip) == 'string') + local id = get_id(name_or_ip) + return bans[id] ~= nil + end + + -- Fetch ban status for a player name or ip address + -- @param name_or_ip string + -- @return keypair table record + sban.ban_record = function(name_or_ip) + assert(type(name_or_ip) == 'string') + local id = get_id(name_or_ip) + if id then + return bans[id] end - update_ban_record(id, name, reason, name) - return true, ("Unbanned %s."):format(name) - else - return false, ("No records exist for %s"):format(name) end -end --- Fetch ban status for a player name or ip address --- @param name_or_ip string --- @return bool -sban.ban_status = function(name_or_ip) - assert(type(name_or_ip) == 'string') - local id = get_id(name_or_ip) - return bans[id] ~= nil -end - --- Fetch ban status for a player name or ip address --- @param name_or_ip string --- @return keypair table record -sban.ban_record = function(name_or_ip) - assert(type(name_or_ip) == 'string') - local id = get_id(name_or_ip) - if id then - return bans[id] + -- Fetch active bans + -- @return keypair table of active bans + sban.list_active = function() + return bans end end --- Fetch active bans --- @return keypair table of active bans -sban.list_active = function() - return bans -end - --[[ ############################ ### Register callbacks ###