From 2bafe122355ee165e5900505c3e492db4ebfde9e Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Thu, 22 Jun 2023 16:07:14 -0400 Subject: [PATCH] organize sintax.. add comments and put variables to detects --- commands.lua | 31 ++++++++++++++---- geoip.lua | 6 ++++ init.lua | 89 +++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 94 insertions(+), 32 deletions(-) diff --git a/commands.lua b/commands.lua index 574f7bd..fe45cbd 100644 --- a/commands.lua +++ b/commands.lua @@ -11,6 +11,12 @@ ---------------------------------------------------------------------------- + + + + +--[[ commands for killme implementation no matter of those mods ]] + if not governing.modkillme and not governing.modcommand then minetest.register_chatcommand("killme", { description = "Kill player or yourselft to respawn", @@ -37,8 +43,17 @@ if not governing.modkillme and not governing.modcommand then }) end +--[[ end of commands for killme implementation no matter of those mods ]] + + + + + + +-- ----------------------------------------------------------------------------------------- + +--[[ commands for geoip and ip location information ]] --- manual query if not governing.modgeoip then minetest.register_chatcommand("geoip", { params = "", @@ -73,11 +88,15 @@ minetest.register_chatcommand("govip", { local ip = minetest.get_player_ip(param) if not ip then return true, "[governing] no ip available! seems "..param.." does not provide such info!" end governing.checkip(ip, function(result) - local txt = format_result_checkip(result) - if not txt then return true, "[governing]: "..param..":"..ip" error: "..(result.description or "unknown error") end - minetest.log("action", "[governing] "..param..": "..txt) - minetest.chat_send_player(name, param..": "..txt) - end) + local txt = format_result_checkip(result) + if not txt then return true, "[governing]: "..param..":"..ip" error: "..(result.description or "unknown error") end + minetest.log("action", "[governing] "..param..": "..txt) + minetest.chat_send_player(name, param..": "..txt) + end) end }) +--[[ end of commands for geoip and ip location information ]] + + + diff --git a/geoip.lua b/geoip.lua index 7ddfd30..d982fc1 100644 --- a/geoip.lua +++ b/geoip.lua @@ -107,8 +107,11 @@ function format_result_checkip(result) end end + governing.joinplayer_callback = function() end -- function(name, result) + +--[[ init of call back on join of a player, ]] minetest.register_on_joinplayer(function(player) -- query ip on join, record in logs and execute callback if not player then return end if not player:is_player() then return end @@ -137,3 +140,6 @@ minetest.register_on_joinplayer(function(player) -- query ip on join, record in end end end) +--[[ end of call back on join of a player, ]] + + diff --git a/init.lua b/init.lua index 0b5e264..0634d4d 100644 --- a/init.lua +++ b/init.lua @@ -11,17 +11,20 @@ ---------------------------------------------------------------------------- -local modname = "governing" -local modpath = minetest.get_modpath("governing") -local modstor = minetest.get_mod_storage() -local worlddir = minetest.get_worldpath() -local modmail = minetest.get_modpath("mail") -local modgeoip = minetest.get_modpath("geoip") -local moddefault = minetest.get_modpath("default") -local modkillme = minetest.get_modpath("killme") -local modcommand = minetest.get_modpath("game_commands") -local modcreative = minetest.get_modpath("creative") -local checkapikey = minetest.settings:get("governing.checkapikey") or "" + +--[[ init - initialization of variables ]] + +local modname = "governing" -- name of the mod , need to be used later in namespace mod variable +local modpath = minetest.get_modpath("governing") -- path of the mod +local modstor = minetest.get_mod_storage() -- request of storage for the mod, if valid, otherwise false/nil +local worlddir = minetest.get_worldpath() -- path of the world were the mod is running, otherwise false/nil +local modmail = minetest.get_modpath("mail") -- path of the mail mod if available for sending messages internaly on private, otherwise false/nil +local modgeoip = minetest.get_modpath("geoip") -- if available, their commands wil be used, otherwise we provided +local moddefault = minetest.get_modpath("default") -- path of default mod if available, otherwise false/nil +local modkillme = minetest.get_modpath("killme") -- if killme is present as mod if available, otherwise we use own +local modcommand = minetest.get_modpath("game_commands") -- updated killme is present as mod if available, otherwise we use own +local modcreative = minetest.get_modpath("creative") -- if creative is available, otherwise false/nil +local checkapikey = minetest.settings:get("governing.checkapikey") or "" -- need for geoip improved ip information, then geoip normal will be used local is_46 = minetest.has_feature("add_entity_with_staticdata") -- detect minetest engine 4.0.16 or mayor local is_50 = minetest.has_feature("object_use_texture_alpha") -- detect mineitest engine more modern than 5.0.0 @@ -30,8 +33,16 @@ local is_54 = minetest.has_feature("direct_velocity_on_players") -- detect minei local httpapi = minetest.request_http_api and minetest.request_http_api() -- Only works at init time and must be called from the mod's main scope (not from a function). +local creative_mode_cache = minetest.settings:get_bool("creative_mode") -- detection if game is running in main creative + local S +--[[ end - all local variables ]] + + + +--[[ init - translation boilerplace, currently some issues with intlib mod ]] + if minetest.get_translator ~= nil then S = minetest.get_translator(modname) -- 5.x translation function else @@ -53,29 +64,38 @@ else end end -local creative_mode_cache = minetest.settings:get_bool("creative_mode") +--[[ end - translation boilerplace, currently some issues with intlib mod ]] + + governing = {} -governing.is_46 = is_46 -governing.is_50 = is_50 -governing.is_53 = is_53 -governing.is_54 = is_54 +governing.is_46 = is_46 -- detect minetest engine 4.0.16 or mayor +governing.is_50 = is_50 -- detect mineitest engine more modern than 5.0.0 +governing.is_53 = is_53 -- detect mineitest engine more modern than 5.3.1 +governing.is_54 = is_54 -- detect mineitest engine more modern than 5.4.0 -governing.S = S +governing.S = S -- translations if available governing.httpapi = httpapi -- must be called early at the beggining to work governing.modname = modname -- name of the mod governing.modpath = modpath -- path of the mod -governing.modstor = modstor -- request of storage for the mod -governing.worlddir = worlddir -- path of the world were the mod is running -governing.modgeoip = modgeoip -- path of the geoip mod if available for sending messages internaly on private -governing.modmail = modmail -- path of the mail mod if available for sending messages internaly on private -governing.moddefault = moddefault -- path of default mod if availalbe -governing.modkillme = modkillme -- if killme is present as mod if available -governing.modcommand = modcommand -- if same killme and commands is present as mod if available +governing.modstor = modstor -- request of storage for the mod, otherwise false/nil +governing.worlddir = worlddir -- path of the world were the mod is running, otherwise false/nil +governing.modgeoip = modgeoip -- path of the geoip mod if available for sending messages internaly on private, otherwise false/nil +governing.modmail = modmail -- path of the mail mod if available for sending messages internaly on private, otherwise false/nil +governing.moddefault = moddefault -- path of default mod if available, otherwise false/nil +governing.modkillme = modkillme -- if killme is present as mod if available, otherwise we use own +governing.modcommand = modcommand -- if same killme and commands is present as mod if available, otherwise we use own governing.checkapikey = checkapikey -- need for geoip improved ip information, then geoip normal will be used +--[[ end namespace of the mod and varible usages ]] + + + + +--[[ init privileges registrations ]] + function governing.is_creative(name) if creative then return creative.is_creative(name) @@ -96,6 +116,12 @@ if not governing.modgeoip then }) end +--[[ end privileges registrations ]] + + + +--[[ init http calls, must be only on main ]] + function governing.lookup(ip, callback) if not httpapi then minetest.log("error", "[governing/geoip] mod not in the trusted http mods!") @@ -134,8 +160,19 @@ function governing.checkip(ip, callback) end) end -dofile(governing.modpath.."/geoip.lua") -dofile(governing.modpath.."/commands.lua") +--[[ end http calls, must be only on main ]] + + + + +--[[ include code files ]] + +dofile(governing.modpath.."/geoip.lua") -- format the geoip responses managed by "callback(data)" +dofile(governing.modpath.."/commands.lua") -- must be at end. so relies on others functionalities + + + +--[[ log files and finished of mod loading ]] if governing.checkapikey == "" then minetest.log("warning", "[goberning] governing.checkapikey not set or empty") end