From a0f9244fca067807533617341daccdf7b539a4c4 Mon Sep 17 00:00:00 2001 From: Braxton Plaxco Date: Fri, 12 May 2017 08:06:43 -0400 Subject: Add basic names support ~ B'ezrat Hashem ~ --- miniircd | 23 +++++++++++++++++++++++ test.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/miniircd b/miniircd index f7d7315..98c52ac 100755 --- a/miniircd +++ b/miniircd @@ -364,6 +364,28 @@ class Client(object): def motd_handler(): self.send_motd() + def names_handler(): + channelname = irc_lower(arguments[0]) + channel = self.channels[channelname] + names_prefix = "353 %s = %s :" % (self.nickname, channelname) + names = "" + # Max length: reply prefix ":server_name(space)" plus CRLF in + # the end. + names_max_len = 512 - (len(self.server.name) + 2 + 2) + for name in sorted(x.nickname for x in channel.members): + if not names: + names = names_prefix + name + # Using >= to include the space between "names" and "name". + elif len(names) + len(name) >= names_max_len: + self.reply(names) + names = names_prefix + name + else: + names += " " + name + if names: + self.reply(names) + self.reply("366 %s %s :End of NAMES list" + % (self.nickname, channelname)) + def nick_handler(): if len(arguments) < 1: self.reply("431 :No nickname given") @@ -530,6 +552,7 @@ class Client(object): "LUSERS": lusers_handler, "MODE": mode_handler, "MOTD": motd_handler, + "NAMES": names_handler, "NICK": nick_handler, "NOTICE": notice_and_privmsg_handler, "PART": part_handler, diff --git a/test.py b/test.py index 296e0c1..3e2afc2 100644 --- a/test.py +++ b/test.py @@ -297,6 +297,63 @@ class TestBasicStuff(ServerFixture): ) self.expect(long_nick, r":local\S+ 366 %s #fisk :.*" % long_nick) + def test_join_and_request_names(self): + base_nick = 'A' * 49 + # :FQDN 353 nick = #fisk : + base_len = len(socket.getfqdn()) + 66 + + one_line = (512 - base_len) / 50 + nick_list_one = [] + for i in range(one_line): + long_nick = '%s%d' % (base_nick, i) + nick_list_one.append(long_nick) + self.connect(long_nick) + self.send(long_nick, "JOIN #fisk") + + nick_list_two = [] + for i in range(10 - one_line): + long_nick = '%s%d' % (base_nick, one_line + i) + nick_list_two.append(long_nick) + self.connect(long_nick) + self.send(long_nick, "JOIN #fisk") + + self.expect( + long_nick, + r":%(nick)s!%(nick)s@127.0.0.1 JOIN #fisk" % { + 'nick': long_nick + } + ) + self.expect(long_nick, r":local\S+ 331 %s #fisk :.*" % long_nick) + self.expect( + long_nick, + r":local\S+ 353 %s = #fisk :%s" % ( + long_nick, ' '.join(nick_list_one) + ) + ) + self.expect( + long_nick, + r":local\S+ 353 %s = #fisk :%s" % ( + long_nick, ' '.join(nick_list_two) + ) + ) + self.expect(long_nick, r":local\S+ 366 %s #fisk :.*" % long_nick) + + # Send names request + self.send(long_nick, "NAMES #fisk") + self.expect( + long_nick, + r":local\S+ 353 %s = #fisk :%s" % ( + long_nick, ' '.join(nick_list_one) + ) + ) + self.expect( + long_nick, + r":local\S+ 353 %s = #fisk :%s" % ( + long_nick, ' '.join(nick_list_two) + ) + ) + self.expect(long_nick, r":local\S+ 366 %s #fisk :.*" % long_nick) + def test_ison(self): self.connect("apa") self.send("apa", "ISON apa lemur") -- cgit v1.2.3