Browse Source

Fix usermask length calculation

Didn't account for the ! and @ symbols, so in certain cases, two bytes at the ends of lines vanished.
master
JustAnotherArchivist 2 years ago
parent
commit
1e69a42eae
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      http2irc.py

+ 2
- 2
http2irc.py View File

@@ -516,7 +516,7 @@ class IRCClientProtocol(asyncio.Protocol):
def _self_usermask_length(self):
if not self.server.nickname or not self.server.username or not self.server.hostname:
return 100
return len(self.server.nickname) + len(self.server.username) + len(self.server.hostname)
return len(self.server.nickname) + 1 + len(self.server.username) + 1 + len(self.server.hostname) # nickname!username@hostname

async def send_messages(self):
while self.connected:
@@ -527,7 +527,7 @@ class IRCClientProtocol(asyncio.Protocol):
break
channelB = channel.encode('utf-8')
messageB = message.encode('utf-8')
usermaskPrefixLength = 1 + self._self_usermask_length() + 1
usermaskPrefixLength = 1 + self._self_usermask_length() + 1 # :usermask<SP>
if usermaskPrefixLength + len(b'PRIVMSG ' + channelB + b' :' + messageB) > 510:
# Message too long, need to split or truncate. First try to split on spaces, then on codepoints. Ideally, would use graphemes between, but that's too complicated.
self.logger.debug(f'Message too long, overlongmode = {overlongmode}')


Loading…
Cancel
Save