From 2a55620cccee23fac36d662197956fa1e0169593 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 19 Feb 2026 20:41:15 +0100 Subject: [PATCH] fix: relay raw IRC bytes instead of re-formatting messages Preserve original server bytes in IRCMessage.raw and forward those to clients, avoiding parse/format round-trip that altered messages. Co-Authored-By: Claude Opus 4.6 --- src/bouncer/irc.py | 3 ++- src/bouncer/router.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bouncer/irc.py b/src/bouncer/irc.py index a0f1c1d..720d1e4 100644 --- a/src/bouncer/irc.py +++ b/src/bouncer/irc.py @@ -13,6 +13,7 @@ class IRCMessage: params: list[str] = field(default_factory=list) prefix: str | None = None tags: dict[str, str | None] = field(default_factory=dict) + raw: bytes | None = None @property def trailing(self) -> str | None: @@ -78,7 +79,7 @@ def parse(data: bytes) -> IRCMessage: command = parts[0].upper() params = parts[1:] - return IRCMessage(command=command, params=params, prefix=prefix, tags=tags) + return IRCMessage(command=command, params=params, prefix=prefix, tags=tags, raw=data + b"\r\n") def parse_prefix(prefix: str) -> tuple[str, str | None, str | None]: diff --git a/src/bouncer/router.py b/src/bouncer/router.py index ff99fb2..bcbe78e 100644 --- a/src/bouncer/router.py +++ b/src/bouncer/router.py @@ -104,9 +104,9 @@ class Router: if max_msgs > 0: await self.backlog.prune(network_name, keep=max_msgs) - # Forward to all attached clients + # Forward to all attached clients (prefer raw bytes from server) clients = self.clients.get(network_name, []) - data = msg.format() + data = msg.raw if msg.raw else msg.format() for client in clients: try: client.write(data)