From a96f8391d8ff79ddd90c32a49cc01e626a2dae64 Mon Sep 17 00:00:00 2001 From: elite Date: Mon, 24 Jul 2017 18:51:26 -0400 Subject: [PATCH] add names_per_ip mod, update .conf --- minetest.conf | 16 ++-- worldmods/names_per_ip/README.md | 23 ++++++ worldmods/names_per_ip/depends.txt | 0 worldmods/names_per_ip/functions.lua | 111 +++++++++++++++++++++++++++ worldmods/names_per_ip/init.lua | 106 +++++++++++++++++++++++++ 5 files changed, 249 insertions(+), 7 deletions(-) create mode 100644 worldmods/names_per_ip/README.md create mode 100644 worldmods/names_per_ip/depends.txt create mode 100644 worldmods/names_per_ip/functions.lua create mode 100644 worldmods/names_per_ip/init.lua diff --git a/minetest.conf b/minetest.conf index d13553a..8c21807 100755 --- a/minetest.conf +++ b/minetest.conf @@ -1,10 +1,10 @@ -#################UGX###################### -name = cessna151 +#################UGX Realms###################### +name = aerozoic ################Server##################### # server_announce = false server_name = UGX Realms (AMHI Inspired remake) -server_description = A survival server based on the old AMHI server, but with several improvements and new features. +server_description = A survival server inspired by the old AMHI server, but with several improvements and new features. (Unified inventory, PVP toggle button, and more!) server_address = minetestservers.ddns.net server_url = max_users = 30 @@ -20,9 +20,10 @@ debug_log_level = action strict_protocol_version_checking = false secure.trusted_mods = mysql_auth,mysql_base,sql,irc,stacktraceplus,multiskin secure.enable_security = false -mysql_auth.cfgfile = /home/minetestservers/.minetest/worlds/UGXmr/mysql.cfgfile -mysql_base.cfgfile = /home/minetestservers/.minetest/worlds/UGXmr/mysql.cfgfile +mysql_auth.cfgfile = ~/.minetest/worlds/UGXmr/mysql.cfgfile +mysql_base.cfgfile = ~/.minetest/worlds/UGXmr/mysql.cfgfile name_restrictions.pronounceability = # nil=disabled, 0=everything blocked, .5=strict, 1=normal, 2=relaxed +max_names_per_ip = 2 # #################Game################## @@ -35,6 +36,7 @@ share_bones_time_early = 0 #If player dies in protected area... (0=disabled) default_privs = interact, home, shout, spawn, fast enable_floating_dungeons = false give_initial_stuff = true +initial_stuff = default:pick_steel,default:axe_steel,default:shovel_steel,default:torch 99,default:cobble 99,wool:white 99,default:goldblock enable_fire = false playereffects_autosave = 60 enable_sprinting = true @@ -45,8 +47,8 @@ protector_flip = true protector_spawn = 35 protector_pvp = false protector_radius = 7 -day_time_ratio = 75 -night_time_ratio = 25 +day_time_ratio = 80 +night_time_ratio = 20 maximum_characters_per_message = 300 # #################IRC################ diff --git a/worldmods/names_per_ip/README.md b/worldmods/names_per_ip/README.md new file mode 100644 index 0000000..2278674 --- /dev/null +++ b/worldmods/names_per_ip/README.md @@ -0,0 +1,23 @@ +names_per_ip +============ + +A mod for Minetest to stop annoyed kids + +It will limit the accounts to 2 (+3 if the player is whitelisted) per IP and delete IP history. + +Initial mod creator: Krock + +License: WTFPL + +Depends: nothing + +Chat commands +------------- + +``` +/ipnames + whois -> Gets all accounts of + list -> Lists all exceptions/whitelist entries (players which can have "unlimited" accounts) + ignore -> Adds an exception/whitelist entry for + unignore -> Removes an exception/whitelist entry for +``` diff --git a/worldmods/names_per_ip/depends.txt b/worldmods/names_per_ip/depends.txt new file mode 100644 index 0000000..e69de29 diff --git a/worldmods/names_per_ip/functions.lua b/worldmods/names_per_ip/functions.lua new file mode 100644 index 0000000..f74a7e8 --- /dev/null +++ b/worldmods/names_per_ip/functions.lua @@ -0,0 +1,111 @@ +function ipnames.command_list(name) + local names = "" + for k, v in pairs(ipnames.whitelist) do + names = names.." "..k + end + minetest.chat_send_player(name, "All exceptions: "..names) +end + +function ipnames.command_whois(name, param) + if not ipnames.data[param] then + minetest.chat_send_player(name, "The player '"..param.."' did not join yet.") + return + end + + local ip = ipnames.data[param][1] + local names = "" + for k, v in pairs(ipnames.data) do + if v[1] == ip then + names = names.." "..k + end + end + minetest.chat_send_player(name, "Following players share an IP: "..names) +end + +function ipnames.command_ignore(name, param) + if not ipnames.data[param] then + minetest.chat_send_player(name, "The player '"..param.."' did not join yet.") + return + end + + ipnames.whitelist[param] = true + minetest.chat_send_player(name, "Added an exception!") + ipnames.save_whitelist() +end + +function ipnames.command_unignore(name, param) + if not ipnames.whitelist[param] then + minetest.chat_send_player(name, "The player '"..param.."' is not on the whitelist.") + return + end + + ipnames.whitelist[param] = nil + minetest.chat_send_player(name, "Removed an exception!") + ipnames.save_whitelist() +end + +function ipnames.load_data() + local file = io.open(ipnames.file, "r") + if not file then + return + end + local t = os.time() + for line in file:lines() do + if line ~= "" then + local data = line:split("|") + if #data >= 2 then + -- Special stuff - only save if player has not been deleted yet + local ignore = false + if not minetest.auth_table[data[1]] then + ignore = true + end + if not ignore then + data[3] = tonumber(data[3]) or 0 + -- Remove IP after 2 weeks + if data[3] > 0 and t - data[3] > (3600 * 24 * 14) then + ignore = true + end + end + if not ignore then + ipnames.data[data[1]] = {data[2], data[3]} + end + end + end + end + io.close(file) +end + +function ipnames.save_data() + if not ipnames.changes then + return + end + ipnames.changes = false + local file = io.open(ipnames.file, "w") + for k, v in pairs(ipnames.data) do + v[2] = v[2] or os.time() + file:write(k.."|"..v[1].."|"..v[2].."\n") + end + io.close(file) +end + +function ipnames.load_whitelist() + local file = io.open(ipnames.whitelist_file, "r") + if not file then + return + end + for line in file:lines() do + if line ~= "" then + ipnames.whitelist[line] = true + end + end +end + +function ipnames.save_whitelist() + local file = io.open(ipnames.whitelist_file, "w") + for k, v in pairs(ipnames.whitelist) do + if v ~= nil then + file:write(k.."\n") + end + end + io.close(file) +end diff --git a/worldmods/names_per_ip/init.lua b/worldmods/names_per_ip/init.lua new file mode 100644 index 0000000..7edd2a1 --- /dev/null +++ b/worldmods/names_per_ip/init.lua @@ -0,0 +1,106 @@ +-- Created by Krock to stop mass-account-creators +-- License: WTFPL +ipnames = {} +ipnames.data = {} +ipnames.tmp_data = {} +ipnames.whitelist = {} +ipnames.changes = false +ipnames.save_time = 0 +ipnames.file = minetest.get_worldpath().."/ipnames.data" +ipnames.whitelist_file = minetest.get_worldpath().."/ipnames_whitelist.data" + +-- Limit 2 = maximal 2 accounts, the 3rd under the same IP gets blocked +ipnames.name_per_ip_limit = tonumber(minetest.setting_get("max_names_per_ip")) or 2 +-- 2 + 3 = 5 accounts as limit for "ignored" players +ipnames.extended_limit = 3 + +-- Interval where the IP list gets saved/updated +ipnames.save_interval = 240 + +dofile(minetest.get_modpath("names_per_ip").."/functions.lua") + +minetest.register_chatcommand("ipnames", { + description = "Get the features of names_per_ip", + privs = {ban=true}, + func = function(name, param) + if param == "" then + minetest.chat_send_player(name, "Available commands: ") + minetest.chat_send_player(name, "Get all accounts of : /ipnames whois ") + minetest.chat_send_player(name, "List all exceptions: /ipnames list") + minetest.chat_send_player(name, "Remove/add an exception: /ipnames (un)ignore ") + return + end + if param == "list" then + ipnames.command_list(name) + return + end + + local args = param:split(" ") + if #args < 2 then + minetest.chat_send_player(name, "Error: Please check again '/ipnames' for correct usage.") + return + end + + if args[1] == "whois" then + ipnames.command_whois(name, args[2]) + elseif args[1] == "ignore" then + ipnames.command_ignore(name, args[2]) + elseif args[1] == "unignore" then + ipnames.command_unignore(name, args[2]) + else + minetest.chat_send_player(name, "Error: No known argument for #1 '"..args[1].."'") + end + end +}) + +-- Get IP if player tries to join, ban if there are too much names per IP +minetest.register_on_prejoinplayer(function(name, ip) + -- Only stop new accounts + ipnames.tmp_data[name] = ip + + if ipnames.data[name] then + return + end + + local count = 1 + local names = "" + local limit_ext = false + for k, v in pairs(ipnames.data) do + if v[1] == ip then + if not limit_ext and ipnames.whitelist[k] then + count = count - ipnames.extended_limit + limit_ext = true + end + count = count + 1 + names = names..k..", " + end + end + -- Return error message if too many accounts have been created + if count > ipnames.name_per_ip_limit then + ipnames.tmp_data[name] = nil + return ("\nYou exceeded the limit of accounts.\nYou already own the following accounts:\n"..names) + end +end) + +-- Save IP if player joined +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + local t = os.time() + ipnames.data[name] = {ipnames.tmp_data[name], t} + ipnames.tmp_data[name] = nil + ipnames.changes = true +end) + +minetest.register_globalstep(function(t) + ipnames.save_time = ipnames.save_time + t + if ipnames.save_time < ipnames.save_interval then + return + end + ipnames.save_time = 0 + ipnames.save_data() +end) + +minetest.register_on_shutdown(function() ipnames.save_data() end) + +minetest.after(3, function() ipnames.load_data() end) +minetest.after(3, function() ipnames.load_whitelist() end) \ No newline at end of file