diff --git a/builtin.go b/builtin.go index 9edc4b8..d8ef40a 100644 --- a/builtin.go +++ b/builtin.go @@ -78,7 +78,9 @@ func handleConnect(c *Client, e Event) { // the one we supplied during connection, but some networks will rename // users on connect. if len(e.Params) > 0 { + c.state.mu.Lock() c.state.nick = e.Params[0] + c.state.mu.Unlock() } time.Sleep(2 * time.Second) diff --git a/event.go b/event.go index 1094ed5..dd70edc 100644 --- a/event.go +++ b/event.go @@ -125,17 +125,25 @@ func ParseEvent(raw string) (e *Event) { // functions/handlers edit the event without causing potential issues with // other handlers. func (e *Event) Copy() *Event { - newEvent := &Event{} + if e == nil { + return nil + } - *newEvent = *e + newEvent := &Event{ + Command: e.Command, + Trailing: e.Trailing, + EmptyTrailing: e.EmptyTrailing, + Sensitive: e.Sensitive, + } // Copy Source field, as it's a pointer and needs to be dereferenced. if e.Source != nil { - *newEvent.Source = *e.Source + newEvent.Source = e.Source.Copy() } // Copy Params in order to dereference as well. if e.Params != nil { + newEvent.Params = make([]string, len(e.Params)) copy(newEvent.Params, e.Params) } @@ -422,6 +430,21 @@ type Source struct { Host string } +// Copy returns a deep copy of Source. +func (s *Source) Copy() *Source { + if s == nil { + return nil + } + + newSource := &Source{ + Name: s.Name, + Ident: s.Ident, + Host: s.Host, + } + + return newSource +} + // ParseSource takes a string and attempts to create a Source struct. func ParseSource(raw string) (src *Source) { src = new(Source)