mirror of
https://github.com/ergochat/ergo.git
synced 2025-02-16 21:50:39 +01:00
client_lookup_set: Expose ByNick so we can loop over all clients
This commit is contained in:
parent
b23707c12a
commit
d96ca0ba25
@ -34,12 +34,12 @@ func ExpandUserHost(userhost string) (expanded string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ClientLookupSet struct {
|
type ClientLookupSet struct {
|
||||||
byNick map[string]*Client
|
ByNick map[string]*Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClientLookupSet() *ClientLookupSet {
|
func NewClientLookupSet() *ClientLookupSet {
|
||||||
return &ClientLookupSet{
|
return &ClientLookupSet{
|
||||||
byNick: make(map[string]*Client),
|
ByNick: make(map[string]*Client),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,14 +48,14 @@ func (clients *ClientLookupSet) Has(nick string) bool {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
_, exists := clients.byNick[casefoldedName]
|
_, exists := clients.ByNick[casefoldedName]
|
||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clients *ClientLookupSet) Get(nick string) *Client {
|
func (clients *ClientLookupSet) Get(nick string) *Client {
|
||||||
casefoldedName, err := CasefoldName(nick)
|
casefoldedName, err := CasefoldName(nick)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return clients.byNick[casefoldedName]
|
return clients.ByNick[casefoldedName]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func (clients *ClientLookupSet) Add(client *Client) error {
|
|||||||
if clients.Get(client.nick) != nil {
|
if clients.Get(client.nick) != nil {
|
||||||
return ErrNicknameInUse
|
return ErrNicknameInUse
|
||||||
}
|
}
|
||||||
clients.byNick[client.nickCasefolded] = client
|
clients.ByNick[client.nickCasefolded] = client
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ func (clients *ClientLookupSet) Remove(client *Client) error {
|
|||||||
if clients.Get(client.nick) != client {
|
if clients.Get(client.nick) != client {
|
||||||
return ErrNicknameMismatch
|
return ErrNicknameMismatch
|
||||||
}
|
}
|
||||||
delete(clients.byNick, client.nickCasefolded)
|
delete(clients.ByNick, client.nickCasefolded)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ func (clients *ClientLookupSet) FindAll(userhost string) (set ClientSet) {
|
|||||||
}
|
}
|
||||||
matcher := ircmatch.MakeMatch(userhost)
|
matcher := ircmatch.MakeMatch(userhost)
|
||||||
|
|
||||||
for _, client := range clients.byNick {
|
for _, client := range clients.ByNick {
|
||||||
if matcher.Match(client.nickMaskCasefolded) {
|
if matcher.Match(client.nickMaskCasefolded) {
|
||||||
set.Add(client)
|
set.Add(client)
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ func (clients *ClientLookupSet) Find(userhost string) *Client {
|
|||||||
}
|
}
|
||||||
matcher := ircmatch.MakeMatch(userhost)
|
matcher := ircmatch.MakeMatch(userhost)
|
||||||
|
|
||||||
for _, client := range clients.byNick {
|
for _, client := range clients.ByNick {
|
||||||
if matcher.Match(client.nickMaskCasefolded) {
|
if matcher.Match(client.nickMaskCasefolded) {
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user