-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
135 lines (124 loc) · 6.77 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
local http = minetest.request_http_api()
local version = "0.7.4"
local modpath = minetest.get_modpath(minetest.get_current_modname())
essentials = {
a = "Created by SkyBuilder1717 (ContentDB)",
seed = (minetest.settings:get_bool("essentials_seed") or false),
biome = (minetest.settings:get_bool("essentials_biome") or true),
killed_by = (minetest.settings:get_bool("essentials_killed_by") or true),
admin_ip_check = (minetest.settings:get_bool("essentials_ip_verified") or true),
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"),
add_privs = (minetest.settings:get_bool("essentials_additional_privileges") or true),
have_unified_inventory = minetest.get_modpath("unified_inventory"),
trusted_ip_users = {}
}
if essentials.watermark == nil then
essentials.watermark = true
end
minetest.log("action", "[Essentials] Mod initialised. Version: ".. version)
minetest.log("action", "\n███████╗░██████╗░██████╗███████╗███╗░░██╗████████╗██╗░█████╗░██╗░░░░░░██████╗\n██╔════╝██╔════╝██╔════╝██╔════╝████╗░██║╚══██╔══╝██║██╔══██╗██║░░░░░██╔════╝\n█████╗░░╚█████╗░╚█████╗░█████╗░░██╔██╗██║░░░██║░░░██║███████║██║░░░░░╚█████╗░\n██╔══╝░░░╚═══██╗░╚═══██╗██╔══╝░░██║╚████║░░░██║░░░██║██╔══██║██║░░░░░░╚═══██╗\n███████╗██████╔╝██████╔╝███████╗██║░╚███║░░░██║░░░██║██║░░██║███████╗██████╔╝\n╚══════╝╚═════╝░╚═════╝░╚══════╝╚═╝░░╚══╝░░░╚═╝░░░╚═╝╚═╝░░╚═╝╚══════╝╚═════╝░\n[Essentials] "..essentials.a)
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
minetest.after(0, function()
core.chat_send_all(dump(essentials))
end)
minetest.after(0, function()
if essentials.check_for_updates then
minetest.log("action", "[Essentials] Checking for updates...")
if not minetest.request_insecure_environment() then
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
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
minetest.log("error", "[Essentials] Versions doesnt match! something wrong seems YOU ARE USING OLDER VERSION!")
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
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")
end
end
end)
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
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
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)
--==[[ Connections ]]==--
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")
dofile(modpath.."/ui/ip.lua")
dofile(modpath.."/ui/rename_me.lua")
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)