From e8573115f9e6460f676936a344928611b1a82e7a Mon Sep 17 00:00:00 2001 From: Sledmine <40512223+Sledmine@users.noreply.github.com> Date: Sat, 25 Nov 2023 11:15:08 -0600 Subject: [PATCH] improve serve command --- cmd/serve.lua | 32 +++++++++++++++++++++----------- mercury.lua | 30 ++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/cmd/serve.lua b/cmd/serve.lua index 29e09c2..61cc8ac 100644 --- a/cmd/serve.lua +++ b/cmd/serve.lua @@ -75,33 +75,34 @@ end local loadFile = [[ sv_public 0 -sv_name "%s" -sv_rcon 1 -sv_rcon_password 1234 +sv_name {sv_name} +sv_rcon {sv_rcon} +sv_rcon_password {sv_rcon_password} sv_timelimit 0 sv_maxplayers 16 -sv_map "%s" "%s" +sv_map "{map}" "{gametype}" +allow_client_side_weapon_projectiles {allow_client_side_weapon_projectiles} load ]] local init = { "lua 1", "antihalofp 1", - "antispam 2", + -- "antispam 2", "antilagspawn 0", "antiglitch 0", "no_lead 1", -- "save_scores 1", - "mtv 1", + -- "mtv 1", "disable_timer_offsets 1", - -- "msg_prefix \"Mercury: \"", + "msg_prefix \"Server: \"", -- "aimbot_ban 5000 1", "network_thread 0", - "auto_update 0", - "full_ipban 1" + "auto_update 0" + -- "full_ipban 1" } -local function serve(map, gametype, port, template, scripts, isUsingNewDataPath) +local function serve(map, gametype, port, template, scripts, isUsingNewDataPath, config) map = map or "bloodgulch" gametype = gametype or "slayer" port = port or 2302 @@ -109,6 +110,7 @@ local function serve(map, gametype, port, template, scripts, isUsingNewDataPath) for _, script in pairs(scripts) do table.insert(init, "lua_load " .. script) end + config = config or {} local serverDataPath = paths.myGamesPath if isUsingNewDataPath then @@ -121,7 +123,15 @@ local function serve(map, gametype, port, template, scripts, isUsingNewDataPath) local loadFilePath = gpath(serverDataPath, "/load.txt") local initFilePath = gpath(serverDataPath, "/sapp/init.txt") - writeFile(loadFilePath, string.format(loadFile, map, map, gametype)) + local load = loadFile:template{ + map = map, + gametype = gametype, + sv_name = map, + sv_rcon = config.rcon and 1 or 0, + sv_rcon_password = config.rcon_password or "merc", + allow_client_side_weapon_projectiles = config.server_side_projectiles and 1 or 0 + } + writeFile(loadFilePath, string.format(load, map, map, gametype)) writeFile(initFilePath, table.concat(init, "\n")) -- Prepare the command to setup the server diff --git a/mercury.lua b/mercury.lua index a771cb7..b2d386a 100644 --- a/mercury.lua +++ b/mercury.lua @@ -100,6 +100,7 @@ local function flagsCheck(args, skipPathValidation) os.exit(1) end if args.debug then + dprint(args) IsDebugModeEnabled = true cprint("Warning Debug mode enabled.") end @@ -332,8 +333,8 @@ buildCmd:action(function(args, name) return end dprint(args) - if build("buildspec.yaml", args.command, args.verbose, args.release, args.output, - args.scenario, args.crc) then + if build("buildspec.yaml", args.command, args.verbose, args.release, args.output, args.scenario, + args.crc) then os.exit(0) end os.exit(1) @@ -376,6 +377,16 @@ configCmd:action(function(args, name) print(output) end) +---Get option value from argparse table +---@param v table +---@return unknown +local function option(v) + if v then + return v[1] + end + return nil +end + local serveCmd = parser:command("serve", "Serve a Halo Custom Edition server.") serveCmd:argument("map", "Map to load on the server."):args("?") serveCmd:argument("gametype", "Gametype to load on the server."):args("?") @@ -383,9 +394,16 @@ serveCmd:option("-p --port", "Port to use for the server."):args("?") -- serveCmd:option("-t --template", "Template server to use."):args("?") serveCmd:option("-s --scripts", "Scripts to load on the server."):args("*") serveCmd:flag("-n --new", "Create a new temporal server data profile path.") -serveCmd:action(function(args, name) +serveCmd:flag("--server-side-projectiles", "Enable server side projectiles.") +serveCmd:flag("-r --rcon", "Enable remote console on the server.") +serveCmd:option("--rcon-password", "Remote console password to use for the server."):args("?") +serveCmd:action(function(args) flagsCheck(args) - serve(args.map, args.gametype, args.port, args.template, args.scripts, args.new) + serve(args.map, args.gametype, option(args.port), args.template, args.scripts, args.new, { + server_side_projectiles = args.server_side_projectiles, + rcon = args.rcon, + rcon_password = option(args.rcon_password) + }) config.clean() end) @@ -402,14 +420,14 @@ aboutCmd:action(function(args, name) end) -- Show commands information if no args -if (not arg[1]) then +if not arg[1] then print(parser:get_help()) end -- Override args array with parser ones local args = parser:parse() -if (args.v) then +if args.v then cprint(constants.mercuryVersion) os.exit(0) end