20 Commits

Author SHA1 Message Date
1d4718ccdb Update dependency de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring3x to v4.16.1 2024-07-18 16:01:26 +00:00
Lee
9771b04589 Merge pull request 'Update dependency com.google.code.gson:gson to v2.10.1' (#1) from renovate/com.google.code.gson-gson-2.x into master
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m22s
Reviewed-on: #1
2024-04-28 02:11:49 +00:00
3a60a8050b Update dependency com.google.code.gson:gson to v2.10.1 2024-04-28 01:00:54 +00:00
8d1ef26183 add Sentry
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m31s
2024-04-28 01:07:26 +01:00
d96a38a996 don't save banned or inactive accounts
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m21s
2024-04-25 20:23:51 +01:00
6c63534988 Don't fetch new scores if the account is inactive or banned.
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m19s
2024-04-25 20:22:07 +01:00
f2f45ffa87 move it to another repo
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m22s
2024-04-25 20:12:58 +01:00
0b5f083366 don't load again if only page params changed
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Has been cancelled
2024-04-25 20:12:16 +01:00
ddaa1e7c97 fix double data loading
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m20s
2024-04-25 20:08:41 +01:00
c0d2781fd0 use account name not id
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m19s
2024-04-25 20:06:06 +01:00
e7ee0ef4af fix changing pages on the script
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Has been cancelled
2024-04-25 20:05:51 +01:00
80331ba972 maybe fix page switching?
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m19s
2024-04-25 19:56:06 +01:00
f5b8aa82c7 improve score fetching and add a curve version to scores
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m24s
2024-04-25 19:43:48 +01:00
e5fbb3d44c bump script version
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m19s
2024-04-25 08:32:15 +01:00
54b20cf016 make the script work when changing pages
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m20s
2024-04-25 08:30:50 +01:00
bc8a9f6fdc fix
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m21s
2024-04-25 08:15:19 +01:00
ae19233ddf return null bio if the raw bio is null
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m20s
2024-04-25 08:09:59 +01:00
2b8b135cf8 fix script failing to load on page load
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m19s
2024-04-25 07:34:22 +01:00
4cd6c27b2b joe
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m19s
2024-04-25 07:11:06 +01:00
b08961adf8 start work on the tampermonkey script 2024-04-25 07:11:05 +01:00
12 changed files with 140 additions and 73 deletions

12
pom.xml
View File

@ -80,7 +80,15 @@
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
<version>2.9.1</version> <version>2.10.1</version>
</dependency>
<!-- Sentry -->
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring-boot-starter-jakarta</artifactId>
<version>7.8.0</version>
<scope>compile</scope>
</dependency> </dependency>
<!-- Websockets --> <!-- Websockets -->
@ -98,7 +106,7 @@
<dependency> <dependency>
<groupId>de.flapdoodle.embed</groupId> <groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo.spring3x</artifactId> <artifactId>de.flapdoodle.embed.mongo.spring3x</artifactId>
<version>4.12.6</version> <version>4.16.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -1,5 +1,8 @@
package cc.fascinated.backend.common; package cc.fascinated.backend.common;
import lombok.experimental.UtilityClass;
@UtilityClass
public class MathUtils { public class MathUtils {
/** /**

View File

@ -1,5 +1,8 @@
package cc.fascinated.backend.common; package cc.fascinated.backend.common;
import lombok.experimental.UtilityClass;
@UtilityClass
public class Timer { public class Timer {
/** /**

View File

@ -2,6 +2,7 @@ package cc.fascinated.backend.exception;
import cc.fascinated.backend.model.response.ErrorResponse; import cc.fascinated.backend.model.response.ErrorResponse;
import io.micrometer.common.lang.NonNull; import io.micrometer.common.lang.NonNull;
import io.sentry.Sentry;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
@ -39,6 +40,7 @@ public final class ExceptionControllerAdvice {
} }
if (status == null) { // Fallback to 500 if (status == null) { // Fallback to 500
status = HttpStatus.INTERNAL_SERVER_ERROR; status = HttpStatus.INTERNAL_SERVER_ERROR;
Sentry.captureException(ex); // Capture the exception
} }
return new ResponseEntity<>(new ErrorResponse(status, message), status); return new ResponseEntity<>(new ErrorResponse(status, message), status);
} }

View File

@ -10,6 +10,11 @@ public class Leaderboard {
*/ */
private final String name; private final String name;
/**
* The version of the leaderboard.
*/
private int curveVersion;
/** /**
* The curve of the leaderboard. * The curve of the leaderboard.
*/ */

View File

@ -24,7 +24,7 @@ public class ScoreSaberLeaderboard extends Leaderboard {
private final double weightCoefficient = 0.965; private final double weightCoefficient = 0.965;
public ScoreSaberLeaderboard() { public ScoreSaberLeaderboard() {
super("ScoreSaber", new LeaderboardCurvePoint[] { super("ScoreSaber", 1, new LeaderboardCurvePoint[] {
new LeaderboardCurvePoint(1.0, 5.367394282890631), new LeaderboardCurvePoint(1.0, 5.367394282890631),
new LeaderboardCurvePoint(0.9995, 5.019543595874787), new LeaderboardCurvePoint(0.9995, 5.019543595874787),
new LeaderboardCurvePoint(0.999, 4.715470646416203), new LeaderboardCurvePoint(0.999, 4.715470646416203),

View File

@ -163,6 +163,9 @@ public class Account {
* @return The bio. * @return The bio.
*/ */
public static Bio fromRaw(String raw) { public static Bio fromRaw(String raw) {
if (raw == null || raw.isEmpty()) {
return null;
}
return new Bio( return new Bio(
raw.split("\n"), raw.split("\n"),
raw.replaceAll("<[^>]*>", "").split("\n") raw.replaceAll("<[^>]*>", "").split("\n")

View File

@ -1,6 +1,7 @@
package cc.fascinated.backend.model.score; package cc.fascinated.backend.model.score;
import cc.fascinated.backend.common.DateUtils; import cc.fascinated.backend.common.DateUtils;
import cc.fascinated.backend.leaderboard.impl.ScoreSaberLeaderboard;
import cc.fascinated.backend.model.token.ScoreSaberLeaderboardToken; import cc.fascinated.backend.model.token.ScoreSaberLeaderboardToken;
import cc.fascinated.backend.model.token.ScoreSaberPlayerScoreToken; import cc.fascinated.backend.model.token.ScoreSaberPlayerScoreToken;
import cc.fascinated.backend.model.token.ScoreSaberScoreToken; import cc.fascinated.backend.model.token.ScoreSaberScoreToken;
@ -8,8 +9,6 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,7 +19,7 @@ import java.util.List;
* A score for an account. * A score for an account.
*/ */
@Document @Document
@AllArgsConstructor @Getter @Setter @Getter @Setter
public class Score { public class Score {
/** /**
* The id for this score. * The id for this score.
@ -128,11 +127,45 @@ public class Score {
*/ */
private String leaderboardId; private String leaderboardId;
/**
* The curve version for this score.
*/
private Integer curveVersion;
/** /**
* The difficulty this score was set on. * The difficulty this score was set on.
*/ */
private Difficulty difficulty; private Difficulty difficulty;
public Score(String id, int rank, int baseScore, int modifiedScore, Double pp, int weight, List<String> modifiers,
int multiplier, int badCuts, int missedNotes, int maxCombo, boolean fullCombo, int hmd, Date timeSet,
boolean hasReplay, String deviceHmd, String deviceControllerLeft, String deviceControllerRight,
List<Score> previousScores, String accountId, String leaderboardId, Integer curveVersion, Difficulty difficulty) {
this.id = id;
this.rank = rank;
this.baseScore = baseScore;
this.modifiedScore = modifiedScore;
this.pp = pp;
this.weight = weight;
this.modifiers = modifiers;
this.multiplier = multiplier;
this.badCuts = badCuts;
this.missedNotes = missedNotes;
this.maxCombo = maxCombo;
this.fullCombo = fullCombo;
this.hmd = hmd;
this.timeSet = timeSet;
this.hasReplay = hasReplay;
this.deviceHmd = deviceHmd;
this.deviceControllerLeft = deviceControllerLeft;
this.deviceControllerRight = deviceControllerRight;
this.previousScores = previousScores;
this.accountId = accountId;
this.leaderboardId = leaderboardId;
this.curveVersion = curveVersion == null ? ScoreSaberLeaderboard.INSTANCE.getCurveVersion() : curveVersion;
this.difficulty = difficulty;
}
/** /**
* Gets a score from the given token. * Gets a score from the given token.
* *
@ -171,6 +204,7 @@ public class Score {
new ArrayList<>(), new ArrayList<>(),
playerId, playerId,
leaderboard.getId(), leaderboard.getId(),
ScoreSaberLeaderboard.INSTANCE.getCurveVersion(), // Get the curve version from the leaderboard.
Difficulty.fromId(leaderboard.getDifficulty().getDifficulty()) Difficulty.fromId(leaderboard.getDifficulty().getDifficulty())
); );
} }

View File

@ -18,7 +18,7 @@ public interface ScoreRepository extends MongoRepository<Score, String> {
* @return The scores for the account. * @return The scores for the account.
*/ */
@Query("{ 'accountId' : ?0 }") @Query("{ 'accountId' : ?0 }")
List<Score> getScoresForAccount(String accountId); List<Score> getScores(String accountId);
/** /**
* Gets the ranked scores for an account. * Gets the ranked scores for an account.
@ -27,7 +27,7 @@ public interface ScoreRepository extends MongoRepository<Score, String> {
* @return The ranked scores for the account. * @return The ranked scores for the account.
*/ */
@Query(value = "{ 'accountId' : ?0, 'pp' : { $gt : 0 } }", sort = "{ 'pp' : -1 }") @Query(value = "{ 'accountId' : ?0, 'pp' : { $gt : 0 } }", sort = "{ 'pp' : -1 }")
List<Score> getRankedScoresForAccount(String accountId); List<Score> getRankedScores(String accountId);
/** /**
* Gets the scores sorted by the newest for an account. * Gets the scores sorted by the newest for an account.
@ -37,4 +37,14 @@ public interface ScoreRepository extends MongoRepository<Score, String> {
*/ */
@Query(value = "{ 'accountId' : ?0 }", sort = "{ 'timeSet' : -1 }") @Query(value = "{ 'accountId' : ?0 }", sort = "{ 'timeSet' : -1 }")
List<Score> getScoresSortedByNewest(String accountId); List<Score> getScoresSortedByNewest(String accountId);
/**
* Gets the scores for an account and a leaderboard.
*
* @param accountId The id of the account.
* @param leaderboardId The id of the leaderboard.
* @return The scores for the leaderboard.
*/
@Query(value = "{ 'accountId' : ?0, 'leaderboardId' : ?1 }", sort = "{ 'timeSet' : -1 }")
List<Score> getScoreForLeaderboard(String accountId, String leaderboardId);
} }

View File

@ -70,7 +70,6 @@ public class AccountService {
Optional<Account> optionalAccount = accountRepository.findById(id); Optional<Account> optionalAccount = accountRepository.findById(id);
if (optionalAccount.isEmpty()) { if (optionalAccount.isEmpty()) {
log.info("Account '{}' not found in the database. Fetching from ScoreSaber API.", id); log.info("Account '{}' not found in the database. Fetching from ScoreSaber API.", id);
return updateAccount(Account.fromToken(scoreSaberService.getAccount(id))); return updateAccount(Account.fromToken(scoreSaberService.getAccount(id)));
} }
log.info("Account '{}' found in the database.", id); log.info("Account '{}' found in the database.", id);
@ -95,15 +94,19 @@ public class AccountService {
// Update the account with the new token. // Update the account with the new token.
account = Account.fromToken(accountToken); account = Account.fromToken(accountToken);
accountRepository.save(account);
// Don't fetch new scores if the account is inactive or banned.
if (account.isInactive() || account.isBanned()) {
return account;
}
// Fetch the scores for the account. // Fetch the scores for the account.
scoreSaberService.updateScores(account); scoreSaberService.updateScores(account);
// Set the raw pp per +1 global pp // Set the raw pp per +1 global pp
double rawPerGlobalPP = ScoreSaberLeaderboard.INSTANCE.getRawPerGlobalPP(scoreRepository.getRankedScoresForAccount(id), 1); double rawPerGlobalPP = ScoreSaberLeaderboard.INSTANCE.getRawPerGlobalPP(scoreRepository.getRankedScores(id), 1);
account.setRawPerGlobalPerformancePoints(rawPerGlobalPP); account.setRawPerGlobalPerformancePoints(rawPerGlobalPP);
// Save the account to the database.
return accountRepository.save(account); return accountRepository.save(account);
} }
} }

View File

@ -4,6 +4,7 @@ import cc.fascinated.backend.Main;
import cc.fascinated.backend.common.DateUtils; import cc.fascinated.backend.common.DateUtils;
import cc.fascinated.backend.common.Timer; import cc.fascinated.backend.common.Timer;
import cc.fascinated.backend.common.WebRequest; import cc.fascinated.backend.common.WebRequest;
import cc.fascinated.backend.exception.impl.BadRequestException;
import cc.fascinated.backend.exception.impl.RateLimitException; import cc.fascinated.backend.exception.impl.RateLimitException;
import cc.fascinated.backend.exception.impl.ResourceNotFoundException; import cc.fascinated.backend.exception.impl.ResourceNotFoundException;
import cc.fascinated.backend.model.account.Account; import cc.fascinated.backend.model.account.Account;
@ -79,6 +80,12 @@ public class ScoreSaberService extends TextWebSocketHandler {
log.info("Account with id '{}' not found.", id); log.info("Account with id '{}' not found.", id);
throw new ResourceNotFoundException("Account with id '%s' not found.".formatted(id)); throw new ResourceNotFoundException("Account with id '%s' not found.".formatted(id));
} }
if (account.isBanned()) {
throw new BadRequestException("Account with id '%s' is banned.".formatted(id));
}
if (account.isInactive()) {
throw new BadRequestException("Account with id '%s' is inactive.".formatted(id));
}
return account; return account;
} }
@ -90,7 +97,7 @@ public class ScoreSaberService extends TextWebSocketHandler {
* @return The scores. * @return The scores.
*/ */
public ScoreSaberScoresPageToken getPageScores(Account account, int page) { public ScoreSaberScoresPageToken getPageScores(Account account, int page) {
log.info("Fetching scores for account '{}' from page {}.", account.getId(), page); log.info("Fetching scores for account '{}' from page {}.", account.getName(), page);
ScoreSaberScoresPageToken pageToken = WebRequest.getAsEntity(String.format(GET_PLAYER_SCORES_ENDPOINT, account.getId(), "recent", page), ScoreSaberScoresPageToken.class); ScoreSaberScoresPageToken pageToken = WebRequest.getAsEntity(String.format(GET_PLAYER_SCORES_ENDPOINT, account.getId(), "recent", page), ScoreSaberScoresPageToken.class);
if (pageToken == null) { // Check if the page doesn't exist. if (pageToken == null) { // Check if the page doesn't exist.
return null; return null;
@ -120,54 +127,29 @@ public class ScoreSaberService extends TextWebSocketHandler {
return scores; return scores;
} }
/**
* Fetch the scores until the specified score id.
*
* @param account The account.
* @param scoreUntil The score to fetch until.
* @return The scores.
*/
public List<ScoreSaberPlayerScoreToken> getScoreUntil(Account account, Score scoreUntil) {
List<ScoreSaberPlayerScoreToken> scores = new ArrayList<>();
int page = 1;
do {
ScoreSaberScoresPageToken pageToken = getPageScores(account, page);
for (ScoreSaberPlayerScoreToken score : pageToken.getPlayerScores()) {
// If the score isn't the same as the scoreUntil, add it to the list.
if (!DateUtils.getDateFromString(score.getScore().getTimeSet()).equals(scoreUntil.getTimeSet())) {
scores.add(score);
}
if (score.getScore().getId().equals(scoreUntil.getId())) {
// If the current score matches the specified scoreUntil, stop fetching.
return scores;
}
}
page++;
} while (true);
}
/** /**
* Fetches the scores for the account. * Fetches the scores for the account.
* *
* @param account The account. * @param account The account.
*/ */
public void updateScores(Account account) { public void updateScores(Account account) {
String id = account.getId(); String name = account.getName();
// Fetch the scores for the account. // Fetch the scores for the account.
List<Score> scores = scoreRepository.getScoresForAccount(id); List<Score> scores = scoreRepository.getScores(account.getId());
if (scores.isEmpty()) { if (scores.isEmpty()) {
log.warn("Account '{}' has no scores, fetching them.", id); log.warn("Account '{}' has no scores, fetching them.", name);
List<ScoreSaberScoresPageToken> scoresPageTokens = this.getScores(account); List<ScoreSaberScoresPageToken> scoresPageTokens = this.getScores(account);
List<Score> newScores = new ArrayList<>(); List<Score> newScores = new ArrayList<>();
List<Leaderboard> leaderboardToSave = new ArrayList<>(); List<Leaderboard> leaderboardToSave = new ArrayList<>();
for (ScoreSaberScoresPageToken page : scoresPageTokens) { for (ScoreSaberScoresPageToken page : scoresPageTokens) {
for (ScoreSaberPlayerScoreToken score : page.getPlayerScores()) { for (ScoreSaberPlayerScoreToken scoreToken : page.getPlayerScores()) {
newScores.add(Score.fromToken(id, score)); Score score = Score.fromToken(account.getId(), scoreToken);
leaderboardToSave.add(Leaderboard.fromToken(score.getLeaderboard())); newScores.add(score);
scores.add(score);
leaderboardToSave.add(Leaderboard.fromToken(scoreToken.getLeaderboard()));
} }
} }
@ -179,28 +161,36 @@ public class ScoreSaberService extends TextWebSocketHandler {
} }
scoreRepository.saveAll(newScores); // Save the player's scores. scoreRepository.saveAll(newScores); // Save the player's scores.
log.info("Found {} scores for account '{}'.", newScores.size(), id); log.info("Found {} scores for account '{}'.", newScores.size(), name);
return; return;
} }
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
log.info("Fetching new scores for account '{}'.", id); log.info("Fetching new scores for account '{}'.", name);
Score latestScore = scoreRepository.getScoresSortedByNewest(id).get(0);
List<ScoreSaberPlayerScoreToken> newScores = this.getScoreUntil(account, latestScore); int page = 1; // The current page to search for scores.
if (newScores.isEmpty()) { boolean done = false; // Whether we are done fetching scores.
log.info("No new scores found for account '{}'.", id); List<ScoreSaberPlayerScoreToken> newScores = new ArrayList<>();
return; do {
// This will keep fetching score pages until it finds a score that already exists.
ScoreSaberScoresPageToken pageScores = getPageScores(account, page);
for (ScoreSaberPlayerScoreToken score : pageScores.getPlayerScores()) {
boolean exists = scores.stream().anyMatch(s -> s.getId().equals(score.getScore().getId()));
if (!exists) {
newScores.add(score);
continue;
}
done = true;
}
page++;
} while (!done);
// Save the new scores.
for (ScoreSaberPlayerScoreToken score : newScores) {
saveScore(account, score);
} }
int newScoreCount = 0; log.info("Found {} new scores for account '{}'. (took: {}ms)", newScores.size(), name, System.currentTimeMillis() - start);
for (ScoreSaberPlayerScoreToken newScore : newScores) {
if (saveScore(account, newScore)) {
newScoreCount++;
}
}
log.info("Found {} new scores for account '{}'. (took: {}ms)", newScoreCount, id, System.currentTimeMillis() - start);
} }
/** /**
@ -208,10 +198,8 @@ public class ScoreSaberService extends TextWebSocketHandler {
* *
* @param account The account. * @param account The account.
* @param score The score to save. * @param score The score to save.
* @return Whether the score was saved.
*/ */
private boolean saveScore(Account account, ScoreSaberPlayerScoreToken score) { private void saveScore(Account account, ScoreSaberPlayerScoreToken score) {
boolean didSave = false;
Leaderboard newScoreLeaderboard = Leaderboard.fromToken(score.getLeaderboard()); Leaderboard newScoreLeaderboard = Leaderboard.fromToken(score.getLeaderboard());
Score oldScore = scoreRepository.findById(score.getScore().getId()).orElse(null); Score oldScore = scoreRepository.findById(score.getScore().getId()).orElse(null);
@ -227,19 +215,16 @@ public class ScoreSaberService extends TextWebSocketHandler {
scoreRepository.delete(oldScore); // Delete the old score. scoreRepository.delete(oldScore); // Delete the old score.
scoreRepository.save(scoreSet); // Save the new score. scoreRepository.save(scoreSet); // Save the new score.
didSave = true;
} }
} else { } else {
// The score is new // The score is new
scoreRepository.save(Score.fromToken(account.getId(), score)); // Save the new score. scoreRepository.save(Score.fromToken(account.getId(), score)); // Save the new score.
didSave = true;
} }
// Check if the leaderboard doesn't already exist. // Check if the leaderboard doesn't already exist.
if (leaderboardRepository.findById(newScoreLeaderboard.getId()).isEmpty()) { if (leaderboardRepository.findById(newScoreLeaderboard.getId()).isEmpty()) {
leaderboardRepository.save(newScoreLeaderboard); // Save the leaderboard. leaderboardRepository.save(newScoreLeaderboard); // Save the leaderboard.
} }
return didSave;
} }
/** /**
@ -276,9 +261,21 @@ public class ScoreSaberService extends TextWebSocketHandler {
*/ */
@SneakyThrows @SneakyThrows
private void connectWebSocket() { private void connectWebSocket() {
log.info("Connecting to the ScoreSaber WSS.");
new StandardWebSocketClient().execute(this, "wss://scoresaber.com/ws").get(); new StandardWebSocketClient().execute(this, "wss://scoresaber.com/ws").get();
} }
@Override
public void afterConnectionEstablished(@NonNull WebSocketSession session) {
log.info("Connected to the ScoreSaber WSS.");
}
@Override
public void afterConnectionClosed(@NonNull WebSocketSession session, @NonNull CloseStatus status) {
log.info("Disconnected from the ScoreSaber WSS.");
connectWebSocket(); // Reconnect to the WebSocket.
}
@Override @SneakyThrows @Override @SneakyThrows
protected void handleTextMessage(@NonNull WebSocketSession session, @NonNull TextMessage message) { protected void handleTextMessage(@NonNull WebSocketSession session, @NonNull TextMessage message) {
// Ignore the connection message. // Ignore the connection message.
@ -310,10 +307,4 @@ public class ScoreSaberService extends TextWebSocketHandler {
log.error("An error occurred while handling the message.", ex); log.error("An error occurred while handling the message.", ex);
} }
} }
@Override
public void afterConnectionClosed(@NonNull WebSocketSession session, @NonNull CloseStatus status) {
log.info("Disconnected from the ScoreSaber WSS.");
connectWebSocket(); // Reconnect to the WebSocket.
}
} }

View File

@ -15,6 +15,11 @@ spring:
uri: mongodb://localhost:27017 uri: mongodb://localhost:27017
database: ssu-prod database: ssu-prod
# Sentry Configuration
sentry:
dsn: ""
tracesSampleRate: 1.0
# Set the embedded MongoDB version # Set the embedded MongoDB version
de: de:
flapdoodle: flapdoodle: