def update(path, port): action.say("Downloading minecraft_server...", 0) #remove any old leftovers action.send_sys("rm /tmp/"+port+"/minecraft_server.jar", 1) #download latest version action.send_sys("wget -b --directory-prefix=/tmp/"+port+"/ https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar", 10) action.say("Done, comparing versions..", 0.5) server = path + "minecraft_server.jar" #compare with current compare = filecmp.cmp("/tmp/"+port+"/minecraft_server.jar", server) print "comparing " + '/tmp/'+port+'/minecraft_server.jar' + " with " + server #if no difference do nothing if compare == True: action.say("Latest version installed", 1) action.say("- Doing nothing.", 1) return "No update found" #else shutdown and update else: action.say("Versions does not match!", 3) action.say("Im going to try something crazy and update myself!", 4) action.say("Dont be mad if shit goes bad :3", 2) action.stop_server() action.send_sys("rm "+ server, 1) action.send_sys("mv /tmp/"+port+"/minecraft_server.jar "+ server, 1) action.start_server() return "Updated server!"
def restart(): #stop action.say("[Warning] Server restarting in 10 seconds!", 5) action.say("[Warning] Server restarting in 5 seconds!", 5) action.send("save-all", 2) action.stop_server() #start #yeah this is hard though rcon >.< action.start_server()
def monsters(path): #real and tempfile properties = path + "server.properties" mc_out = "/tmp/tempsett.txt" #open them mc_settings = open(properties, "r") mc_out = open(mc_out, "w") # loop through the test file line by line # and write only the lines back out that do # not contain the search string search = "spawn-monsters=" for line in mc_settings: if search not in line: mc_out.write(line) else: print "found monsters line!" print line if "false" in line: action.say("[Warning] Turning monsters ON!", 2) action.say("[Warning] Monsters will appear in the next night cycle.", 3) action.stop_server() mc_out.write("spawn-monsters=True\n") return "ON" if "true" in line: action.say("[Warning] Turning monsters OFF!", 2) action.say("[Warning] Monsters will stop spawning.", 3) action.stop_server() mc_out.write("spawn-monsters=False\n") return "OFF" # close the file handles mc_settings.close() mc_out.close() time.sleep(2) action.send_sys("rm " + properties, 0) action.send_sys("mv /tmp/tempsett.txt " + properties, 0) time.sleep(1) action.start_server()
def change_world(new_world, path): print " <<< changing realm to folder: "+new_world+" >>>" #real and tempfile properties = path + "server.properties" mc_out = "/tmp/tempsett.txt" #open them mc_settings = open(properties, "r") mc_out = open(mc_out, "w") # loop through the test file line by line # and write only the lines back out that do # not contain the search string search = "level-name=" for line in mc_settings: if search not in line: mc_out.write(line) else: mc_out.write("level-name="+new_world+"\n") # close the file handles mc_settings.close() mc_out.close() action.say("§e[Warning] §fServer going down for realm-change in 10 seconds", 5) action.say("§e[Warning] §fServer going down for realm-change in 5 seconds.", 5) action.say("\"Now, I am become Death, the destroyer of worlds.\"", 1) action.stop_server() time.sleep(3) print "DEBUG: exec command: rm " + properties action.send_sys("rm " + properties, 0) print "DEBUG: exec command: cp /tmp/tempsett.txt " + properties action.send_sys("mv /tmp/tempsett.txt " + properties, 1) time.sleep(2) action.start_server()