summaryrefslogtreecommitdiff
path: root/standalone_server.lua
diff options
context:
space:
mode:
Diffstat (limited to 'standalone_server.lua')
-rwxr-xr-xstandalone_server.lua47
1 files changed, 36 insertions, 11 deletions
diff --git a/standalone_server.lua b/standalone_server.lua
index a1dd571..9221984 100755
--- a/standalone_server.lua
+++ b/standalone_server.lua
@@ -1,20 +1,45 @@
#!/usr/bin/env lua5.1
local server = require("server")
-local srv = server.create()
-local started = false
+local srv, err = server.create(assert(arg[1]))
+if err then
+ if err == "save_corrupted" then
+ print("[standalone_server] savefile corrupted (try restoring backup?)")
+ elseif err == "save_write_failed" then
+ print("[standalone_server] failed to open savefile for writing")
+ else
+ print(err)
+ end
+ os.exit(1)
+end
-while true do
- server.update(srv)
- local status, invite = server.match_status(srv)
+local function server_loop()
+ local started = false
+ while true do
+ server.update(srv)
+ local status, invite = server.match_status(srv)
- if status == "fail" then
- print("failed to register match (match server down?)")
- break
- elseif status == "active" and not started then
- started = true
- print("invite: " .. invite)
+ if status == "fail" then
+ print("[standalone_server] failed to register match (match server down?)")
+ return false
+ elseif status == "active" and not started then
+ started = true
+ print("[standalone_server] invite: " .. invite)
+ end
end
end
+local _, success = xpcall(server_loop, function(err)
+ if err:find("interrupted!") then
+ return true
+ end
+ print(debug.traceback(err, 2))
+ return false
+end, srv)
+
+print("[standalone_server] shutting down")
server.close(srv)
+
+if not success then
+ os.exit(1)
+end