Skip to content

Instantly share code, notes, and snippets.

@thomasboyt
Created July 12, 2012 21:12
Show Gist options
  • Save thomasboyt/3101034 to your computer and use it in GitHub Desktop.
Save thomasboyt/3101034 to your computer and use it in GitHub Desktop.
ShootMania Server Scripts
#!/usr/bin/python
import urllib2
import json
import shutil
import os
import argparse
import subprocess
parser = argparse.ArgumentParser(description="Download, rename, and move maps from Mania-Exchange.")
parser.add_argument('ids', metavar='id', type=str, nargs="+", help="The IDs of the maps to download.")
args = parser.parse_args()
map_ids = args.ids
for map_id in map_ids:
json_returned = urllib2.urlopen("http://api.mania-exchange.com/sm/maps/" + map_id).read()
map_info = json.loads(json_returned)
filename = map_info[0]['Name'] + ".Map.Gbx"
maptype = map_info[0]['MapType']
if maptype[-5:] == "Arena":
maptype = maptype[:-5]
#maptype = maptype.lower().capitalize()
subprocess.check_call(['wget', 'http://sm.mania-exchange.com/maps/download/' + map_id])
try:
shutil.move(map_id, maptype + '/' + filename)
except IOError as e:
if e.errno == 2:
os.mkdir(maptype)
shutil.move(map_id, maptype + '/' + filename)
else:
raise
print "Downloaded map %s/%s\n" % (maptype, filename)
#!/usr/bin/python
import glob
import argparse
import subprocess
ROOT = "/home/anvolcano/ManiaPlanet/"
MAPS_DIR = "Customs/"
# parse arguments
parser = argparse.ArgumentParser(description="Generate a map list.")
parser.add_argument('mode', metavar='M', type=str, help="the mode for the gametype (Battle, Melee, Royal, Jailbreak)")
args = parser.parse_args()
###### Create Mode CFG File #####
cfg_filename = "SMStorm" + args.mode + ".txt"
# open the new mode CFG file
new_cfg_file = open(ROOT + "UserData/Maps/MatchSettings/" + cfg_filename, 'w')
# read mode cfg file template
mode_cfg_template = open(ROOT + "UserData/Maps/MatchSettings/Templates/SMStorm" + args.mode + ".txt")
mode_cfg = file.read(mode_cfg_template)
# read maps
maps = glob.glob(ROOT + "UserData/Maps/" + MAPS_DIR + args.mode + "/*.Gbx")
for map_path in maps:
path = map_path[len(ROOT + "UserData/Maps/"):]
mode_cfg += "\
<map>\n\
<file>" + path + "</file>\n\
</map>\n"
mode_cfg += "</playlist>"
# write new CFG file
new_cfg_file.write(mode_cfg)
##### Run server #####
subprocess.call(["./ManiaPlanetServer", "/title=SMStorm", "/game_settings=MatchSettings/" + cfg_filename, "/dedicated_cfg=dedicated_cfg.txt"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment