Reduce raciness
This commit is contained in:
parent
f6902689f1
commit
e835e5898d
@ -112,7 +112,7 @@ func handleConnect(c *Client, e Event) {
|
||||
if len(split) < i {
|
||||
break search
|
||||
}
|
||||
c.IRCd.Network = split[i+1]
|
||||
c.IRCd.Network.Store(split[i+1])
|
||||
break search
|
||||
default:
|
||||
break search
|
||||
@ -515,7 +515,7 @@ func handleISUPPORT(c *Client, e Event) {
|
||||
}
|
||||
|
||||
if split[0] == "NETWORK" {
|
||||
c.state.network = split[1]
|
||||
c.state.network.Store(split[1])
|
||||
}
|
||||
|
||||
c.state.serverOptions.Set(split[0], split[1])
|
||||
|
15
client.go
15
client.go
@ -70,7 +70,7 @@ type Client struct {
|
||||
// Server contains information about the IRC server that the client is connected to.
|
||||
type Server struct {
|
||||
// Network is the name of the IRC network we are connected to as acquired by 001.
|
||||
Network string
|
||||
Network atomic.Value
|
||||
// Version is the software version of the IRC daemon as acquired by 004.
|
||||
Version string
|
||||
// Host is the hostname/id/IP of the leaf, as acquired by 002.
|
||||
@ -299,11 +299,14 @@ func New(config Config) *Client {
|
||||
}
|
||||
|
||||
c.IRCd = Server{
|
||||
Network: atomic.Value{},
|
||||
Version: "",
|
||||
UserCount: 0,
|
||||
MaxUserCount: 0,
|
||||
}
|
||||
|
||||
c.IRCd.Network.Store("")
|
||||
|
||||
c.Cmd = &Commands{c: c}
|
||||
|
||||
if c.Config.PingDelay >= 0 && c.Config.PingDelay < (20*time.Second) {
|
||||
@ -734,17 +737,17 @@ func (c *Client) NetworkName() (name string) {
|
||||
c.panicIfNotTracking()
|
||||
var ok bool
|
||||
|
||||
if len(c.state.network) > 0 {
|
||||
return c.state.network
|
||||
if len(c.state.network.Load().(string)) > 0 {
|
||||
return c.state.network.Load().(string)
|
||||
}
|
||||
|
||||
name, ok = c.GetServerOpt("NETWORK")
|
||||
if !ok {
|
||||
return c.IRCd.Network
|
||||
return c.IRCd.Network.Load().(string)
|
||||
}
|
||||
|
||||
if len(name) < 1 && len(c.IRCd.Network) > 1 {
|
||||
name = c.IRCd.Network
|
||||
if len(name) < 1 && len(c.IRCd.Network.Load().(string)) > 1 {
|
||||
name = c.IRCd.Network.Load().(string)
|
||||
}
|
||||
|
||||
return name
|
||||
|
3
state.go
3
state.go
@ -39,7 +39,7 @@ type state struct {
|
||||
serverOptions cmap.ConcurrentMap
|
||||
|
||||
// network is an alternative way to store and retrieve the NETWORK server option.
|
||||
network string
|
||||
network atomic.Value
|
||||
|
||||
// motd is the servers message of the day.
|
||||
motd string
|
||||
@ -60,6 +60,7 @@ func (s *state) reset(initial bool) {
|
||||
s.nick.Store("")
|
||||
s.ident.Store("")
|
||||
s.host.Store("")
|
||||
s.network.Store("")
|
||||
var cmaps = []*cmap.ConcurrentMap{&s.channels, &s.users, &s.serverOptions}
|
||||
for _, cm := range cmaps {
|
||||
if initial {
|
||||
|
Loading…
Reference in New Issue
Block a user