|  | @@ -17,7 +17,7 @@ LISTEN_PORT = 9999
 | 
	
		
			
				|  |  |  LISTEN_ON = "127.0.0.1"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -class ProxyClientProtocol(protocol.Protocol):
 | 
	
		
			
				|  |  | +class PlayerProtocol(protocol.Protocol):
 | 
	
		
			
				|  |  |      def __init__(self):
 | 
	
		
			
				|  |  |          self.user = None
 | 
	
		
			
				|  |  |          self.dbinit = False
 | 
	
	
		
			
				|  | @@ -111,26 +111,37 @@ class ProxyClientProtocol(protocol.Protocol):
 | 
	
		
			
				|  |  |          self.transport.loseConnection()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -class ProxyClientFactory(protocol.ClientFactory):
 | 
	
		
			
				|  |  | +class GlueFactory(protocol.ClientFactory):
 | 
	
		
			
				|  |  |      maxDelay = 10
 | 
	
		
			
				|  |  | -    protocol = ProxyClientProtocol
 | 
	
		
			
				|  |  | +    protocol = PlayerProtocol
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def __init__(self, svr_queue, cli_queue):
 | 
	
		
			
				|  |  |          self.svr_queue = svr_queue
 | 
	
		
			
				|  |  |          self.cli_queue = cli_queue
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    def closeIt(self):
 | 
	
		
			
				|  |  | +        log.msg("closeIt")
 | 
	
		
			
				|  |  | +        self.svr_queue.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")
 | 
	
		
			
				|  |  | +        # syncterm gets cranky/locks up if we close this here.
 | 
	
		
			
				|  |  | +        # (Because it is still sending rlogin information?)
 | 
	
		
			
				|  |  | +        reactor.callLater(2, self.closeIt)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # ProxyServer is created for each connection
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -class ProxyServer(protocol.Protocol):
 | 
	
		
			
				|  |  | +class TWGSServer(protocol.Protocol):
 | 
	
		
			
				|  |  |      def connectionMade(self):
 | 
	
		
			
				|  |  |          self.svr_queue = defer.DeferredQueue()
 | 
	
		
			
				|  |  |          self.cli_queue = defer.DeferredQueue()
 | 
	
		
			
				|  |  |          self.svr_queue.get().addCallback(self.clientDataReceived)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        factory = ProxyClientFactory(self.svr_queue, self.cli_queue)
 | 
	
		
			
				|  |  | -        reactor.connectTCP(HOST, PORT, factory)
 | 
	
		
			
				|  |  | +        factory = GlueFactory(self.svr_queue, self.cli_queue)
 | 
	
		
			
				|  |  | +        reactor.connectTCP(HOST, PORT, factory, 5)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def clientDataReceived(self, chunk):
 | 
	
		
			
				|  |  |          if chunk is False:
 | 
	
	
		
			
				|  | @@ -148,10 +159,13 @@ class ProxyServer(protocol.Protocol):
 | 
	
		
			
				|  |  |          log.msg("lost connection %s" % why)
 | 
	
		
			
				|  |  |          self.cli_queue.put(False)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    def connectionFailed(self, why):
 | 
	
		
			
				|  |  | +        log.msg("connectionFailed: %s" % why)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  if __name__ == "__main__":
 | 
	
		
			
				|  |  |      log.startLogging(sys.stdout)
 | 
	
		
			
				|  |  |      factory = protocol.Factory()
 | 
	
		
			
				|  |  | -    factory.protocol = ProxyServer
 | 
	
		
			
				|  |  | +    factory.protocol = TWGSServer
 | 
	
		
			
				|  |  |      reactor.listenTCP(LISTEN_PORT, factory, interface=LISTEN_ON)
 | 
	
		
			
				|  |  |      reactor.run()
 |