init.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. -- mod governor by mckaygerhard
  2. -- Copyright 2020
  3. ----------------------------------------------------------------------------
  4. -- this program can be used free but cannot be used commertially or
  5. -- modified for, licenced CC-BY-SA-NC 4.0
  6. -- This program is distributed in the hope that it will be useful,
  7. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. ----------------------------------------------------------------------------
  10. --[[ init - initialization of variables ]]
  11. local modname = "governing" -- name of the mod , need to be used later in namespace mod variable
  12. local modpath = minetest.get_modpath("governing") -- path of the mod
  13. local modstor = minetest.get_mod_storage() -- request of storage for the mod, if valid, otherwise false/nil
  14. local worlddir = minetest.get_worldpath() -- path of the world were the mod is running, otherwise false/nil
  15. local modmail = minetest.get_modpath("mail") -- path of the mail mod if available for sending messages internaly on private, otherwise false/nil
  16. local modgeoip = minetest.get_modpath("geoip") -- if available, their commands wil be used, otherwise we provided
  17. local moddefault = minetest.get_modpath("default") -- path of default mod if available, otherwise false/nil
  18. local modkillme = minetest.get_modpath("killme") -- if killme is present as mod if available, otherwise we use own
  19. local modcommand = minetest.get_modpath("game_commands") -- updated killme is present as mod if available, otherwise we use own
  20. local modcreative = minetest.get_modpath("creative") -- if creative is available, otherwise false/nil
  21. local modantispawn = minetest.get_modpath("antispam") -- if rnd1 anticheat mod is loaded, cos only wolrs with mt4
  22. local modanticheat = minetest.get_modpath("anticheat") -- if rnd1 anticheat mod is loaded, cos only wolrs with mt4
  23. local modbeowulf = minetest.get_modpath("beowulf") -- if rnd1 anticheat mod is loaded, cos only wolrs with mt4
  24. local modhudbars = minetest.get_modpath("hudbars") -- if the hudbars mod is loaded and working, from wuzzy
  25. local modhbhunger = minetest.get_modpath("hbhunger") -- if the hudbars hunger mod is loaded and working, from wuzzy
  26. local checkapikey = minetest.settings:get("governing.checkapikey") or "" -- need for geoip improved ip information, then geoip normal will be used
  27. local is_46 = minetest.has_feature("add_entity_with_staticdata") -- detect minetest engine 4.0.16 or mayor
  28. local is_50 = minetest.has_feature("object_use_texture_alpha") -- detect mineitest engine more modern than 5.0.0
  29. local is_53 = minetest.has_feature("object_step_has_moveresult") -- detect mineitest engine more modern than 5.3.1
  30. local is_54 = minetest.has_feature("direct_velocity_on_players") -- detect mineitest engine more modern than 5.4.0
  31. 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).
  32. local creative_mode_cache = minetest.settings:get_bool("creative_mode") -- detection if game is running in main creative
  33. local S
  34. --[[ end - all local variables ]]
  35. --[[ init - translation boilerplace, currently some issues with intlib mod ]]
  36. if minetest.get_translator ~= nil then
  37. S = minetest.get_translator(modname) -- 5.x translation function
  38. else
  39. if minetest.get_modpath("intllib") then
  40. dofile(minetest.get_modpath("intllib") .. "/init.lua")
  41. if intllib.make_gettext_pair then
  42. gettext, ngettext = intllib.make_gettext_pair() -- new gettext method
  43. else
  44. gettext = intllib.Getter() -- old text file method
  45. end
  46. S = gettext
  47. else -- boilerplate function
  48. S = function(str, ...)
  49. local args = {...}
  50. return str:gsub("@%d+", function(match)
  51. return args[tonumber(match:sub(2))]
  52. end)
  53. end
  54. end
  55. end
  56. --[[ end - translation boilerplace, currently some issues with intlib mod ]]
  57. --[[ init - namespace of the mod and varible usages ]]
  58. gapi = {}
  59. governing = {}
  60. governing.is_46 = is_46 -- detect minetest engine 4.0.16 or mayor
  61. governing.is_50 = is_50 -- detect mineitest engine more modern than 5.0.0
  62. governing.is_53 = is_53 -- detect mineitest engine more modern than 5.3.1
  63. governing.is_54 = is_54 -- detect mineitest engine more modern than 5.4.0
  64. governing.S = S -- translations if available
  65. governing.httpapi = httpapi -- must be called early at the beggining to work
  66. governing.modname = modname -- name of the mod
  67. governing.modpath = modpath -- path of the mod
  68. governing.modstor = modstor -- request of storage for the mod, otherwise false/nil
  69. governing.worlddir = worlddir -- path of the world were the mod is running, otherwise false/nil
  70. governing.modgeoip = modgeoip -- path of the geoip mod if available for sending messages internaly on private, otherwise false/nil
  71. governing.modmail = modmail -- path of the mail mod if available for sending messages internaly on private, otherwise false/nil
  72. governing.moddefault = moddefault -- path of default mod if available, otherwise false/nil
  73. governing.modkillme = modkillme -- if killme is present as mod if available, otherwise we use own
  74. governing.modcommand = modcommand -- if same killme and commands is present as mod if available, otherwise we use own
  75. governing.modantispawn = modantispawn -- autodetect if older mod antispan by appguru are present
  76. governing.modanticheat = modanticheat -- if rnd1 anticheat mod is present cos only works with mt4
  77. governing.modbeowulf = modbeowulf -- if beowulf anticheat mod is present cos only works with mt5
  78. governing.modhudbars = modhudbars -- if hudbars is present or the mproved hudbars redo
  79. governing.modhbhunger = modhbhunger -- if hbhunger is present or the mproved hudbars redo
  80. governing.checkapikey = checkapikey -- need for geoip improved ip information, then geoip normal will be used
  81. --[[ end - namespace of the mod and varible usages ]]
  82. --[[ init http calls, must be only on main ]]
  83. function governing.lookup(ip, callback)
  84. if not httpapi then
  85. minetest.log("error", "[governing/geoip] mod not in the trusted http mods!")
  86. return
  87. end
  88. httpapi.fetch( {
  89. url = "https://tools.keycdn.com/geo.json?host=" .. ip,
  90. extra_headers = { "User-Agent: keycdn-tools:https://minetest.org" },
  91. timeout = 5,
  92. }, function(res)
  93. if res.code == 200 then
  94. local data = minetest.parse_json(res.data)
  95. callback(data)
  96. else
  97. minetest.log("warning", "[governing/geoip] http request returned status: " .. res.code)
  98. end
  99. end)
  100. end
  101. function governing.checkip(ip, callback)
  102. if not httpapi then
  103. minetest.log("error", "[governing] mod not in the trusted http mods!")
  104. return
  105. end
  106. httpapi.fetch( {
  107. url = "https://vpnapi.io/api/" .. ip .. "?key==" .. governing.checkapikey,
  108. extra_headers = { "User-Agent: VenenuX-minenux:https://git.minetest.io/minenux" },
  109. timeout = 5,
  110. }, function(res)
  111. if res.code == 200 then
  112. local data = minetest.parse_json(res.data)
  113. callback(data)
  114. else
  115. minetest.log("warning", "[governing/ip] http request returned status: " .. res.code)
  116. end
  117. end)
  118. end
  119. --[[ end http calls, must be only on main ]]
  120. --[[ include code files mod features ]]
  121. dofile(governing.modpath.."/administration.lua") -- more of commonformats
  122. dofile(governing.modpath.."/anticheats.lua") -- load anticheat mod that combined rnd + beowulf + fairplay
  123. dofile(governing.modpath.."/antispawn.lua") -- load antispawn chat features only if mod antispan is not loaded
  124. dofile(governing.modpath.."/commands.lua") -- must be at end. so relies on others functionalities
  125. dofile(governing.modpath.."/process.lua") -- must be at end. so relies on others functionalities
  126. --[[ end of include code files mod features ]]
  127. --[[ log files and finished of mod loading ]]
  128. if governing.checkapikey == "" then minetest.log("warning", "[goberning] governing.checkapikey not set or empty, only basic geoip will work") end
  129. print("[MOD] governing mod loaded" )