3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 07:59:31 +01:00

I don't understand why USERHOST is working with spaces...

This commit is contained in:
vegax87 2017-01-23 18:49:42 +01:00
parent f3c9c2b4b5
commit 1bb9502206
2 changed files with 21 additions and 3 deletions

View File

@ -1843,12 +1843,13 @@ func lusersHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
} }
} }
client.Send(nil, server.name, RPL_LUSERCLIENT, client.nick, fmt.Sprintf("There are %d users and %d invisible on %d server(s)", totalcount, invisiblecount, 1)) client.Send(nil, server.name, RPL_LUSERCLIENT, client.nick, fmt.Sprintf("There are %d users and %d invisible on %d server(s)", totalcount, invisiblecount, 1))
client.Send(nil, server.name, RPL_LUSEROP, client.nick, fmt.Sprintf("%d operators online", opercount)) client.Send(nil, server.name, RPL_LUSEROP, client.nick, fmt.Sprintf("%d IRC Operators online", opercount))
client.Send(nil, server.name, RPL_LUSERCHANNELS, client.nick, fmt.Sprintf("%d channels formed", len(server.channels))) client.Send(nil, server.name, RPL_LUSERCHANNELS, client.nick, fmt.Sprintf("%d channels formed", len(server.channels)))
client.Send(nil, server.name, RPL_LUSERME, client.nick, fmt.Sprintf("I have %d clients and %d servers", totalcount, 1)) client.Send(nil, server.name, RPL_LUSERME, client.nick, fmt.Sprintf("I have %d clients and %d servers", totalcount, 1))
return false return false
} }
// USERHOST <nickname> [<nickname> <nickname> ...]
func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
nickname := msg.Params[0] nickname := msg.Params[0]
@ -1860,9 +1861,9 @@ func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
} }
if target.flags[Away] { if target.flags[Away] {
client.Send(nil, client.server.name, RPL_USERHOST, client.nick, fmt.Sprintf(strings.TrimSpace("%s =- %s @ %s"), target.nick, target.username, target.hostname)) client.Send(nil, client.server.name, RPL_USERHOST, client.nick, fmt.Sprintf("%s =- %s @ %s", target.nick, target.username, target.hostname))
} else { } else {
client.Send(nil, client.server.name, RPL_USERHOST, client.nick, fmt.Sprintf(strings.TrimSpace("%s =+ %s @ %s"), target.nick, target.username, target.hostname)) client.Send(nil, client.server.name, RPL_USERHOST, client.nick, fmt.Sprintf("%s =- %s @ %s", target.nick, target.username, target.hostname))
} }
return false return false
} }

View File

@ -3,6 +3,11 @@
package irc package irc
import (
"strings"
"unicode"
)
// argsToStrings takes the arguments and splits them into a series of strings, // argsToStrings takes the arguments and splits them into a series of strings,
// each argument separated by delim and each string bounded by maxLength. // each argument separated by delim and each string bounded by maxLength.
func argsToStrings(maxLength int, arguments []string, delim string) []string { func argsToStrings(maxLength int, arguments []string, delim string) []string {
@ -33,3 +38,15 @@ func argsToStrings(maxLength int, arguments []string, delim string) []string {
return messages return messages
} }
// stripSpaces removes all whitespaces inside a string
func stripSpaces(str string) string {
return strings.Map(func(r rune) rune {
if unicode.IsSpace(r) {
// if the character is a space, drop it
return -1
}
// else keep it in the string
return r
}, str)
}