prod & completion

This commit is contained in:
jeffcheasey88 2023-10-01 22:44:23 +02:00
parent 894ed9fb46
commit 4f11822c12
4 changed files with 20 additions and 10 deletions

View file

@ -10,6 +10,8 @@ import java.lang.reflect.Field;
import dev.peerat.backend.utils.Mail;
public class Configuration {
private boolean prod;
private String db_host;
private int db_port;
@ -125,6 +127,10 @@ public class Configuration {
writer.flush();
writer.close();
}
public boolean isProduction(){
return this.prod;
}
public String getDbHost() {
return this.db_host;

View file

@ -114,9 +114,12 @@ public class Main{
Locker<Group> groupLock = new Locker<>();
Locker<Completion> leaderboard = new Locker<>();
if(config.isProduction())
router.
register(new Register(repo, playersWaiting, mail)).
register(new MailConfirmation(repo, router, config.getUsersFiles(), config.getGitToken(), playersWaiting, mail));
router.
register(new Register(repo, playersWaiting, mail)).
register(new MailConfirmation(repo, router, config.getUsersFiles(), config.getGitToken(), playersWaiting, mail)).
register(new Login(repo, router)).
register(new ProfileSettings(repo)).
register(new ChangePassword(repo)).

View file

@ -11,7 +11,7 @@ public class Completion{
private int score;
private String puzzleName;
public Completion(int playerId, int puzzleId, int tries, String fileName, int score) {
public Completion(int playerId, int puzzleId, int tries, String fileName, int score){
this(playerId, puzzleId, tries, score, fileName, null, null, null, null);
}
public Completion(int playerId, int puzzleId, int tries, String fileName, int score, String puzzleName) {
@ -22,13 +22,13 @@ public class Completion{
this(playerId, puzzleId, 0, 0, fileName, file, response, currentPuzzle, null);
}
public Completion(int initTries, int initScore) {
public Completion(int initTries, int initScore){
// For group leaderboard
this(-1, -1, initTries, initScore, null, null, null, null, null);
}
public Completion(int playerId, int puzzleId, int tries, int score, String fileName, byte[] file, byte[] response,
Puzzle currentPuzzle, String initPuzzleName) {
Puzzle currentPuzzle, String initPuzzleName){
this.playerId = playerId;
this.puzzleId = puzzleId;
this.fileName = fileName;
@ -40,7 +40,7 @@ public class Completion{
this.score = score;
if (currentPuzzle != null)
addTry(currentPuzzle, response);
addTry(currentPuzzle, response, 0);
puzzleName = initPuzzleName;
}
@ -62,13 +62,14 @@ public class Completion{
return tries;
}
public void addTry(Puzzle currentPuzzle, byte[] response){
public void addTry(Puzzle currentPuzzle, byte[] response, int chapter){
if (score <= 0){
tries++;
if(chapter < 4) return;
if (response != null && Arrays.equals(currentPuzzle.getSoluce(), response)){
if (tries > 1) { // Loose 5% each try with a minimum of 1 for score
// score = (int) Math.ceil(currentPuzzle.getScoreMax() * (1 - ((tries - 1) / 20.)));
score = currentPuzzle.getScoreMax();
score = (int) Math.ceil(currentPuzzle.getScoreMax() * (1 - ((tries - 1) / 20.)));
// score = currentPuzzle.getScoreMax();
if (score < 1)
score = 1;
} else

View file

@ -593,7 +593,7 @@ public class DatabaseRepository {
insertCompletion(completion);
} else {
System.out.println(completion);
completion.addTry(currentPuzzle, response);
completion.addTry(currentPuzzle, response, getChapter(currentPuzzle).getId());
int lastUserId = completion.getPlayerId();
completion.updatePlayer(userId);
updateCompletion(completion, lastUserId);