fix minor bugs with state mutex locking; add support to fetch user realnames during WHO
This commit is contained in:
parent
f187f3abc6
commit
dbab766dc3
20
helpers.go
20
helpers.go
@ -76,22 +76,23 @@ func handleJOIN(c *Client, e Event) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the user in state. 2This will also verify the channel.
|
||||||
c.state.mu.Lock()
|
c.state.mu.Lock()
|
||||||
channel := c.state.createChanIfNotExists(e.Params[0])
|
user := c.state.createUserIfNotExists(e.Params[0], e.Source.Name)
|
||||||
c.state.mu.Unlock()
|
c.state.mu.Unlock()
|
||||||
if channel == nil {
|
if user == nil {
|
||||||
return // Invalid channel.
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Source.Name == c.GetNick() {
|
if e.Source.Name == c.GetNick() {
|
||||||
// If it's us, don't just add our user to the list. Run a WHO which
|
// If it's us, don't just add our user to the list. Run a WHO which
|
||||||
// will tell us who exactly is in the entire channel.
|
// will tell us who exactly is in the entire channel.
|
||||||
c.Send(&Event{Command: WHO, Params: []string{e.Params[0], "%tcuhn,1"}})
|
c.Send(&Event{Command: WHO, Params: []string{e.Params[0], "%tcuhnr,1"}})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the user in state. Only WHO the user, which is more efficient.
|
// Only WHO the user, which is more efficient.
|
||||||
c.Send(&Event{Command: WHO, Params: []string{e.Source.Name, "%tcuhn,1"}})
|
c.Send(&Event{Command: WHO, Params: []string{e.Source.Name, "%tcuhnr,1"}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlePART ensures that the state is clean of old user and channel entries.
|
// handlePART ensures that the state is clean of old user and channel entries.
|
||||||
@ -100,13 +101,14 @@ func handlePART(c *Client, e Event) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.state.mu.Lock()
|
|
||||||
if e.Source.Name == c.GetNick() {
|
if e.Source.Name == c.GetNick() {
|
||||||
|
c.state.mu.Lock()
|
||||||
c.state.deleteChannel(e.Params[0])
|
c.state.deleteChannel(e.Params[0])
|
||||||
c.state.mu.Unlock()
|
c.state.mu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.state.mu.Lock()
|
||||||
c.state.deleteUser(e.Source.Name)
|
c.state.deleteUser(e.Source.Name)
|
||||||
c.state.mu.Unlock()
|
c.state.mu.Unlock()
|
||||||
}
|
}
|
||||||
@ -166,6 +168,7 @@ func handleWHO(c *Client, e Event) {
|
|||||||
|
|
||||||
user.Host = host
|
user.Host = host
|
||||||
user.Ident = ident
|
user.Ident = ident
|
||||||
|
user.Name = e.Trailing
|
||||||
c.state.mu.Unlock()
|
c.state.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,14 +180,15 @@ func handleKICK(c *Client, e Event) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.state.mu.Lock()
|
|
||||||
if e.Params[1] == c.GetNick() {
|
if e.Params[1] == c.GetNick() {
|
||||||
|
c.state.mu.Lock()
|
||||||
c.state.deleteChannel(e.Params[0])
|
c.state.deleteChannel(e.Params[0])
|
||||||
c.state.mu.Unlock()
|
c.state.mu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assume it's just another user.
|
// Assume it's just another user.
|
||||||
|
c.state.mu.Lock()
|
||||||
c.state.deleteUser(e.Params[1])
|
c.state.deleteUser(e.Params[1])
|
||||||
c.state.mu.Unlock()
|
c.state.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user