diff --git a/squinnondation/messages.py b/squinnondation/messages.py index 0f31845..7fd9541 100644 --- a/squinnondation/messages.py +++ b/squinnondation/messages.py @@ -453,8 +453,8 @@ class WarningTLV(TLV): def handle(self, user: Any, sender: Any) -> None: user.add_message(f"warning: *A client warned you: {self.message}*" - if not user.squinnondation.no_markdown else - f"warning: A client warned you: {self.message}") + if not user.squinnondation.no_markdown else + "warning: A client warned you: {self.message}") @staticmethod def construct(message: str) -> "WarningTLV": diff --git a/squinnondation/peers.py b/squinnondation/peers.py index 0229151..cea8ff1 100644 --- a/squinnondation/peers.py +++ b/squinnondation/peers.py @@ -662,14 +662,17 @@ class User(Peer): """ Remove messages which are overdue (older than 2 minutes) from the inundation dictionnary. """ + self.data_lock.acquire() for key in self.recent_messages: if time.time() - self.recent_messages[key][1] > 120: self.recent_messages.pop(key) + self.data_lock.release() def main_inundation(self) -> None: """ The main inundation function. """ + self.data_lock.acquire() for key in self.recent_messages: k = list(self.recent_messages[key][2].keys()) for key2 in k: @@ -691,6 +694,7 @@ class User(Peer): peer = self.recent_messages[key][2][key2][0] self.send_packet(peer, pkt) self.recent_messages[key][2].pop(key2) + self.data_lock.release() def add_system_message(self, msg: str, italic: bool = True, ignore_debug: bool = False) -> None: """ @@ -1157,17 +1161,20 @@ class Inondator(Thread): def run(self) -> None: while True: - # clean the dictionnary - if time.time() - self.last_check > 30: - self.user.clean_inundation() - self.last_check = time.time() + try: + # clean the dictionnary + if time.time() - self.last_check > 30: + self.user.clean_inundation() + self.last_check = time.time() - # inundate - self.user.main_inundation() + # inundate + self.user.main_inundation() - self.user.refresh_history() - self.user.refresh_input() - self.user.refresh_emoji_pad() + self.user.refresh_history() + self.user.refresh_input() + self.user.refresh_emoji_pad() + except Exception as e: + self.user.add_system_message(f"An error occured while inondating: {e}", ignore_debug=True) # Avoid infinite loops time.sleep(1)