Skip to content

Commit

Permalink
improve serve command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sledmine committed Nov 25, 2023
1 parent 1acd7d4 commit e857311
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
32 changes: 21 additions & 11 deletions cmd/serve.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,42 @@ 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
scripts = scripts or {}
for _, script in pairs(scripts) do
table.insert(init, "lua_load " .. script)
end
config = config or {}

local serverDataPath = paths.myGamesPath
if isUsingNewDataPath then
Expand All @@ -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
Expand Down
30 changes: 24 additions & 6 deletions mercury.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -376,16 +377,33 @@ 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("?")
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)

Expand All @@ -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

0 comments on commit e857311

Please sign in to comment.