Skip to content

Instantly share code, notes, and snippets.

@bjorn
Created July 14, 2012 21:01
Show Gist options
  • Save bjorn/3113347 to your computer and use it in GitHub Desktop.
Save bjorn/3113347 to your computer and use it in GitHub Desktop.
Scripts around manaserv
#!/usr/bin/env lua
local function checkenv(varname)
local value = os.getenv(varname)
if not value then
print(varname .. ' not set')
os.exit(1)
end
return value
end
local WORLD_DATA_REPOSITORY = checkenv('WORLD_DATA_REPOSITORY')
local CLIENT_UPDATES_DIR = checkenv('CLIENT_UPDATES_DIR')
local function trim(s)
s = string.gsub(s, '^%s+', '') -- strip preceding whitespace
s = string.gsub(s, '%s+$', '') -- strip trailing whitespace
return s
end
local function capture(command)
local f = assert(io.popen(command, 'r'))
local s = assert(f:read('*a'))
f:close()
return trim(s)
end
local function execute(command)
local result = assert(os.execute(command))
if result ~= 0 then
print("Error executing:")
print(" " .. command)
os.exit(1)
end
end
local function git(subcommand)
return 'git --git-dir=' .. WORLD_DATA_REPOSITORY .. ' ' .. subcommand
end
local function adler32(file)
return string.sub(capture('adler32 ' .. file), -8)
end
local function last_revision(paths)
local output = capture(git('log -1 --oneline -- ' .. table.concat(paths, ' ')))
return assert(string.match(output, '(%w+) '))
end
local packages = {
{
name = "definitions",
paths = {
"attributes.xml",
"effects.xml",
"emotes.xml",
"equip.xml",
"hair.xml",
"items.xml",
"maps.xml",
"monsters.xml",
"npcs.xml",
"paths.xml",
"permissions.xml",
"skills.xml",
"specials.xml",
"status-effects.xml",
"units.xml",
},
},
{ name = "music", type = "music", required = "no", paths = { "music" }, },
{ name = "sound", paths = { "sfx" }, },
{ name = "maps", paths = { "maps" }, },
{ name = "graphics", paths = { "tiles", "sprites", "particles", "items", "automapping" }, },
}
local resources_lines = {
'<?xml version="1.0"?>',
'<updates>',
}
for i=1,#packages do
local package = packages[i]
local revision = last_revision(package.paths)
local filename = package.name .. "-" .. revision .. ".zip"
local fullname = CLIENT_UPDATES_DIR .. '/' .. filename
print("Creating " .. filename)
execute(git('archive HEAD --output=' .. fullname .. ' ' .. table.concat(package.paths, ' ')))
local type = package.type or "data"
local hash = adler32(fullname)
local line = ' <update type="' .. type .. '" '
if package.required == "no" then
line = line .. ' required="no"'
end
line = line .. ' file="' .. filename .. '"'
line = line .. ' hash="' .. hash .. '" '
if package.description then
line = line .. ' description="' .. package.description .. '"'
end
line = line .. '/>'
table.insert(resources_lines, line)
end
table.insert(resources_lines, '</updates>')
print("Writing resources.xml")
local file = io.open(CLIENT_UPDATES_DIR .. "/resources.xml", "w")
file:write(table.concat(resources_lines, '\n') .. '\n')
file:close()
description "Mana account server"
author "Thorbjorn Lindeijer <thorbjorn@lindeijer.nl>"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
kill timeout 10
respawn
respawn limit 10 5
chdir /home/mana/serverhome
exec /home/mana/manaserv/src/manaserv-account --verbosity 3
description "Mana game server"
author "Thorbjorn Lindeijer <thorbjorn@lindeijer.nl>"
start on (net-device-up
and local-filesystems
and runlevel [2345]
and started manaserv-account)
stop on runlevel [016]
kill timeout 10
respawn
respawn limit 10 5
chdir /home/mana/serverhome
exec /home/mana/manaserv/src/manaserv-game --verbosity 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment