diff --git a/builtin.go b/builtin.go index 35706b4..6f5e066 100644 --- a/builtin.go +++ b/builtin.go @@ -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]) diff --git a/client.go b/client.go index ad82f7a..4fc322a 100644 --- a/client.go +++ b/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 diff --git a/state.go b/state.go index bb0f49a..47a1aa2 100644 --- a/state.go +++ b/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 {