diff --git a/state/channel.go b/state/channel.go index 8ed63f6..d01116a 100644 --- a/state/channel.go +++ b/state/channel.go @@ -90,9 +90,12 @@ func init() { * Channel methods for state management \******************************************************************************/ -func (ch *Channel) initialise() { - ch.Modes = new(ChanMode) - ch.nicks = make(map[*Nick]*ChanPrivs) +func NewChannel(name string) *Channel { + return &Channel{ + Name: name, + Modes: new(ChanMode), + nicks: make(map[*Nick]*ChanPrivs), + } } // Associates a Nick with a Channel using a shared set of ChanPrivs diff --git a/state/nick.go b/state/nick.go index 006e0f0..25890e3 100644 --- a/state/nick.go +++ b/state/nick.go @@ -44,9 +44,12 @@ func init() { * Nick methods for state management \******************************************************************************/ -func (n *Nick) initialise() { - n.Modes = new(NickMode) - n.chans = make(map[*Channel]*ChanPrivs) +func NewNick(nick string) *Nick { + return &Nick{ + Nick: nick, + Modes: new(NickMode), + chans: make(map[*Channel]*ChanPrivs), + } } // Associates a Channel with a Nick using a shared ChanPrivs diff --git a/state/tracker.go b/state/tracker.go index 91dd9b8..5bff676 100644 --- a/state/tracker.go +++ b/state/tracker.go @@ -29,14 +29,10 @@ type stateTracker struct { \******************************************************************************/ func NewTracker() *stateTracker { - st := &stateTracker{} - st.initialise() - return st -} - -func (st *stateTracker) initialise() { - st.nicks = make(map[string]*Nick) - st.chans = make(map[string]*Channel) + return &stateTracker{ + chans: make(map[string]*Channel), + nicks: make(map[string]*Nick), + } } // Creates a new Nick, initialises it, and stores it so it @@ -46,10 +42,9 @@ func (st *stateTracker) NewNick(nick string) *Nick { logging.Warn("StateTracker.NewNick(): %s already tracked.", nick) return nil } - n := &Nick{Nick: nick, st: st} - n.initialise() - st.nicks[nick] = n - return n + st.nicks[nick] = NewNick(nick) + st.nicks[nick].st = st + return st.nicks[nick] } // Returns a Nick for the nick n, if we're tracking it. @@ -92,10 +87,9 @@ func (st *stateTracker) NewChannel(c string) *Channel { logging.Warn("StateTracker.NewChannel(): %s already tracked", c) return nil } - ch := &Channel{Name: c, st: st} - ch.initialise() - st.chans[c] = ch - return ch + st.chans[c] = NewChannel(c) + st.chans[c].st = st + return st.chans[c] } // Returns a Channel for the channel c, if we're tracking it.