Browse Source

USERHOST: Clean up a bit, support multiple nicks

tags/v0.7.0
Daniel Oaks 7 years ago
parent
commit
9f6c4363b7
2 changed files with 34 additions and 14 deletions
  1. 3
    2
      irc/help.go
  2. 31
    12
      irc/server.go

+ 3
- 2
irc/help.go View File

@@ -371,8 +371,9 @@ Used in connection registration, sets your username and realname to the given
371 371
 values (though your username may also be looked up with Ident).`,
372 372
 	},
373 373
 	"userhost": {
374
-		text: `Show the nick, user and host of a user. Normally only used by the client or in scripts.
375
-Note: if you are not an IRCOp then it will show a cloaked hostname if the user is +x (and it's not yourself). `,
374
+		text: `USERHOST <nickname>{ <nickname>}
375
+		
376
+Shows information about the given users. Takes up to 10 nicknames.`,
376 377
 	},
377 378
 	"version": {
378 379
 		text: `VERSION [server]

+ 31
- 12
irc/server.go View File

@@ -339,7 +339,7 @@ func (server *Server) setISupport() {
339 339
 	server.isupport.Add("RPCHAN", "E")
340 340
 	server.isupport.Add("RPUSER", "E")
341 341
 	server.isupport.Add("STATUSMSG", "~&@%+")
342
-	server.isupport.Add("TARGMAX", fmt.Sprintf("NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:%s,TAGMSG:%s,NOTICE:%s,MONITOR:", maxTargetsString, maxTargetsString, maxTargetsString))
342
+	server.isupport.Add("TARGMAX", fmt.Sprintf("NAMES:1,LIST:1,KICK:1,WHOIS:1,USERHOST:10,PRIVMSG:%s,TAGMSG:%s,NOTICE:%s,MONITOR:", maxTargetsString, maxTargetsString, maxTargetsString))
343 343
 	server.isupport.Add("TOPICLEN", strconv.Itoa(server.limits.TopicLen))
344 344
 
345 345
 	// account registration
@@ -1851,19 +1851,38 @@ func lusersHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1851 1851
 
1852 1852
 // USERHOST <nickname> [<nickname> <nickname> ...]
1853 1853
 func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1854
-	nickname := msg.Params[0]
1854
+	returnedNicks := make(map[string]bool)
1855 1855
 
1856
-	casefoldedNickname, err := CasefoldName(nickname)
1857
-	target := server.clients.Get(casefoldedNickname)
1858
-	if err != nil || target == nil {
1859
-		client.Send(nil, client.server.name, ERR_NOSUCHNICK, nickname, "No such nick")
1860
-		return false
1861
-	}
1856
+	for i, nickname := range msg.Params {
1857
+		if i >= 10 {
1858
+			break
1859
+		}
1862 1860
 
1863
-	if target.flags[Away] {
1864
-		client.Send(nil, client.server.name, RPL_USERHOST, client.nick, fmt.Sprintf("%s=-%s@%s", target.nick, target.username, target.hostname))
1865
-	} else {
1866
-		client.Send(nil, client.server.name, RPL_USERHOST, client.nick, fmt.Sprintf("%s=+%s@%s", target.nick, target.username, target.hostname))
1861
+		casefoldedNickname, err := CasefoldName(nickname)
1862
+		target := server.clients.Get(casefoldedNickname)
1863
+		if err != nil || target == nil {
1864
+			client.Send(nil, client.server.name, ERR_NOSUCHNICK, nickname, "No such nick")
1865
+			return false
1866
+		}
1867
+		if returnedNicks[casefoldedNickname] {
1868
+			continue
1869
+		}
1870
+
1871
+		// to prevent returning multiple results for a single nick
1872
+		returnedNicks[casefoldedNickname] = true
1873
+
1874
+		var isOper, isAway string
1875
+
1876
+		if target.flags[Operator] {
1877
+			isOper = "*"
1878
+		}
1879
+		if target.flags[Away] {
1880
+			isAway = "-"
1881
+		} else {
1882
+			isAway = "+"
1883
+		}
1884
+		client.Send(nil, client.server.name, RPL_USERHOST, client.nick, fmt.Sprintf("%s%s=%s%s@%s", target.nick, isOper, isAway, target.username, target.hostname))
1867 1885
 	}
1886
+
1868 1887
 	return false
1869 1888
 }

Loading…
Cancel
Save