From 81c44c0172dbb56b6e36915a6f87cdcec132addb Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 16 Apr 2013 07:57:59 -0400 Subject: [PATCH] Prevent actually sending an empty privmsg. --- irkerd | 30 +++++++++++++++++------------- irkerd.xml | 7 ++++--- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/irkerd b/irkerd index 3889cc7..cacd4bf 100755 --- a/irkerd +++ b/irkerd @@ -252,19 +252,23 @@ class Connection: if channel not in self.channels_joined: self.connection.join(channel) self.irker.debug(1, "joining %s on %s." % (channel, self.servername)) - for segment in message.split("\n"): - # Truncate the message if it's too long, - # but we're working with characters here, - # not bytes, so we could be off. - # 500 = 512 - CRLF - 'PRIVMSG ' - ' :' - maxlength = 500 - len(channel) - if len(segment) > maxlength: - segment = segment[:maxlength] - try: - self.connection.privmsg(channel, segment) - except ValueError as err: - self.irker.debug(1, "irclib rejected a message to %s on %s because: %s" % (channel, self.servername, str(err))) - time.sleep(ANTI_FLOOD_DELAY) + # An empty message might be used as a keepalive or + # to join a channel for logging, so suppress the + # privmsg send unless there is actual traffic. + if message: + for segment in message.split("\n"): + # Truncate the message if it's too long, + # but we're working with characters here, + # not bytes, so we could be off. + # 500 = 512 - CRLF - 'PRIVMSG ' - ' :' + maxlength = 500 - len(channel) + if len(segment) > maxlength: + segment = segment[:maxlength] + try: + self.connection.privmsg(channel, segment) + except ValueError as err: + self.irker.debug(1, "irclib rejected a message to %s on %s because: %s" % (channel, self.servername, str(err))) + time.sleep(ANTI_FLOOD_DELAY) self.last_xmit = self.channels_joined[channel] = time.time() self.irker.debug(1, "XMIT_TTL bump (%s transmission) at %s" % (self.servername, time.asctime())) self.queue.task_done() diff --git a/irkerd.xml b/irkerd.xml index 345c053..6102245 100644 --- a/irkerd.xml +++ b/irkerd.xml @@ -57,10 +57,11 @@ colon, as shown in the third example; otherwise irkerd sends messages to the the default 6667 IRC port of each server. -An empty message is legal and will cause +An empty message is legal and will cause irkerd to join the target channels without actually emitting a message. This may be useful for advertising that -an instance is up and running. +an instance is up and running, or for joining a channel to log its +traffic. OPTIONS @@ -78,7 +79,7 @@ consult the source code for details. -l Takes a following filename, logs traffic to that file. Each log line consists of three |-separated fields; a numeric -timestamp in Unix time, the fqdn of the sending server, and the +timestamp in Unix time, the FQDN of the sending server, and the message data. -- 2.26.2