Browse Source

Show activate text, get version (from git).

Steve Thielemann 5 năm trước cách đây
mục cha
commit
a79036ab9c
1 tập tin đã thay đổi với 29 bổ sung2 xóa
  1. 29 2
      tcp-proxy.py

+ 29 - 2
tcp-proxy.py

@@ -9,8 +9,9 @@ from twisted.internet import reactor
 from twisted.python import log
 from twisted.enterprise import adbapi
 import pendulum
+from subprocess import check_output
 
-from config import *
+from config_dev import *
 
 # Connect to:
 # HOST = "twgs"
@@ -19,6 +20,20 @@ from config import *
 # LISTEN_PORT = 2002
 # LISTEN_ON = "0.0.0.0"
 
+version = check_output(
+    [
+        "git",
+        "describe",
+        "--long",
+        "--tags",
+        #        "--dirty",
+        "--always",
+        "--match",
+        "v[0-9]\.[0-9]\.[0-9]",
+    ],
+    universal_newlines=True,
+)
+
 cleaner = re.compile(r"\x1b\[[0-9;]*[A-Zmh]")
 makeNL = re.compile(r"\x1b\[[0-9;]*[J]")
 
@@ -183,6 +198,12 @@ class TWGSServer(protocol.Protocol):
         log.msg(">>> [{0}]".format(line))
         if self.fpLines is not None:
             print(line, file=self.fpLines)
+        if "TWGS v2.20b" in line:
+            if "www.eisonline.com" in line:
+                # Must not be unicode
+                self.queue_client.put(
+                    b"TWGS Proxy is active. \x1b[1;34m~\x1b[0m to activate.\n\r\n\r"
+                )
 
     def clientDataReceived(self, chunk):
         if chunk is False:
@@ -217,7 +238,12 @@ class TWGSServer(protocol.Protocol):
 
     def dataReceived(self, chunk):
         # log.msg("Server: %d bytes received" % len(chunk))
-        self.queue_twgs.put(chunk)
+        if chunk == b"~":
+            self.queue_client.put(
+                b"\r\n**********\r\nTWGS Proxy is almost awake...\r\n"
+            )
+        else:
+            self.queue_twgs.put(chunk)
 
     def connectionLost(self, why):
         log.msg("lost connection %s" % why)
@@ -237,6 +263,7 @@ class TWGSServer(protocol.Protocol):
 
 if __name__ == "__main__":
     log.startLogging(sys.stdout)
+    log.msg("This is version: %s" % version)
     factory = protocol.Factory()
     factory.protocol = TWGSServer
     reactor.listenTCP(LISTEN_PORT, factory, interface=LISTEN_ON)