3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-15 08:29:31 +01:00
RPL_WHOISACTUALLY should display some arbitrarily chosen IP address and
hostname.
This commit is contained in:
Shivaram Lingamneni 2021-08-25 22:31:38 -04:00
parent 8b2f6de3e0
commit 26cdb4cf36
3 changed files with 14 additions and 6 deletions

View File

@ -613,11 +613,7 @@ func (client *Client) getIPNoMutex() net.IP {
// IPString returns the IP address of this client as a string. // IPString returns the IP address of this client as a string.
func (client *Client) IPString() string { func (client *Client) IPString() string {
ip := client.IP().String() return utils.IPStringToHostname(client.IP().String())
if 0 < len(ip) && ip[0] == ':' {
ip = "0" + ip
}
return ip
} }
// t returns the translated version of the given string, based on the languages configured by the client. // t returns the translated version of the given string, based on the languages configured by the client.

View File

@ -145,6 +145,17 @@ func (client *Client) removeSession(session *Session) (success bool, length int)
return return
} }
// #1650: show an arbitrarily chosen session IP and hostname in RPL_WHOISACTUALLY
func (client *Client) getWhoisActually() (ip net.IP, hostname string) {
client.stateMutex.RLock()
defer client.stateMutex.RUnlock()
for _, session := range client.sessions {
return session.IP(), session.rawHostname
}
return utils.IPv4LoopbackAddress, client.server.name
}
func (client *Client) Nick() string { func (client *Client) Nick() string {
client.stateMutex.RLock() client.stateMutex.RLock()
defer client.stateMutex.RUnlock() defer client.stateMutex.RUnlock()

View File

@ -482,7 +482,8 @@ func (client *Client) getWhoisOf(target *Client, hasPrivs bool, rb *ResponseBuff
} }
} }
if client == target || oper.HasRoleCapab("ban") { if client == target || oper.HasRoleCapab("ban") {
rb.Add(nil, client.server.name, RPL_WHOISACTUALLY, cnick, tnick, fmt.Sprintf("%s@%s", targetInfo.username, target.RawHostname()), target.IPString(), client.t("Actual user@host, Actual IP")) ip, hostname := target.getWhoisActually()
rb.Add(nil, client.server.name, RPL_WHOISACTUALLY, cnick, tnick, fmt.Sprintf("%s@%s", targetInfo.username, hostname), utils.IPStringToHostname(ip.String()), client.t("Actual user@host, Actual IP"))
} }
if client == target || oper.HasRoleCapab("samode") { if client == target || oper.HasRoleCapab("samode") {
rb.Add(nil, client.server.name, RPL_WHOISMODES, cnick, tnick, fmt.Sprintf(client.t("is using modes +%s"), target.modes.String())) rb.Add(nil, client.server.name, RPL_WHOISMODES, cnick, tnick, fmt.Sprintf(client.t("is using modes +%s"), target.modes.String()))