-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodmain.lua
More file actions
102 lines (94 loc) · 4.33 KB
/
Copy pathmodmain.lua
File metadata and controls
102 lines (94 loc) · 4.33 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
97
98
99
100
101
102
-- Axogc Platform mod entry.
--
-- Topology: a DST "cluster" runs N shards (typically Forest=Master + Caves=Slave).
-- HTTP bridge work is per-cluster, so it must run exactly once — on the Master.
-- Slave shards early-return below; they still load the mod files (the game
-- decides per-shard), but exit before doing anything.
--
-- Module loading: DST mods do not expose `require` for files under the mod
-- folder. We use modimport, which evaluates each file in the mod sandbox.
-- Shared state lives in GLOBAL.AxoPlatform; every module top-locals
-- local Platform = GLOBAL.AxoPlatform
-- and appends its public functions onto it. Load order below = dependency
-- order; a module may only call into modules listed above it.
if not GLOBAL.TheNet:GetIsServer() then return end
if not GLOBAL.TheNet:GetIsMasterSimulation() then return end
GLOBAL.AxoPlatform = GLOBAL.AxoPlatform or {}
local Platform = GLOBAL.AxoPlatform
Platform.MODNAME = modname
-- Expose commonly-used Lua globals to every modimported file. The DST mod
-- sandbox (CreateEnvironment in scripts/mods.lua) only auto-injects
-- pairs / ipairs / print / math / table / type / string / tostring / require
-- / Class — everything else (pcall, tonumber, os, ...) must come via GLOBAL.
-- Assigning here sets them on the shared `env` table so every later
-- modimport sees them as bare names.
pcall = GLOBAL.pcall
tonumber = GLOBAL.tonumber
os = GLOBAL.os
-- Pull deployment-specific values from the per-cluster modoverrides.lua.
-- The option names match the entries declared in modinfo.lua. Admins set
-- real values like:
-- ["axogc-platform"] = {
-- enabled = true,
-- configuration_options = {
-- base_url = "https://www.axogc.net",
-- token = "abcdef...",
-- },
-- }
-- Missing config is tolerated here — settings.lua / init.lua catch the
-- empty-string case and log a clear "bridge disabled" warning.
Platform.BASE_URL = (GetModConfigData("base_url") or ""):gsub("/+$", "")
Platform.TOKEN = GetModConfigData("token") or ""
modimport("scripts/platform/settings.lua")
modimport("scripts/platform/util.lua")
modimport("scripts/platform/transport/http.lua")
modimport("scripts/platform/transport/poll.lua")
modimport("scripts/platform/stats/axes.lua")
modimport("scripts/platform/observation/stats.lua")
modimport("scripts/platform/observation/walk_sampler.lua")
modimport("scripts/platform/chat/chat.lua")
modimport("scripts/platform/commands/bind.lua")
modimport("scripts/platform/handlers/notify.lua")
modimport("scripts/platform/handlers/broadcast.lua")
modimport("scripts/platform/handlers/kick.lua")
modimport("scripts/platform/handlers/chat_from_web.lua")
modimport("scripts/platform/handlers/stats_fetch.lua")
modimport("scripts/platform/handlers/whitelist.lua")
modimport("scripts/platform/handlers/metrics_list.lua")
modimport("scripts/platform/handlers/leaderboard_fetch.lua")
modimport("scripts/platform/handlers/admin_command.lua")
modimport("scripts/platform/handlers/dispatch.lua")
modimport("scripts/platform/rank/snapshot.lua")
modimport("scripts/platform/observation/events.lua")
modimport("scripts/platform/init.lua")
-- Per-player init: fires when each player entity spawns. The handler
-- subscribes per-player events (death / killed / builditem).
AddPlayerPostInit(function(inst)
Platform.on_player_post_init(inst)
end)
-- World postinit: world entity exists, safe to schedule periodic tasks and
-- subscribe to world-level events (ms_playerjoined / ms_playerleft).
AddPrefabPostInit("world", function(inst)
Platform.on_world_post_init(inst)
end)
-- /bind <CODE>: register as a real DST user command (instead of intercepting
-- chat). Client-side parsing keeps the verification code out of public chat.
-- See scripts/platform/commands/bind.lua for the rationale and the handler.
AddUserCommand("bind", {
prettyname = "绑定平台账号",
desc = "Bind your in-game name to your platform account.",
permission = GLOBAL.COMMAND_PERMISSION.USER,
slash = true,
usermenu = false,
servermenu = false,
params = { "code" },
paramsoptional = { false },
vote = false,
serverfn = function(params, caller)
-- serverfn runs on the master sim (this shard). caller is the
-- player entity issuing the command.
if caller and params and params.code then
Platform.bind_handle(caller, params.code)
end
end,
})