IRC WHO command now handles a global mask/request
This commit is contained in:
parent
9e0c276783
commit
aa1780a415
56
client.go
56
client.go
@ -245,3 +245,59 @@ func (c *Client) UpdateNick(newNick string) {
|
|||||||
|
|
||||||
c.Prefix.Name = newNick
|
c.Prefix.Name = newNick
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetVisible returns a map of clients visible to this client
|
||||||
|
func (c *Client) GetVisible() map[string]*Client {
|
||||||
|
clients := map[string]*Client{}
|
||||||
|
for name, client := range c.Server.clientsByNick {
|
||||||
|
if client.HasMode(UserModeInvisible) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
clients[name] = client
|
||||||
|
}
|
||||||
|
for _, channel := range c.channels {
|
||||||
|
for member := range channel.members {
|
||||||
|
tmp, ok := c.Server.GetClientByNick(member)
|
||||||
|
if ok {
|
||||||
|
clients[member] = tmp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return clients
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendMessagetoVisible sends a message to all other visible clients
|
||||||
|
func (c *Client) SendMessagetoVisible(m *irc.Message) {
|
||||||
|
for _, client := range c.GetVisible() {
|
||||||
|
client.Encode(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendWho rmanages responding to the WHO request for all visible clients of this client
|
||||||
|
func (c *Client) SendWho() {
|
||||||
|
clients := map[string]*Client{}
|
||||||
|
for name, client := range c.Server.clientsByNick {
|
||||||
|
if client.HasMode(UserModeInvisible) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
msg := whoLine(client, nil, c.Nickname)
|
||||||
|
m := irc.Message{Prefix: c.Server.Prefix, Command: irc.RPL_WHOREPLY, Params: strings.Fields(msg)}
|
||||||
|
c.Encode(&m)
|
||||||
|
|
||||||
|
clients[name] = client
|
||||||
|
}
|
||||||
|
for _, channel := range c.channels {
|
||||||
|
for member := range channel.members {
|
||||||
|
tmp, ok := c.Server.GetClientByNick(member)
|
||||||
|
_, alreadySent := clients[member]
|
||||||
|
if ok && !alreadySent {
|
||||||
|
msg := whoLine(tmp, channel, c.Nickname)
|
||||||
|
m := irc.Message{Prefix: c.Server.Prefix, Command: irc.RPL_WHOREPLY, Params: strings.Fields(msg)}
|
||||||
|
c.Encode(&m)
|
||||||
|
clients[member] = tmp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m := irc.Message{Prefix: c.Server.Prefix, Command: irc.RPL_ENDOFWHO, Params: []string{c.Nickname, "*"}, Trailing: "End of WHO list"}
|
||||||
|
c.Encode(&m)
|
||||||
|
}
|
||||||
|
@ -313,8 +313,10 @@ func NoticeHandler(message *irc.Message, client *Client) {
|
|||||||
// WhoHandler is a CommandHandler to respond to IRC WHO commands from a client
|
// WhoHandler is a CommandHandler to respond to IRC WHO commands from a client
|
||||||
// Implemented according to RFC 1459 Section 4.5.1 and RFC 2812 Section 3.6.1
|
// Implemented according to RFC 1459 Section 4.5.1 and RFC 2812 Section 3.6.1
|
||||||
func WhoHandler(message *irc.Message, client *Client) {
|
func WhoHandler(message *irc.Message, client *Client) {
|
||||||
if len(message.Params) == 0 {
|
if len(message.Params) == 0 || len(message.Params[0]) == 0 || message.Params[0][0] == '*' {
|
||||||
//return listing of all users
|
//return listing of all visible users - visible people and people in channels with this client
|
||||||
|
client.SendWho()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ch, ok := client.Server.GetChannel(message.Params[0])
|
ch, ok := client.Server.GetChannel(message.Params[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user