Compare commits

..

1 commit

Author SHA1 Message Date
a1a087338b
TD-18: Implement Queue System
All checks were successful
Quality Check / Validate OAS (push) Successful in 38s
Quality Check / Validate OAS (pull_request) Successful in 38s
Quality Check / Testing (push) Successful in 1m19s
Quality Check / Linting (push) Successful in 1m20s
Quality Check / Static Analysis (push) Successful in 1m28s
Quality Check / Linting (pull_request) Successful in 1m11s
Quality Check / Static Analysis (pull_request) Successful in 1m13s
Quality Check / Testing (pull_request) Successful in 48s
2025-02-28 09:06:16 +01:00

View file

@ -28,16 +28,14 @@ public class MatchQueueService {
FoundCallback foundCallback,
QueuedCallback queuedCallback,
AbortCallback abortCallback,
EstablishedCallback establishedCallback
) {
EstablishedCallback establishedCallback) {
queue.add(player);
confirmationCallbacks.put(player, new ConfirmationCallbacks(
foundCallback,
queuedCallback,
abortCallback,
establishedCallback,
this::onRequeue
));
this::onRequeue));
tryMatching();
}
@ -47,12 +45,11 @@ public class MatchQueueService {
FoundCallback foundCallback,
QueuedCallback queuedCallback,
AbortCallback abortCallback,
EstablishedCallback establishedCallback
){
EstablishedCallback establishedCallback) {
abortCallback.call(player, matchId);
try {
queuedCallback.call(player);
} catch (IOException ignored){
} catch (IOException ignored) {
return;
}
queuePlayer(player, foundCallback, queuedCallback, abortCallback, establishedCallback);
@ -68,10 +65,10 @@ public class MatchQueueService {
return;
}
List<Player> playersToUnqueue = new ArrayList<>();
for (int i = 0; i < queue.size() / REQUIRED_PLAYER_COUNT; i++) {
Player player1 = queue.get(REQUIRED_PLAYER_COUNT * i);
Player player2 = queue.get(REQUIRED_PLAYER_COUNT * i + 1);
List<Player> loopQueue = new ArrayList<>(queue);
for (int i = 0; i < loopQueue.size() / REQUIRED_PLAYER_COUNT; i++) {
Player player1 = loopQueue.get(REQUIRED_PLAYER_COUNT * i);
Player player2 = loopQueue.get(REQUIRED_PLAYER_COUNT * i + 1);
ConfirmationCallbacks player1Callbacks = confirmationCallbacks.get(player1);
ConfirmationCallbacks player2Callbacks = confirmationCallbacks.get(player2);
@ -80,22 +77,17 @@ public class MatchQueueService {
player1,
player2,
player1Callbacks,
player2Callbacks
);
player2Callbacks);
sentMatchFound(
match,
player1,
player2,
player1Callbacks,
player2Callbacks
);
player2Callbacks);
playersToUnqueue.add(player1);
playersToUnqueue.add(player2);
}
for (Player player : playersToUnqueue) {
queue.remove(player);
if (queue.size() > REQUIRED_PLAYER_COUNT) {
tryMatching();
}
}
@ -104,11 +96,13 @@ public class MatchQueueService {
Player player1,
Player player2,
ConfirmationCallbacks player1Callbacks,
ConfirmationCallbacks player2Callbacks
) {
ConfirmationCallbacks player2Callbacks) {
boolean player1disconnected = setMatchFoundToPlayer(player1, player1Callbacks.getFoundCallback(), match);
boolean player2disconnected = setMatchFoundToPlayer(player2, player2Callbacks.getFoundCallback(), match);
queue.remove(player1);
queue.remove(player2);
if (!player1disconnected && !player2disconnected) {
return;
}
@ -120,8 +114,7 @@ public class MatchQueueService {
player2Callbacks.getFoundCallback(),
player2Callbacks.getQueuedCallback(),
player2Callbacks.getAbortCallback(),
player2Callbacks.getEstablishedCallback()
);
player2Callbacks.getEstablishedCallback());
}
if (player2disconnected && match.getPlayer1State() != PlayerMatchConfirmState.ABORTED) {
@ -131,8 +124,7 @@ public class MatchQueueService {
player1Callbacks.getFoundCallback(),
player1Callbacks.getQueuedCallback(),
player1Callbacks.getAbortCallback(),
player1Callbacks.getEstablishedCallback()
);
player1Callbacks.getEstablishedCallback());
}
}
@ -142,8 +134,7 @@ public class MatchQueueService {
player,
match.getMatchId(),
match.getCreated(),
UnconfirmedMatch.TTL
);
UnconfirmedMatch.TTL);
} catch (IOException e) {
return true;
}