3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-01 16:39:26 +01:00

convert client bools to a flags map

This commit is contained in:
Jeremy Latt 2014-02-17 13:22:35 -08:00
parent 2ecc66b9d9
commit 6d8b381927
3 changed files with 30 additions and 23 deletions

View File

@ -61,7 +61,7 @@ func (channel *Channel) GetUsers(replier Replier) {
} }
func (channel *Channel) ClientIsOperator(client *Client) bool { func (channel *Channel) ClientIsOperator(client *Client) bool {
return channel.members.HasMode(client, ChannelOperator) return client.flags[Operator] || channel.members.HasMode(client, ChannelOperator)
} }
func (channel *Channel) Nicks() []string { func (channel *Channel) Nicks() []string {
@ -303,7 +303,7 @@ func (channel *Channel) Quit(client *Client) {
} }
func (channel *Channel) Kick(client *Client, target *Client, comment string) { func (channel *Channel) Kick(client *Client, target *Client, comment string) {
if !channel.members.Has(client) { if !client.flags[Operator] && !channel.members.Has(client) {
client.Reply(ErrNotOnChannel(channel)) client.Reply(ErrNotOnChannel(channel))
return return
} }

View File

@ -10,17 +10,15 @@ import (
type Client struct { type Client struct {
atime time.Time atime time.Time
away bool
awayMessage string awayMessage string
channels ChannelSet channels ChannelSet
ctime time.Time ctime time.Time
flags map[UserMode]bool
friends map[*Client]uint friends map[*Client]uint
hostname string hostname string
idleTimer *time.Timer idleTimer *time.Timer
invisible bool
loginTimer *time.Timer loginTimer *time.Timer
nick string nick string
operator bool
phase Phase phase Phase
quitTimer *time.Timer quitTimer *time.Timer
realname string realname string
@ -36,6 +34,7 @@ func NewClient(server *Server, conn net.Conn) *Client {
atime: now, atime: now,
channels: make(ChannelSet), channels: make(ChannelSet),
ctime: now, ctime: now,
flags: make(map[UserMode]bool),
friends: make(map[*Client]uint), friends: make(map[*Client]uint),
hostname: AddrLookupHostname(conn.RemoteAddr()), hostname: AddrLookupHostname(conn.RemoteAddr()),
phase: server.InitPhase(), phase: server.InitPhase(),
@ -163,11 +162,8 @@ func (client *Client) HasUsername() bool {
// <mode> // <mode>
func (c *Client) ModeString() (str string) { func (c *Client) ModeString() (str string) {
if c.invisible { for flag := range c.flags {
str += Invisible.String() str += flag.String()
}
if c.operator {
str += Operator.String()
} }
if len(str) > 0 { if len(str) > 0 {

View File

@ -388,7 +388,7 @@ func (msg *PrivMsgCommand) HandleServer(server *Server) {
return return
} }
target.Reply(RplPrivMsg(client, target, msg.message)) target.Reply(RplPrivMsg(client, target, msg.message))
if target.away { if target.flags[Away] {
client.Reply(RplAway(server, target)) client.Reply(RplAway(server, target))
} }
} }
@ -396,8 +396,8 @@ func (msg *PrivMsgCommand) HandleServer(server *Server) {
func (m *ModeCommand) HandleServer(s *Server) { func (m *ModeCommand) HandleServer(s *Server) {
client := m.Client() client := m.Client()
target := s.clients[m.nickname] target := s.clients[m.nickname]
// TODO other auth
if client != target { if client != target && !client.flags[Operator] {
client.Reply(ErrUsersDontMatch(s)) client.Reply(ErrUsersDontMatch(s))
return return
} }
@ -405,14 +405,21 @@ func (m *ModeCommand) HandleServer(s *Server) {
changes := make(ModeChanges, 0) changes := make(ModeChanges, 0)
for _, change := range m.changes { for _, change := range m.changes {
if change.mode == Invisible { switch change.mode {
case Invisible, ServerNotice, WallOps:
switch change.op { switch change.op {
case Add: case Add:
client.invisible = true client.flags[change.mode] = true
changes = append(changes, change) changes = append(changes, change)
case Remove: case Remove:
client.invisible = false delete(client.flags, change.mode)
changes = append(changes, change)
}
case Operator, LocalOperator:
if change.op == Remove {
delete(client.flags, change.mode)
changes = append(changes, change) changes = append(changes, change)
} }
} }
@ -487,7 +494,7 @@ func (msg *OperCommand) HandleServer(server *Server) {
return return
} }
client.operator = true client.flags[Operator] = true
client.Reply(RplYoureOper(server)) client.Reply(RplYoureOper(server))
client.Reply(RplUModeIs(server, client)) client.Reply(RplUModeIs(server, client))
@ -495,10 +502,14 @@ func (msg *OperCommand) HandleServer(server *Server) {
func (msg *AwayCommand) HandleServer(server *Server) { func (msg *AwayCommand) HandleServer(server *Server) {
client := msg.Client() client := msg.Client()
client.away = msg.away if msg.away {
client.flags[Away] = true
} else {
delete(client.flags, Away)
}
client.awayMessage = msg.text client.awayMessage = msg.text
if client.away { if client.flags[Away] {
client.Reply(RplNowAway(server)) client.Reply(RplNowAway(server))
} else { } else {
client.Reply(RplUnAway(server)) client.Reply(RplUnAway(server))
@ -573,7 +584,8 @@ func (msg *ListCommand) HandleServer(server *Server) {
if len(msg.channels) == 0 { if len(msg.channels) == 0 {
for _, channel := range server.channels { for _, channel := range server.channels {
if channel.flags[Secret] || channel.flags[Private] { if !client.flags[Operator] &&
(channel.flags[Secret] || channel.flags[Private]) {
continue continue
} }
client.Reply(RplList(channel)) client.Reply(RplList(channel))
@ -581,9 +593,8 @@ func (msg *ListCommand) HandleServer(server *Server) {
} else { } else {
for _, chname := range msg.channels { for _, chname := range msg.channels {
channel := server.channels[chname] channel := server.channels[chname]
if channel == nil || if channel == nil || (!client.flags[Operator] &&
channel.flags[Secret] || (channel.flags[Secret] || channel.flags[Private])) {
channel.flags[Private] {
client.Reply(ErrNoSuchChannel(server, chname)) client.Reply(ErrNoSuchChannel(server, chname))
continue continue
} }