Wait 2 seconds before making the draft pick for a timed out player (#10733)

* The draft session waits for 5 seconds before making the pick for the timed out player

* Formatting

* Renamed constant

* Tweak

* If the draft pick's timeout value would increase the client's pick's timer, don't set it (might happen if the client or server is lagging)

* Lowered BOOSTER_LOADING_INTERVAL and AUTOPICK_BUFFER

---------

Co-authored-by: sprangg <a@b.c>
This commit is contained in:
sprangg 2023-08-07 03:00:42 +03:00 committed by GitHub
parent 456ea87107
commit 287df7af21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 12 deletions

View file

@ -62,12 +62,13 @@
private List<String> setCodes; private List<String> setCodes;
// Number of the current booster (for draft log writing). // Number of the current booster (for draft log writing).
// starts with 1 private int packNo = 1;
private int packNo;
// Number of the current card pick (for draft log writing). // Number of the current card pick (for draft log writing).
// starts with 1 private int pickNo = 1;
private int pickNo;
// Number of the latest card pick for which the timeout has been set.
private int timeoutPickNo = 0;
// Cached booster data to be written into the log (see logLastPick). // Cached booster data to be written into the log (see logLastPick).
private String[] currentBooster; private String[] currentBooster;
@ -298,12 +299,16 @@
MageTray.instance.blink(); MageTray.instance.blink();
} }
int newTimeout = draftPickView.getTimeout();
if (pickNo != timeoutPickNo || newTimeout < timeout) { // if the timeout would increase the current pick's timer, don't set it (might happen if the client or server is lagging)
timeoutPickNo = pickNo;
countdown.stop(); countdown.stop();
this.timeout = draftPickView.getTimeout(); timeout = newTimeout;
setTimeout(timeout); setTimeout(timeout);
if (timeout != 0) { if (timeout != 0) {
countdown.start(); countdown.start();
} }
}
if (!draftBooster.isEmptyGrid()) { if (!draftBooster.isEmptyGrid()) {
SessionHandler.setBoosterLoaded(draftId); // confirm to the server that the booster has been successfully loaded, otherwise the server will re-send the booster SessionHandler.setBoosterLoaded(draftId); // confirm to the server that the booster has been successfully loaded, otherwise the server will re-send the booster

View file

@ -31,7 +31,10 @@ public class DraftSession {
protected final Draft draft; protected final Draft draft;
protected boolean killed = false; protected boolean killed = false;
protected UUID markedCard; protected UUID markedCard;
protected int timeoutCardNum; // the pick number for which the current timeout has been set up protected int timeoutCardNum; // the pick number for which the current timeout has been set up
protected int timeoutCounter = 0; // increments every second that the player has run out of picking time
protected final int AUTOPICK_BUFFER = 2; // seconds - when the player has run out of picking time, the autopick happens after this many seconds (to account for client timer possibly lagging behind server)
private ScheduledFuture<?> futureTimeout; private ScheduledFuture<?> futureTimeout;
protected final ScheduledExecutorService timeoutExecutor; protected final ScheduledExecutorService timeoutExecutor;
@ -92,11 +95,16 @@ public class DraftSession {
private synchronized void setupTimeout(int seconds) { private synchronized void setupTimeout(int seconds) {
cancelTimeout(); cancelTimeout();
if (seconds > 0) { if (seconds > 0) {
if (seconds > 1 ) {
timeoutCounter = 0;
}
futureTimeout = timeoutExecutor.schedule( futureTimeout = timeoutExecutor.schedule(
() -> { () -> {
try { try {
if (timeoutCardNum == draft.getCardNum()) { if (timeoutCardNum == draft.getCardNum()) {
if (timeoutCounter++ > AUTOPICK_BUFFER) { // the autopick happens after n seconds (to account for client timer possibly lagging behind server)
managerFactory.draftManager().timeout(draft.getId(), userId); managerFactory.draftManager().timeout(draft.getId(), userId);
}
setupTimeout(1); // The timeout keeps happening at a 1 second interval to make sure that the draft moves onto the next pick setupTimeout(1); // The timeout keeps happening at a 1 second interval to make sure that the draft moves onto the next pick
} }
} catch (Exception e) { } catch (Exception e) {

View file

@ -34,7 +34,7 @@ public abstract class DraftImpl implements Draft {
protected int cardNum = 1; // starts with card number 1, increases by +1 after each picking protected int cardNum = 1; // starts with card number 1, increases by +1 after each picking
protected TimingOption timing; protected TimingOption timing;
protected int boosterLoadingCounter; // number of times the boosters have been sent to players until all are confirmed to have received them protected int boosterLoadingCounter; // number of times the boosters have been sent to players until all are confirmed to have received them
protected final int BOOSTER_LOADING_INTERVAL = 3; // interval in seconds protected final int BOOSTER_LOADING_INTERVAL = 2; // interval in seconds
protected boolean abort = false; protected boolean abort = false;
protected boolean started = false; protected boolean started = false;