diff options
author | Braxton Plaxco <bplaxco@lupnix.org> | 2017-05-12 08:06:43 -0400 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2017-05-22 21:42:42 +0200 |
commit | a0f9244fca067807533617341daccdf7b539a4c4 (patch) | |
tree | 64d764fd18a11ff7379e4c5e70b45b8e0c11ca35 | |
parent | 78b9b19137a2f9b6bea1a8abb6f569f94b214bc7 (diff) | |
download | miniircd-a0f9244fca067807533617341daccdf7b539a4c4.tar.gz miniircd-a0f9244fca067807533617341daccdf7b539a4c4.zip |
Add basic names support
~ B'ezrat Hashem ~
-rwxr-xr-x | miniircd | 23 | ||||
-rw-r--r-- | test.py | 57 |
2 files changed, 80 insertions, 0 deletions
@@ -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, @@ -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") |