From 2912352536a147d715dc95eca458824c1b6e3a32 Mon Sep 17 00:00:00 2001 From: computergeek125 Date: Mon, 17 Jun 2024 23:10:21 -0500 Subject: [PATCH] if your reaction to this is 'what in the sam hill did mac do to bungeecord', you are sane --- app/classes/shared/server.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index ee39b0d4..a6df028f 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -88,7 +88,7 @@ def callback(called_func): class ServerOutBuf: lines = {} - def __init__(self, helper, proc, server_id, newline=os.linesep): + def __init__(self, helper, proc, server_id, newline=os.linesep, termstr=None): self.helper = helper self.proc = proc self.server_id = str(server_id) @@ -98,8 +98,14 @@ class ServerOutBuf: self.line_buffer = "" ServerOutBuf.lines[self.server_id] = [] self.lsi = 0 + self.lsn = None + if termstr: + self.termstr = termstr + self.process_byte = self._process_byte_termstr + else: + self.process_byte = self._process_byte - def process_byte(self, char): + def _process_byte(self, char): if char == self.newline[self.lsi]: self.lsi += 1 else: @@ -116,6 +122,28 @@ class ServerOutBuf: if len(ServerOutBuf.lines[self.server_id]) > self.max_lines: ServerOutBuf.lines[self.server_id].pop(0) + def _process_byte_termstr(self, char): + if char == self.newline[self.lsi]: + self.lsi += 1 + elif char == '\r': + if self.line_buffer == self.termstr: + self.line_buffer = "" + return + else: + self.lsi = 0 + self.line_buffer += char + + if self.lsi >= len(self.newline): + self.lsi = 0 + ServerOutBuf.lines[self.server_id].append(self.line_buffer) + print(repr(self.line_buffer)) + + self.new_line_handler(self.line_buffer) + self.line_buffer = "" + # Limit list length to self.max_lines: + if len(ServerOutBuf.lines[self.server_id]) > self.max_lines: + ServerOutBuf.lines[self.server_id].pop(0) + def check(self): text_wrapper = io.TextIOWrapper( self.proc.stdout, encoding="UTF-8", errors="ignore", newline="" @@ -232,6 +260,7 @@ class ServerInstance: server_data = HelperServers.get_server_data_by_id(self.server_id) self.settings = server_data self.settings['newline'] = self.settings.get('newline', os.linesep) + self.settings['termstr'] = self.settings.get('termstr', None) def do_server_setup(self, server_data_obj): server_id = server_data_obj["server_id"] @@ -579,7 +608,7 @@ class ServerInstance: self.stats_helper.finish_import() return False - out_buf = ServerOutBuf(self.helper, self.process, self.server_id, newline=self.settings['newline']) + out_buf = ServerOutBuf(self.helper, self.process, self.server_id, newline=self.settings['newline'], termstr=self.settings['termstr']) logger.debug(f"Starting virtual terminal listener for server {self.name}") threading.Thread(