Browse Source

Merge pull request #1784 from slingamn/issue1650_whoisactually

fix #1650
tags/v2.8.0-rc1
Shivaram Lingamneni 2 years ago
parent
commit
55cf1e6781
No account linked to committer's email address
3 changed files with 14 additions and 6 deletions
  1. 1
    5
      irc/client.go
  2. 11
    0
      irc/getters.go
  3. 2
    1
      irc/server.go

+ 1
- 5
irc/client.go View File

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

+ 11
- 0
irc/getters.go View File

@@ -145,6 +145,17 @@ func (client *Client) removeSession(session *Session) (success bool, length int)
145 145
 	return
146 146
 }
147 147
 
148
+// #1650: show an arbitrarily chosen session IP and hostname in RPL_WHOISACTUALLY
149
+func (client *Client) getWhoisActually() (ip net.IP, hostname string) {
150
+	client.stateMutex.RLock()
151
+	defer client.stateMutex.RUnlock()
152
+
153
+	for _, session := range client.sessions {
154
+		return session.IP(), session.rawHostname
155
+	}
156
+	return utils.IPv4LoopbackAddress, client.server.name
157
+}
158
+
148 159
 func (client *Client) Nick() string {
149 160
 	client.stateMutex.RLock()
150 161
 	defer client.stateMutex.RUnlock()

+ 2
- 1
irc/server.go View File

@@ -482,7 +482,8 @@ func (client *Client) getWhoisOf(target *Client, hasPrivs bool, rb *ResponseBuff
482 482
 		}
483 483
 	}
484 484
 	if client == target || oper.HasRoleCapab("ban") {
485
-		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"))
485
+		ip, hostname := target.getWhoisActually()
486
+		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"))
486 487
 	}
487 488
 	if client == target || oper.HasRoleCapab("samode") {
488 489
 		rb.Add(nil, client.server.name, RPL_WHOISMODES, cnick, tnick, fmt.Sprintf(client.t("is using modes +%s"), target.modes.String()))

Loading…
Cancel
Save