def handle_create_instance_request(self, msg): instance_id = kv.get("next_instance_id") or "1" kv.set("next_instance_id", base36encode(int(instance_id, 36) + 1)) instance = {} instance["id"] = instance_id instance["schema_version"] = 1 instance["mizname"] = msg["filename"] instance["mizhash"] = msg["md5hash"] if msg["no_passwords"]: instance["red_pw"] = "" instance["blue_pw"] = "" instance["admin_pw"] = "" else: instance["red_pw"] = util.makepw() instance["blue_pw"] = util.makepw() instance["admin_pw"] = util.makepw() instance["red_spectator_pw"] = util.makepw() instance["blue_spectator_pw"] = util.makepw() instance["data"] = msg["data"] for obj in instance["data"]["objects"].values(): if "x" in obj and "z" in obj: lon, lat = dcs_proj(obj["z"], obj["x"], inverse=True) obj["lon"] = lon obj["lat"] = lat del obj["z"] del obj["x"] kv.set("instance-" + instance_id, json.dumps(instance)) instance_list = json.loads(kv.get("instance-list", "[]")) instance_list.append(instance_id) kv.set("instance-list", json.dumps(instance_list)) return { "success": True, "instance_id": instance_id, "red_pw": instance["red_pw"], "blue_pw": instance["blue_pw"], "red_spectator_pw": instance["red_spectator_pw"], "blue_spectator_pw": instance["blue_spectator_pw"], "admin_pw": instance["admin_pw"], }
def upgrade_0_to_1(self, instance): instance["red_spectator_pw"] = util.makepw() instance["blue_spectator_pw"] = util.makepw() instance["schema_version"] = 1