prod & completion
This commit is contained in:
parent
894ed9fb46
commit
4f11822c12
4 changed files with 20 additions and 10 deletions
|
@ -11,6 +11,8 @@ import dev.peerat.backend.utils.Mail;
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
|
private boolean prod;
|
||||||
|
|
||||||
private String db_host;
|
private String db_host;
|
||||||
private int db_port;
|
private int db_port;
|
||||||
private String db_user;
|
private String db_user;
|
||||||
|
@ -126,6 +128,10 @@ public class Configuration {
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProduction(){
|
||||||
|
return this.prod;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDbHost() {
|
public String getDbHost() {
|
||||||
return this.db_host;
|
return this.db_host;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,9 +114,12 @@ public class Main{
|
||||||
Locker<Group> groupLock = new Locker<>();
|
Locker<Group> groupLock = new Locker<>();
|
||||||
Locker<Completion> leaderboard = new Locker<>();
|
Locker<Completion> leaderboard = new Locker<>();
|
||||||
|
|
||||||
|
if(config.isProduction())
|
||||||
router.
|
router.
|
||||||
register(new Register(repo, playersWaiting, mail)).
|
register(new Register(repo, playersWaiting, mail)).
|
||||||
register(new MailConfirmation(repo, router, config.getUsersFiles(), config.getGitToken(), playersWaiting, mail)).
|
register(new MailConfirmation(repo, router, config.getUsersFiles(), config.getGitToken(), playersWaiting, mail));
|
||||||
|
|
||||||
|
router.
|
||||||
register(new Login(repo, router)).
|
register(new Login(repo, router)).
|
||||||
register(new ProfileSettings(repo)).
|
register(new ProfileSettings(repo)).
|
||||||
register(new ChangePassword(repo)).
|
register(new ChangePassword(repo)).
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class Completion{
|
||||||
private int score;
|
private int score;
|
||||||
private String puzzleName;
|
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);
|
this(playerId, puzzleId, tries, score, fileName, null, null, null, null);
|
||||||
}
|
}
|
||||||
public Completion(int playerId, int puzzleId, int tries, String fileName, int score, String puzzleName) {
|
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);
|
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
|
// For group leaderboard
|
||||||
this(-1, -1, initTries, initScore, null, null, null, null, null);
|
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,
|
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.playerId = playerId;
|
||||||
this.puzzleId = puzzleId;
|
this.puzzleId = puzzleId;
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
|
@ -40,7 +40,7 @@ public class Completion{
|
||||||
this.score = score;
|
this.score = score;
|
||||||
|
|
||||||
if (currentPuzzle != null)
|
if (currentPuzzle != null)
|
||||||
addTry(currentPuzzle, response);
|
addTry(currentPuzzle, response, 0);
|
||||||
|
|
||||||
puzzleName = initPuzzleName;
|
puzzleName = initPuzzleName;
|
||||||
}
|
}
|
||||||
|
@ -62,13 +62,14 @@ public class Completion{
|
||||||
return tries;
|
return tries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTry(Puzzle currentPuzzle, byte[] response){
|
public void addTry(Puzzle currentPuzzle, byte[] response, int chapter){
|
||||||
if (score <= 0){
|
if (score <= 0){
|
||||||
tries++;
|
tries++;
|
||||||
|
if(chapter < 4) return;
|
||||||
if (response != null && Arrays.equals(currentPuzzle.getSoluce(), response)){
|
if (response != null && Arrays.equals(currentPuzzle.getSoluce(), response)){
|
||||||
if (tries > 1) { // Loose 5% each try with a minimum of 1 for score
|
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 = (int) Math.ceil(currentPuzzle.getScoreMax() * (1 - ((tries - 1) / 20.)));
|
||||||
score = currentPuzzle.getScoreMax();
|
// score = currentPuzzle.getScoreMax();
|
||||||
if (score < 1)
|
if (score < 1)
|
||||||
score = 1;
|
score = 1;
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -593,7 +593,7 @@ public class DatabaseRepository {
|
||||||
insertCompletion(completion);
|
insertCompletion(completion);
|
||||||
} else {
|
} else {
|
||||||
System.out.println(completion);
|
System.out.println(completion);
|
||||||
completion.addTry(currentPuzzle, response);
|
completion.addTry(currentPuzzle, response, getChapter(currentPuzzle).getId());
|
||||||
int lastUserId = completion.getPlayerId();
|
int lastUserId = completion.getPlayerId();
|
||||||
completion.updatePlayer(userId);
|
completion.updatePlayer(userId);
|
||||||
updateCompletion(completion, lastUserId);
|
updateCompletion(completion, lastUserId);
|
||||||
|
|
Loading…
Add table
Reference in a new issue