mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-30 06:04:05 +01:00
Prevent copying locks because that's silly
This commit is contained in:
parent
4254672133
commit
2bd4d03ecc
@ -15,7 +15,7 @@ func (client *Client) alertMonitors() {
|
||||
// alert monitors
|
||||
for _, mClient := range client.server.monitoring[client.nickCasefolded] {
|
||||
// don't have to notify ourselves
|
||||
if &mClient != client {
|
||||
if mClient != client {
|
||||
mClient.SendFromClient("", client, nil, RPL_MONONLINE, mClient.nick, client.nickMaskString)
|
||||
}
|
||||
}
|
||||
@ -28,7 +28,7 @@ func (client *Client) clearMonitorList() {
|
||||
orig := client.server.monitoring[name]
|
||||
var index int
|
||||
for i, cli := range orig {
|
||||
if &cli == client {
|
||||
if cli == client {
|
||||
index = i
|
||||
break
|
||||
}
|
||||
@ -87,7 +87,7 @@ func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
|
||||
orig := server.monitoring[casefoldedTarget]
|
||||
var index int
|
||||
for i, cli := range orig {
|
||||
if &cli == client {
|
||||
if cli == client {
|
||||
index = i
|
||||
break
|
||||
}
|
||||
@ -139,7 +139,7 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
|
||||
client.monitoring[casefoldedTarget] = true
|
||||
|
||||
orig := server.monitoring[casefoldedTarget]
|
||||
server.monitoring[casefoldedTarget] = append(orig, *client)
|
||||
server.monitoring[casefoldedTarget] = append(orig, client)
|
||||
}
|
||||
|
||||
// add to online / offline lists
|
||||
|
@ -107,7 +107,7 @@ type Server struct {
|
||||
listenerUpdateMutex sync.Mutex
|
||||
logger *logger.Manager
|
||||
MaxSendQBytes uint64
|
||||
monitoring map[string][]Client
|
||||
monitoring map[string][]*Client
|
||||
motdLines []string
|
||||
name string
|
||||
nameCasefolded string
|
||||
@ -193,7 +193,7 @@ func NewServer(configFilename string, config *Config, logger *logger.Manager) (*
|
||||
accountAuthenticationEnabled: config.Accounts.AuthenticationEnabled,
|
||||
accounts: make(map[string]*ClientAccount),
|
||||
channelRegistrationEnabled: config.Channels.Registration.Enabled,
|
||||
channels: NewChannelNameMap(),
|
||||
channels: *NewChannelNameMap(),
|
||||
checkIdent: config.Server.CheckIdent,
|
||||
clients: NewClientLookupSet(),
|
||||
commands: make(chan Command),
|
||||
@ -219,7 +219,7 @@ func NewServer(configFilename string, config *Config, logger *logger.Manager) (*
|
||||
listeners: make(map[string]ListenerInterface),
|
||||
logger: logger,
|
||||
MaxSendQBytes: config.Server.MaxSendQBytes,
|
||||
monitoring: make(map[string][]Client),
|
||||
monitoring: make(map[string][]*Client),
|
||||
name: config.Server.Name,
|
||||
nameCasefolded: casefoldedName,
|
||||
networkName: config.Network.Name,
|
||||
|
33
irc/types.go
33
irc/types.go
@ -11,22 +11,21 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
//
|
||||
// simple types
|
||||
//
|
||||
|
||||
// ChannelNameMap is a map that converts channel names to actual channel objects.
|
||||
type ChannelNameMap struct {
|
||||
ChansLock sync.RWMutex
|
||||
Chans map[string]*Channel
|
||||
}
|
||||
|
||||
func NewChannelNameMap() ChannelNameMap {
|
||||
// NewChannelNameMap returns a new ChannelNameMap.
|
||||
func NewChannelNameMap() *ChannelNameMap {
|
||||
var channels ChannelNameMap
|
||||
channels.Chans = make(map[string]*Channel)
|
||||
return channels
|
||||
return &channels
|
||||
}
|
||||
|
||||
func (channels ChannelNameMap) Get(name string) *Channel {
|
||||
// Get returns the given channel if it exists.
|
||||
func (channels *ChannelNameMap) Get(name string) *Channel {
|
||||
name, err := CasefoldChannel(name)
|
||||
if err == nil {
|
||||
channels.ChansLock.RLock()
|
||||
@ -36,7 +35,8 @@ func (channels ChannelNameMap) Get(name string) *Channel {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (channels ChannelNameMap) Add(channel *Channel) error {
|
||||
// Add adds the given channel to our map.
|
||||
func (channels *ChannelNameMap) Add(channel *Channel) error {
|
||||
channels.ChansLock.Lock()
|
||||
defer channels.ChansLock.Unlock()
|
||||
if channels.Chans[channel.nameCasefolded] != nil {
|
||||
@ -46,7 +46,8 @@ func (channels ChannelNameMap) Add(channel *Channel) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (channels ChannelNameMap) Remove(channel *Channel) error {
|
||||
// Remove removes the given channel from our map.
|
||||
func (channels *ChannelNameMap) Remove(channel *Channel) error {
|
||||
channels.ChansLock.Lock()
|
||||
defer channels.ChansLock.Unlock()
|
||||
if channel != channels.Chans[channel.nameCasefolded] {
|
||||
@ -56,7 +57,8 @@ func (channels ChannelNameMap) Remove(channel *Channel) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (channels ChannelNameMap) Len() int {
|
||||
// Len returns how many channels we have.
|
||||
func (channels *ChannelNameMap) Len() int {
|
||||
channels.ChansLock.RLock()
|
||||
defer channels.ChansLock.RUnlock()
|
||||
return len(channels.Chans)
|
||||
@ -72,7 +74,7 @@ func (set ModeSet) String() string {
|
||||
index := 0
|
||||
for mode := range set {
|
||||
strs[index] = mode.String()
|
||||
index += 1
|
||||
index++
|
||||
}
|
||||
return strings.Join(strs, "")
|
||||
}
|
||||
@ -139,12 +141,3 @@ func (channels ChannelSet) First() *Channel {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//
|
||||
// interfaces
|
||||
//
|
||||
|
||||
type Identifiable interface {
|
||||
Id() string
|
||||
Nick() string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user