diff --git a/modules/api/v2/patched/inventory.lua b/modules/api/v2/patched/inventory.lua index d5a236b..f490479 100644 --- a/modules/api/v2/patched/inventory.lua +++ b/modules/api/v2/patched/inventory.lua @@ -1,5 +1,4 @@ local inventories_manager = start_require("server:lib/private/sandbox/inventories_manager") - local global_inventory = _G["inventory"] PACK_ENV["inventory"] = table.deep_copy(global_inventory) diff --git a/modules/globals.lua b/modules/globals.lua index 4bdf078..871027a 100644 --- a/modules/globals.lua +++ b/modules/globals.lua @@ -25,6 +25,7 @@ RESERVED_USERNAMES = { IS_RUNNING = false IS_FIRST_RUN = false IS_RELEASE = false +IS_HEADLESS = true PROTOCOL_VERSION = "3.2" API_VERSION = "2" PROTOCOL_STATES = { diff --git a/modules/init/engine_patcher.lua b/modules/init/engine_patcher.lua index e784765..ed5e68c 100644 --- a/modules/init/engine_patcher.lua +++ b/modules/init/engine_patcher.lua @@ -10,31 +10,33 @@ entities["despawn"] = function(eid) entities_manager.despawn(eid) end --- Патчим skeleton, ибо кому-то пришла ахуительная идея снести нахуй скелеты в хеадлессе ПОЛНОСТЬЮ НАХУЙ -local skeletons_info = { - textures = {}, - models = {} -} - -__skeleton.set_texture = function(id, key, texture) - table.set_default(skeletons_info.textures, id, {})[key] = texture -end +if IS_HEADLESS then + -- Патчим skeleton, ибо кому-то пришла ахуительная идея снести нахуй скелеты в хеадлессе ПОЛНОСТЬЮ НАХУЙ + local skeletons_info = { + textures = {}, + models = {} + } + + __skeleton.set_texture = function(id, key, texture) + table.set_default(skeletons_info.textures, id, {})[key] = texture + end -__skeleton.set_model = function(id, key, model) - table.set_default(skeletons_info.models, id, {})[key] = model -end + __skeleton.set_model = function(id, key, model) + table.set_default(skeletons_info.models, id, {})[key] = model + end -__skeleton.get_texture = function(id, key) - local skeleton = skeletons_info.textures[id] - if skeleton then - return skeleton[key] + __skeleton.get_texture = function(id, key) + local skeleton = skeletons_info.textures[id] + if skeleton then + return skeleton[key] + end end -end -__skeleton.get_model = function(id, key) - local skeleton = skeletons_info.models[id] - if skeleton then - return skeleton[key] + __skeleton.get_model = function(id, key) + local skeleton = skeletons_info.models[id] + if skeleton then + return skeleton[key] + end end end diff --git a/modules/init/server.lua b/modules/init/server.lua index 7752e26..86a3986 100644 --- a/modules/init/server.lua +++ b/modules/init/server.lua @@ -1,7 +1,4 @@ local lib = require "lib/private/min" -local protect = require "lib/private/protect" - -if protect.protect_require() then return end local world = lib.world @@ -11,7 +8,7 @@ logger.log("std initialized") do if not file.exists(CONFIG_PATH) then file.write(CONFIG_PATH, file.read(PACK_ID .. ":resources/server_config.json")) - IS_FIRST_RUN = true + if IS_HEADLESS then IS_FIRST_RUN = true end end end @@ -23,7 +20,9 @@ do if CONFIG.server.chunks_loading_distance > 255 then CONFIG.server.chunks_loading_distance = 255 - logger.log("Chunks distance is too high. Please select a value in the range of 0-255. The current chunks distance is set to 255", 'W') + logger.log( + "Chunks distance is too high. Please select a value in the range of 0-255. The current chunks distance is set to 255", + 'W') end CONFIG = table.freeze(CONFIG) @@ -46,18 +45,20 @@ end logger.log("sandbox const initialized") ---Загружаем настройки -do - local settings = { - ["chunks_loading_distance"] = "chunks.load-distance", - ["chunks_loading_speed"] = "chunks.load-speed" - } +if IS_HEADLESS then + --Загружаем настройки + do + local settings = { + ["chunks_loading_distance"] = "chunks.load-distance", + ["chunks_loading_speed"] = "chunks.load-speed" + } - for cname, sname in pairs(settings) do - app.set_setting(sname, CONFIG.server[cname]) - end + for cname, sname in pairs(settings) do + app.set_setting(sname, CONFIG.server[cname]) + end - app.set_setting("debug.do-write-lights", false) + app.set_setting("debug.do-write-lights", false) + end end --Другое @@ -68,4 +69,4 @@ end logger.log("settings initialized") world.preparation_main() -logger.log("world initialized") \ No newline at end of file +logger.log("world initialized") diff --git a/modules/lib/private/accounts/account.lua b/modules/lib/private/accounts/account.lua index 4c2f087..65bcdf4 100644 --- a/modules/lib/private/accounts/account.lua +++ b/modules/lib/private/accounts/account.lua @@ -1,6 +1,3 @@ -local protect = require "lib/private/protect" -if protect.protect_require() then return end - local metadata = start_require "lib/private/files/metadata" local lib = require "lib/private/min" local account = {} diff --git a/modules/lib/private/accounts/account_manager.lua b/modules/lib/private/accounts/account_manager.lua index 209836a..0573cd8 100644 --- a/modules/lib/private/accounts/account_manager.lua +++ b/modules/lib/private/accounts/account_manager.lua @@ -1,6 +1,3 @@ -local protect = require "lib/private/protect" -if protect.protect_require() then return end - local Account = require "lib/private/accounts/account" local sandbox = require "lib/private/sandbox/sandbox" local container = require "lib/private/common/container" diff --git a/modules/lib/private/common/container.lua b/modules/lib/private/common/container.lua index 2203f12..e8456f7 100644 --- a/modules/lib/private/common/container.lua +++ b/modules/lib/private/common/container.lua @@ -1,6 +1,3 @@ -local protect = require "lib/private/protect" -if protect.protect_require() then return end - local module = { player_online = {}, clients_all = {}, @@ -44,4 +41,4 @@ function module.clients_all.get() return DATA.clients_all end -return module \ No newline at end of file +return module diff --git a/modules/lib/private/common/culling.lua b/modules/lib/private/common/culling.lua index 550bf23..058d9bc 100644 --- a/modules/lib/private/common/culling.lua +++ b/modules/lib/private/common/culling.lua @@ -1,10 +1,9 @@ -local protect = require "lib/private/protect" local sandbox = require "lib/private/sandbox/sandbox" local module = {} function module.in_radius(center, radius, dot) - return ((center.x - dot.x)^2 + (center.y - dot.y)^2)^0.5 <= radius + return ((center.x - dot.x) ^ 2 + (center.y - dot.y) ^ 2) ^ 0.5 <= radius end -return protect.protect_return(module) \ No newline at end of file +return module diff --git a/modules/lib/private/common/timeout_executor.lua b/modules/lib/private/common/timeout_executor.lua index edbab95..bc40587 100644 --- a/modules/lib/private/common/timeout_executor.lua +++ b/modules/lib/private/common/timeout_executor.lua @@ -1,5 +1,3 @@ -local protect = require "lib/private/protect" - local module = {} local delayed_responses = {} @@ -11,11 +9,11 @@ function module.push(func, args, time_out, step) time_out = time_out, step = step or 0 } -) + ) end function module.process() - for i=#delayed_responses, 1, -1 do + for i = #delayed_responses, 1, -1 do local responce = delayed_responses[i] local cur_time = time.uptime() if cur_time - responce.time_create > responce.time_out then @@ -31,4 +29,4 @@ function module.process() end end -return protect.protect_return(module) \ No newline at end of file +return module diff --git a/modules/lib/private/entities/entities_manager.lua b/modules/lib/private/entities/entities_manager.lua index 3ea1423..c3bdd27 100644 --- a/modules/lib/private/entities/entities_manager.lua +++ b/modules/lib/private/entities/entities_manager.lua @@ -1,6 +1,3 @@ -local protect = require "lib/private/protect" -if protect.protect_require() then return end - local protocol = require "multiplayer/protocol-kernel/protocol" local server_echo = require "multiplayer/server/server_echo" diff --git a/modules/lib/private/files/metadata.lua b/modules/lib/private/files/metadata.lua index 502ca3a..6b0932a 100644 --- a/modules/lib/private/files/metadata.lua +++ b/modules/lib/private/files/metadata.lua @@ -1,6 +1,3 @@ -local protect = require "lib/private/protect" -if protect.protect_require() then return end - local bson = require "lib/private/files/bson" local module = { diff --git a/modules/lib/private/gfx/audio_manager.lua b/modules/lib/private/gfx/audio_manager.lua index 2649fa1..d12bf9c 100644 --- a/modules/lib/private/gfx/audio_manager.lua +++ b/modules/lib/private/gfx/audio_manager.lua @@ -2,13 +2,9 @@ Work In Progress ]] -local protect = require "lib/private/protect" +local module = {} -if protect.protect_require() then return end - -local module = { } - -local SPEAKERS = { } +local SPEAKERS = {} local SOUNDS_DURATIONS = {} local aliveSpeakersCount = 0 @@ -18,7 +14,7 @@ local NEXT_ID = 1 local function ensureSpeaker(id) if not SPEAKERS[id] then - error("undefined speaker with id '"..id.."'") + error("undefined speaker with id '" .. id .. "'") end end @@ -39,14 +35,14 @@ end local function ensureArgs(args, names) for i = 1, #args do if not args[i] then - error("'"..names[i].."' argument is undefined") + error("'" .. names[i] .. "' argument is undefined") end end end local function checkVolPitch(num, name) if num < 0 or num > 1 then - error("invalid "..name) + error("invalid " .. name) end end @@ -79,7 +75,9 @@ local function basePlay(name, x, y, z, volume, pitch, channel, loop) local sound = { path = name, - x = x, y = y, z = z, + x = x, + y = y, + z = z, volume = volume, pitch = pitch, channel = channel, @@ -281,7 +279,9 @@ function module.get_time_left(speaker) local sound = SPEAKERS[speaker] if not SOUNDS_DURATIONS[sound.path] then - logger.log('The "audio.get_duration" function in the API returns 0 for technical reasons, please use "audio.register_duration" to fix it', 'W') + logger.log( + 'The "audio.get_duration" function in the API returns 0 for technical reasons, please use "audio.register_duration" to fix it', + 'W') return 0 else local playback = sound.offsetTime + SOUNDS_DURATIONS[sound.path] - module.get_time(speaker) @@ -324,4 +324,4 @@ function module.get_in_radius(x, y, z, radius) return speakers end -return module \ No newline at end of file +return module diff --git a/modules/lib/private/gfx/blockwraps_manager.lua b/modules/lib/private/gfx/blockwraps_manager.lua index 2eed6ce..8ec82dc 100644 --- a/modules/lib/private/gfx/blockwraps_manager.lua +++ b/modules/lib/private/gfx/blockwraps_manager.lua @@ -1,7 +1,3 @@ -local protect = require "lib/private/protect" - -if protect.protect_require() then return end - local module = {} local WRAPS = {} @@ -90,4 +86,4 @@ function module.get_in_radius(x, z, radius) return wraps end -return module \ No newline at end of file +return module diff --git a/modules/lib/private/gfx/particles_manager.lua b/modules/lib/private/gfx/particles_manager.lua index cfb87d4..6d9dbc7 100644 --- a/modules/lib/private/gfx/particles_manager.lua +++ b/modules/lib/private/gfx/particles_manager.lua @@ -1,7 +1,3 @@ -local protect = require "lib/private/protect" - -if protect.protect_require() then return end - local module = {} local PARTICLES = {} @@ -10,7 +6,7 @@ local MAX_PID = 0 function module.emit(origin, count, preset, extension) local pid = MAX_PID - functions.args_check("emit", {origin = origin or false, count = count or false, preset = preset or false}) + functions.args_check("emit", { origin = origin or false, count = count or false, preset = preset or false }) PARTICLES[tohex(pid)] = { origin = origin, @@ -68,4 +64,4 @@ function module.get_in_radius(x, z, radius) return particles end -return module \ No newline at end of file +return module diff --git a/modules/lib/private/gfx/text3d_manager.lua b/modules/lib/private/gfx/text3d_manager.lua index a46cdf6..57352cb 100644 --- a/modules/lib/private/gfx/text3d_manager.lua +++ b/modules/lib/private/gfx/text3d_manager.lua @@ -1,10 +1,6 @@ -local protect = require "lib/private/protect" +local module = {} -if protect.protect_require() then return end - -local module = { } - -local TEXTS = { } +local TEXTS = {} local NEXT_ID = 1 @@ -72,7 +68,7 @@ end function module.get_axis_x(id) ensureText(id) - return TEXTS[id].axisX or {1, 0, 0} + return TEXTS[id].axisX or { 1, 0, 0 } end function module.set_axis_x(id, axis) @@ -83,7 +79,7 @@ end function module.get_axis_y(id) ensureText(id) - return TEXTS[id].axisY or {0, 1, 0} + return TEXTS[id].axisY or { 0, 1, 0 } end function module.set_axis_y(id, axis) @@ -123,4 +119,4 @@ function module.get_in_radius(x, z, radius) return texts end -return module \ No newline at end of file +return module diff --git a/modules/lib/private/gfx/weather_manager.lua b/modules/lib/private/gfx/weather_manager.lua index 2d84a12..c7000fe 100644 --- a/modules/lib/private/gfx/weather_manager.lua +++ b/modules/lib/private/gfx/weather_manager.lua @@ -1,7 +1,3 @@ -local protect = require "lib/private/protect" - -if protect.protect_require() then return end - local bson = require "lib/private/files/bson" local module = {} @@ -13,8 +9,8 @@ local WRITE_PATH = "world:server_resources/weather.bson" local WEATHER_SEED_START = nil local WEATHER_SEED_END = nil -local WEATHER_CYCLE_DURATION = 20000 -- Полный цикл 20 часов (10 часов в каждую сторону) -local LAST_CYCLE_UPDATE = 0 -- Время последнего обновления цикла +local WEATHER_CYCLE_DURATION = 20000 -- Полный цикл 20 часов (10 часов в каждую сторону) +local LAST_CYCLE_UPDATE = 0 -- Время последнего обновления цикла local function generate_weather_seeds() @@ -22,7 +18,7 @@ local function generate_weather_seeds() local combined_seed = bit.bxor(world.get_seed(), current_cycle) WEATHER_SEED_START = bit.band(combined_seed, 0x598CC129D23) - WEATHER_SEED_END = bit.band(combined_seed, 0x6D82EDA8C33) + WEATHER_SEED_END = bit.band(combined_seed, 0x6D82EDA8C33) LAST_CYCLE_UPDATE = current_cycle * WEATHER_CYCLE_DURATION end @@ -50,7 +46,7 @@ local function get_weather_map(x, z, gen_map) return start_map end -events.on("server:save", function () +events.on("server:save", function() file.mktree( WRITE_PATH, bson.serialize({ @@ -103,7 +99,7 @@ function module.remove_weather(wid) end local function point_get_by_pos(weather, x, z) - if ( weather.time_start + weather.duration < world.get_total_time() ) and weather.duration ~= -1 then + if (weather.time_start + weather.duration < world.get_total_time()) and weather.duration ~= -1 then module.remove_weather(weather.wid) if weather.on_finished then weather.on_finished(weather) @@ -124,7 +120,7 @@ local function heightmap_get_by_pos(weather, x, z) end local map = get_weather_map(x, z, weather.heightmap_generator) - local res = map:at({x, z}) + local res = map:at({ x, z }) local min, max = weather.range[1], weather.range[2] if res >= min and res <= max then @@ -157,4 +153,4 @@ end module.load() -return module \ No newline at end of file +return module diff --git a/modules/lib/private/hash.lua b/modules/lib/private/hash.lua index cf1e834..31a2438 100644 --- a/modules/lib/private/hash.lua +++ b/modules/lib/private/hash.lua @@ -1,8 +1,7 @@ -local module = {} - -local protect = require "lib/private/protect" local sha256 = require("lib/private/sha256") +local module = {} + for key, func in pairs(sha256) do module[key] = func end @@ -52,4 +51,4 @@ function module.equals(str, hash) return false end -return protect.protect_return(module) +return module diff --git a/modules/lib/private/min.lua b/modules/lib/private/min.lua index 5542c1d..4d6a803 100644 --- a/modules/lib/private/min.lua +++ b/modules/lib/private/min.lua @@ -1,4 +1,3 @@ -local protect = require "lib/private/protect" local hash = require "lib/private/hash" local lib = { @@ -9,11 +8,12 @@ local lib = { hash = hash } -ROOT = 0 +local ROOT = 0 ---WORLD--- function lib.world.preparation_main() + if not IS_HEADLESS then return end --Загружаем мир local packs = table.freeze_unpack(CONFIG.game.content_packs) local plugins = table.freeze_unpack(CONFIG.game.plugins) @@ -75,23 +75,31 @@ end function lib.world.open_main() logger.log("Discovery of the main world") - app.reset_content({ "server" }) - app.open_world(CONFIG.game.main_world) - player.set_suspended(ROOT, false) - time.post_runnable(function() - player.set_noclip(ROOT, true) - player.set_flight(ROOT, true) - player.set_pos(ROOT, 0, 262, 0) + if IS_HEADLESS then + app.reset_content({ "server" }) + app.open_world(CONFIG.game.main_world) + player.set_suspended(ROOT, false) + + time.post_runnable(function() + player.set_noclip(ROOT, true) + player.set_flight(ROOT, true) + player.set_pos(ROOT, 0, 262, 0) - local root_entity = entities.get(player.get_entity(ROOT)) + local root_entity = entities.get(player.get_entity(ROOT)) - PLAYER_ENTITY_ID = root_entity:def_index() - end) + PLAYER_ENTITY_ID = root_entity:def_index() + end) - -- Загружаем команды - do - require "init/cmd" + -- Загружаем команды + do + require "init/cmd" + end + else + time.post_runnable(function() + local root_entity = entities.get(player.get_entity(ROOT)) + PLAYER_ENTITY_ID = root_entity:def_index() + end) end end @@ -157,4 +165,4 @@ function lib.validate.plugins() return true end -return protect.protect_return(lib) +return lib diff --git a/modules/lib/private/protect.lua b/modules/lib/private/protect.lua deleted file mode 100644 index a9394b2..0000000 --- a/modules/lib/private/protect.lua +++ /dev/null @@ -1,78 +0,0 @@ -local module = {} - -local LOG_ACCESS_DENIES = "Unauthorized Access attempt from " -local ACCESS_DENIES = "Access denied" - -local function parse_path(path) - if table.has({ - "main.lua", "=[C]", "tests.lua", "script:main.lua", "script:tests.lua" - }, path) then - return "server", "" - end - - local index = string.find(path, ':') - if index == nil then - error("invalid path syntax (':' missing)") - end - return string.sub(path, 1, index-1), string.sub(path, index+1, -1) -end - -local function get_traceback_length() - local traceback = debug.traceback() - local count = 0 - - for _ in traceback:gmatch("[^\n]+") do - count = count + 1 - end - - return count-2 -end - -local function freeze(original) - local copy = {} - setmetatable(copy, { - __index = original, - __metatable = false, - __newindex = function(t, key, value) - logger.log("Unauthorized Access attempt to the system meta-table", "W") - end, - }) - - return copy -end - -function module.protect_return(val) - for call=1, get_traceback_length() do - local source = debug.getinfo(call).source - - local prefix, path = parse_path(source) - if prefix == "server" and path:find("api") then - break - end - - if prefix ~= "server" and prefix ~= "core" then - logger.log(LOG_ACCESS_DENIES .. source, "W") - return ACCESS_DENIES - end - end - - return val -end - -function module.protect_require() - for call=1, get_traceback_length() do - local source = debug.getinfo(call).source - - local prefix, path = parse_path(source) - if prefix == "server" and path:find("api") then - break - end - - if prefix ~= "server" and prefix ~= "core" then - logger.log(LOG_ACCESS_DENIES .. source, "W") - return ACCESS_DENIES - end - end -end - -return freeze(module) \ No newline at end of file diff --git a/modules/lib/private/sandbox/classes/player.lua b/modules/lib/private/sandbox/classes/player.lua index 075e380..b51bae9 100644 --- a/modules/lib/private/sandbox/classes/player.lua +++ b/modules/lib/private/sandbox/classes/player.lua @@ -1,6 +1,3 @@ -local protect = require "lib/private/protect" -if protect.protect_require() then return end - local metadata = start_require "lib/private/files/metadata" local Player = {} Player.__index = Player diff --git a/modules/lib/private/sandbox/inventories_manager.lua b/modules/lib/private/sandbox/inventories_manager.lua index f24caa5..a8dc6f2 100644 --- a/modules/lib/private/sandbox/inventories_manager.lua +++ b/modules/lib/private/sandbox/inventories_manager.lua @@ -1,4 +1,3 @@ -local protect = require "lib/private/protect" local protocol = require "multiplayer/protocol-kernel/protocol" local account_manager = require "lib/private/accounts/account_manager" local sandbox = require "lib/private/sandbox/sandbox" @@ -412,4 +411,4 @@ function module.interact(player, id, slot, action, mode, item_id, client_checksu return true end -return protect.protect_return(module) +return module diff --git a/modules/lib/private/sandbox/sandbox.lua b/modules/lib/private/sandbox/sandbox.lua index de80659..deeb101 100644 --- a/modules/lib/private/sandbox/sandbox.lua +++ b/modules/lib/private/sandbox/sandbox.lua @@ -1,4 +1,3 @@ -local protect = require "lib/private/protect" local container = require "lib/private/common/container" local Player = require "lib/private/sandbox/classes/player" local metadata = require "lib/private/files/metadata" @@ -51,7 +50,12 @@ function module.join_player(username, account) return end - local pid = player.create(account_player.username, table.count_pairs(metadata.players.get_all()) + 1) + local pid = ROOT_PID + if IS_HEADLESS then + local next_pid = table.count_pairs(metadata.players.get_all()) + 1 + pid = player.create(account_player.username, next_pid) + end + logger.log(string.format('Player [#%s] has been created with pid: %s', logger.shorted(identity), pid)) account_player:set("pid", pid) account_player:set("entity_id", player.get_entity(account_player.pid)) @@ -296,4 +300,4 @@ function module.by_invid.get(invid) end end -return protect.protect_return(module) +return module diff --git a/modules/multiplayer/server/chat/chat.lua b/modules/multiplayer/server/chat/chat.lua index bd5c672..b270d6c 100644 --- a/modules/multiplayer/server/chat/chat.lua +++ b/modules/multiplayer/server/chat/chat.lua @@ -1,4 +1,3 @@ -local protect = require "lib/private/protect" local protocol = require "multiplayer/protocol-kernel/protocol" local server_echo = require "multiplayer/server/server_echo" local states = require "multiplayer/server/chat/chat_states" @@ -143,4 +142,4 @@ function module.get_handlers() return pairs_handlers end -return protect.protect_return(module) +return module diff --git a/modules/multiplayer/server/chat/chat_states.lua b/modules/multiplayer/server/chat/chat_states.lua index a67b772..add9899 100644 --- a/modules/multiplayer/server/chat/chat_states.lua +++ b/modules/multiplayer/server/chat/chat_states.lua @@ -1,7 +1,3 @@ -local protect = require "lib/private/protect" - -if protect.protect_require() then return end - local module = {} local states = {} @@ -60,4 +56,4 @@ function module.get_state(client) return states[client] end -return module \ No newline at end of file +return module diff --git a/modules/multiplayer/server/client_pipe.lua b/modules/multiplayer/server/client_pipe.lua index 4735073..636caa5 100644 --- a/modules/multiplayer/server/client_pipe.lua +++ b/modules/multiplayer/server/client_pipe.lua @@ -1,6 +1,5 @@ local Pipeline = require "lib/public/pipeline" local protocol = require "multiplayer/protocol-kernel/protocol" -local protect = require "lib/private/protect" local sandbox = require "lib/private/sandbox/sandbox" local inventories_manager = require "lib/private/sandbox/inventories_manager" local matches = require "multiplayer/server/handlers/general_matches" @@ -584,4 +583,4 @@ ClientPipe:add_middleware(function(client) return client end) -return protect.protect_return(ClientPipe) +return ClientPipe diff --git a/modules/multiplayer/server/handlers/general_matches.lua b/modules/multiplayer/server/handlers/general_matches.lua index 65f4df2..180ff21 100644 --- a/modules/multiplayer/server/handlers/general_matches.lua +++ b/modules/multiplayer/server/handlers/general_matches.lua @@ -1,6 +1,5 @@ local protocol = require "multiplayer/protocol-kernel/protocol" local switcher = require "lib/public/common/switcher" -local protect = require "lib/private/protect" local sandbox = require "lib/private/sandbox/sandbox" local inventories_manager = require "lib/private/sandbox/inventories_manager" local account_manager = require "lib/private/accounts/account_manager" @@ -847,4 +846,4 @@ matches.client_online_handler:add_case(protocol.ClientMsg.InventoryInteract, ( -return protect.protect_return(matches) +return matches diff --git a/modules/multiplayer/server/handlers/http_matches.lua b/modules/multiplayer/server/handlers/http_matches.lua index 5d0d6d0..4472275 100644 --- a/modules/multiplayer/server/handlers/http_matches.lua +++ b/modules/multiplayer/server/handlers/http_matches.lua @@ -1,6 +1,5 @@ local protocol = require "multiplayer/protocol-kernel/protocol" local switcher = require "lib/public/common/switcher" -local protect = require "lib/private/protect" local sandbox = require "lib/private/sandbox/sandbox" local http = require "server:lib/private/http/httprequestparser" @@ -72,4 +71,4 @@ matches:add_case("/status", function(packet, client) send_responce(client, responce) end) -return protect.protect_return(matches) +return matches diff --git a/modules/multiplayer/server/http_pipe.lua b/modules/multiplayer/server/http_pipe.lua index 09206b9..ae34c99 100644 --- a/modules/multiplayer/server/http_pipe.lua +++ b/modules/multiplayer/server/http_pipe.lua @@ -1,6 +1,5 @@ local Pipeline = require "lib/public/async_pipeline" local protocol = require "multiplayer/protocol-kernel/protocol" -local protect = require "lib/private/protect" local matches = require "multiplayer/server/handlers/http_matches" local List = require "lib/public/common/list" local interceptors = require "api/v2/interceptors" @@ -90,4 +89,4 @@ HttpPipe:add_middleware(function(client) return client end) -return protect.protect_return(HttpPipe) +return HttpPipe diff --git a/modules/multiplayer/server/main_pipe.lua b/modules/multiplayer/server/main_pipe.lua index 217addd..5961506 100644 --- a/modules/multiplayer/server/main_pipe.lua +++ b/modules/multiplayer/server/main_pipe.lua @@ -1,6 +1,5 @@ local Pipeline = require "lib/public/async_pipeline" local protocol = require "multiplayer/protocol-kernel/protocol" -local protect = require "lib/private/protect" local matches = require "multiplayer/server/handlers/general_matches" local ClientPipe = require "multiplayer/server/client_pipe" local List = require "lib/public/common/list" @@ -48,7 +47,7 @@ ServerPipe:add_middleware(function(client) end local packet = List.popleft(client.received_packets) - + debug.print(packet) local success, err = pcall(function() if client.active == false then local status = interceptors.receive.__process(packet, client) @@ -85,4 +84,4 @@ ServerPipe:add_middleware(function(client) return client end) -return protect.protect_return(ServerPipe) +return ServerPipe diff --git a/modules/multiplayer/server/server.lua b/modules/multiplayer/server/server.lua index 13bb55b..21510c9 100644 --- a/modules/multiplayer/server/server.lua +++ b/modules/multiplayer/server/server.lua @@ -1,4 +1,3 @@ -local protect = require "lib/private/protect" local Client = require "multiplayer/server/classes/client" local container = require "lib/private/common/container" local main_pipe = require "multiplayer/server/main_pipe" @@ -166,4 +165,4 @@ function server:tick() server_echo.proccess(self.main_clients) end -return protect.protect_return(server) +return server diff --git a/modules/multiplayer/server/server_echo.lua b/modules/multiplayer/server/server_echo.lua index 0693e6e..242f31c 100644 --- a/modules/multiplayer/server/server_echo.lua +++ b/modules/multiplayer/server/server_echo.lua @@ -1,5 +1,3 @@ -local protect = require "lib/private/protect" - local events = {} local ServerEcho = {} @@ -30,4 +28,4 @@ function ServerEcho.proccess(clients) end end -return protect.protect_return(ServerEcho) +return ServerEcho diff --git a/modules/run/main.lua b/modules/run/main.lua index 5f5b512..6ba88f0 100644 --- a/modules/run/main.lua +++ b/modules/run/main.lua @@ -6,10 +6,6 @@ local function main() require "server:globals" require "server:std/stdmin" - local protect = require "server:lib/private/protect" - if protect.protect_require() then return end - - if IS_RELEASE then logger.log(LOGO) else diff --git a/modules/run/standalone.lua b/modules/run/standalone.lua new file mode 100644 index 0000000..e4d708d --- /dev/null +++ b/modules/run/standalone.lua @@ -0,0 +1,45 @@ +require "server:std/stdboot" +require "server:globals" +IS_HEADLESS = false + +require "server:std/stdmin" + +logger.log("Launching Neutron in standalone mode...") + +-- Чтобы start_require работал как обычный require +_G["/$p"] = package.loaded + +local lib = require "server:lib/private/min" + +require "server:init/engine_patcher" +require "server:init/server" +require "server:multiplayer/server/chat/commands" + +local timeout_executor = require "server:lib/private/common/timeout_executor" +local server = require "server:multiplayer/server/server" + +local metadata = require "server:lib/private/files/metadata" +local world = lib.world +IS_RUNNING = true +world.open_main() + +metadata.load() +server = server.new(CONFIG.server.port) +server:start_main() + +-- Совершаем невозможное, знакомим сервер и клиент +require(string.format("client:api/%s/shell/api", _G["$Multiplayer"].api_references.Neutron.latest)).__run_in_standalone( +CONFIG.server.port) + +events.on("server:.worldtick", function() + timeout_executor.process() + server:tick() + + events.emit("server:main_tick") +end) + +events.on("server:.worldsave", function() + logger.log("Saving world...") + events.emit("server:save") + metadata.save() +end) diff --git a/modules/run/tests.lua b/modules/run/tests.lua index b1c4e3a..d3b24f3 100644 --- a/modules/run/tests.lua +++ b/modules/run/tests.lua @@ -15,10 +15,6 @@ local function main() require "server:globals" require "server:std/stdmin" - local protect = require "server:lib/private/protect" - if protect.protect_require() then return end - - if IS_RELEASE then logger.log(LOGO) else diff --git a/modules/std/stdboot.lua b/modules/std/stdboot.lua index 4cf6539..3512adb 100644 --- a/modules/std/stdboot.lua +++ b/modules/std/stdboot.lua @@ -52,6 +52,8 @@ function logger.log(text, type, only_save, custom_source) source = custom_source end + source = "S:/" .. source + local out = '[' .. string.left_pad(source, 20) .. '] ' .. text local uptime = time.formatted_time() diff --git a/modules/std/stdmin.lua b/modules/std/stdmin.lua index 0b38b1b..df954cc 100644 --- a/modules/std/stdmin.lua +++ b/modules/std/stdmin.lua @@ -1,8 +1,7 @@ local data_buffer = require "lib/public/bit_buffer" -_G['$Neutron'] = "server" _G['$Multiplayer'] = { - side = "server", + side = "server" and IS_HEADLESS or "standalone", pack_id = "server", api_references = { Neutron = { "v1", "v2", latest = "v2" } @@ -844,13 +843,13 @@ function start_require(path) local old_path = path local prefix, file = parse_path(path) - path = prefix .. ":modules/" .. file .. ".lua" + local module_path = prefix .. ":modules/" .. file .. ".lua" - if not _G["/$p"] then - return require(old_path) + if _G["/$p"] and _G["/$p"][module_path] then + return _G["/$p"][module_path] end - return _G["/$p"][path] + return require(old_path) end function tohex(num) diff --git a/resources/server_config.json b/resources/server_config.json index fa3ad36..b511b01 100644 --- a/resources/server_config.json +++ b/resources/server_config.json @@ -11,7 +11,7 @@ "main_world": "overworld" }, "server": { - "version": "0.28.0", + "version": "0.31.0", "max_players": 16, "short_description": "MasterServer", "description": "", diff --git a/scripts/world.lua b/scripts/world.lua index e2f22f3..b01329b 100644 --- a/scripts/world.lua +++ b/scripts/world.lua @@ -4,14 +4,15 @@ local function start_require(path) return start_require(prefix .. ':' .. path) end + local old_path = path local prefix, file = parse_path(path) - path = prefix .. ":modules/" .. file .. ".lua" + local module_path = prefix .. ":modules/" .. file .. ".lua" - if not _G["/$p"] then - return + if _G["/$p"] and _G["/$p"][module_path] then + return _G["/$p"][module_path] end - return _G["/$p"][path] + return require(old_path) end local server_echo = nil @@ -19,6 +20,7 @@ local protocol = nil local sandbox = nil local function upd(blockid, x, y, z, playerid) + if not IS_HEADLESS then return end playerid = math.max(playerid, 0) local data = { @@ -60,6 +62,10 @@ local function upd(blockid, x, y, z, playerid) end function on_world_open() + if not IS_HEADLESS then + require "run/standalone" + end + server_echo = start_require("server:multiplayer/server/server_echo") protocol = start_require("server:multiplayer/protocol-kernel/protocol") sandbox = start_require("server:lib/private/sandbox/sandbox") @@ -73,6 +79,10 @@ function on_block_broken(...) upd(...) end +function on_world_tick() end + +function on_world_save() end + events.on("server:block_interact", function(...) upd(...) end)