mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Mark server log messages
This commit is contained in:
parent
8595393623
commit
7c52e10e3b
33 changed files with 188 additions and 118 deletions
|
@ -1,5 +1,7 @@
|
|||
package brainwine.api;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -24,18 +26,18 @@ public class Api {
|
|||
|
||||
public Api(DataFetcher dataFetcher) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
logger.info("Starting API ...");
|
||||
logger.info(SERVER_MARKER, "Starting API ...");
|
||||
this.dataFetcher = dataFetcher;
|
||||
logger.info("Using data fetcher {}", dataFetcher.getClass().getName());
|
||||
logger.info("Loading configuration ...");
|
||||
logger.info(SERVER_MARKER, "Using data fetcher {}", dataFetcher.getClass().getName());
|
||||
logger.info(SERVER_MARKER, "Loading configuration ...");
|
||||
config = loadConfig();
|
||||
gatewayService = new GatewayService(this, config.getGatewayPort());
|
||||
portalService = new PortalService(this, config.getPortalPort());
|
||||
logger.info("All done! API startup took {} milliseconds", System.currentTimeMillis() - startTime);
|
||||
logger.info(SERVER_MARKER, "All done! API startup took {} milliseconds", System.currentTimeMillis() - startTime);
|
||||
}
|
||||
|
||||
public void onShutdown() {
|
||||
logger.info("Shutting down API ...");
|
||||
logger.info(SERVER_MARKER, "Shutting down API ...");
|
||||
gatewayService.stop();
|
||||
portalService.stop();
|
||||
}
|
||||
|
@ -52,7 +54,7 @@ public class Api {
|
|||
|
||||
return JsonHelper.readValue(file, ApiConfig.class);
|
||||
} catch (Exception e) {
|
||||
logger.fatal("Failed to load configuration", e);
|
||||
logger.fatal(SERVER_MARKER, "Failed to load configuration", e);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.api;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
@ -20,7 +22,7 @@ public class GatewayService {
|
|||
private final Javalin gateway;
|
||||
|
||||
public GatewayService(Api api, int port) {
|
||||
logger.info("Starting GatewayService @ port {} ...", port);
|
||||
logger.info(SERVER_MARKER, "Starting GatewayService @ port {} ...", port);
|
||||
DataFetcher dataFetcher = api.getDataFetcher();
|
||||
String gameServerHost = api.getGameServerHost();
|
||||
gateway = Javalin.create(config -> config.jsonMapper(new JavalinJackson(JsonHelper.MAPPER))).start(port);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.api;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
@ -18,7 +20,7 @@ public class PortalService {
|
|||
private final Javalin portal;
|
||||
|
||||
public PortalService(Api api, int port) {
|
||||
logger.info("Starting PortalService @ port {} ...", port);
|
||||
logger.info(SERVER_MARKER, "Starting PortalService @ port {} ...", port);
|
||||
DataFetcher dataFetcher = api.getDataFetcher();
|
||||
portal = Javalin.create(config -> config.jsonMapper(new JavalinJackson(JsonHelper.MAPPER))).start(port);
|
||||
portal.exception(Exception.class, new SimpleExceptionHandler());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package brainwine.api.handlers;
|
||||
|
||||
import static brainwine.api.util.ContextUtils.*;
|
||||
import static brainwine.api.util.ContextUtils.error;
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@ -14,7 +15,7 @@ public class SimpleExceptionHandler implements ExceptionHandler<Exception> {
|
|||
|
||||
@Override
|
||||
public void handle(Exception exception, Context ctx) {
|
||||
logger.error("Exception caught", exception);
|
||||
logger.error(SERVER_MARKER, "Exception caught", exception);
|
||||
error(ctx, "%s", exception);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -43,16 +45,16 @@ public class GameConfiguration {
|
|||
baseConfig.clear();
|
||||
configUpdates.clear();
|
||||
versionedConfigs.clear();
|
||||
logger.info("Loading game configuration ...");
|
||||
logger.info(SERVER_MARKER, "Loading game configuration ...");
|
||||
LoaderOptions options = new LoaderOptions();
|
||||
options.setMaxAliasesForCollections(Short.MAX_VALUE);
|
||||
yaml = new Yaml(options);
|
||||
loadConfigFiles();
|
||||
logger.info("Configuring ...");
|
||||
logger.info(SERVER_MARKER, "Configuring ...");
|
||||
configure();
|
||||
logger.info("Caching versioned configurations ...");
|
||||
logger.info(SERVER_MARKER, "Caching versioned configurations ...");
|
||||
cacheVersionedConfigs();
|
||||
logger.info("Load complete! Took {} milliseconds", System.currentTimeMillis() - startTime);
|
||||
logger.info(SERVER_MARKER, "Load complete! Took {} milliseconds", System.currentTimeMillis() - startTime);
|
||||
}
|
||||
|
||||
private static void cacheVersionedConfigs() {
|
||||
|
@ -158,7 +160,7 @@ public class GameConfiguration {
|
|||
Item item = JsonHelper.readValue(config, Item.class);
|
||||
ItemRegistry.registerItem(item);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.fatal("Failed to register item {}", id, e);
|
||||
logger.fatal(SERVER_MARKER, "Failed to register item {}", id, e);
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
@ -168,7 +170,7 @@ public class GameConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
logger.info("Successfully loaded {} item(s)", ItemRegistry.getItems().size());
|
||||
logger.info(SERVER_MARKER, "Successfully loaded {} item(s)", ItemRegistry.getItems().size());
|
||||
}
|
||||
|
||||
private static void loadConfigFiles() {
|
||||
|
@ -196,7 +198,7 @@ public class GameConfiguration {
|
|||
baseConfig.putAll(config);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.fatal("Could not load configuration files", e);
|
||||
logger.fatal(SERVER_MARKER, "Could not load configuration files", e);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
|
@ -41,7 +43,7 @@ public class GameServer implements CommandExecutor {
|
|||
instance = this;
|
||||
handlerThread = Thread.currentThread();
|
||||
long startTime = System.currentTimeMillis();
|
||||
logger.info("Starting GameServer ...");
|
||||
logger.info(SERVER_MARKER, "Starting GameServer ...");
|
||||
CommandManager.init();
|
||||
GameConfiguration.init();
|
||||
AchievementManager.loadAchievements();
|
||||
|
@ -55,7 +57,7 @@ public class GameServer implements CommandExecutor {
|
|||
NetworkRegistry.init();
|
||||
server = new Server();
|
||||
server.addEndpoint(5002);
|
||||
logger.info("All done! GameServer startup took {} milliseconds", System.currentTimeMillis() - startTime);
|
||||
logger.info(SERVER_MARKER, "All done! GameServer startup took {} milliseconds", System.currentTimeMillis() - startTime);
|
||||
}
|
||||
|
||||
public static GameServer getInstance() {
|
||||
|
@ -64,7 +66,7 @@ public class GameServer implements CommandExecutor {
|
|||
|
||||
@Override
|
||||
public void notify(Object message, NotificationType type) {
|
||||
consoleLogger.info(message);
|
||||
consoleLogger.info(SERVER_MARKER, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,12 +111,12 @@ public class GameServer implements CommandExecutor {
|
|||
* Called by the bootstrapper when the program closes.
|
||||
*/
|
||||
public void onShutdown() {
|
||||
logger.info("Shutting down GameServer ...");
|
||||
logger.info(SERVER_MARKER, "Shutting down GameServer ...");
|
||||
server.close();
|
||||
ZoneGenerator.stopAsyncZoneGenerator(true);
|
||||
logger.info("Saving zone data ...");
|
||||
logger.info(SERVER_MARKER, "Saving zone data ...");
|
||||
zoneManager.onShutdown();
|
||||
logger.info("Saving player data ...");
|
||||
logger.info(SERVER_MARKER, "Saving player data ...");
|
||||
playerManager.savePlayers();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.achievements;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -28,11 +30,11 @@ public class AchievementManager {
|
|||
achievements.clear();
|
||||
unknownTypeIds.clear();
|
||||
|
||||
logger.info("Loading achievements ...");
|
||||
logger.info(SERVER_MARKER, "Loading achievements ...");
|
||||
Map<String, Map<String, Object>> achievementConfigs = MapHelper.getMap(GameConfiguration.getBaseConfig(), "achievements");
|
||||
|
||||
if(achievementConfigs == null) {
|
||||
logger.warn("No achievement configurations exist!");
|
||||
logger.warn(SERVER_MARKER, "No achievement configurations exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -52,23 +54,24 @@ public class AchievementManager {
|
|||
} catch(MismatchedInputException e) {
|
||||
unknownTypeIds.add(MapHelper.getString(config, "type"));
|
||||
} catch(Exception e) {
|
||||
logger.error("Could not deserialize achievement '{}'", title, e);
|
||||
logger.error(SERVER_MARKER, "Could not deserialize achievement '{}'", title, e);
|
||||
}
|
||||
}
|
||||
|
||||
if(!unknownTypeIds.isEmpty()) {
|
||||
logger.warn("Some achievements could not be loaded due to missing implementations: {}", unknownTypeIds);
|
||||
logger.warn(SERVER_MARKER, "Some achievements could not be loaded due to missing implementations:");
|
||||
logger.warn(SERVER_MARKER, unknownTypeIds);
|
||||
}
|
||||
|
||||
int achievementCount = achievements.size();
|
||||
logger.info("Successfully loaded {} achievement{}", achievementCount, achievementCount == 1 ? "" : "s");
|
||||
logger.info(SERVER_MARKER, "Successfully loaded {} achievement{}", achievementCount, achievementCount == 1 ? "" : "s");
|
||||
}
|
||||
|
||||
public static void registerAchievement(Achievement achievement) {
|
||||
String title = achievement.getTitle();
|
||||
|
||||
if(getAchievement(title) != null) {
|
||||
logger.warn("Attempted to register duplicate achievement '{}'", title);
|
||||
logger.warn(SERVER_MARKER, "Attempted to register duplicate achievement '{}'", title);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.behavior;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -37,13 +39,13 @@ public abstract class CompositeBehavior extends Behavior {
|
|||
try {
|
||||
addChild(JsonHelper.readValue(config, type, new InjectableValues.Std().addValue(Npc.class, entity)));
|
||||
} catch(IOException e) {
|
||||
logger.error("Could not add child behavior of type {}.", type.getName(), e);
|
||||
logger.error(SERVER_MARKER, "Could not add child behavior of type {}.", type.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addChild(Behavior child) {
|
||||
if(children.contains(child)) {
|
||||
logger.warn("Duplicate child instance {} for behavior {}", child, this);
|
||||
logger.warn(SERVER_MARKER, "Duplicate child instance {} for behavior {}", child, this);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.behavior;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -39,11 +41,11 @@ public class SequenceBehavior extends CompositeBehavior {
|
|||
|
||||
// TODO get rid of this once we add the remaining behaviors
|
||||
if(!loggedInvalidTypes.contains(type)) {
|
||||
logger.warn("No implementation exists for behavior type '{}'", type);
|
||||
logger.warn(SERVER_MARKER, "No implementation exists for behavior type '{}'", type);
|
||||
loggedInvalidTypes.add(type);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
logger.error("Could not add behavior type '{}' to behavior tree for entity with type '{}'",
|
||||
logger.error(SERVER_MARKER, "Could not add behavior type '{}' to behavior tree for entity with type '{}'",
|
||||
MapHelper.getString(config, "type", "unknown"), npc.getType(), e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package brainwine.gameserver.command;
|
||||
|
||||
import static brainwine.gameserver.entity.player.NotificationType.SYSTEM;
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -47,7 +48,7 @@ public class CommandManager {
|
|||
|
||||
public static void init() {
|
||||
if(initialized) {
|
||||
logger.warn("CommandManager is already initialized - skipping!");
|
||||
logger.warn(SERVER_MARKER, "CommandManager is already initialized - skipping!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -56,7 +57,7 @@ public class CommandManager {
|
|||
}
|
||||
|
||||
private static void registerCommands() {
|
||||
logger.info("Registering commands ...");
|
||||
logger.info(SERVER_MARKER, "Registering commands ...");
|
||||
registerCommand(new StopCommand());
|
||||
registerCommand(new RegisterCommand());
|
||||
registerCommand(new TeleportCommand());
|
||||
|
@ -119,7 +120,7 @@ public class CommandManager {
|
|||
String name = command.getName();
|
||||
|
||||
if(commands.containsKey(name)) {
|
||||
logger.warn("Attempted to register duplicate command {} with name {}", command.getClass(), name);
|
||||
logger.warn(SERVER_MARKER, "Attempted to register duplicate command {} with name {}", command.getClass(), name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -129,7 +130,7 @@ public class CommandManager {
|
|||
if(aliases != null) {
|
||||
for(String alias : aliases) {
|
||||
if(commands.containsKey(alias) || CommandManager.aliases.containsKey(alias)) {
|
||||
logger.warn("Duplicate alias {} for command {}", alias, command.getClass());
|
||||
logger.warn(SERVER_MARKER, "Duplicate alias {} for command {}", alias, command.getClass());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.dialog;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -30,7 +32,7 @@ public class DialogHelper {
|
|||
try {
|
||||
return JsonHelper.readValue(config, Dialog.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("Failed to deserialize dialog: {}", path, e);
|
||||
logger.error(SERVER_MARKER, "Failed to deserialize dialog: {}", path, e);
|
||||
return messageDialog(String.format("Deserialization for dialog '%s' failed: %s", path, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +50,7 @@ public class DialogHelper {
|
|||
try {
|
||||
input = JsonHelper.readValue(config, DialogInput.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("Failed to deserialize dialog: {}", path, e);
|
||||
logger.error(SERVER_MARKER, "Failed to deserialize dialog: {}", path, e);
|
||||
return messageDialog(String.format("Deserialization for dialog '%s' failed: %s", path, e.getMessage()));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.entity;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -23,7 +25,7 @@ public class EntityRegistry {
|
|||
Map<String, Map<String, Object>> entityConfigs = MapHelper.getMap(GameConfiguration.getBaseConfig(), "entities");
|
||||
|
||||
if(entityConfigs == null) {
|
||||
logger.warn("No entity configurations exist!");
|
||||
logger.warn(SERVER_MARKER, "No entity configurations exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -39,17 +41,17 @@ public class EntityRegistry {
|
|||
registerEntityConfig(name, JsonHelper.readValue(config, EntityConfig.class,
|
||||
new InjectableValues.Std().addValue("name", name)));
|
||||
} catch(Exception e) {
|
||||
logger.error("Could not deserialize entity config for entity '{}'", name, e);
|
||||
logger.error(SERVER_MARKER, "Could not deserialize entity config for entity '{}'", name, e);
|
||||
}
|
||||
}
|
||||
|
||||
int entityCount = entities.size();
|
||||
logger.info("Successfully loaded {} entit{}", entityCount, entityCount == 1 ? "y" : "ies");
|
||||
logger.info(SERVER_MARKER, "Successfully loaded {} entit{}", entityCount, entityCount == 1 ? "y" : "ies");
|
||||
}
|
||||
|
||||
public static void registerEntityConfig(String name, EntityConfig config) {
|
||||
if(entities.containsKey(name)) {
|
||||
logger.warn("Attempted to register entity with name '{}' twice", name);
|
||||
logger.warn(SERVER_MARKER, "Attempted to register entity with name '{}' twice", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.entity.player;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -34,7 +36,7 @@ public class PlayerManager {
|
|||
}
|
||||
|
||||
private void loadPlayers() {
|
||||
logger.info("Loading player data ...");
|
||||
logger.info(SERVER_MARKER, "Loading player data ...");
|
||||
File dataDir = new File("players");
|
||||
dataDir.mkdirs();
|
||||
|
||||
|
@ -44,7 +46,7 @@ public class PlayerManager {
|
|||
}
|
||||
}
|
||||
|
||||
logger.info("Successfully loaded {} player(s)", playersById.size());
|
||||
logger.info(SERVER_MARKER, "Successfully loaded {} player(s)", playersById.size());
|
||||
}
|
||||
|
||||
private void loadPlayer(File file) {
|
||||
|
@ -61,14 +63,14 @@ public class PlayerManager {
|
|||
String name = player.getName();
|
||||
|
||||
if(playersByName.containsKey(name)) {
|
||||
logger.warn("Duplicate name {} for player id {}", name, id);
|
||||
logger.warn(SERVER_MARKER, "Duplicate name {} for player id {}", name, id);
|
||||
return;
|
||||
}
|
||||
|
||||
playersById.put(id, player);
|
||||
playersByName.put(name.toLowerCase(), player);
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not load configuration for player id {}", id, e);
|
||||
logger.error(SERVER_MARKER, "Could not load configuration for player id {}", id, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +86,7 @@ public class PlayerManager {
|
|||
try {
|
||||
JsonHelper.writeValue(file, new PlayerConfigFile(player));
|
||||
} catch(Exception e) {
|
||||
logger.error("Could not save player id {}", player.getDocumentId(), e);
|
||||
logger.error(SERVER_MARKER, "Could not save player id {}", player.getDocumentId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.item;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -25,12 +27,12 @@ public class ItemRegistry {
|
|||
int code = item.getCode();
|
||||
|
||||
if(items.containsKey(id)) {
|
||||
logger.warn("Duplicate item id {} for code {}", id, code);
|
||||
logger.warn(SERVER_MARKER, "Duplicate item id {} for code {}", id, code);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(itemsByCode.containsKey(code)) {
|
||||
logger.warn("Duplicate item code {} for id {}", code, id);
|
||||
logger.warn(SERVER_MARKER, "Duplicate item code {} for id {}", code, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.loot;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
@ -33,7 +35,7 @@ public class LootManager {
|
|||
}
|
||||
|
||||
private void loadLootTables() {
|
||||
logger.info("Loading loot tables ...");
|
||||
logger.info(SERVER_MARKER, "Loading loot tables ...");
|
||||
File file = new File("loottables.json");
|
||||
ResourceUtils.copyDefaults("loottables.json");
|
||||
|
||||
|
@ -42,7 +44,7 @@ public class LootManager {
|
|||
Map<String, List<Loot>> loot = JsonHelper.readValue(file, new TypeReference<Map<String, List<Loot>>>(){});
|
||||
lootTables.putAll(loot);
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load loot tables", e);
|
||||
logger.error(SERVER_MARKER, "Failed to load loot tables", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.prefab;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
|
@ -34,7 +36,7 @@ public class PrefabManager {
|
|||
private final Map<String, Prefab> prefabs = new HashMap<>();
|
||||
|
||||
public PrefabManager() {
|
||||
logger.info("Loading prefabs ...");
|
||||
logger.info(SERVER_MARKER, "Loading prefabs ...");
|
||||
ResourceUtils.copyDefaults("prefabs/");
|
||||
|
||||
if(dataDir.isDirectory()) {
|
||||
|
@ -45,7 +47,7 @@ public class PrefabManager {
|
|||
}
|
||||
}
|
||||
|
||||
logger.info("Successfully loaded {} prefab(s)", prefabs.size());
|
||||
logger.info(SERVER_MARKER, "Successfully loaded {} prefab(s)", prefabs.size());
|
||||
}
|
||||
|
||||
private void loadPrefab(File file) {
|
||||
|
@ -58,7 +60,7 @@ public class PrefabManager {
|
|||
PrefabBlocksFile blockData = null;
|
||||
|
||||
if(legacyBlocksFile.exists() && !blocksFile.exists()) {
|
||||
logger.info("Updating blocks file for prefab '{}' ...", name);
|
||||
logger.info(SERVER_MARKER, "Updating blocks file for prefab '{}' ...", name);
|
||||
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(
|
||||
ZipUtils.inflateBytes(Files.readAllBytes(legacyBlocksFile.toPath())));
|
||||
int width = unpacker.unpackInt();
|
||||
|
@ -91,13 +93,13 @@ public class PrefabManager {
|
|||
PrefabConfigFile config = JsonHelper.readValue(configFile, PrefabConfigFile.class);
|
||||
prefabs.put(name, new Prefab(config, blockData));
|
||||
} catch(Exception e) {
|
||||
logger.error("Could not load prefab {}:", name, e);
|
||||
logger.error(SERVER_MARKER, "Could not load prefab {}:", name, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPrefab(String name, Prefab prefab) throws Exception {
|
||||
if(prefabs.containsKey(name)) {
|
||||
logger.warn("Duplicate prefab name: {}", name);
|
||||
logger.warn(SERVER_MARKER, "Duplicate prefab name: {}", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.server;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -21,7 +23,7 @@ public class NetworkRegistry {
|
|||
|
||||
public static void init() {
|
||||
if(initialized) {
|
||||
logger.warn("NetworkRegistry is already initialized - skipping!");
|
||||
logger.warn(SERVER_MARKER, "NetworkRegistry is already initialized - skipping!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -31,13 +33,13 @@ public class NetworkRegistry {
|
|||
}
|
||||
|
||||
private static void registerRequests() {
|
||||
logger.info("Registering requests ...");
|
||||
logger.info(SERVER_MARKER, "Registering requests ...");
|
||||
Reflections reflections = new Reflections("brainwine.gameserver.server.requests");
|
||||
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(RequestInfo.class);
|
||||
|
||||
for(Class<?> clazz : classes) {
|
||||
if(!Request.class.isAssignableFrom(clazz)) {
|
||||
logger.warn("Attempted to register non-request class {}", clazz.getSimpleName());
|
||||
logger.warn(SERVER_MARKER, "Attempted to register non-request class {}", clazz.getSimpleName());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -47,13 +49,13 @@ public class NetworkRegistry {
|
|||
}
|
||||
|
||||
private static void registerMessages() {
|
||||
logger.info("Registering messages ...");
|
||||
logger.info(SERVER_MARKER, "Registering messages ...");
|
||||
Reflections reflections = new Reflections("brainwine.gameserver.server.messages");
|
||||
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(MessageInfo.class);
|
||||
|
||||
for(Class<?> clazz : classes) {
|
||||
if(!Message.class.isAssignableFrom(clazz)) {
|
||||
logger.warn("Attempted to register non-message class {}", clazz.getSimpleName());
|
||||
logger.warn(SERVER_MARKER, "Attempted to register non-message class {}", clazz.getSimpleName());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -64,12 +66,12 @@ public class NetworkRegistry {
|
|||
|
||||
public static void registerRequest(int id, Class<? extends Request> type) {
|
||||
if(!type.isAnnotationPresent(RequestInfo.class)) {
|
||||
logger.warn("RequestInfo annotation not present for class {}", type.getTypeName());
|
||||
logger.warn(SERVER_MARKER, "RequestInfo annotation not present for class {}", type.getTypeName());
|
||||
return;
|
||||
}
|
||||
|
||||
if(requests.containsKey(id)) {
|
||||
logger.warn("Attempted to register duplicate request {}", type.getTypeName());
|
||||
logger.warn(SERVER_MARKER, "Attempted to register duplicate request {}", type.getTypeName());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -82,12 +84,12 @@ public class NetworkRegistry {
|
|||
|
||||
public static void registerMessage(Class<? extends Message> type, int id) {
|
||||
if(!type.isAnnotationPresent(MessageInfo.class)) {
|
||||
logger.warn("MessageInfo annotation not present for class {}", type.getTypeName());
|
||||
logger.warn(SERVER_MARKER, "MessageInfo annotation not present for class {}", type.getTypeName());
|
||||
return;
|
||||
}
|
||||
|
||||
if(messageIds.containsKey(type)) {
|
||||
logger.warn("Attempted to register duplicate message {}", type.getTypeName());
|
||||
logger.warn(SERVER_MARKER, "Attempted to register duplicate message {}", type.getTypeName());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.server;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -75,11 +77,11 @@ public class Server {
|
|||
eventLoopGroup = new NioEventLoopGroup(0, threadFactory);
|
||||
}
|
||||
|
||||
logger.info("Using channel type {}", eventLoopGroup.getClass());
|
||||
logger.info(SERVER_MARKER, "Using channel type {}", eventLoopGroup.getClass());
|
||||
}
|
||||
|
||||
public void addEndpoint(int port) {
|
||||
logger.info("Opening endpoint @ port {} ...", port);
|
||||
logger.info(SERVER_MARKER, "Opening endpoint @ port {} ...", port);
|
||||
endpoints.add(new ServerBootstrap().group(eventLoopGroup).channel(channelType).childHandler(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel channel) throws Exception {
|
||||
|
@ -93,7 +95,7 @@ public class Server {
|
|||
}
|
||||
|
||||
public void close() {
|
||||
logger.info("Closing endpoints ...");
|
||||
logger.info(SERVER_MARKER, "Closing endpoints ...");
|
||||
eventLoopGroup.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.server.pipeline;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -59,7 +61,7 @@ public class Connection extends SimpleChannelInboundHandler<Request> {
|
|||
}
|
||||
|
||||
String error = cause.getMessage();
|
||||
logger.warn(error);
|
||||
logger.warn(SERVER_MARKER, error);
|
||||
//kick(error);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.zone;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -50,7 +52,7 @@ public class ChunkManager {
|
|||
File legacyBlocksFile = new File(zone.getDirectory(), "blocks");
|
||||
|
||||
if(!blocksFile.exists() && legacyBlocksFile.exists()) {
|
||||
logger.info("Updating blocks file for zone {} ...", zone.getDocumentId());
|
||||
logger.info(SERVER_MARKER, "Updating blocks file for zone {} ...", zone.getDocumentId());
|
||||
DataInputStream inputStream = null;
|
||||
DataOutputStream outputStream = null;
|
||||
|
||||
|
@ -87,7 +89,7 @@ public class ChunkManager {
|
|||
inputStream.close();
|
||||
outputStream.close();
|
||||
} catch(Exception e) {
|
||||
logger.error("Could not update blocks file for zone {}", zone.getDocumentId(), e);
|
||||
logger.error(SERVER_MARKER, "Could not update blocks file for zone {}", zone.getDocumentId(), e);
|
||||
}
|
||||
|
||||
legacyBlocksFile.delete();
|
||||
|
@ -99,7 +101,7 @@ public class ChunkManager {
|
|||
try {
|
||||
file.close();
|
||||
} catch(IOException e) {
|
||||
logger.error("Could not close blocks file stream for zone {}", zone.getDocumentId());
|
||||
logger.error(SERVER_MARKER, "Could not close blocks file stream for zone {}", zone.getDocumentId());
|
||||
} finally {
|
||||
file = null;
|
||||
}
|
||||
|
@ -153,7 +155,7 @@ public class ChunkManager {
|
|||
file.write(bytes);
|
||||
chunk.setModified(false);
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not save chunk {} of zone {}", index, zone.getDocumentId(), e);
|
||||
logger.error(SERVER_MARKER, "Could not save chunk {} of zone {}", index, zone.getDocumentId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +170,7 @@ public class ChunkManager {
|
|||
file.read(bytes);
|
||||
return mapper.readValue(ZipUtils.inflateBytes(bytes), Chunk.class);
|
||||
} catch(Exception e) {
|
||||
logger.error("Could not load chunk {} of zone {}", index, zone.getDocumentId(), e);
|
||||
logger.error(SERVER_MARKER, "Could not load chunk {} of zone {}", index, zone.getDocumentId(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.zone;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -59,7 +61,7 @@ public class EntityManager {
|
|||
|
||||
public static void loadEntitySpawns() {
|
||||
spawns.clear();
|
||||
logger.info("Loading entity spawns ...");
|
||||
logger.info(SERVER_MARKER, "Loading entity spawns ...");
|
||||
File file = new File("spawning.json");
|
||||
ResourceUtils.copyDefaults("spawning.json");
|
||||
|
||||
|
@ -67,7 +69,7 @@ public class EntityManager {
|
|||
try {
|
||||
spawns.putAll(JsonHelper.readValue(file, new TypeReference<Map<Biome, List<EntitySpawn>>>(){}));
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load entity spawns", e);
|
||||
logger.error(SERVER_MARKER, "Failed to load entity spawns", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.zone;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -36,7 +38,7 @@ public class ZoneManager {
|
|||
private Map<String, Zone> zonesByName = new HashMap<>();
|
||||
|
||||
public ZoneManager() {
|
||||
logger.info("Loading zone data ...");
|
||||
logger.info(SERVER_MARKER, "Loading zone data ...");
|
||||
dataDir.mkdirs();
|
||||
|
||||
for(File file : dataDir.listFiles()) {
|
||||
|
@ -46,18 +48,18 @@ public class ZoneManager {
|
|||
}
|
||||
|
||||
if(zones.isEmpty()) {
|
||||
logger.info("No zones were loaded. Generating default zone ...");
|
||||
logger.info(SERVER_MARKER, "No zones were loaded. Generating default zone ...");
|
||||
ZoneGenerator generator = ZoneGenerator.getZoneGenerator(Biome.PLAIN);
|
||||
|
||||
if(generator == null) {
|
||||
logger.warn("No generator for plain biomes was found! The default generator will be used.");
|
||||
logger.warn(SERVER_MARKER, "No generator for plain biomes was found! The default generator will be used.");
|
||||
generator = ZoneGenerator.getDefaultZoneGenerator();
|
||||
}
|
||||
|
||||
Zone zone = generator.generateZone(Biome.PLAIN, 2000, 600);
|
||||
addZone(zone);
|
||||
} else {
|
||||
logger.info("Successfully loaded {} zone(s)", zonesByName.size());
|
||||
logger.info(SERVER_MARKER, "Successfully loaded {} zone(s)", zonesByName.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +96,7 @@ public class ZoneManager {
|
|||
zone.setMetaBlocks(JsonHelper.readList(new File(file, "metablocks.json"), MetaBlock.class));
|
||||
addZone(zone);
|
||||
} catch (Exception e) {
|
||||
logger.error("Zone load failure. id: {}", id, e);
|
||||
logger.error(SERVER_MARKER, "Zone load failure. id: {}", id, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,7 +148,7 @@ public class ZoneManager {
|
|||
JsonHelper.writeValue(new File(file, "config.json"), new ZoneConfigFile(zone));
|
||||
Files.write(new File(file, "zone.dat").toPath(), ZipUtils.deflateBytes(mapper.writeValueAsBytes(new ZoneDataFile(zone))));
|
||||
} catch(Exception e) {
|
||||
logger.error("Zone save failure. id: {}", zone.getDocumentId(), e);
|
||||
logger.error(SERVER_MARKER, "Zone save failure. id: {}", zone.getDocumentId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +157,7 @@ public class ZoneManager {
|
|||
String name = zone.getName();
|
||||
|
||||
if(zonesByName.containsKey(name.toLowerCase())) {
|
||||
logger.warn("Duplicate name {} for zone id {}", name, id);
|
||||
logger.warn(SERVER_MARKER, "Duplicate name {} for zone id {}", name, id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.zone.gen;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.function.Consumer;
|
||||
|
@ -38,7 +40,8 @@ public class AsyncZoneGenerator extends Thread {
|
|||
try {
|
||||
zone = generator.generateZone(biome, width, height, seed);
|
||||
} catch(Exception e) {
|
||||
logger.error("An unexpected error occured while generating zone [biome:{}, width:{}, height:{}, seed:{}]", biome, width, height, generator, seed, e);
|
||||
logger.error(SERVER_MARKER, "An unexpected error occured while generating zone [biome:{}, width:{}, height:{}, seed:{}]",
|
||||
biome, width, height, seed, e);
|
||||
}
|
||||
|
||||
Zone generated = zone;
|
||||
|
@ -48,7 +51,7 @@ public class AsyncZoneGenerator extends Thread {
|
|||
GameServer gameServer = GameServer.getInstance();
|
||||
|
||||
if(gameServer.shouldStop()) {
|
||||
logger.warn("Server shutdown has been requested while generating a zone!"
|
||||
logger.warn(SERVER_MARKER, "Server shutdown has been requested while generating a zone!"
|
||||
+ " Callback will be fired immediately on the async zone generator thread."
|
||||
+ " Don't blame me for what happens!");
|
||||
callback.accept(generated);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine.gameserver.zone.gen;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -73,7 +75,7 @@ public class ZoneGenerator {
|
|||
|
||||
public static void init() {
|
||||
generators.clear();
|
||||
logger.info("Loading zone generator configurations ...");
|
||||
logger.info(SERVER_MARKER, "Loading zone generator configurations ...");
|
||||
ResourceUtils.copyDefaults("generators/");
|
||||
File dataDir = new File("generators");
|
||||
|
||||
|
@ -83,19 +85,19 @@ public class ZoneGenerator {
|
|||
String name = ResourceUtils.removeFileSuffix(file.getName()).toLowerCase();
|
||||
|
||||
if(generators.containsKey(name)) {
|
||||
logger.warn("Duplicate generator config name '{}'", name);
|
||||
logger.warn(SERVER_MARKER, "Duplicate generator config name '{}'", name);
|
||||
continue;
|
||||
}
|
||||
|
||||
GeneratorConfig config = JsonHelper.readValue(file, GeneratorConfig.class);
|
||||
generators.put(name, new ZoneGenerator(config));
|
||||
} catch(Exception e) {
|
||||
logger.error("Failed to load generator config '{}'", file.getName(), e);
|
||||
logger.error(SERVER_MARKER, "Failed to load generator config '{}'", file.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Starting async zone generator thread ...");
|
||||
logger.info(SERVER_MARKER, "Starting async zone generator thread ...");
|
||||
asyncGenerator = new AsyncZoneGenerator();
|
||||
asyncGenerator.start();
|
||||
}
|
||||
|
@ -116,14 +118,14 @@ public class ZoneGenerator {
|
|||
*/
|
||||
public static void stopAsyncZoneGenerator(boolean wait) {
|
||||
if(asyncGenerator != null && asyncGenerator.isAlive()) {
|
||||
logger.info("Stopping async zone generator thread ...");
|
||||
logger.info(SERVER_MARKER, "Stopping async zone generator thread ...");
|
||||
asyncGenerator.stopGracefully();
|
||||
|
||||
if(wait) {
|
||||
try {
|
||||
asyncGenerator.join();
|
||||
} catch(InterruptedException e) {
|
||||
logger.error("Wait for zone generator thread death interrupted", e);
|
||||
logger.error(SERVER_MARKER, "Wait for zone generator thread death interrupted", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
shared/src/main/java/brainwine/shared/LogMarkers.java
Normal file
10
shared/src/main/java/brainwine/shared/LogMarkers.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package brainwine.shared;
|
||||
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
public class LogMarkers {
|
||||
|
||||
public static final Marker GUI_MARKER = MarkerManager.getMarker("GUI");
|
||||
public static final Marker SERVER_MARKER = MarkerManager.getMarker("SERVER");
|
||||
}
|
|
@ -2,7 +2,9 @@ package brainwine;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.logging.log4j.core.Appender;
|
||||
|
@ -23,7 +25,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory;
|
|||
printObject = true)
|
||||
public class ListenableAppender extends AbstractAppender {
|
||||
|
||||
protected static final List<Consumer<LogMessage>> listeners = new ArrayList<>();
|
||||
protected static final Map<String, List<Consumer<LogMessage>>> listenersByAppender = new HashMap<>();
|
||||
|
||||
protected ListenableAppender(String name, Filter filter,
|
||||
Layout<? extends Serializable> layout, boolean ignoreExceptions,
|
||||
|
@ -40,9 +42,11 @@ public class ListenableAppender extends AbstractAppender {
|
|||
return new ListenableAppender(name, filter, layout, ignoreExceptions, null);
|
||||
}
|
||||
|
||||
public static void addListener(Consumer<LogMessage> listener) {
|
||||
synchronized(listeners) {
|
||||
public static void addListener(String appenderName, Consumer<LogMessage> listener) {
|
||||
synchronized(listenersByAppender) {
|
||||
List<Consumer<LogMessage>> listeners = listenersByAppender.getOrDefault(appenderName, new ArrayList<>());
|
||||
listeners.add(listener);
|
||||
listenersByAppender.putIfAbsent(appenderName, listeners);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,9 +56,13 @@ public class ListenableAppender extends AbstractAppender {
|
|||
String formattedMessage = getLayout().toSerializable(event).toString();
|
||||
LogMessage logMessage = new LogMessage(event.getLevel(), message, formattedMessage);
|
||||
|
||||
synchronized(listeners) {
|
||||
for(Consumer<LogMessage> listener : listeners) {
|
||||
listener.accept(logMessage);
|
||||
synchronized(listenersByAppender) {
|
||||
List<Consumer<LogMessage>> listeners = listenersByAppender.get(getName());
|
||||
|
||||
if(listeners != null) {
|
||||
for(Consumer<LogMessage> listener : listeners) {
|
||||
listener.accept(logMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package brainwine;
|
||||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
@ -24,15 +26,15 @@ public class ServerThread extends Thread {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
logger.warn("NOTE: THIS SERVER IS INCOMPLETE! EXPECT BAD CODE, BUGS, AND MISSING FEATURES!");
|
||||
logger.info("Starting server ...");
|
||||
logger.warn(SERVER_MARKER, "NOTE: THIS SERVER IS INCOMPLETE! EXPECT BAD CODE, BUGS, AND MISSING FEATURES!");
|
||||
logger.info(SERVER_MARKER, "Starting server ...");
|
||||
gameServer = new GameServer();
|
||||
api = new Api(new DirectDataFetcher(gameServer.getPlayerManager(), gameServer.getZoneManager()));
|
||||
TickLoop tickLoop = new TickLoop(8, () -> {
|
||||
gameServer.tick();
|
||||
});
|
||||
|
||||
logger.info("Server has started");
|
||||
logger.info(SERVER_MARKER, "Server has started");
|
||||
running = true;
|
||||
bootstrap.onServerStarted();
|
||||
|
||||
|
@ -40,7 +42,7 @@ public class ServerThread extends Thread {
|
|||
tickLoop.update();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.error("An unexpected exception occured", e);
|
||||
logger.error(SERVER_MARKER, "An unexpected exception occured", e);
|
||||
} finally {
|
||||
stopUnsafe();
|
||||
}
|
||||
|
@ -63,12 +65,19 @@ public class ServerThread extends Thread {
|
|||
|
||||
private void stopUnsafe() {
|
||||
try {
|
||||
logger.info("Stopping server ...");
|
||||
gameServer.onShutdown();
|
||||
api.onShutdown();
|
||||
logger.info("Server has stopped");
|
||||
logger.info(SERVER_MARKER, "Stopping server ...");
|
||||
|
||||
if(gameServer != null) {
|
||||
gameServer.onShutdown();
|
||||
}
|
||||
|
||||
if(api != null) {
|
||||
api.onShutdown();
|
||||
}
|
||||
|
||||
logger.info(SERVER_MARKER, "Server has stopped");
|
||||
} catch(Exception e) {
|
||||
logger.error("An unexpected exception occured whilst shutting down", e);
|
||||
logger.error(SERVER_MARKER, "An unexpected exception occured whilst shutting down", e);
|
||||
} finally {
|
||||
running = false;
|
||||
bootstrap.onServerStopped();
|
||||
|
|
|
@ -2,12 +2,12 @@ package brainwine.gui;
|
|||
|
||||
import static brainwine.gui.GuiConstants.DEEPWORLD_ASSEMBLY_PATH;
|
||||
import static brainwine.gui.GuiConstants.DEEPWORLD_PLAYERPREFS;
|
||||
import static brainwine.gui.GuiConstants.GUI_MARKER;
|
||||
import static brainwine.gui.GuiConstants.HTTP_COMMUNITY_HUB_URL;
|
||||
import static brainwine.gui.GuiConstants.HTTP_STEAM_DOWNLOAD_URL;
|
||||
import static brainwine.gui.GuiConstants.STEAM_COMMUNITY_HUB_URL;
|
||||
import static brainwine.gui.GuiConstants.STEAM_REGISTRY_LOCATION;
|
||||
import static brainwine.gui.GuiConstants.STEAM_RUN_GAME_URL;
|
||||
import static brainwine.shared.LogMarkers.GUI_MARKER;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
|
|
@ -2,9 +2,6 @@ package brainwine.gui;
|
|||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
public class GuiConstants {
|
||||
|
||||
public static final String GITHUB_REPOSITORY_URL = "https://github.com/kuroppoi/brainwine";
|
||||
|
@ -19,5 +16,4 @@ public class GuiConstants {
|
|||
public static final Color ERROR_COLOR = Color.RED.darker();
|
||||
public static final Color WARNING_COLOR = Color.YELLOW.darker();
|
||||
public static final Color INFO_COLOR = Color.WHITE.darker();
|
||||
public static final Marker GUI_MARKER = MarkerManager.getMarker("gui");
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package brainwine.gui;
|
|||
|
||||
import static brainwine.gui.GuiConstants.DEEPWORLD_PLAYERPREFS;
|
||||
import static brainwine.gui.GuiConstants.GITHUB_REPOSITORY_URL;
|
||||
import static brainwine.gui.GuiConstants.GUI_MARKER;
|
||||
import static brainwine.shared.LogMarkers.GUI_MARKER;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ServerPanel extends JPanel {
|
|||
}
|
||||
};;
|
||||
consoleOutput.setEditable(false);
|
||||
ListenableAppender.addListener(message -> {
|
||||
ListenableAppender.addListener("GuiServerOutput", message -> {
|
||||
Level level = message.getLevel();
|
||||
Color color = level == Level.ERROR ? ERROR_COLOR : level == Level.WARN ? WARNING_COLOR : INFO_COLOR;
|
||||
appendConsoleOutput(message.getFormattedMessage(), color);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package brainwine.gui.theme;
|
||||
|
||||
import static brainwine.gui.GuiConstants.GUI_MARKER;
|
||||
import static brainwine.shared.LogMarkers.GUI_MARKER;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
|
@ -12,9 +12,8 @@
|
|||
</Policies>
|
||||
</RollingFile>
|
||||
<Listenable name="GuiServerOutput">
|
||||
<!--It might a be better idea to mark server messages instead-->
|
||||
<MarkerFilter marker="gui" onMatch="DENY" onMismatch="ACCEPT"/>
|
||||
<PatternLayout pattern="(%d{yyyy-MM-dd HH:mm:ss.SSS}) [%level] [%logger{1}]: %msg%n"/>
|
||||
<MarkerFilter marker="SERVER" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
<PatternLayout pattern="(%d{yyyy-MM-dd HH:mm:ss.SSS}) [%level] [%logger{1}]: %msg%n"/>
|
||||
</Listenable>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
|
|
Loading…
Add table
Reference in a new issue