mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 03:02:48 +01:00
clean up /theater so that it doesn't need a bunch of pointers and that it reuses channel-scoped-user-modes machinery
This commit is contained in:
parent
bffad06a26
commit
6267b6a40c
@ -14,7 +14,6 @@ type Channel struct {
|
|||||||
server *Server
|
server *Server
|
||||||
topic Text
|
topic Text
|
||||||
userLimit uint64
|
userLimit uint64
|
||||||
theaterUser *Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewChannel creates a new channel from a `Server` and a `name`
|
// 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,
|
return channel.applyModeMember(client, change.mode, change.op,
|
||||||
NewName(change.arg))
|
NewName(change.arg))
|
||||||
|
|
||||||
case Theater:
|
|
||||||
client.ErrConfiguredMode(change.mode)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
client.ErrUnknownMode(change.mode, channel)
|
client.ErrUnknownMode(change.mode, channel)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ type Client struct {
|
|||||||
server *Server
|
server *Server
|
||||||
socket *Socket
|
socket *Socket
|
||||||
username Name
|
username Name
|
||||||
theaterChannels []*Channel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(server *Server, conn net.Conn) *Client {
|
func NewClient(server *Server, conn net.Conn) *Client {
|
||||||
@ -260,10 +259,6 @@ func (client *Client) Quit(message Text) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, channel := range client.theaterChannels {
|
|
||||||
delete(channel.flags, Theater)
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Reply(RplError("connection closed"))
|
client.Reply(RplError("connection closed"))
|
||||||
client.hasQuit = true
|
client.hasQuit = true
|
||||||
client.server.whoWas.Append(client)
|
client.server.whoWas.Append(client)
|
||||||
|
@ -83,7 +83,7 @@ const (
|
|||||||
Quiet ChannelMode = 'q' // flag
|
Quiet ChannelMode = 'q' // flag
|
||||||
ReOp ChannelMode = 'r' // flag
|
ReOp ChannelMode = 'r' // flag
|
||||||
Secret ChannelMode = 's' // flag, deprecated
|
Secret ChannelMode = 's' // flag, deprecated
|
||||||
Theater ChannelMode = 'T' // flag arg, nonstandard
|
Theater ChannelMode = 'T' // flag, nonstandard
|
||||||
UserLimit ChannelMode = 'l' // flag arg
|
UserLimit ChannelMode = 'l' // flag arg
|
||||||
Voice ChannelMode = 'v' // arg
|
Voice ChannelMode = 'v' // arg
|
||||||
)
|
)
|
||||||
|
@ -51,10 +51,8 @@ func (m *TheaterIdentifyCommand) HandleServer(s *Server) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.theaterUser == nil {
|
if !channel.members.AnyHasMode(Theater) {
|
||||||
client.theaterChannels = append(client.theaterChannels, channel)
|
channel.members[client][Theater] = true
|
||||||
channel.flags[Theater] = true
|
|
||||||
channel.theaterUser = client
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +80,7 @@ func (m *TheaterPrivMsgCommand) HandleServer(s *Server) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.theaterUser == client {
|
if channel.members.HasMode(client, Theater) {
|
||||||
for member := range channel.members {
|
for member := range channel.members {
|
||||||
member.Reply(RplPrivMsg(TheaterClient(m.asNick), channel, m.message))
|
member.Reply(RplPrivMsg(TheaterClient(m.asNick), channel, m.message))
|
||||||
}
|
}
|
||||||
@ -113,7 +111,7 @@ func (m *TheaterActionCommand) HandleServer(s *Server) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.theaterUser == client {
|
if channel.members.HasMode(client, Theater) {
|
||||||
for member := range channel.members {
|
for member := range channel.members {
|
||||||
member.Reply(RplPrivMsg(TheaterClient(m.asNick), channel, NewText(fmt.Sprintf("\001ACTION %s\001", m.action))))
|
member.Reply(RplPrivMsg(TheaterClient(m.asNick), channel, NewText(fmt.Sprintf("\001ACTION %s\001", m.action))))
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,15 @@ func (members MemberSet) HasMode(member *Client, mode ChannelMode) bool {
|
|||||||
return modes[mode]
|
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
|
type ChannelSet map[*Channel]bool
|
||||||
|
|
||||||
func (channels ChannelSet) Add(channel *Channel) {
|
func (channels ChannelSet) Add(channel *Channel) {
|
||||||
|
Loading…
Reference in New Issue
Block a user