Skip to content

Commit 1cd0984

Browse files
author
MadeByIToncek
committed
Removing no longer needed stuff
1 parent 86301c9 commit 1cd0984

3 files changed

Lines changed: 27 additions & 186 deletions

File tree

server/src/main/java/space/itoncek/trailcompass/TrailServer.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package space.itoncek.trailcompass;
22

33
import io.javalin.Javalin;
4-
import static io.javalin.apibuilder.ApiBuilder.post;
5-
import static io.javalin.apibuilder.ApiBuilder.ws;
6-
import static org.apache.commons.codec.digest.DigestUtils.sha512;
74
import org.hibernate.SessionFactory;
85
import org.hibernate.jpa.HibernatePersistenceConfiguration;
96
import org.hibernate.tool.schema.Action;
@@ -20,14 +17,16 @@
2017
import java.io.IOException;
2118
import java.util.TreeSet;
2219

20+
import static io.javalin.apibuilder.ApiBuilder.post;
21+
import static org.apache.commons.codec.digest.DigestUtils.sha512;
22+
import static space.itoncek.trailcompass.commons.utils.RandomUtils.generateRandomString;
23+
import static space.itoncek.trailcompass.commons.utils.RandomUtils.pickRandomStrings;
24+
2325
public class TrailServer {
2426
private static final Logger log = LoggerFactory.getLogger(TrailServer.class);
2527
public final boolean dev = System.getenv("dev") != null && Boolean.parseBoolean(System.getenv("dev"));
2628
private final int PORT = System.getenv("PORT") == null ? 8080 : Integer.parseInt(System.getenv("PORT"));
27-
private final String CONNECTION_STRING = System.getenv("CONNECTION_STRING") == null ? "jdbc:postgresql://localhost:5002/TrailCompass" : System.getenv("CONNECTION_STRING");
28-
private final String CONNECTION_USER = System.getenv("CONNECTION_USER") == null ? "postgres" : System.getenv("CONNECTION_USER");
29-
private final String CONNECTION_PASSWORD = System.getenv("CONNECTION_PASSWORD") == null ? "postgres" : System.getenv("CONNECTION_PASSWORD");
30-
public final SessionFactory ef;
29+
public final SessionFactory ef;
3130
private final Javalin app;
3231
public final TrailCompassHandler tch;
3332
public final LocationManager lm;
@@ -36,6 +35,9 @@ public class TrailServer {
3635
public final ConfigManager config;
3736

3837
public TrailServer() {
38+
String connString = System.getenv("CONNECTION_STRING") == null ? "jdbc:postgresql://localhost:5002/TrailCompass" : System.getenv("CONNECTION_STRING");
39+
String connUser = System.getenv("CONNECTION_USER") == null ? "postgres" : System.getenv("CONNECTION_USER");
40+
String connPassword = System.getenv("CONNECTION_PASSWORD") == null ? "postgres" : System.getenv("CONNECTION_PASSWORD");
3941
ef = new HibernatePersistenceConfiguration("TrailCompass")
4042
.managedClasses(
4143
PerformanceTrace.class,
@@ -46,10 +48,10 @@ public TrailServer() {
4648
)
4749
.jdbcPoolSize(8)
4850
// PostgreSQL
49-
.jdbcUrl(CONNECTION_STRING)
51+
.jdbcUrl(connString)
5052
// Credentials
51-
.jdbcUsername(CONNECTION_USER)
52-
.jdbcPassword(CONNECTION_PASSWORD)
53+
.jdbcUsername(connUser)
54+
.jdbcPassword(connPassword)
5355
// Automatic schema export
5456
.schemaToolingAction(Action.UPDATE)
5557
// SQL statement logging
@@ -96,10 +98,7 @@ public TrailServer() {
9698
cfg.router.caseInsensitiveRoutes = true;
9799
cfg.router.treatMultipleSlashesAsSingleSlash = true;
98100
cfg.router.ignoreTrailingSlashes = true;
99-
cfg.router.apiBuilder(() -> {
100-
post("/", tch::handle);
101-
ws("/gamemanager/await", gm::awaitWS);
102-
});
101+
cfg.router.apiBuilder(() -> post("/", tch::handle));
103102
});
104103
}
105104

@@ -130,14 +129,14 @@ public void start() {
130129
}
131130

132131
final boolean[] needsCardReset = {false};
133-
ef.runInTransaction(em-> {
132+
ef.runInTransaction(em -> {
134133
KeyStore ks = em.find(KeyStore.class, KeyStore.KeystoreKeys.DECK_DEALT);
135134
if (!Boolean.parseBoolean(ks.getKvalue())) {
136135
needsCardReset[0] = true;
137136
}
138137
});
139138

140-
if(needsCardReset[0]) {
139+
if (needsCardReset[0]) {
141140
dm.resetDeck();
142141
ef.runInTransaction(em -> {
143142
KeyStore ks = em.find(KeyStore.class, KeyStore.KeystoreKeys.DECK_DEALT);
@@ -149,14 +148,18 @@ public void start() {
149148
log.info("{}\n{}", TextGraphics.generateIntroMural(), TextGraphics.isDebuggerPresent() ? TextGraphics.generateDevWarningBox() : "");
150149

151150
if (tch.ex.auth().needsDefaultUser()) {
152-
// TODO)) REMOVE BEFORE RELEASE! DEBUG ONLY!
153-
// String user = pickRandomStrings();
154-
String user = "itoncek";
155-
// String password = generateRandomString(16, true, false);
156-
String password = "root";
157-
tch.ex.auth().createUser(user, sha512(password), true);
158-
log.info(TextGraphics.generateLoginBox(user, password));
159-
}
151+
String user;
152+
String password;
153+
if (dev) {
154+
user = "admin";
155+
password = "root";
156+
}else {
157+
user = pickRandomStrings();
158+
password = generateRandomString(16, true, false);
159+
}
160+
tch.ex.auth().createUser(user, sha512(password), true);
161+
log.info(TextGraphics.generateLoginBox(user, password));
162+
}
160163
}
161164

162165
private void stop() throws IOException {

server/src/main/java/space/itoncek/trailcompass/gamedata/utils/Randoms.java

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package space.itoncek.trailcompass.modules;
22

3-
import io.javalin.websocket.WsConfig;
4-
import io.javalin.websocket.WsContext;
53
import space.itoncek.trailcompass.TrailServer;
64
import space.itoncek.trailcompass.commons.objects.GameState;
75
import space.itoncek.trailcompass.modules.config.Config;
86

97
import java.io.IOException;
10-
import java.time.Duration;
118
import java.time.ZonedDateTime;
12-
import java.util.ArrayList;
13-
import java.util.List;
149
import java.util.UUID;
1510

1611
public class GameManager {
@@ -39,29 +34,4 @@ public UUID getCurrentHider() throws IOException {
3934
public ZonedDateTime getStartingTime() throws IOException {
4035
return server.config.getConfig().getStartTime();
4136
}
42-
43-
final List<WsContext> ctxs = new ArrayList<>();
44-
45-
public void sendUpdateMessage() {
46-
for (WsContext ctx : ctxs) {
47-
if(ctx.session.isOpen()) {
48-
ctx.send("update");
49-
} else {
50-
ctxs.remove(ctx);
51-
}
52-
}
53-
}
54-
55-
public void awaitWS(WsConfig wsc) {
56-
wsc.onConnect(ctx-> {
57-
ctx.session.setIdleTimeout(Duration.ofDays(365));
58-
ctxs.add(ctx);
59-
});
60-
61-
wsc.onClose(ctx -> {
62-
if (ctxs.stream().map(WsContext::sessionId).toList().contains(ctx.sessionId())) {
63-
ctxs.removeIf(x -> x.sessionId().equals(ctx.sessionId()));
64-
}
65-
});
66-
}
6737
}

0 commit comments

Comments
 (0)