Ver código fonte

When we quit, we wait 5 seconds, then save and close.

This allows us to work around the wine/tradewars bug
where it hangs upon exit.
Steve Thielemann 5 anos atrás
pai
commit
cb2b4d89b8
1 arquivos alterados com 20 adições e 0 exclusões
  1. 20 0
      proxy.py

+ 20 - 0
proxy.py

@@ -223,6 +223,7 @@ class Game(protocol.Protocol):
         elif line.startswith("Warps to Sector(s) :"):
             # Warps to Sector(s) :  5468
             _, _, work = line.partition(":")
+            # TO FIX:  We are interested in (unexplored) sectors.
             work = work.strip().replace("(", "").replace(")", "").replace(" - ", " ")
             parts = [int(x) for x in work.split(" ")]
             self.log.debug("Sectorline warps {0}".format(parts))
@@ -250,8 +251,21 @@ class Game(protocol.Protocol):
             self.gamedata.set_port(self.current_sector, data)
             # log.debug("NOW: {0}".format(self.gamedata.ports[self.current_sector]))
 
+    def goodbye(self):
+        # hey hey hey, goodbye!
+        self.connectionLost("We don't go there.")        
+
+    def chicken(self):
+        if not self.received:
+            self.log.debug("checking ... FAILED (chicken!)")
+            # this should force the proxy to save
+            self.observer.emit("user-game", (self.factory.player.user, None))
+            self.queue_game.put("\r\n" + Fore.MAGENTA + "...Now leaving " + Fore.BLUE + "Trade Wars 2002" + Fore.MAGENTA + " and returning to system." + Style.RESET_ALL + "\r\n")
+            reactor.callLater(2, self.goodbye)
+
     def lineReceived(self, line: str):
         """ line received from the game. """
+        self.received = True
         if "log_lines" in config and config["log_lines"]:
             self.log.debug("<< [{0}]".format(line))
 
@@ -267,6 +281,12 @@ class Game(protocol.Protocol):
                 self.game = game
                 log.info("Game: {0}".format(self.game))
                 self.observer.emit("user-game", (self.factory.player.user, self.game))
+        elif "Confirmed? (Y/N)? Yes" in line:
+            # Ok, here's what we going to do.
+            # Set timer for 5 seconds.  If we don't receive anything before that --
+            # hang up the server connection.  :P
+            self.received = False
+            reactor.callLater( 5, self.chicken)
 
         # Process.pas parse line
         if line.startswith("Command [TL=]"):