commit - 32d1199ddfacc2acda862cd1ad7032be610f2d37
commit + 3af4a1f76a207c8113cce7539b513a3af26dff8d
blob - bc434819232f19ca5d0cc7d99151faf0dbfa103e
blob + 9579989b001f202a240eeb511659dd4d28608520
--- mata_bot.pl
+++ mata_bot.pl
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,
$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) {
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);
+ }
}
}
}