Skip to content

Commit

Permalink
Add window transaction timeout (#3003)
Browse files Browse the repository at this point in the history
* add window transaction timeout

* add timeout error message

* lint
  • Loading branch information
firejoust committed May 20, 2023
1 parent cc9a38b commit acf14c8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/plugins/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const DIG_CLICK_TIMEOUT = 500
// This number is larger than the eat time of 1.61 seconds to account for latency and low tps.
// The eat time comes from https://minecraft.fandom.com/wiki/Food#Usage
const CONSUME_TIMEOUT = 2500
// milliseconds to wait for the server to respond to a window click transaction
const WINDOW_TIMEOUT = 5000

const ALWAYS_CONSUMABLES = [
'potion',
Expand Down Expand Up @@ -544,7 +546,10 @@ function inject (bot, { hideErrors }) {
if (!window.transactionRequiresConfirmation(click)) {
confirmTransaction(window.id, actionId, true)
}
const [success] = await response
const [success] = await withTimeout(response, WINDOW_TIMEOUT)
.catch(() => {
throw new Error(`Server didn't respond to transaction for clicking on slot ${slot} on window with id ${window?.id}.`)
})
if (!success) {
throw new Error(`Server rejected transaction for clicking on slot ${slot}, on window with id ${window?.id}.`)
}
Expand Down

0 comments on commit acf14c8

Please sign in to comment.