From e709aecbac488368db7b57541626e6c9aa798c88 Mon Sep 17 00:00:00 2001 From: defanor Date: Mon, 21 Feb 2022 00:32:15 +0300 Subject: Fix accidental swapping of SB and data in dwproxy.py The callback is invoked by telnetlib before data processing even if it's after the data in a received stream, which led in particular to the proxy sending SB before the data to a client, making the client to hide it. --- dwproxy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dwproxy.py b/dwproxy.py index e4205cc..d23660d 100755 --- a/dwproxy.py +++ b/dwproxy.py @@ -74,8 +74,13 @@ class TelnetHandler(socketserver.BaseRequestHandler): logging.debug("GMCP command received: %s %s", gmcp_cmd.decode('ascii'), json.loads(gmcp_json)) - self.request.sendall(sb_data) - self.request.sendall(telnetlib.IAC + c + opt) + self.request.sendall(telnetlib.IAC + telnetlib.SB + self.sb_opt + + sb_data + + telnetlib.IAC + telnetlib.SE) + elif c == telnetlib.SB: + self.sb_opt = opt + else: + self.request.sendall(telnetlib.IAC + c + opt) def process_cmd(self, s): """Processes client commands.""" @@ -179,6 +184,7 @@ class TelnetHandler(socketserver.BaseRequestHandler): """Client connection handling.""" logging.info("A new connection from %s", self.client_address) self.gmcp_data = {"room.info": {"identifier": None}} + self.sb_opt = None try: with telnetlib.Telnet(self.server.args.host, self.server.args.port) as tn: -- cgit v1.2.3