diff --git a/MultiServer.py b/MultiServer.py index 185a5efe..3ebe07b7 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -150,7 +150,7 @@ class Context(Node): return False - def _save(self) -> bool: + def _save(self, exit_save:bool=False) -> bool: try: jsonstr = json.dumps(self.get_save()) with open(self.save_filename, "wb") as f: @@ -192,7 +192,7 @@ class Context(Node): self.auto_saver_thread.start() import atexit - atexit.register(self._save) # make sure we save on exit too + atexit.register(self._save, True) # make sure we save on exit too def get_save(self) -> dict: d = { @@ -212,8 +212,9 @@ class Context(Node): def set_save(self, savedata: dict): rom_names = savedata["rom_names"] # convert from TrackerList to List in case of ponyorm - if rom_names != self.rom_names: - adjusted = {tuple(rom): (team, slot) for (rom, (team, slot)) in rom_names} # old format, ponyorm friendly + + if {rom: other for rom, other in rom_names} != self.rom_names: + adjusted = {rom: (team, slot) for (rom, (team, slot)) in rom_names} # old format, ponyorm friendly if self.rom_names != adjusted: logging.warning('Save file mismatch, will start a new game') return diff --git a/WebHostLib/customserver.py b/WebHostLib/customserver.py index 0bba2b90..e82044a0 100644 --- a/WebHostLib/customserver.py +++ b/WebHostLib/customserver.py @@ -81,11 +81,12 @@ class WebHostContext(Context): threading.Thread(target=self.listen_to_db_commands, daemon=True).start() @db_session - def _save(self) -> bool: + def _save(self, exit_save:bool = False) -> bool: room = Room.get(id=self.room_id) room.multisave = self.get_save() # saving only occurs on activity, so we can "abuse" this information to mark this as last_activity - room.last_activity = datetime.utcnow() + if not exit_save: # we don't want to count a shutdown as activity, which would restart the server again + room.last_activity = datetime.utcnow() return True def get_save(self) -> dict: