From 5d813175a1404cf61cbd7239a632a791deed597f Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 19 Nov 2018 10:12:52 +0000 Subject: [PATCH] Don't enable write throttling until we get 005 --- modules/line_handler.py | 1 + src/IRCServer.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/line_handler.py b/modules/line_handler.py index 2e081962..00f424f2 100644 --- a/modules/line_handler.py +++ b/modules/line_handler.py @@ -65,6 +65,7 @@ class Module(ModuleManager.BaseModule): # first numeric line the server sends @utils.hook("raw.received.001", default_event=True) def handle_001(self, event): + event["server"].set_write_throttling(True) event["server"].name = event["prefix"].nickname event["server"].set_own_nickname(event["args"][0]) event["server"].send_whois(event["server"].nickname) diff --git a/src/IRCServer.py b/src/IRCServer.py index 0eab2c89..7ca9c293 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -30,6 +30,7 @@ class Server(IRCObject.Object): self.write_buffer = b"" self.buffered_lines = [] # type: typing.List[bytes] + self._write_throttling = False self.read_buffer = b"" self.recent_sends = [] # type: typing.List[float] self.cached_fileno = None # type: typing.Optional[int] @@ -290,7 +291,7 @@ class Server(IRCObject.Object): def throttle_done(self): return self.send_throttle_timeout() == 0 def send_throttle_timeout(self): - if len(self.write_buffer): + if len(self.write_buffer) or not self._write_throttling: return 0 now = time.monotonic() @@ -307,6 +308,8 @@ class Server(IRCObject.Object): time_left = self.recent_sends[0]+THROTTLE_SECONDS time_left = time_left-now return time_left + def set_write_throttling(self, is_on: bool): + self._write_throttling = is_on def send_user(self, username: str, realname: str): self.send("USER %s 0 * :%s" % (username, realname))