3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

implement who reply like ngircd

This commit is contained in:
Jeremy Latt 2014-02-17 21:30:14 -08:00
parent b17e62d0b0
commit bb64d38684
3 changed files with 31 additions and 10 deletions

View File

@ -19,6 +19,7 @@ type Client struct {
ctime time.Time
flags map[UserMode]bool
friends map[*Client]uint
hops uint
hostname string
idleTimer *time.Timer
loginTimer *time.Timer

View File

@ -341,14 +341,32 @@ func RplChannelModeIs(channel *Channel) Reply {
// <channel> <user> <host> <server> <nick> ( "H" / "G" ) ["*"] [ ( "@" / "+" ) ]
// :<hopcount> <real name>
func RplWhoReply(server *Server, channel *Channel, client *Client) Reply {
func RplWhoReply(channel *Channel, client *Client) Reply {
channelName := "*"
flags := ""
if client.flags[Away] {
flags = "G"
} else {
flags = "H"
}
if client.flags[Operator] {
flags += "*"
}
if channel != nil {
channelName = channel.name
if channel.members[client][ChannelOperator] {
flags += "@"
} else if channel.members[client][Voice] {
flags += "+"
}
}
return NewNumericReply(server, RPL_WHOREPLY, "%s %s %s %s %s H :0 %s",
channelName, client.username, client.hostname, server.name, client.Nick(),
client.realname)
return NewNumericReply(client.server, RPL_WHOREPLY,
"%s %s %s %s %s %s :%d %s",
channelName, client.username, client.hostname, client.server.name,
client.Nick(), flags, client.hops, client.realname)
}
// <name> :End of WHO list

View File

@ -477,9 +477,11 @@ func (msg *ChannelModeCommand) HandleServer(server *Server) {
channel.Mode(client, msg.changes)
}
func whoChannel(client *Client, server *Server, channel *Channel) {
func whoChannel(client *Client, channel *Channel) {
for member := range channel.members {
client.Reply(RplWhoReply(server, channel, member))
if !client.flags[Invisible] {
client.Reply(RplWhoReply(channel, member))
}
}
}
@ -490,17 +492,17 @@ func (msg *WhoCommand) HandleServer(server *Server) {
mask := string(msg.mask)
if mask == "" {
for _, channel := range server.channels {
whoChannel(client, server, channel)
whoChannel(client, channel)
}
} else if IsChannel(mask) {
channel := server.channels[mask]
if channel != nil {
whoChannel(client, server, channel)
whoChannel(client, channel)
}
} else {
mclient := server.clients[mask]
if mclient != nil {
client.Reply(RplWhoReply(server, mclient.channels.First(), mclient))
if mclient != nil && !mclient.flags[Invisible] {
client.Reply(RplWhoReply(nil, mclient))
}
}