mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
disallow TAKE and REQUEST while under a FORBID
This commit is contained in:
parent
e1f56aaee3
commit
5426c9fdc0
@ -1183,6 +1183,10 @@ func (am *AccountManager) VHostSet(account string, vhost string) (result VHostIn
|
|||||||
func (am *AccountManager) VHostRequest(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
|
func (am *AccountManager) VHostRequest(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
|
||||||
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
||||||
output = input
|
output = input
|
||||||
|
if input.Forbidden {
|
||||||
|
err = errVhostsForbidden
|
||||||
|
return
|
||||||
|
}
|
||||||
// you can update your existing request, but if you were approved or rejected,
|
// you can update your existing request, but if you were approved or rejected,
|
||||||
// you can't spam a new request
|
// you can't spam a new request
|
||||||
if output.RequestedVHost == "" {
|
if output.RequestedVHost == "" {
|
||||||
@ -1204,7 +1208,10 @@ func (am *AccountManager) VHostRequest(account string, vhost string, cooldown ti
|
|||||||
func (am *AccountManager) VHostTake(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
|
func (am *AccountManager) VHostTake(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
|
||||||
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
munger := func(input VHostInfo) (output VHostInfo, err error) {
|
||||||
output = input
|
output = input
|
||||||
|
if input.Forbidden {
|
||||||
|
err = errVhostsForbidden
|
||||||
|
return
|
||||||
|
}
|
||||||
// if you have a request pending, you can cancel it using take;
|
// if you have a request pending, you can cancel it using take;
|
||||||
// otherwise, you're subject to the same throttling as if you were making a request
|
// otherwise, you're subject to the same throttling as if you were making a request
|
||||||
if output.RequestedVHost == "" {
|
if output.RequestedVHost == "" {
|
||||||
|
@ -50,6 +50,7 @@ var (
|
|||||||
errBanned = errors.New("IP or nickmask banned")
|
errBanned = errors.New("IP or nickmask banned")
|
||||||
errInvalidParams = utils.ErrInvalidParams
|
errInvalidParams = utils.ErrInvalidParams
|
||||||
errNoVhost = errors.New(`You do not have an approved vhost`)
|
errNoVhost = errors.New(`You do not have an approved vhost`)
|
||||||
|
errVhostsForbidden = errors.New(`An administrator has denied you the ability to use vhosts`)
|
||||||
errLimitExceeded = errors.New("Limit exceeded")
|
errLimitExceeded = errors.New("Limit exceeded")
|
||||||
errNoop = errors.New("Action was a no-op")
|
errNoop = errors.New("Action was a no-op")
|
||||||
errCASFailed = errors.New("Compare-and-swap update of database value failed")
|
errCASFailed = errors.New("Compare-and-swap update of database value failed")
|
||||||
|
@ -216,6 +216,8 @@ func hsRequestHandler(server *Server, client *Client, command string, params []s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if throttled, ok := err.(*vhostThrottleExceeded); ok {
|
if throttled, ok := err.(*vhostThrottleExceeded); ok {
|
||||||
hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before making another request"), throttled.timeRemaining))
|
hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before making another request"), throttled.timeRemaining))
|
||||||
|
} else if err == errVhostsForbidden {
|
||||||
|
hsNotice(rb, client.t("An administrator has denied you the ability to use vhosts"))
|
||||||
} else {
|
} else {
|
||||||
hsNotice(rb, client.t("An error occurred"))
|
hsNotice(rb, client.t("An error occurred"))
|
||||||
}
|
}
|
||||||
@ -408,6 +410,8 @@ func hsTakeHandler(server *Server, client *Client, command string, params []stri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if throttled, ok := err.(*vhostThrottleExceeded); ok {
|
if throttled, ok := err.(*vhostThrottleExceeded); ok {
|
||||||
hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining))
|
hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining))
|
||||||
|
} else if err == errVhostsForbidden {
|
||||||
|
hsNotice(rb, client.t("An administrator has denied you the ability to use vhosts"))
|
||||||
} else {
|
} else {
|
||||||
hsNotice(rb, client.t("An error occurred"))
|
hsNotice(rb, client.t("An error occurred"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user