Skip to content

Commit

Permalink
chore: check for matches based on gameTxHash
Browse files Browse the repository at this point in the history
  • Loading branch information
yHSJ committed Dec 10, 2024
1 parent 7c64c1d commit cfa7acf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
9 changes: 0 additions & 9 deletions app/src/main/java/fi/sundae/bot/api/MatchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public class MatchRequest {
private String gameId;
private String gameTxHash;
private Competitor competitorOne;
private Competitor competitorTwo;
private MatchResult result;
Expand Down Expand Up @@ -40,12 +39,4 @@ public void setResult(MatchResult result) {
public Competitor getPlayerTwo() {
return competitorTwo;
}

public void setGameTxHash(String gameTxHash) {
this.gameTxHash = gameTxHash;
}

public String getGameTxHash() {
return gameTxHash;
}
}
10 changes: 5 additions & 5 deletions app/src/main/java/fi/sundae/bot/tournament/Matchmaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ public void announceMatchStart(Match match, JDA jda) {
public void endMatch(MatchRequest matchRequest, JDA jda) {
Optional<Match> maybeMatch =
ACTIVE_MATCHES.stream()
.filter(activeMatch -> matchRequest.getGameId().equals(activeMatch.getCode()))
.filter(activeMatch -> matchRequest.getGameId().equals(activeMatch.getGameTxHash()))
.findFirst();

if (maybeMatch.isEmpty()) {
LOGGER.info("Match {} is not in ACTIVE_MATCHES", matchRequest.getGameTxHash());
LOGGER.info("Match {} is not in ACTIVE_MATCHES", matchRequest.getGameId());
return;
}
Match match = maybeMatch.get();
ACTIVE_MATCHES.remove(match);
match.getThread().delete().queue();

if (matchRequest.getResult() == MatchResult.TIMEOUT) {
LOGGER.info("Match {} is over due to timeout", matchRequest.getGameTxHash());
LOGGER.info("Match {} is over due to timeout", matchRequest.getGameId());
announceMatchTimeout(match, jda);
return;
} else if (matchRequest.getResult() == MatchResult.DISAGREEMENT) {
LOGGER.info("Match {} is over due to disagreement", matchRequest.getGameTxHash());
LOGGER.info("Match {} is over due to disagreement", matchRequest.getGameId());
announceMatchDisagreement(match, jda);
return;
} else if (matchRequest.getResult() == MatchResult.DISCONNECT) {
LOGGER.info("Match {} is over due to disconnect", matchRequest.getGameTxHash());
LOGGER.info("Match {} is over due to disconnect", matchRequest.getGameId());
announceMatchDisconnect(match, jda);
return;
}
Expand Down

0 comments on commit cfa7acf

Please sign in to comment.