Browse Source

fix #764

tags/v2.0.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
e1f56aaee3
2 changed files with 26 additions and 7 deletions
  1. 24
    5
      irc/accounts.go
  2. 2
    2
      irc/hostserv.go

+ 24
- 5
irc/accounts.go View File

@@ -1169,13 +1169,9 @@ func (vh *VHostInfo) checkThrottle(cooldown time.Duration) (err error) {
1169 1169
 // callback type implementing the actual business logic of vhost operations
1170 1170
 type vhostMunger func(input VHostInfo) (output VHostInfo, err error)
1171 1171
 
1172
-func (am *AccountManager) VHostSet(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
1172
+func (am *AccountManager) VHostSet(account string, vhost string) (result VHostInfo, err error) {
1173 1173
 	munger := func(input VHostInfo) (output VHostInfo, err error) {
1174 1174
 		output = input
1175
-		err = output.checkThrottle(cooldown)
1176
-		if err != nil {
1177
-			return
1178
-		}
1179 1175
 		output.Enabled = true
1180 1176
 		output.ApprovedVHost = vhost
1181 1177
 		return
@@ -1205,6 +1201,29 @@ func (am *AccountManager) VHostRequest(account string, vhost string, cooldown ti
1205 1201
 	return am.performVHostChange(account, munger)
1206 1202
 }
1207 1203
 
1204
+func (am *AccountManager) VHostTake(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
1205
+	munger := func(input VHostInfo) (output VHostInfo, err error) {
1206
+		output = input
1207
+
1208
+		// if you have a request pending, you can cancel it using take;
1209
+		// otherwise, you're subject to the same throttling as if you were making a request
1210
+		if output.RequestedVHost == "" {
1211
+			err = output.checkThrottle(cooldown)
1212
+		}
1213
+		if err != nil {
1214
+			return
1215
+		}
1216
+		output.ApprovedVHost = vhost
1217
+		output.RequestedVHost = ""
1218
+		output.RejectedVHost = ""
1219
+		output.RejectionReason = ""
1220
+		output.LastRequestTime = time.Now().UTC()
1221
+		return
1222
+	}
1223
+
1224
+	return am.performVHostChange(account, munger)
1225
+}
1226
+
1208 1227
 func (am *AccountManager) VHostApprove(account string) (result VHostInfo, err error) {
1209 1228
 	munger := func(input VHostInfo) (output VHostInfo, err error) {
1210 1229
 		output = input

+ 2
- 2
irc/hostserv.go View File

@@ -298,7 +298,7 @@ func hsSetHandler(server *Server, client *Client, command string, params []strin
298 298
 	}
299 299
 	// else: command == "del", vhost == ""
300 300
 
301
-	_, err := server.accounts.VHostSet(user, vhost, 0)
301
+	_, err := server.accounts.VHostSet(user, vhost)
302 302
 	if err != nil {
303 303
 		hsNotice(rb, client.t("An error occurred"))
304 304
 	} else if vhost != "" {
@@ -404,7 +404,7 @@ func hsTakeHandler(server *Server, client *Client, command string, params []stri
404 404
 		return
405 405
 	}
406 406
 
407
-	_, err := server.accounts.VHostSet(client.Account(), vhost, config.Accounts.VHosts.UserRequests.Cooldown)
407
+	_, err := server.accounts.VHostTake(client.Account(), vhost, config.Accounts.VHosts.UserRequests.Cooldown)
408 408
 	if err != nil {
409 409
 		if throttled, ok := err.(*vhostThrottleExceeded); ok {
410 410
 			hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining))

Loading…
Cancel
Save