-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
96 lines (85 loc) · 3.21 KB
/
init.lua
File metadata and controls
96 lines (85 loc) · 3.21 KB
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
-- EclipseCore
-- Copyright (C) 2025 ProunceDev
-- MIT License
dofile(core.get_modpath("eclipse_core") .. "/restrictions.lua")
local settings = {
require_official_build = core.settings:get("eclipse_core_require_official_build") or false,
log_incorrect_clients = core.settings:get("eclipse_core_log_incorrect_clients") or true,
kick_message = core.settings:get("eclipse_core_kick_message") or "You must use an official build of Eclipse client to join this server.",
}
eclipse_core = {
player_data = {},
}
local backend_url = core.settings:get("eclipse_core_backend_url") or "http://teamacedia.baselinux.net:22222"
local server_address = core.settings:get("server_address") or "0.0.0.0"
local server_port = tonumber(core.settings:get("port")) or 30000
local latest_build_string = ""
local http = core.request_http_api()
if not http then
core.log("error", "EclipseCore: HTTP API not available, Eclipse client enforcement disabled.")
core.log("error", "EclipseCore: Please add 'eclipse_core' to 'secure.http_mods' and restart the server.")
return
end
local function async_http_get(data, callback)
local handle = http.fetch_async(data)
local function check_response()
local result = http.fetch_async_get(handle)
if not result.completed then
core.after(0.1, check_response)
else
callback(result)
end
end
check_response()
end
async_http_get({url = "https://api.ipify.org", timeout = 5}, function(result)
if result.succeeded then
server_address = result.data:gsub("%s+", "")
core.log("info", "EclipseCore: Detected public IP address as "..server_address)
else
core.log("error", "EclipseCore: Failed to fetch public IP: "..tostring(result.code))
end
end)
async_http_get({url = backend_url .. "/api/latest_build", timeout = 5}, function(result)
if result.succeeded and result.code == 200 then
latest_build_string = core.parse_json(result.data).latest_build
core.log("info", "EclipseCore: Latest Eclipse client build is "..latest_build_string)
else
core.log("error", "EclipseCore: Failed to fetch latest build string: "..tostring(result.code))
end
end)
core.register_on_joinplayer(function(player)
core.after(1, function()
local pname = player:get_player_name()
async_http_get(
{
url = backend_url .. "/api/server/get_player_info",
post_data=core.write_json({
server_address = server_address,
server_port = tostring(server_port),
username = pname
}),
extra_headers = {
"Content-Type: application/json"
},
timeout = 5
}, function(result)
if result.succeeded then
if result.code == 200 then
local json = core.parse_json(result.data)
eclipse_core.player_data[pname] = json
local data = eclipse_core.player_data[pname]
if settings.log_incorrect_clients and data.official_build == false then
core.log("warning", "EclipseCore: Player " .. pname .. " joined with a modified Eclipse client.")
end
if settings.log_incorrect_clients and data.build_string ~= latest_build_string then
core.log("warning", "EclipseCore: Player " .. pname .. " joined with an outdated Eclipse client.")
end
if settings.require_official_build and data.official_build == false then
core.kick_player(pname, settings.kick_message)
end
end
end
end)
end)
end)