mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 03:49:27 +01:00
add sadrop command
This commit is contained in:
parent
679f25491c
commit
fd34c78d6b
@ -358,29 +358,37 @@ func unmarshalReservedNicks(nicks string) (result []string) {
|
|||||||
return strings.Split(nicks, ",")
|
return strings.Split(nicks, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (am *AccountManager) SetNickReserved(client *Client, nick string, reserve bool) error {
|
func (am *AccountManager) SetNickReserved(client *Client, nick string, saUnreserve bool, reserve bool) error {
|
||||||
cfnick, err := CasefoldName(nick)
|
cfnick, err := CasefoldName(nick)
|
||||||
if err != nil {
|
// garbage nick, or garbage options, or disabled
|
||||||
|
nrconfig := am.server.AccountConfig().NickReservation
|
||||||
|
if err != nil || cfnick == "" || (reserve && saUnreserve) || !nrconfig.Enabled {
|
||||||
return errAccountNickReservationFailed
|
return errAccountNickReservationFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
// sanity check so we don't persist bad data
|
// the cache is in sync with the DB while we hold serialCacheUpdateMutex
|
||||||
account := client.Account()
|
|
||||||
if account == "" || cfnick == "" || !am.server.AccountConfig().NickReservation.Enabled {
|
|
||||||
return errAccountNickReservationFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
limit := am.server.AccountConfig().NickReservation.AdditionalNickLimit
|
|
||||||
|
|
||||||
am.serialCacheUpdateMutex.Lock()
|
am.serialCacheUpdateMutex.Lock()
|
||||||
defer am.serialCacheUpdateMutex.Unlock()
|
defer am.serialCacheUpdateMutex.Unlock()
|
||||||
|
|
||||||
// the cache is in sync with the DB while we hold serialCacheUpdateMutex
|
// find the affected account, which is usually the client's:
|
||||||
|
account := client.Account()
|
||||||
|
if saUnreserve {
|
||||||
|
// unless this is a sadrop:
|
||||||
|
account = am.NickToAccount(cfnick)
|
||||||
|
if account == "" {
|
||||||
|
// nothing to do
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if account == "" {
|
||||||
|
return errAccountNotLoggedIn
|
||||||
|
}
|
||||||
|
|
||||||
accountForNick := am.NickToAccount(cfnick)
|
accountForNick := am.NickToAccount(cfnick)
|
||||||
if reserve && accountForNick != "" {
|
if reserve && accountForNick != "" {
|
||||||
return errNicknameReserved
|
return errNicknameReserved
|
||||||
} else if !reserve && accountForNick != account {
|
} else if !reserve && !saUnreserve && accountForNick != account {
|
||||||
return errAccountNickReservationFailed
|
return errNicknameReserved
|
||||||
} else if !reserve && cfnick == account {
|
} else if !reserve && cfnick == account {
|
||||||
return errAccountCantDropPrimaryNick
|
return errAccountCantDropPrimaryNick
|
||||||
}
|
}
|
||||||
@ -405,7 +413,7 @@ func (am *AccountManager) SetNickReserved(client *Client, nick string, reserve b
|
|||||||
nicks := unmarshalReservedNicks(rawNicks)
|
nicks := unmarshalReservedNicks(rawNicks)
|
||||||
|
|
||||||
if reserve {
|
if reserve {
|
||||||
if len(nicks) >= limit {
|
if len(nicks) >= nrconfig.AdditionalNickLimit {
|
||||||
return errAccountTooManyNicks
|
return errAccountTooManyNicks
|
||||||
}
|
}
|
||||||
nicks = append(nicks, cfnick)
|
nicks = append(nicks, cfnick)
|
||||||
|
@ -90,7 +90,10 @@ func (server *Server) nickservPrivmsgHandler(client *Client, message string, rb
|
|||||||
server.nickservGroupHandler(client, rb)
|
server.nickservGroupHandler(client, rb)
|
||||||
} else if command == "drop" {
|
} else if command == "drop" {
|
||||||
nick, _ := extractParam(params)
|
nick, _ := extractParam(params)
|
||||||
server.nickservDropHandler(client, nick, rb)
|
server.nickservDropHandler(client, nick, false, rb)
|
||||||
|
} else if command == "sadrop" {
|
||||||
|
nick, _ := extractParam(params)
|
||||||
|
server.nickservDropHandler(client, nick, true, rb)
|
||||||
} else {
|
} else {
|
||||||
rb.Notice(client.t("Command not recognised. To see the available commands, run /NS HELP"))
|
rb.Notice(client.t("Command not recognised. To see the available commands, run /NS HELP"))
|
||||||
}
|
}
|
||||||
@ -294,13 +297,13 @@ func (server *Server) nickservGroupHandler(client *Client, rb *ResponseBuffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nick := client.NickCasefolded()
|
nick := client.NickCasefolded()
|
||||||
err := server.accounts.SetNickReserved(client, nick, true)
|
err := server.accounts.SetNickReserved(client, nick, false, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rb.Notice(fmt.Sprintf(client.t("Successfully grouped nick %s with your account"), nick))
|
rb.Notice(fmt.Sprintf(client.t("Successfully grouped nick %s with your account"), nick))
|
||||||
} else if err == errAccountTooManyNicks {
|
} else if err == errAccountTooManyNicks {
|
||||||
rb.Notice(client.t("You have too many nicks reserved already (you can remove some with /NS DROP)"))
|
rb.Notice(client.t("You have too many nicks reserved already (you can remove some with /NS DROP)"))
|
||||||
} else if err == errNicknameReserved {
|
} else if err == errNicknameReserved {
|
||||||
rb.Notice(client.t("That nickname is already reserved"))
|
rb.Notice(client.t("That nickname is already reserved by someone else"))
|
||||||
} else {
|
} else {
|
||||||
rb.Notice(client.t("Error reserving nickname"))
|
rb.Notice(client.t("Error reserving nickname"))
|
||||||
}
|
}
|
||||||
@ -334,20 +337,23 @@ func (server *Server) nickservInfoHandler(client *Client, nick string, rb *Respo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) nickservDropHandler(client *Client, nick string, rb *ResponseBuffer) {
|
func (server *Server) nickservDropHandler(client *Client, nick string, sadrop bool, rb *ResponseBuffer) {
|
||||||
account := client.Account()
|
if sadrop {
|
||||||
if account == "" {
|
if !client.HasRoleCapabs("unregister") {
|
||||||
rb.Notice(client.t("You're not logged into an account"))
|
rb.Notice(client.t("Insufficient oper privs"))
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := server.accounts.SetNickReserved(client, nick, false)
|
err := server.accounts.SetNickReserved(client, nick, sadrop, false)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rb.Notice(fmt.Sprintf(client.t("Successfully ungrouped nick %s with your account"), nick))
|
rb.Notice(fmt.Sprintf(client.t("Successfully ungrouped nick %s with your account"), nick))
|
||||||
|
} else if err == errAccountNotLoggedIn {
|
||||||
|
rb.Notice(fmt.Sprintf(client.t("You're not logged into an account")))
|
||||||
} else if err == errAccountCantDropPrimaryNick {
|
} else if err == errAccountCantDropPrimaryNick {
|
||||||
rb.Notice(fmt.Sprintf(client.t("You can't ungroup your primary nickname (try unregistering your account instead)")))
|
rb.Notice(fmt.Sprintf(client.t("You can't ungroup your primary nickname (try unregistering your account instead)")))
|
||||||
} else if err == errAccountNickReservationFailed {
|
} else if err == errNicknameReserved {
|
||||||
rb.Notice(fmt.Sprintf(client.t("You don't own that nick")))
|
rb.Notice(fmt.Sprintf(client.t("That nickname is already reserved by someone else")))
|
||||||
} else {
|
} else {
|
||||||
rb.Notice(client.t("Error ungrouping nick"))
|
rb.Notice(client.t("Error ungrouping nick"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user