From 78e741af3ba6318a4620c96a144cdd5f3a182ea2 Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Sun, 9 Dec 2012 21:46:22 -0800 Subject: [PATCH] Some user/channel modes. --- src/irc/channel.go | 34 ++++++++++++++++++++++++++++------ src/irc/commands.go | 25 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/irc/channel.go b/src/irc/channel.go index 2a0fb74f..7db9a765 100644 --- a/src/irc/channel.go +++ b/src/irc/channel.go @@ -1,13 +1,31 @@ package irc type Channel struct { - name string - key string - topic string - members ClientSet + server *Server + name string + key string + topic string + members ClientSet + operators ClientSet + creators ClientSet + voiced ClientSet + invites map[string]bool + // modes + anonymous bool inviteOnly bool - invites map[string]bool - server *Server + moderated bool + noOutside bool + quiet bool + private bool + secret bool + serverReop bool + operTopic bool + // modes with args + password string + userLimit int + banMask string + banExceptMask string + inviteMask string } type ChannelSet map[*Channel]bool @@ -43,6 +61,10 @@ func (ch *Channel) Nicks() []string { return nicks } +func (ch *Channel) IsEmpty() bool { + return len(ch.members) == 0 +} + // // channel functionality // diff --git a/src/irc/commands.go b/src/irc/commands.go index 8c1b1141..e59004d1 100644 --- a/src/irc/commands.go +++ b/src/irc/commands.go @@ -165,16 +165,41 @@ type ModeMessage struct { modes []string } +type ChannelModeMessage struct { + *ModeMessage + channel string + modeParams []string +} + // mode s is accepted but ignored, like some other modes var MODE_RE = regexp.MustCompile("^[-+][iwroOs]+$") +var CHANNEL_RE = regexp.MustCompile("^[+\\&\\!#][:alnum:]+$") +var EXTRACT_MODE_RE = regexp.MustCompile("^([-+])?([aimnqpsrtklbeI]+)$") func NewModeMessage(args []string) (Message, error) { if len(args) < 1 { return nil, NotEnoughArgsError } + msg := &ModeMessage{ nickname: args[0], } + if (len(args) > 1) && CHANNEL_RE.MatchString(args[1]) { + cmsg := &ChannelModeMessage{msg} + if len(args) > 2 { + groups := EXTRACT_MODE_RE.FindStringSubmatch(args[2]) + cmsg.modes = make([]string, len(groups[2])) + i := 0 + for _, char := range groups[2] { + cmsg.modes[i] = fmt.Sprintf("%s%c", groups[1], char) + i++ + } + } + if len(args > 3) { + cmsg.modeParams = strings.Split(args[3], ",") + } + return cmsg + } for _, arg := range args[1:] { if !MODE_RE.MatchString(arg) { return nil, ErrUModeUnknownFlag