From 6267b6a40c226baea699ad515dfbe57fa8d214f1 Mon Sep 17 00:00:00 2001 From: Edmund Huber Date: Sat, 22 Mar 2014 22:25:24 +0100 Subject: [PATCH] clean up /theater so that it doesn't need a bunch of pointers and that it reuses channel-scoped-user-modes machinery --- irc/channel.go | 4 ---- irc/client.go | 5 ----- irc/modes.go | 2 +- irc/theater.go | 10 ++++------ irc/types.go | 9 +++++++++ 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index a771b8a0..3308b295 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -14,7 +14,6 @@ type Channel struct { server *Server topic Text userLimit uint64 - theaterUser *Client } // NewChannel creates a new channel from a `Server` and a `name` @@ -406,9 +405,6 @@ func (channel *Channel) applyMode(client *Client, change *ChannelModeChange) boo return channel.applyModeMember(client, change.mode, change.op, NewName(change.arg)) - case Theater: - client.ErrConfiguredMode(change.mode) - default: client.ErrUnknownMode(change.mode, channel) } diff --git a/irc/client.go b/irc/client.go index 26634405..f1f87d27 100644 --- a/irc/client.go +++ b/irc/client.go @@ -34,7 +34,6 @@ type Client struct { server *Server socket *Socket username Name - theaterChannels []*Channel } func NewClient(server *Server, conn net.Conn) *Client { @@ -260,10 +259,6 @@ func (client *Client) Quit(message Text) { return } - for _, channel := range client.theaterChannels { - delete(channel.flags, Theater) - } - client.Reply(RplError("connection closed")) client.hasQuit = true client.server.whoWas.Append(client) diff --git a/irc/modes.go b/irc/modes.go index 44dd1607..717e9c32 100644 --- a/irc/modes.go +++ b/irc/modes.go @@ -83,7 +83,7 @@ const ( Quiet ChannelMode = 'q' // flag ReOp ChannelMode = 'r' // flag Secret ChannelMode = 's' // flag, deprecated - Theater ChannelMode = 'T' // flag arg, nonstandard + Theater ChannelMode = 'T' // flag, nonstandard UserLimit ChannelMode = 'l' // flag arg Voice ChannelMode = 'v' // arg ) diff --git a/irc/theater.go b/irc/theater.go index 43f1d8d0..783c851b 100644 --- a/irc/theater.go +++ b/irc/theater.go @@ -51,10 +51,8 @@ func (m *TheaterIdentifyCommand) HandleServer(s *Server) { return } - if channel.theaterUser == nil { - client.theaterChannels = append(client.theaterChannels, channel) - channel.flags[Theater] = true - channel.theaterUser = client + if !channel.members.AnyHasMode(Theater) { + channel.members[client][Theater] = true } } @@ -82,7 +80,7 @@ func (m *TheaterPrivMsgCommand) HandleServer(s *Server) { return } - if channel.theaterUser == client { + if channel.members.HasMode(client, Theater) { for member := range channel.members { member.Reply(RplPrivMsg(TheaterClient(m.asNick), channel, m.message)) } @@ -113,7 +111,7 @@ func (m *TheaterActionCommand) HandleServer(s *Server) { return } - if channel.theaterUser == client { + if channel.members.HasMode(client, Theater) { for member := range channel.members { member.Reply(RplPrivMsg(TheaterClient(m.asNick), channel, NewText(fmt.Sprintf("\001ACTION %s\001", m.action)))) } diff --git a/irc/types.go b/irc/types.go index 7c8a5a2f..db698254 100644 --- a/irc/types.go +++ b/irc/types.go @@ -83,6 +83,15 @@ func (members MemberSet) HasMode(member *Client, mode ChannelMode) bool { return modes[mode] } +func (members MemberSet) AnyHasMode(mode ChannelMode) bool { + for _, modes := range members { + if modes[Theater] { + return true + } + } + return false +} + type ChannelSet map[*Channel]bool func (channels ChannelSet) Add(channel *Channel) {