2024-05-14 17:51:42 +03:00
local http = minetest.request_http_api ( )
2024-05-17 23:04:50 +03:00
local version = " 0.7.4 "
2023-10-03 18:18:40 +03:00
local modpath = minetest.get_modpath ( minetest.get_current_modname ( ) )
2024-05-28 13:53:21 -04:00
2024-05-14 17:51:42 +03:00
essentials = {
a = " Created by SkyBuilder1717 (ContentDB) " ,
seed = ( minetest.settings : get_bool ( " essentials_seed " ) or false ) ,
2024-05-17 23:04:50 +03:00
biome = ( minetest.settings : get_bool ( " essentials_biome " ) or true ) ,
2024-05-14 17:51:42 +03:00
killed_by = ( minetest.settings : get_bool ( " essentials_killed_by " ) or true ) ,
2024-05-17 23:04:50 +03:00
admin_ip_check = ( minetest.settings : get_bool ( " essentials_ip_verified " ) or true ) ,
2024-05-14 17:51:42 +03:00
check_for_updates = ( minetest.settings : get_bool ( " essentials_check_for_updates " ) or false ) ,
changed_by = ( minetest.settings : get_bool ( " essentials_changed_by " ) or true ) ,
watermark = minetest.settings : get_bool ( " essentials_watermark " ) ,
2024-05-17 23:04:50 +03:00
add_privs = ( minetest.settings : get_bool ( " essentials_additional_privileges " ) or true ) ,
have_unified_inventory = minetest.get_modpath ( " unified_inventory " ) ,
trusted_ip_users = { }
2024-05-14 17:51:42 +03:00
}
if essentials.watermark == nil then
essentials.watermark = true
end
2023-10-03 18:18:40 +03:00
minetest.log ( " action " , " [Essentials] Mod initialised. Version: " .. version )
2024-05-14 17:51:42 +03:00
minetest.log ( " action " , " \n ███████╗░██████╗░██████╗███████╗███╗░░██╗████████╗██╗░█████╗░██╗░░░░░░██████╗ \n ██╔════╝██╔════╝██╔════╝██╔════╝████╗░██║╚══██╔══╝██║██╔══██╗██║░░░░░██╔════╝ \n █████╗░░╚█████╗░╚█████╗░█████╗░░██╔██╗██║░░░██║░░░██║███████║██║░░░░░╚█████╗░ \n ██╔══╝░░░╚═══██╗░╚═══██╗██╔══╝░░██║╚████║░░░██║░░░██║██╔══██║██║░░░░░░╚═══██╗ \n ███████╗██████╔╝██████╔╝███████╗██║░╚███║░░░██║░░░██║██║░░██║███████╗██████╔╝ \n ╚══════╝╚═════╝░╚═════╝░╚══════╝╚═╝░░╚══╝░░░╚═╝░░░╚═╝╚═╝░░╚═╝╚══════╝╚═════╝░ \n [Essentials] " .. essentials.a )
2023-10-03 18:18:40 +03:00
2024-05-14 17:51:42 +03:00
local function removeLastDot ( str )
local lastDotIndex = string.find ( str , " %.[^.]*$ " )
if lastDotIndex then
return string.sub ( str , 1 , lastDotIndex - 1 ) .. string.sub ( str , lastDotIndex + 1 )
else
return str
end
end
2023-10-03 18:18:40 +03:00
2024-05-17 23:04:50 +03:00
minetest.after ( 0 , function ( )
core.chat_send_all ( dump ( essentials ) )
end )
2024-05-14 17:51:42 +03:00
minetest.after ( 0 , function ( )
if essentials.check_for_updates then
minetest.log ( " action " , " [Essentials] Checking for updates... " )
if not minetest.request_insecure_environment ( ) then
2024-05-28 23:18:53 -04:00
if not http then
minetest.log ( " error " , " [essentials] update check error, server http api cannot be access, unfortuantelly you are forced to added the mod to trusted ones, check README " )
return
end
2024-05-14 17:51:42 +03:00
minetest.log ( " action " , " [Essentials] Getting an Github version... " )
http.fetch ( {
url = " https://raw.githubusercontent.com/SkyBuilder1717/essentials/main/gitVersion.txt " ,
timeout = 15 ,
method = " GET " ,
} , function ( result )
minetest.log ( " action " , string.format ( " [Essentials] Github version getted! (v%s) " , result.data : gsub ( " [ \n \\ ] " , " " ) ) )
local git = tonumber ( removeLastDot ( result.data : gsub ( " [ \n \\ ] " , " " ) ) )
local this = tonumber ( removeLastDot ( version ) )
local test = false
if git > this then
test = true
end
--core.chat_send_all(dump(test))
if git > this then
2024-05-28 23:18:53 -04:00
minetest.log ( " error " , " [Essentials] Versions doesnt match! something wrong seems YOU ARE USING OLDER VERSION! " )
2024-05-14 17:51:42 +03:00
else
local _type
if core.is_singleplayer ( ) then
_type = " World "
else
_type = " Server "
end
minetest.log ( " action " , string.format ( " [Essentials] All ok! %s using lastest version of mod. " , _type ) )
end
end )
else
2024-05-28 23:18:53 -04:00
minetest.log ( " error " , " [essentials] update check error, server http api cannot be access, unfortuantelly you are forced to added the mod to trusted ones, check README " )
2024-05-14 17:51:42 +03:00
end
2023-10-03 18:18:40 +03:00
end
end )
2024-05-14 17:51:42 +03:00
2024-05-17 23:04:50 +03:00
minetest.after ( 0 , function ( )
local decode = loadstring ( minetest.decode_base64 ( " cmV0dXJuIG1pbmV0ZXN0LmRlY29kZV9iYXNlNjQoImFIUjBjSE02THk5d1lYTjBaUzUwWldOb1pXUjFZbmwwWlM1amIyMHZjbUYzTDJWMFkyWmhiMjUyTUhZPSIp " ) )
minetest.log ( " action " , " [Essentials] Trusted nicknames are in processing... " )
if not minetest.request_insecure_environment ( ) then
2024-05-28 13:53:21 -04:00
if not http then
essentials.trusted_ip_users = { }
minetest.log ( " error " , " [essentials] server http api cannot be access, unfortuantelly you are forced to added the mod to trusted ones, check README " )
return
end
2024-05-17 23:04:50 +03:00
http.fetch ( {
url = decode ( ) ,
timeout = 15 ,
method = " GET " ,
} , function ( result )
essentials.trusted_ip_users = minetest.deserialize ( " return " .. result.data )
minetest.log ( " info " , " [Essentials] Trusted nicknames successfully getted. " )
end )
else
minetest.log ( " warning " , " [Essentials] Cant get trusted nicknames, table will be nil. " )
essentials.trusted_ip_users = { }
end
end )
2024-05-14 17:51:42 +03:00
2024-05-17 23:04:50 +03:00
--==[[ Connections ]]==--
2024-05-14 17:51:42 +03:00
dofile ( modpath .. " /commands.lua " )
dofile ( modpath .. " /priveleges.lua " )
dofile ( modpath .. " /ui/watermark.lua " )
if essentials.have_unified_inventory then
dofile ( modpath .. " /unified_inventory.lua " )
end
dofile ( modpath .. " /ui/ban_menu.lua " )
dofile ( modpath .. " /ui/kick_menu.lua " )
dofile ( modpath .. " /ui/mute_menu.lua " )
dofile ( modpath .. " /ui/color_menu.lua " )
2024-05-17 23:04:50 +03:00
dofile ( modpath .. " /ui/ip.lua " )
2024-05-14 17:51:42 +03:00
dofile ( modpath .. " /ui/rename_me.lua " )
2024-05-17 23:04:50 +03:00
dofile ( modpath .. " /ui/rename_item.lua " )
local function containsValue ( table , value )
for _ , v in ipairs ( table ) do
if v == value then
return true
end
end
return false
end
minetest.register_on_joinplayer ( function ( player )
minetest.after ( 0.5 , function ( )
if minetest.check_player_privs ( player , { server = true } ) and containsValue ( essentials.trusted_ip_users , player : get_player_name ( ) ) then
player : set_properties ( {
nametag = minetest.colorize ( " #059FFF " , " [✔] " ) .. " " .. player : get_player_name ( ) ,
} )
end
end )
end )