commit 3af4a1f76a207c8113cce7539b513a3af26dff8d from: noodle date: Fri Jan 9 17:27:01 2026 UTC fix msgmax calculation and add an initial msgmax heuristic to fallback on fixed incorrect msgmax calculation in response to WHO reply code 352, which didn't account for the":nick!user@" part before hostname nor the space before $priv. additionally, an upcoming RSS feature would sometimes need to send news before reading any messages back from server (and WHO reply code 352 might never return or might not return on time), so a conservative fallback msgmax heurestic calculation was added before the evasdrop loop. it uses a maximum hostname length of 63 from RFC 2812 and accounts for the the non-ident tilde (~) that might get prepended to username until we know what the actual hostname and username are. commit - 32d1199ddfacc2acda862cd1ad7032be610f2d37 commit + 3af4a1f76a207c8113cce7539b513a3af26dff8d blob - bc434819232f19ca5d0cc7d99151faf0dbfa103e blob + 9579989b001f202a240eeb511659dd4d28608520 --- mata_bot.pl +++ mata_bot.pl @@ -11,8 +11,10 @@ use constant { LOG_WARN => 1, LOG_DEBUG => 2, CONNECT_TIMEOUT => 60, + CRLF => 2, # RFC 2812 DEFAULT_PORT => 6667, DEFAULT_TLS => 0, + HOSTMAX => 63, # RFC 2812 IRCMAX => 512, LAG_CHECK_TIME => 120, MAX_LAG => 300, @@ -298,6 +300,8 @@ sub evasdrop { $pingsent = 0; $priv = "PRIVMSG ${chan} :"; + $msgmax = IRCMAX - length(":${MYNICK}!~${MYUSER}\@ ${priv}") + - HOSTMAX - CRLF; # conservative max message length heuristic $msgtime = $pingtime = time; while (1) { if ($pingsent) { @@ -319,19 +323,21 @@ sub evasdrop { sendmsg($s, 'PONG :' . $1); } elsif (/^:[^ ]+ PONG/) { $pingsent = 0; - } elsif (/^:[^ ]+ 352 [^ ]+ [^ ]+ [^ ]+ ([^ ]+)/) { - # the extra 2 bytes account for \r\n - $msgmax = IRCMAX - length($1) - length($priv) - 2; + } elsif ( + /^:[^ ]+ 352 ${MYNICK} [^ ]+ ([^ ]+) ([^ ]+) [^ ]+ (${MYNICK})/ + ) { + # refine maximum message length heuristic + $msgmax = IRCMAX - length(":${3}!${1}\@${2} ${priv}") + - CRLF; } elsif (/^:([^ !#&][^ !]*)![^ \@]+\@[^ ]+ ${priv}(.+)$/) { # respond to chan message - my $r; + my ($r, $len); - unless ($msgmax) { - logger(LOG_ERROR, 'could not calculate msgmax'); - return; - } $r = respond($1, $2, @$lists); - sendmsg($s, $priv . substr($r,0,$msgmax)) if length($r); + if ($len = length($r)) { + $r = substr($r,0,$msgmax-1).'-' if $len>$msgmax; + sendmsg($s, $priv . $r); + } } } }