mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 15:40:02 +01:00
commit
8b01d19336
@ -2594,10 +2594,10 @@ func resumeHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
|
|||||||
|
|
||||||
// SANICK <oldnick> <nickname>
|
// SANICK <oldnick> <nickname>
|
||||||
func sanickHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
func sanickHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
||||||
targetNick := strings.TrimSpace(msg.Params[0])
|
targetNick := msg.Params[0]
|
||||||
target := server.clients.Get(targetNick)
|
target := server.clients.Get(targetNick)
|
||||||
if target == nil {
|
if target == nil {
|
||||||
rb.Add(nil, server.name, ERR_NOSUCHNICK, client.nick, msg.Params[0], client.t("No such nick"))
|
rb.Add(nil, server.name, "FAIL", "SANICK", "NO_SUCH_NICKNAME", utils.SafeErrorParam(targetNick), client.t("No such nick"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
performNickChange(server, client, target, nil, msg.Params[1], rb)
|
performNickChange(server, client, target, nil, msg.Params[1], rb)
|
||||||
|
@ -28,28 +28,57 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func performNickChange(server *Server, client *Client, target *Client, session *Session, nickname string, rb *ResponseBuffer) error {
|
func performNickChange(server *Server, client *Client, target *Client, session *Session, nickname string, rb *ResponseBuffer) error {
|
||||||
currentNick := client.Nick()
|
|
||||||
details := target.Details()
|
details := target.Details()
|
||||||
hadNick := details.nick != "*"
|
hadNick := details.nick != "*"
|
||||||
origNickMask := details.nickMask
|
origNickMask := details.nickMask
|
||||||
|
isSanick := client != target
|
||||||
|
|
||||||
assignedNickname, err, back := client.server.clients.SetNick(target, session, nickname)
|
assignedNickname, err, back := client.server.clients.SetNick(target, session, nickname)
|
||||||
if err == errNicknameInUse {
|
if err == errNicknameInUse {
|
||||||
rb.Add(nil, server.name, ERR_NICKNAMEINUSE, currentNick, utils.SafeErrorParam(nickname), client.t("Nickname is already in use"))
|
if !isSanick {
|
||||||
|
rb.Add(nil, server.name, ERR_NICKNAMEINUSE, details.nick, utils.SafeErrorParam(nickname), client.t("Nickname is already in use"))
|
||||||
|
} else {
|
||||||
|
rb.Add(nil, server.name, "FAIL", "SANICK", "NICKNAME_IN_USE", utils.SafeErrorParam(nickname), client.t("Nickname is already in use"))
|
||||||
|
}
|
||||||
} else if err == errNicknameReserved {
|
} else if err == errNicknameReserved {
|
||||||
rb.Add(nil, server.name, ERR_NICKNAMEINUSE, currentNick, utils.SafeErrorParam(nickname), client.t("Nickname is reserved by a different account"))
|
if !isSanick {
|
||||||
|
rb.Add(nil, server.name, ERR_NICKNAMEINUSE, details.nick, utils.SafeErrorParam(nickname), client.t("Nickname is reserved by a different account"))
|
||||||
|
} else {
|
||||||
|
rb.Add(nil, server.name, "FAIL", "SANICK", "NICKNAME_RESERVED", utils.SafeErrorParam(nickname), client.t("Nickname is reserved by a different account"))
|
||||||
|
}
|
||||||
} else if err == errNicknameInvalid {
|
} else if err == errNicknameInvalid {
|
||||||
rb.Add(nil, server.name, ERR_ERRONEUSNICKNAME, currentNick, utils.SafeErrorParam(nickname), client.t("Erroneous nickname"))
|
if !isSanick {
|
||||||
|
rb.Add(nil, server.name, ERR_ERRONEUSNICKNAME, details.nick, utils.SafeErrorParam(nickname), client.t("Erroneous nickname"))
|
||||||
|
} else {
|
||||||
|
rb.Add(nil, server.name, "FAIL", "SANICK", "NICKNAME_INVALID", utils.SafeErrorParam(nickname), client.t("Erroneous nickname"))
|
||||||
|
}
|
||||||
} else if err == errNickAccountMismatch {
|
} else if err == errNickAccountMismatch {
|
||||||
// this used to use ERR_NICKNAMEINUSE, but it displayed poorly in some clients;
|
// this used to use ERR_NICKNAMEINUSE, but it displayed poorly in some clients;
|
||||||
// ERR_UNKNOWNERROR at least has a better chance of displaying our error text
|
// ERR_UNKNOWNERROR at least has a better chance of displaying our error text
|
||||||
rb.Add(nil, server.name, ERR_UNKNOWNERROR, currentNick, "NICK", client.t("You must use your account name as your nickname"))
|
if !isSanick {
|
||||||
|
rb.Add(nil, server.name, ERR_UNKNOWNERROR, details.nick, "NICK", client.t("You must use your account name as your nickname"))
|
||||||
|
} else {
|
||||||
|
rb.Add(nil, server.name, "FAIL", "SANICK", "UNKNOWN_ERROR", utils.SafeErrorParam(nickname), client.t("This user's nickname and account name need to be equal"))
|
||||||
|
}
|
||||||
} else if err == errNickMissing {
|
} else if err == errNickMissing {
|
||||||
rb.Add(nil, server.name, ERR_NONICKNAMEGIVEN, currentNick, client.t("No nickname given"))
|
if !isSanick {
|
||||||
|
rb.Add(nil, server.name, ERR_NONICKNAMEGIVEN, details.nick, client.t("No nickname given"))
|
||||||
|
} else {
|
||||||
|
rb.Add(nil, server.name, "FAIL", "SANICK", "NICKNAME_INVALID", utils.SafeErrorParam(nickname), client.t("No nickname given"))
|
||||||
|
}
|
||||||
} else if err == errNoop {
|
} else if err == errNoop {
|
||||||
|
if !isSanick {
|
||||||
// no message
|
// no message
|
||||||
|
} else {
|
||||||
|
rb.Add(nil, server.name, "NOTE", "SANICK", "NOOP", utils.SafeErrorParam(nickname), client.t("Client already had the desired nickname"))
|
||||||
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
rb.Add(nil, server.name, ERR_UNKNOWNERROR, currentNick, "NICK", fmt.Sprintf(client.t("Could not set or change nickname: %s"), err.Error()))
|
client.server.logger.Error("internal", "couldn't change nick", nickname, err.Error())
|
||||||
|
if !isSanick {
|
||||||
|
rb.Add(nil, server.name, ERR_UNKNOWNERROR, details.nick, "NICK", client.t("Could not set or change nickname"))
|
||||||
|
} else {
|
||||||
|
rb.Add(nil, server.name, "FAIL", "SANICK", "UNKNOWN_ERROR", utils.SafeErrorParam(nickname), client.t("Could not set or change nickname"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user