mirror of https://github.com/fluffle/goirc
gofix weekly fixes for state.
This commit is contained in:
parent
0dc19703ab
commit
81eb9ee3df
|
@ -11,9 +11,9 @@ import (
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
Name, Topic string
|
Name, Topic string
|
||||||
Modes *ChanMode
|
Modes *ChanMode
|
||||||
lookup map[string]*Nick
|
lookup map[string]*Nick
|
||||||
nicks map[*Nick]*ChanPrivs
|
nicks map[*Nick]*ChanPrivs
|
||||||
l logging.Logger
|
l logging.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// A struct representing the modes of an IRC Channel
|
// A struct representing the modes of an IRC Channel
|
||||||
|
@ -93,11 +93,11 @@ func init() {
|
||||||
|
|
||||||
func NewChannel(name string, l logging.Logger) *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,
|
l: l,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,8 +125,8 @@ func (ch *Channel) addNick(nk *Nick, cp *ChanPrivs) {
|
||||||
// Disassociates a Nick from a Channel.
|
// Disassociates a Nick from a Channel.
|
||||||
func (ch *Channel) delNick(nk *Nick) {
|
func (ch *Channel) delNick(nk *Nick) {
|
||||||
if _, ok := ch.nicks[nk]; ok {
|
if _, ok := ch.nicks[nk]; ok {
|
||||||
ch.nicks[nk] = nil, false
|
delete(ch.nicks, nk)
|
||||||
ch.lookup[nk.Nick] = nil, false
|
delete(ch.lookup, nk.Nick)
|
||||||
} else {
|
} else {
|
||||||
ch.l.Warn("Channel.delNick(): %s not on %s.", nk.Nick, ch.Name)
|
ch.l.Warn("Channel.delNick(): %s not on %s.", nk.Nick, ch.Name)
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ func (ch *Channel) ParseModes(modes string, modeargs ...string) {
|
||||||
}
|
}
|
||||||
case 'q', 'a', 'o', 'h', 'v':
|
case 'q', 'a', 'o', 'h', 'v':
|
||||||
if len(modeargs) != 0 {
|
if len(modeargs) != 0 {
|
||||||
if nk, ok := ch.lookup[modeargs[0]]; ok {
|
if nk, ok := ch.lookup[modeargs[0]]; ok {
|
||||||
cp := ch.nicks[nk]
|
cp := ch.nicks[nk]
|
||||||
switch m {
|
switch m {
|
||||||
case 'q':
|
case 'q':
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
type Nick struct {
|
type Nick struct {
|
||||||
Nick, Ident, Host, Name string
|
Nick, Ident, Host, Name string
|
||||||
Modes *NickMode
|
Modes *NickMode
|
||||||
lookup map[string]*Channel
|
lookup map[string]*Channel
|
||||||
chans map[*Channel]*ChanPrivs
|
chans map[*Channel]*ChanPrivs
|
||||||
l logging.Logger
|
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)
|
||||||
|
@ -46,11 +46,11 @@ func init() {
|
||||||
|
|
||||||
func NewNick(n string, l logging.Logger) *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,
|
l: l,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ func (nk *Nick) addChannel(ch *Channel, cp *ChanPrivs) {
|
||||||
// Disassociates a Channel from a Nick.
|
// Disassociates a Channel from a Nick.
|
||||||
func (nk *Nick) delChannel(ch *Channel) {
|
func (nk *Nick) delChannel(ch *Channel) {
|
||||||
if _, ok := nk.chans[ch]; ok {
|
if _, ok := nk.chans[ch]; ok {
|
||||||
nk.chans[ch] = nil, false
|
delete(nk.chans, ch)
|
||||||
nk.lookup[ch.Name] = nil, false
|
delete(nk.lookup, ch.Name)
|
||||||
} else {
|
} else {
|
||||||
nk.l.Warn("Nick.delChannel(): %s not on %s.", nk.Nick, ch.Name)
|
nk.l.Warn("Nick.delChannel(): %s not on %s.", nk.Nick, ch.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ 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,
|
l: l,
|
||||||
}
|
}
|
||||||
st.me = st.NewNick(mynick)
|
st.me = st.NewNick(mynick)
|
||||||
return st
|
return st
|
||||||
|
@ -88,12 +88,12 @@ func (st *stateTracker) ReNick(old, neu string) {
|
||||||
if nk, ok := st.nicks[old]; ok {
|
if nk, ok := st.nicks[old]; ok {
|
||||||
if _, ok := st.nicks[neu]; !ok {
|
if _, ok := st.nicks[neu]; !ok {
|
||||||
nk.Nick = neu
|
nk.Nick = neu
|
||||||
st.nicks[old] = nil, false
|
delete(st.nicks, old)
|
||||||
st.nicks[neu] = nk
|
st.nicks[neu] = nk
|
||||||
for ch, _ := range nk.chans {
|
for ch, _ := range nk.chans {
|
||||||
// We also need to update the lookup maps of all the channels
|
// We also need to update the lookup maps of all the channels
|
||||||
// the nick is on, to keep things in sync.
|
// the nick is on, to keep things in sync.
|
||||||
ch.lookup[old] = nil, false
|
delete(ch.lookup, old)
|
||||||
ch.lookup[neu] = nk
|
ch.lookup[neu] = nk
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -123,7 +123,7 @@ func (st *stateTracker) delNick(nk *Nick) {
|
||||||
st.l.Error("StateTracker.DelNick(): TRYING TO DELETE ME :-(")
|
st.l.Error("StateTracker.DelNick(): TRYING TO DELETE ME :-(")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
st.nicks[nk.Nick] = nil, false
|
delete(st.nicks, nk.Nick)
|
||||||
for ch, _ := range nk.chans {
|
for ch, _ := range nk.chans {
|
||||||
nk.delChannel(ch)
|
nk.delChannel(ch)
|
||||||
ch.delNick(nk)
|
ch.delNick(nk)
|
||||||
|
@ -165,7 +165,7 @@ func (st *stateTracker) DelChannel(c string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stateTracker) delChannel(ch *Channel) {
|
func (st *stateTracker) delChannel(ch *Channel) {
|
||||||
st.chans[ch.Name] = nil, false
|
delete(st.chans, ch.Name)
|
||||||
for nk, _ := range ch.nicks {
|
for nk, _ := range ch.nicks {
|
||||||
ch.delNick(nk)
|
ch.delNick(nk)
|
||||||
nk.delChannel(ch)
|
nk.delChannel(ch)
|
||||||
|
|
Loading…
Reference in New Issue