-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcore.lua
More file actions
164 lines (134 loc) · 4.34 KB
/
Copy pathcore.lua
File metadata and controls
164 lines (134 loc) · 4.34 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
MPAPI = SMODS.current_mod
-- Add mod root, lib/ and networking/ to package.path so the MQTT thread can
-- require("mqtt") (vendored luamqtt at lib/mqtt/init.lua) and require("openssl_ffi")
package.path = MPAPI.path
.. '/?.lua;'
.. MPAPI.path
.. '/?/init.lua;'
.. MPAPI.path
.. '/lib/?.lua;'
.. MPAPI.path
.. '/lib/?/init.lua;'
.. MPAPI.path
.. '/networking/?.lua;'
.. package.path
-----------------------------
-- CORE FUNCTIONS
-----------------------------
function MPAPI.sendDebugMessage(msg)
sendDebugMessage(msg, MPAPI.id)
end
function MPAPI.sendWarnMessage(msg)
sendWarnMessage(msg, MPAPI.id)
end
function MPAPI.load_mpapi_file(file)
local chunk, err = SMODS.load_file(file, MPAPI.id)
if not chunk then
error('MPAPI: failed to find or compile file \'' .. file .. '\': ' .. tostring(err), 0)
end
local ok, result = pcall(chunk)
if not ok then
error('MPAPI: failed to execute file \'' .. file .. '\': ' .. tostring(result), 0)
end
return result
end
function MPAPI.load_mpapi_dir(directory, recursive)
recursive = recursive or false
local dir_path = MPAPI.path .. '/' .. directory
local items = NFS.getDirectoryItemsInfo(dir_path)
for _, item in ipairs(items) do
local path = directory .. '/' .. item.name
if item.type ~= 'directory' then
MPAPI.load_mpapi_file(path)
elseif recursive then
MPAPI.load_mpapi_dir(path, recursive)
end
end
end
-----------------------------
-- DOMAIN & CONTRACTS
-----------------------------
-- Load enums and contracts first: networking and api modules reference them at
-- load time (e.g. networking/connection.lua uses MPAPI.ConnectionState).
MPAPI.load_mpapi_dir('domain', true)
MPAPI.load_mpapi_dir('contracts', true)
-----------------------------
-- NETWORKING
-----------------------------
MPAPI.networking = {}
MPAPI.load_mpapi_file('networking/openssl_ffi.lua')
if MPAPI.networking.openssl_ffi then
MPAPI.sendDebugMessage('OpenSSL FFI module loaded')
local available = MPAPI.networking.openssl_ffi.available()
if available then
local ctx, err = MPAPI.networking.openssl_ffi.new_context({ verify = false })
if ctx then
MPAPI.networking.openssl_ffi.free_context(ctx)
else
MPAPI.sendWarnMessage('SSL context creation FAILED: ' .. tostring(err))
end
end
else
MPAPI.sendWarnMessage('OpenSSL FFI module failed to load')
end
MPAPI.load_mpapi_file('networking/mqtt_client.lua')
if MPAPI.networking.mqtt_client then
MPAPI.sendDebugMessage('MQTT client wrapper loaded')
else
MPAPI.sendWarnMessage('MQTT client wrapper failed to load')
end
MPAPI.load_mpapi_file('networking/steam.lua')
if MPAPI.networking.steam then
MPAPI.sendDebugMessage('Steam module loaded (G.STEAM available after love.load)')
else
MPAPI.sendWarnMessage('Steam module failed to load')
end
MPAPI.load_mpapi_file('networking/api_client.lua')
MPAPI.load_mpapi_file('networking/connection.lua')
-----------------------------
-- FILE LOADING & STARTUP
-----------------------------
function MPAPI.update()
-- This will be intentionally hooked by other files in the mod
end
MPAPI._internal = {}
-----------------------------
-- RANKED-MODE ANTI-CHEAT (launcher<->mod supervision channel)
-----------------------------
-- Entirely inert unless BET_RANKED_SUPERVISOR_PORT/_SECRET are set (a
-- Ranked-mode launch via BET only) - see anticheat/launcher_channel.lua's
-- header comment. Loaded here (after the MPAPI.update stub above, before
-- lib/api/ui) since it chain-wraps MPAPI.update itself, the same
-- convention api/connection/lifecycle.lua uses for the MQTT client.
MPAPI.load_mpapi_file('anticheat/crypto.lua')
MPAPI.load_mpapi_file('anticheat/launcher_channel.lua')
MPAPI.load_mpapi_dir('lib')
MPAPI.load_mpapi_dir('api', true)
MPAPI.load_mpapi_dir('ui', true)
-- Load dev overrides if the dev/ directory exists (stripped in release builds) --
-- absence here is expected, so guard explicitly rather than relying on
-- load_mpapi_file's (now-fatal) missing-file path.
if NFS.getInfo(MPAPI.path .. '/dev/init.lua') then
MPAPI.load_mpapi_file('dev/init.lua')
end
G.E_MANAGER:add_event(Event({
blockable = false,
blocking = false,
no_delete = true,
func = function()
MPAPI.update()
end,
}))
G.E_MANAGER:add_event(Event({
blockable = false,
blocking = false,
func = function()
if not G.STEAM then
return false
end
MPAPI._internal.set_ready(true)
MPAPI.connect()
MPAPI._internal.run_ready_callbacks()
return true
end,
}))