mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-14 07:59:31 +01:00
fix the issue for AllNickmasks as well
This commit is contained in:
parent
a2a9788f39
commit
4bbba5b478
@ -98,6 +98,7 @@ type Client struct {
|
|||||||
socket *Socket
|
socket *Socket
|
||||||
stateMutex sync.RWMutex // tier 1
|
stateMutex sync.RWMutex // tier 1
|
||||||
username string
|
username string
|
||||||
|
usernameCasefolded string
|
||||||
vhost string
|
vhost string
|
||||||
history *history.Buffer
|
history *history.Buffer
|
||||||
}
|
}
|
||||||
@ -175,10 +176,9 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) {
|
|||||||
resp, err := ident.Query(clientHost, serverPort, clientPort, IdentTimeoutSeconds)
|
resp, err := ident.Query(clientHost, serverPort, clientPort, IdentTimeoutSeconds)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
username := resp.Identifier
|
username := resp.Identifier
|
||||||
_, err := CasefoldName(username) // ensure it's a valid username
|
err := client.SetNames(username, "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
client.Notice(client.t("*** Found your username"))
|
client.Notice(client.t("*** Found your username"))
|
||||||
client.username = username
|
|
||||||
// we don't need to updateNickMask here since nickMask is not used for anything yet
|
// we don't need to updateNickMask here since nickMask is not used for anything yet
|
||||||
} else {
|
} else {
|
||||||
client.Notice(client.t("*** Got a malformed username, ignoring"))
|
client.Notice(client.t("*** Got a malformed username, ignoring"))
|
||||||
@ -619,7 +619,7 @@ func (client *Client) HasUsername() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) SetNames(username, realname string) error {
|
func (client *Client) SetNames(username, realname string) error {
|
||||||
_, err := CasefoldName(username)
|
usernameCasefolded, err := CasefoldName(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errInvalidUsername
|
return errInvalidUsername
|
||||||
}
|
}
|
||||||
@ -629,6 +629,7 @@ func (client *Client) SetNames(username, realname string) error {
|
|||||||
|
|
||||||
if client.username == "" {
|
if client.username == "" {
|
||||||
client.username = "~" + username
|
client.username = "~" + username
|
||||||
|
client.usernameCasefolded = "~" + usernameCasefolded
|
||||||
}
|
}
|
||||||
|
|
||||||
if client.realname == "" {
|
if client.realname == "" {
|
||||||
@ -759,7 +760,6 @@ func (client *Client) updateNickMaskNoMutex() {
|
|||||||
client.hostname = client.rawHostname
|
client.hostname = client.rawHostname
|
||||||
}
|
}
|
||||||
|
|
||||||
cfusername, _ := Casefold(client.username) // we already checked for errors in SetNames
|
|
||||||
cfhostname, err := Casefold(client.hostname)
|
cfhostname, err := Casefold(client.hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.server.logger.Error("internal", "hostname couldn't be casefolded", client.hostname, err.Error())
|
client.server.logger.Error("internal", "hostname couldn't be casefolded", client.hostname, err.Error())
|
||||||
@ -767,40 +767,38 @@ func (client *Client) updateNickMaskNoMutex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.nickMaskString = fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.hostname)
|
client.nickMaskString = fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.hostname)
|
||||||
client.nickMaskCasefolded = fmt.Sprintf("%s!%s@%s", client.nickCasefolded, cfusername, cfhostname)
|
client.nickMaskCasefolded = fmt.Sprintf("%s!%s@%s", client.nickCasefolded, client.usernameCasefolded, cfhostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllNickmasks returns all the possible nickmasks for the client.
|
// AllNickmasks returns all the possible nickmasks for the client.
|
||||||
func (client *Client) AllNickmasks() []string {
|
func (client *Client) AllNickmasks() (masks []string) {
|
||||||
var masks []string
|
|
||||||
var mask string
|
|
||||||
var err error
|
|
||||||
|
|
||||||
client.stateMutex.RLock()
|
client.stateMutex.RLock()
|
||||||
nick := client.nick
|
nick := client.nickCasefolded
|
||||||
username := client.username
|
username := client.usernameCasefolded
|
||||||
rawHostname := client.rawHostname
|
rawHostname := client.rawHostname
|
||||||
vhost := client.getVHostNoMutex()
|
vhost := client.getVHostNoMutex()
|
||||||
client.stateMutex.RUnlock()
|
client.stateMutex.RUnlock()
|
||||||
|
|
||||||
if len(vhost) > 0 {
|
if len(vhost) > 0 {
|
||||||
mask, err = Casefold(fmt.Sprintf("%s!%s@%s", nick, username, vhost))
|
cfvhost, err := Casefold(vhost)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
masks = append(masks, mask)
|
masks = append(masks, fmt.Sprintf("%s!%s@%s", nick, username, cfvhost))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mask, err = Casefold(fmt.Sprintf("%s!%s@%s", nick, username, rawHostname))
|
var rawhostmask string
|
||||||
|
cfrawhost, err := Casefold(rawHostname)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
masks = append(masks, mask)
|
rawhostmask = fmt.Sprintf("%s!%s@%s", nick, username, cfrawhost)
|
||||||
|
masks = append(masks, rawhostmask)
|
||||||
}
|
}
|
||||||
|
|
||||||
mask2, err := Casefold(fmt.Sprintf("%s!%s@%s", nick, username, client.IPString()))
|
ipmask := fmt.Sprintf("%s!%s@%s", nick, username, client.IPString())
|
||||||
if err == nil && mask2 != mask {
|
if ipmask != rawhostmask {
|
||||||
masks = append(masks, mask2)
|
masks = append(masks, ipmask)
|
||||||
}
|
}
|
||||||
|
|
||||||
return masks
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoggedIntoAccount returns true if this client is logged into an account.
|
// LoggedIntoAccount returns true if this client is logged into an account.
|
||||||
|
Loading…
Reference in New Issue
Block a user