mirror of https://github.com/fluffle/goirc
Switch to using and propagating logger.
This commit is contained in:
parent
88a664833e
commit
1fbd0a8b17
|
@ -13,6 +13,7 @@ type Channel struct {
|
||||||
Modes *ChanMode
|
Modes *ChanMode
|
||||||
lookup map[string]*Nick
|
lookup map[string]*Nick
|
||||||
nicks map[*Nick]*ChanPrivs
|
nicks map[*Nick]*ChanPrivs
|
||||||
|
l logging.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// A struct representing the modes of an IRC Channel
|
// A struct representing the modes of an IRC Channel
|
||||||
|
@ -90,12 +91,13 @@ func init() {
|
||||||
* Channel methods for state management
|
* Channel methods for state management
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
|
||||||
func NewChannel(name string) *Channel {
|
func NewChannel(name string, l logging.Logger) *Channel {
|
||||||
return &Channel{
|
return &Channel{
|
||||||
Name: name,
|
Name: name,
|
||||||
Modes: new(ChanMode),
|
Modes: new(ChanMode),
|
||||||
nicks: make(map[*Nick]*ChanPrivs),
|
nicks: make(map[*Nick]*ChanPrivs),
|
||||||
lookup: make(map[string]*Nick),
|
lookup: make(map[string]*Nick),
|
||||||
|
l: l,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +117,8 @@ func (ch *Channel) addNick(nk *Nick, cp *ChanPrivs) {
|
||||||
if _, ok := ch.nicks[nk]; !ok {
|
if _, ok := ch.nicks[nk]; !ok {
|
||||||
ch.nicks[nk] = cp
|
ch.nicks[nk] = cp
|
||||||
ch.lookup[nk.Nick] = nk
|
ch.lookup[nk.Nick] = nk
|
||||||
|
} else {
|
||||||
|
ch.l.Warn("Channel.addNick(): %s already on %s.", nk.Nick, ch.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +127,8 @@ func (ch *Channel) delNick(nk *Nick) {
|
||||||
if _, ok := ch.nicks[nk]; ok {
|
if _, ok := ch.nicks[nk]; ok {
|
||||||
ch.nicks[nk] = nil, false
|
ch.nicks[nk] = nil, false
|
||||||
ch.lookup[nk.Nick] = nil, false
|
ch.lookup[nk.Nick] = nil, false
|
||||||
|
} else {
|
||||||
|
ch.l.Warn("Channel.delNick(): %s not on %s.", nk.Nick, ch.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +166,7 @@ func (ch *Channel) ParseModes(modes string, modeargs []string) {
|
||||||
} else if !modeop {
|
} else if !modeop {
|
||||||
ch.Modes.Key = ""
|
ch.Modes.Key = ""
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("Channel.ParseModes(): not enough arguments to "+
|
ch.l.Warn("Channel.ParseModes(): not enough arguments to "+
|
||||||
"process MODE %s %s%s", ch.Name, modestr, m)
|
"process MODE %s %s%s", ch.Name, modestr, m)
|
||||||
}
|
}
|
||||||
case 'l':
|
case 'l':
|
||||||
|
@ -170,7 +176,7 @@ func (ch *Channel) ParseModes(modes string, modeargs []string) {
|
||||||
} else if !modeop {
|
} else if !modeop {
|
||||||
ch.Modes.Limit = 0
|
ch.Modes.Limit = 0
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("Channel.ParseModes(): not enough arguments to "+
|
ch.l.Warn("Channel.ParseModes(): not enough arguments to "+
|
||||||
"process MODE %s %s%s", ch.Name, modestr, m)
|
"process MODE %s %s%s", ch.Name, modestr, m)
|
||||||
}
|
}
|
||||||
case 'q', 'a', 'o', 'h', 'v':
|
case 'q', 'a', 'o', 'h', 'v':
|
||||||
|
@ -191,13 +197,15 @@ func (ch *Channel) ParseModes(modes string, modeargs []string) {
|
||||||
}
|
}
|
||||||
modeargs = modeargs[1:]
|
modeargs = modeargs[1:]
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("Channel.ParseModes(): untracked nick %s "+
|
ch.l.Warn("Channel.ParseModes(): untracked nick %s "+
|
||||||
"recieved MODE on channel %s", modeargs[0], ch.Name)
|
"recieved MODE on channel %s", modeargs[0], ch.Name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("Channel.ParseModes(): not enough arguments to "+
|
ch.l.Warn("Channel.ParseModes(): not enough arguments to "+
|
||||||
"process MODE %s %s%s", ch.Name, modestr, m)
|
"process MODE %s %s%s", ch.Name, modestr, m)
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
ch.l.Info("Channel.ParseModes(): unknown mode char %c", m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ type Nick struct {
|
||||||
Modes *NickMode
|
Modes *NickMode
|
||||||
lookup map[string]*Channel
|
lookup map[string]*Channel
|
||||||
chans map[*Channel]*ChanPrivs
|
chans map[*Channel]*ChanPrivs
|
||||||
|
l logging.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// A struct representing the modes of an IRC Nick (User Modes)
|
// A struct representing the modes of an IRC Nick (User Modes)
|
||||||
|
@ -43,12 +44,13 @@ func init() {
|
||||||
* Nick methods for state management
|
* Nick methods for state management
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
|
||||||
func NewNick(n string) *Nick {
|
func NewNick(n string, l logging.Logger) *Nick {
|
||||||
return &Nick{
|
return &Nick{
|
||||||
Nick: n,
|
Nick: n,
|
||||||
Modes: new(NickMode),
|
Modes: new(NickMode),
|
||||||
chans: make(map[*Channel]*ChanPrivs),
|
chans: make(map[*Channel]*ChanPrivs),
|
||||||
lookup: make(map[string]*Channel),
|
lookup: make(map[string]*Channel),
|
||||||
|
l: l,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +70,8 @@ func (nk *Nick) addChannel(ch *Channel, cp *ChanPrivs) {
|
||||||
if _, ok := nk.chans[ch]; !ok {
|
if _, ok := nk.chans[ch]; !ok {
|
||||||
nk.chans[ch] = cp
|
nk.chans[ch] = cp
|
||||||
nk.lookup[ch.Name] = ch
|
nk.lookup[ch.Name] = ch
|
||||||
|
} else {
|
||||||
|
nk.l.Warn("Nick.addChannel(): %s already on %s.", nk.Nick, ch.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +80,8 @@ func (nk *Nick) delChannel(ch *Channel) {
|
||||||
if _, ok := nk.chans[ch]; ok {
|
if _, ok := nk.chans[ch]; ok {
|
||||||
nk.chans[ch] = nil, false
|
nk.chans[ch] = nil, false
|
||||||
nk.lookup[ch.Name] = nil, false
|
nk.lookup[ch.Name] = nil, false
|
||||||
|
} else {
|
||||||
|
nk.l.Warn("Nick.delChannel(): %s not on %s.", nk.Nick, ch.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +105,7 @@ func (nk *Nick) ParseModes(modes string) {
|
||||||
case 'z':
|
case 'z':
|
||||||
nk.Modes.SSL = modeop
|
nk.Modes.SSL = modeop
|
||||||
default:
|
default:
|
||||||
logging.Info("Nick.ParseModes(): unknown mode char %c", m)
|
nk.l.Info("Nick.ParseModes(): unknown mode char %c", m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,17 @@ type stateTracker struct {
|
||||||
|
|
||||||
// We need to keep state on who we are :-)
|
// We need to keep state on who we are :-)
|
||||||
me *Nick
|
me *Nick
|
||||||
|
|
||||||
|
// For great logging justice.
|
||||||
|
l logging.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... and finally a constructor to make it.
|
// ... and finally a constructor to make it.
|
||||||
func NewTracker(mynick string) *stateTracker {
|
func NewTracker(mynick string, l logging.Logger) *stateTracker {
|
||||||
st := &stateTracker{
|
st := &stateTracker{
|
||||||
chans: make(map[string]*Channel),
|
chans: make(map[string]*Channel),
|
||||||
nicks: make(map[string]*Nick),
|
nicks: make(map[string]*Nick),
|
||||||
|
l: l,
|
||||||
}
|
}
|
||||||
st.me = st.NewNick(mynick)
|
st.me = st.NewNick(mynick)
|
||||||
return st
|
return st
|
||||||
|
@ -52,10 +56,10 @@ func NewTracker(mynick string) *stateTracker {
|
||||||
// can be properly tracked for state management purposes.
|
// can be properly tracked for state management purposes.
|
||||||
func (st *stateTracker) NewNick(n string) *Nick {
|
func (st *stateTracker) NewNick(n string) *Nick {
|
||||||
if _, ok := st.nicks[n]; ok {
|
if _, ok := st.nicks[n]; ok {
|
||||||
logging.Warn("StateTracker.NewNick(): %s already tracked.", n)
|
st.l.Warn("StateTracker.NewNick(): %s already tracked.", n)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
st.nicks[n] = NewNick(n)
|
st.nicks[n] = NewNick(n, st.l)
|
||||||
return st.nicks[n]
|
return st.nicks[n]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +86,10 @@ func (st *stateTracker) ReNick(old, neu string) {
|
||||||
ch.lookup[neu] = nk
|
ch.lookup[neu] = nk
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("StateTracker.ReNick(): %s already exists.", neu)
|
st.l.Warn("StateTracker.ReNick(): %s already exists.", neu)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("StateTracker.ReNick(): %s not tracked.", old)
|
st.l.Warn("StateTracker.ReNick(): %s not tracked.", old)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,17 +99,17 @@ func (st *stateTracker) DelNick(n string) {
|
||||||
if nk != st.me {
|
if nk != st.me {
|
||||||
st.delNick(nk)
|
st.delNick(nk)
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("StateTracker.DelNick(): won't delete myself.")
|
st.l.Warn("StateTracker.DelNick(): won't delete myself.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("StateTracker.DelNick(): %s not tracked.", n)
|
st.l.Warn("StateTracker.DelNick(): %s not tracked.", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stateTracker) delNick(nk *Nick) {
|
func (st *stateTracker) delNick(nk *Nick) {
|
||||||
if nk == st.me {
|
if nk == st.me {
|
||||||
// Shouldn't get here => internal state tracking code is fubar.
|
// Shouldn't get here => internal state tracking code is fubar.
|
||||||
logging.Error("StateTracker.DelNick(): TRYING TO DELETE ME :-(")
|
st.l.Error("StateTracker.DelNick(): TRYING TO DELETE ME :-(")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
st.nicks[nk.Nick] = nil, false
|
st.nicks[nk.Nick] = nil, false
|
||||||
|
@ -115,8 +119,8 @@ func (st *stateTracker) delNick(nk *Nick) {
|
||||||
if len(ch.nicks) == 0 {
|
if len(ch.nicks) == 0 {
|
||||||
// Deleting a nick from tracking shouldn't empty any channels as
|
// Deleting a nick from tracking shouldn't empty any channels as
|
||||||
// *we* should be on the channel with them to be tracking them.
|
// *we* should be on the channel with them to be tracking them.
|
||||||
logging.Error("StateTracker.delNick(): deleting nick %s emptied "+
|
st.l.Error("StateTracker.delNick(): deleting nick %s emptied "+
|
||||||
"channel %s, this shouldn't happen", nk.Nick, ch.Name)
|
"channel %s, this shouldn't happen!", nk.Nick, ch.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,10 +129,10 @@ func (st *stateTracker) delNick(nk *Nick) {
|
||||||
// can be properly tracked for state management purposes.
|
// can be properly tracked for state management purposes.
|
||||||
func (st *stateTracker) NewChannel(c string) *Channel {
|
func (st *stateTracker) NewChannel(c string) *Channel {
|
||||||
if _, ok := st.chans[c]; ok {
|
if _, ok := st.chans[c]; ok {
|
||||||
logging.Warn("StateTracker.NewChannel(): %s already tracked", c)
|
st.l.Warn("StateTracker.NewChannel(): %s already tracked.", c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
st.chans[c] = NewChannel(c)
|
st.chans[c] = NewChannel(c, st.l)
|
||||||
return st.chans[c]
|
return st.chans[c]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +149,7 @@ func (st *stateTracker) DelChannel(c string) {
|
||||||
if ch, ok := st.chans[c]; ok {
|
if ch, ok := st.chans[c]; ok {
|
||||||
st.delChannel(ch)
|
st.delChannel(ch)
|
||||||
} else {
|
} else {
|
||||||
logging.Warn("StateTracker.DelChannel(): %s not tracked.", c)
|
st.l.Warn("StateTracker.DelChannel(): %s not tracked.", c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,11 +184,11 @@ func (st *stateTracker) IsOn(c, n string) bool {
|
||||||
// Associates an already known nick with an already known channel.
|
// Associates an already known nick with an already known channel.
|
||||||
func (st *stateTracker) Associate(ch *Channel, nk *Nick) {
|
func (st *stateTracker) Associate(ch *Channel, nk *Nick) {
|
||||||
if ch == nil || nk == nil {
|
if ch == nil || nk == nil {
|
||||||
logging.Error("StateTracker.Associate(): passed nil values :-(")
|
st.l.Error("StateTracker.Associate(): passed nil values :-(")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if nk.IsOn(ch) {
|
if nk.IsOn(ch) {
|
||||||
logging.Warn("StateTracker.Associate(): %s already on %s.",
|
st.l.Warn("StateTracker.Associate(): %s already on %s.",
|
||||||
nk.Nick, ch.Name)
|
nk.Nick, ch.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -199,9 +203,9 @@ func (st *stateTracker) Associate(ch *Channel, nk *Nick) {
|
||||||
func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) {
|
func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) {
|
||||||
switch {
|
switch {
|
||||||
case ch == nil || nk == nil:
|
case ch == nil || nk == nil:
|
||||||
logging.Error("StateTracker.Dissociate(): passed nil values :-(")
|
st.l.Error("StateTracker.Dissociate(): passed nil values :-(")
|
||||||
case !nk.IsOn(ch):
|
case !nk.IsOn(ch):
|
||||||
logging.Warn("StateTracker.Dissociate(): %s not on %s.",
|
st.l.Warn("StateTracker.Dissociate(): %s not on %s.",
|
||||||
nk.Nick, ch.Name)
|
nk.Nick, ch.Name)
|
||||||
case nk == st.me:
|
case nk == st.me:
|
||||||
// I'm leaving the channel for some reason, so it won't be tracked.
|
// I'm leaving the channel for some reason, so it won't be tracked.
|
||||||
|
|
Loading…
Reference in New Issue