Skip to content

Commit

Permalink
Disable match logging to stdout by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nypi committed Jul 3, 2022
1 parent 87b60be commit a39a561
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions server/hypernull.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
server.port=2021
match.log.stdout=false
match.log.folder=./matchlogs/
maps.folder=./maps/
23 changes: 18 additions & 5 deletions server/src/main/java/ru/croccode/hypernull/server/HyperNull.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

import ru.croccode.hypernull.domain.MatchMap;
import ru.croccode.hypernull.domain.MatchMode;
Expand All @@ -35,21 +37,26 @@ public class HyperNull implements Runnable, Closeable {
private final MapRegistry mapRegistry;

private final Server server;

private final String matchLogsFolder;

private final boolean matchLogStdout;

public HyperNull(Properties properties) throws IOException {
Check.notNull(properties);
// start server
int serverPort = Integer.parseInt(
properties.getProperty("server.port", "2021"));
matchLogsFolder = properties.getProperty("match.log.folder","./matchlogs/");
System.out.println("Match logs folder was set to: " + matchLogsFolder);
matchLogStdout = Boolean.parseBoolean(
properties.getProperty("match.log.stdout", "false"));
System.out.println("Log matches to stdout: " + matchLogStdout);
String mapsFolder = properties.getProperty("maps.folder","./maps/");
System.out.println("Maps folder was set to: " + mapsFolder);
mapRegistry = MapStore.load(Paths.get(mapsFolder));
this.server = new Server(serverPort);
System.out.println("Server started on port: " + serverPort);
System.out.println("Server logs output: STDOUT");
}

@Override
Expand Down Expand Up @@ -100,11 +107,17 @@ private void runMatch(MatchMode mode, List<MatchRequest> matchRequests) {
}
MatchConfig config = buildMatchConfig(mode, map);
try (MatchFileLogger<Integer> fileLogger = new MatchFileLogger<>(matchId, this.matchLogsFolder)) {
List<MatchListener<Integer>> listeners = Arrays.asList(
new AsciiMatchPrinter(),
fileLogger
);
List<MatchListener<Integer>> listeners = new ArrayList<>();
if (matchLogStdout) {
listeners.add(new AsciiMatchPrinter());
}
listeners.add(fileLogger);
Match<Integer> match = new Match<>(matchId, map, config, botNames, listeners);

String bots = matchRequests.stream()
.map(r -> r.getBotName() + " [" + r.getMode() + "]")
.collect(Collectors.joining(", "));
System.out.println("Starting match " + matchId + ": " + bots);
new MatchRunner(match, botSessions).run();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void closeSession(Integer botKey) {
}));
}

private CompletableFuture<Move> waitForMove(Integer botKey) throws IOException {
private CompletableFuture<Move> waitForMove(Integer botKey) {
SocketSession session = botSessions.get(botKey);
if (session == null)
return CompletableFuture.completedFuture(null);
Expand Down

0 comments on commit a39a561

Please sign in to comment.