|
@@ -32,7 +32,7 @@ version = check_output(
|
|
|
"v[0-9]\.[0-9]\.[0-9]",
|
|
|
],
|
|
|
universal_newlines=True,
|
|
|
-)
|
|
|
+).strip()
|
|
|
|
|
|
cleaner = re.compile(r"\x1b\[[0-9;]*[A-Zmh]")
|
|
|
makeNL = re.compile(r"\x1b\[[0-9;]*[J]")
|
|
@@ -91,32 +91,9 @@ class PlayerProtocol(protocol.Protocol):
|
|
|
# init sqlite db using the username
|
|
|
self.factory.getUser(self.user)
|
|
|
|
|
|
- # else:
|
|
|
- # process the buffer
|
|
|
- # Handle backspaces by deleting previous character.
|
|
|
-
|
|
|
- # Send the received data into the linereader for "automatic" line processing.
|
|
|
-
|
|
|
- #
|
|
|
- #
|
|
|
- # Strip out ANSI color codes
|
|
|
- # self.buffer = re.sub(r'\x1b[\d;?\d+m', '', self.buffer)
|
|
|
- # Process lines ...
|
|
|
-
|
|
|
self.transport.write(chunk)
|
|
|
self.queue_twgs.get().addCallback(self.serverDataReceived)
|
|
|
|
|
|
- # elif b"$" == chunk:
|
|
|
- # self.factory.svr_queue.put(b"HELLO.\r\n")
|
|
|
- # self.cli_queue.get().addCallback(self.serverDataReceived)
|
|
|
- # elif self.cli_queue:
|
|
|
- # log.msg("Client: writing %d bytes to peer" % len(chunk))
|
|
|
- # log.msg(">>", repr(chunk))
|
|
|
- # self.transport.write(chunk)
|
|
|
- # self.cli_queue.get().addCallback(self.serverDataReceived)
|
|
|
- # else:
|
|
|
- # self.factory.cli_queue.put(chunk)
|
|
|
-
|
|
|
def dataReceived(self, chunk):
|
|
|
# log.msg("Client: %d bytes received from peer" % len(chunk))
|
|
|
# clean, strip ANSI, etc.
|
|
@@ -144,8 +121,6 @@ class GlueFactory(protocol.ClientFactory):
|
|
|
self.queue_client = queue_client
|
|
|
self.queue_twgs = queue_twgs
|
|
|
self.twgs = twgs
|
|
|
- self.fpRaw = None
|
|
|
- self.fpLines = None
|
|
|
|
|
|
def closeIt(self):
|
|
|
log.msg("closeIt")
|
|
@@ -188,7 +163,7 @@ class TWGSServer(protocol.Protocol):
|
|
|
def logUser(self, user):
|
|
|
now = pendulum.now()
|
|
|
filename = now.format("YYYY-MM-DD_HHmm") + "-" + user.lower()
|
|
|
- self.fpRaw = open(filename + ".raw", "ab")
|
|
|
+ # self.fpRaw = open(filename + ".raw", "ab")
|
|
|
self.fpLines = open(filename + ".lines", "a")
|
|
|
# print("Log created:", now.to_rss_string(), "\n", file=self.fpRaw)
|
|
|
print("Log created:", now.to_rss_string(), "\n", file=self.fpLines)
|
|
@@ -201,46 +176,56 @@ class TWGSServer(protocol.Protocol):
|
|
|
if "TWGS v2.20b" in line:
|
|
|
if "www.eisonline.com" in line:
|
|
|
# Must not be unicode
|
|
|
+
|
|
|
+ # Is there a way to NOT have this logged?
|
|
|
self.queue_client.put(
|
|
|
- b"TWGS Proxy is active. \x1b[1;34m~\x1b[0m to activate.\n\r\n\r"
|
|
|
+ (
|
|
|
+ b"TWGS Proxy build "
|
|
|
+ + version.encode()
|
|
|
+ + b" is active. \x1b[1;34m~\x1b[0m to activate.\n\r\n\r",
|
|
|
+ )
|
|
|
)
|
|
|
|
|
|
def clientDataReceived(self, chunk):
|
|
|
if chunk is False:
|
|
|
self.transport.loseConnection()
|
|
|
else:
|
|
|
- if self.fpRaw is not None:
|
|
|
- self.fpRaw.write(chunk)
|
|
|
- self.buffer += chunk.decode("utf-8", "ignore")
|
|
|
+ if type(chunk) is tuple:
|
|
|
+ self.transport.write(chunk[0])
|
|
|
+ self.queue_client.get().addCallback(self.clientDataReceived)
|
|
|
+ else:
|
|
|
+ if self.fpRaw is not None:
|
|
|
+ self.fpRaw.write(chunk)
|
|
|
+ self.buffer += chunk.decode("utf-8", "ignore")
|
|
|
|
|
|
- # Process any backspaces in the buffer
|
|
|
+ # Process any backspaces in the buffer
|
|
|
|
|
|
- while "\x08" in self.buffer:
|
|
|
- part = self.buffer.partition("\x08")
|
|
|
- self.buffer = part[0][:-1] + part[2]
|
|
|
+ while "\x08" in self.buffer:
|
|
|
+ part = self.buffer.partition("\x08")
|
|
|
+ self.buffer = part[0][:-1] + part[2]
|
|
|
|
|
|
- # Treat some ANSI codes as a newline (for purposes of Lines)
|
|
|
- self.buffer = treatAsNL(self.buffer)
|
|
|
+ # Treat some ANSI codes as a newline (for purposes of Lines)
|
|
|
+ self.buffer = treatAsNL(self.buffer)
|
|
|
|
|
|
- # Break the buffer into lines
|
|
|
+ # Break the buffer into lines
|
|
|
|
|
|
- while "\n" in self.buffer:
|
|
|
- part = self.buffer.partition("\n")
|
|
|
- line = part[0].replace("\r", "")
|
|
|
- # Clean ANSI codes from the line
|
|
|
- line = cleanANSI(line)
|
|
|
- self.gotLine(line)
|
|
|
- self.buffer = part[2]
|
|
|
+ while "\n" in self.buffer:
|
|
|
+ part = self.buffer.partition("\n")
|
|
|
+ line = part[0].replace("\r", "")
|
|
|
+ # Clean ANSI codes from the line
|
|
|
+ line = cleanANSI(line)
|
|
|
+ self.gotLine(line)
|
|
|
+ self.buffer = part[2]
|
|
|
|
|
|
- # log.msg("Server: writing %d bytes to original client" % len(chunk))
|
|
|
- self.transport.write(chunk)
|
|
|
- self.queue_client.get().addCallback(self.clientDataReceived)
|
|
|
+ # log.msg("Server: writing %d bytes to original client" % len(chunk))
|
|
|
+ self.transport.write(chunk)
|
|
|
+ self.queue_client.get().addCallback(self.clientDataReceived)
|
|
|
|
|
|
def dataReceived(self, chunk):
|
|
|
# log.msg("Server: %d bytes received" % len(chunk))
|
|
|
if chunk == b"~":
|
|
|
self.queue_client.put(
|
|
|
- b"\r\n**********\r\nTWGS Proxy is almost awake...\r\n"
|
|
|
+ (b"\r\n**********\r\nTWGS Proxy is almost awake...\r\n",)
|
|
|
)
|
|
|
else:
|
|
|
self.queue_twgs.put(chunk)
|