Ver Fonte

Updated: queues are named properly now.

client is the client.
twgs is the game server queue.
Steve Thielemann há 5 anos atrás
pai
commit
4da6b0e2ee
1 ficheiros alterados com 22 adições e 22 exclusões
  1. 22 22
      tcp-proxy.py

+ 22 - 22
tcp-proxy.py

@@ -27,8 +27,8 @@ class PlayerProtocol(protocol.Protocol):
 
     def connectionMade(self):
         log.msg("Client: connected to peer")
-        self.cli_queue = self.factory.cli_queue
-        self.cli_queue.get().addCallback(self.serverDataReceived)
+        self.queue_twgs = self.factory.queue_twgs
+        self.queue_twgs.get().addCallback(self.serverDataReceived)
 
     def serverDataReceived(self, chunk):
         # rlogin looks like this:  \x00 password \x00 username \x00 terminal/speed \x00
@@ -36,7 +36,7 @@ class PlayerProtocol(protocol.Protocol):
         # We're looking for 4 \x00!
         # TODO: Line processing, and line cleaning (remove ANSI color codes)
         if chunk is False:
-            self.cli_queue = None
+            self.queue_twgs = None
             log.msg("Client: disconnecting from peer")
             self.factory.continueTrying = False
             self.transport.loseConnection()
@@ -81,7 +81,7 @@ class PlayerProtocol(protocol.Protocol):
                 # Process lines ...
 
             self.transport.write(chunk)
-            self.cli_queue.get().addCallback(self.serverDataReceived)
+            self.queue_twgs.get().addCallback(self.serverDataReceived)
 
         # elif b"$" == chunk:
         #     self.factory.svr_queue.put(b"HELLO.\r\n")
@@ -98,16 +98,16 @@ class PlayerProtocol(protocol.Protocol):
         # log.msg("Client: %d bytes received from peer" % len(chunk))
         # clean, strip ANSI, etc.
 
-        log.msg("<<", repr(chunk))
-        self.factory.svr_queue.put(chunk)
+        log.msg("<<", chunk.decode("utf-8", "ignore"))
+        self.factory.queue_client.put(chunk)
 
     def connectionLost(self, why):
         log.msg("connectionLost because: %s" % why)
         # if self.cli_queue:
         #     self.cli_queue = None
         #     log.msg("Client: peer disconnect unexpectedly")
-        self.factory.svr_queue.put(False)
-        self.cli_queue = None
+        self.factory.queue_client.put(False)
+        self.queue_twgs = None
         self.transport.loseConnection()
 
 
@@ -115,17 +115,17 @@ class GlueFactory(protocol.ClientFactory):
     maxDelay = 10
     protocol = PlayerProtocol
 
-    def __init__(self, svr_queue, cli_queue):
-        self.svr_queue = svr_queue
-        self.cli_queue = cli_queue
+    def __init__(self, queue_client, queue_twgs):
+        self.queue_client = queue_client
+        self.queue_twgs = queue_twgs
 
     def closeIt(self):
         log.msg("closeIt")
-        self.svr_queue.put(False)
+        self.queue_client.put(False)
 
     def clientConnectionFailed(self, connector, why):
         log.msg("connectionFailed: %s" % why)
-        self.svr_queue.put(b"Unable to connect to the game server.\r\n")
+        self.queue_client.put(b"Sorry!  I'm Unable to connect to the game server.\r\n")
         # syncterm gets cranky/locks up if we close this here.
         # (Because it is still sending rlogin information?)
         reactor.callLater(2, self.closeIt)
@@ -136,28 +136,28 @@ class GlueFactory(protocol.ClientFactory):
 
 class TWGSServer(protocol.Protocol):
     def connectionMade(self):
-        self.svr_queue = defer.DeferredQueue()
-        self.cli_queue = defer.DeferredQueue()
-        self.svr_queue.get().addCallback(self.clientDataReceived)
+        self.queue_client = defer.DeferredQueue()
+        self.queue_twgs = defer.DeferredQueue()
+        self.queue_client.get().addCallback(self.clientDataReceived)
 
-        factory = GlueFactory(self.svr_queue, self.cli_queue)
+        factory = GlueFactory(self.queue_client, self.queue_twgs)
         reactor.connectTCP(HOST, PORT, factory, 5)
 
     def clientDataReceived(self, chunk):
         if chunk is False:
             self.transport.loseConnection()
         else:
-            log.msg("Server: writing %d bytes to original client" % len(chunk))
+            # log.msg("Server: writing %d bytes to original client" % len(chunk))
             self.transport.write(chunk)
-            self.svr_queue.get().addCallback(self.clientDataReceived)
+            self.queue_client.get().addCallback(self.clientDataReceived)
 
     def dataReceived(self, chunk):
-        log.msg("Server: %d bytes received" % len(chunk))
-        self.cli_queue.put(chunk)
+        # log.msg("Server: %d bytes received" % len(chunk))
+        self.queue_twgs.put(chunk)
 
     def connectionLost(self, why):
         log.msg("lost connection %s" % why)
-        self.cli_queue.put(False)
+        self.queue_twgs.put(False)
 
     def connectionFailed(self, why):
         log.msg("connectionFailed: %s" % why)