diff --git a/common/src/main/java/common/block/Block.java b/common/src/main/java/common/block/Block.java index 33ee066..4c7b9ec 100755 --- a/common/src/main/java/common/block/Block.java +++ b/common/src/main/java/common/block/Block.java @@ -526,7 +526,7 @@ public class Block { public void randomTick(AWorldServer worldIn, BlockPos pos, State state, Random random) { this.updateTick(worldIn, pos, state, random); - if(this.radiation > 0.0f && /* worldIn.getTime() % 5L == 0L && */ random.chance(Config.randomTick / 3)) + if(this.radiation > 0.0f) // && /* worldIn.getTime() % 5L == 0L && */ random.chance(Config.randomTick / 3)) this.affectEntities(worldIn, pos, state, this.radiation * 8.0f * 0.25f); } diff --git a/common/src/main/java/common/init/Config.java b/common/src/main/java/common/init/Config.java index 26fb982..b3fece5 100755 --- a/common/src/main/java/common/init/Config.java +++ b/common/src/main/java/common/init/Config.java @@ -9,18 +9,8 @@ public abstract class Config { public static boolean mobGrief = true; @Var(name = "mobSpawning") public static boolean mobs = true; - @Var(name = "tickSpawning") - public static boolean tickSpawn = true; - @Var(name = "genSpawning") - public static boolean genSpawn = true; @Var(name = "spawners") public static boolean spawners = true; - @Var(name = "spawnVillagers") - public static boolean spawnVillager = true; - @Var(name = "spawnCagedVillagers") - public static boolean spawnCagedVillager = true; - @Var(name = "spawnHutMages") - public static boolean spawnHutMage = true; @Var(name = "spawnEggChickens") public static boolean spawnEggChicken = true; @Var(name = "spawnMoreZombies") @@ -49,10 +39,6 @@ public abstract class Config { public static boolean objectDrop = true; @Var(name = "naturalRegeneration") public static boolean regeneration = true; - @Var(name = "daylightCycle") - public static boolean dayCycle = true; - @Var(name = "weatherChanges") - public static boolean weather = true; @Var(name = "seasonLeafUpdate") public static boolean seasonLeaves = true; @Var(name = "leavesDecay") @@ -67,8 +53,6 @@ public abstract class Config { public static boolean portals = true; @Var(name = "portalVoid") public static boolean voidPortal = true; - @Var(name = "dropPlayerSkulls") - public static boolean skullDrop = true; @Var(name = "dropPlayerItems") public static boolean playerDrop = true; @Var(name = "blockGravity") @@ -199,24 +183,12 @@ public abstract class Config { public static boolean locking = true; @Var(name = "teleFragging") public static boolean telefrag = true; - @Var(name = "checkRespawn") - public static boolean checkBed = true; @Var(name = "chunkLoaders") public static boolean loaders = true; @Var(name = "fragileItems") public static boolean itemFallDamage = true; - @Var(name = "registration") - public static boolean register = true; @Var(name = "signEditing") public static boolean editSigns = true; - @Var(name = "pubkeyAuthentication") - public static boolean pubkeyAuth = true; - @Var(name = "requireAccessPassword") - public static boolean accessRequired = true; - @Var(name = "encryption") - public static boolean encrypt = true; - @Var(name = "requireAuthentication") - public static boolean authenticate = true; @Var(name = "keepInventory") public static boolean keepInventory = false; @@ -228,51 +200,15 @@ public abstract class Config { public static boolean mergeFinite = false; @Var(name = "veryHungryRabbits") public static boolean rabidRabbits = false; - @Var(name = "snowStacking") - public static boolean snowStack = false; - @Var(name = "passwordAuthentication") - public static boolean passwordAuth = false; - @Var(name = "randomTickSpeed") - public static int randomTick = 3; - @Var(name = "weatherTickSpeed") - public static int weatherTick = 1; - @Var(name = "lightningChance") - public static int boltChance = 100000; - @Var(name = "igniteChance") - public static int igniteChance = 100; - @Var(name = "spawnRadius") - public static int spawnRadius = 10; - @Var(name = "originRadius", min = 0, max = 262144) - public static int originRadius = 16384; - @Var(name = "respawnTime") - public static int respawnTime = 0; @Var(name = "hurtCooldown") public static int hurtDelay = 20; @Var(name = "attackCooldown") public static int attackDelay = 0; - @Var(name = "spawnGroupCount") - public static int spawnGroups = 3; - @Var(name = "spawnGroupDistance") - public static int spawnGroupDist = 6; - @Var(name = "mobSpawnRadius") - public static int mobSpawnDist = 8; - @Var(name = "mobPlayerDistance") - public static int mobPlayerDist = 24; - @Var(name = "saveInterval") - public static int saveInterval = 900; - @Var(name = "maxPlayers") - public static int playerLimit = 0; - @Var(name = "compressAbove") - public static int compression = 256; @Var(name = "pistonPushLimit") public static int pistonLimit = 16; @Var(name = "gravelFlintChance") public static int flintChance = 10; - @Var(name = "timeFlow") - public static int timeFlow = 1; - @Var(name = "emptyTicks") - public static int unloadTicks = 1200; @Var(name = "rabbitMateChance") public static int rabbitMateChance = 10; @Var(name = "killerBunnyChance") @@ -303,10 +239,6 @@ public abstract class Config { public static int cactusHeight = 3; @Var(name = "orbThorns") public static int orbDamageOther = 0; - @Var(name = "weatherChance") - public static int weatherChance = 48000; - @Var(name = "viewDistance", min = 2, max = 16) - public static int distance = 8; @Var(name = "healChance") public static int healChance = 5; @Var(name = "hopperCooldown", min = 0, max = 160) @@ -315,24 +247,9 @@ public abstract class Config { public static int hopperCartDelay = 1; @Var(name = "xpCooldown", min = 0, max = 10) public static int xpDelay = 0; // 2 - @Var(name = "maxSpawns") - public static int maxMobs = 120; @Var(name = "eggLayTime") public static int eggTimer = 6000; - @Var(name = "connectionTimeout", min = 10, max = 300) - public static int timeout = 30; - @Var(name = "passwordMinLength", min = 8, max = 32) - public static int minPassLength = 8; - @Var(name = "port", min = 1024, max = 32767, nonDefault = true) - public static int port = -1; - @Var(name = "gravity") - public static float gravity = 1.0f; @Var(name = "knockback") public static float knockback = 1.0f; - - @Var(name = "password", nonDefault = true) - public static String password = ""; - @Var(name = "baseSeed", nonDefault = true) - public static String seed = ""; } diff --git a/server/src/main/java/server/Server.java b/server/src/main/java/server/Server.java index db0800b..ee525e6 100755 --- a/server/src/main/java/server/Server.java +++ b/server/src/main/java/server/Server.java @@ -101,6 +101,7 @@ import server.network.HandshakeHandler; import server.network.Player; import server.network.User; import server.util.SVar; +import server.util.ServerConfig; import server.world.Converter; import server.world.Region; import server.world.WorldServer; @@ -257,16 +258,18 @@ public final class Server implements IThreadListener { } private Server() { - for(Field field : Config.class.getDeclaredFields()) { - if(field.isAnnotationPresent(Var.class)) { - if(!Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) - throw new IllegalArgumentException("Feld für Variable " + field + " muss statisch und änderbar sein!"); - Var value = field.getAnnotation(Var.class); - if(value.name().isEmpty()) - throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!"); - if(this.variables.containsKey(value.name())) - throw new IllegalArgumentException("Variable " + value.name() + " existiert bereits!"); - this.variables.put(value.name(), new SVar(field, value)); + for(Class clazz : new Class[] {Config.class, ServerConfig.class}) { + for(Field field : clazz.getDeclaredFields()) { + if(field.isAnnotationPresent(Var.class)) { + if(!Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) + throw new IllegalArgumentException("Feld für Variable " + field + " muss statisch und änderbar sein!"); + Var value = field.getAnnotation(Var.class); + if(value.name().isEmpty()) + throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!"); + if(this.variables.containsKey(value.name())) + throw new IllegalArgumentException("Variable " + value.name() + " existiert bereits!"); + this.variables.put(value.name(), new SVar(field, value)); + } } } this.setCallback(new Runnable() { @@ -274,7 +277,7 @@ public final class Server implements IThreadListener { for(WorldServer world : Server.this.getWorlds()) { world.updatePhysics(); } - Server.this.sendPacket(new SPacketWorld(WorldServer.clampGravity(), Config.dayCycle, Config.timeFlow)); + Server.this.sendPacket(new SPacketWorld(WorldServer.clampGravity(), ServerConfig.dayCycle, ServerConfig.timeFlow)); } }, "daylightCycle", "timeFlow", "gravity"); this.setCallback(new Runnable() { @@ -286,12 +289,12 @@ public final class Server implements IThreadListener { }, "viewDistance"); this.setCallback(new Runnable() { public void run() { - Server.this.bind(Config.port); + Server.this.bind(ServerConfig.port); } }, "port"); this.setCallback(new Runnable() { public void run() { - if((!Config.password.isEmpty() && Config.password.length() < 8) || Config.password.length() > IPlayer.MAX_PASS_LENGTH) + if((!ServerConfig.password.isEmpty() && ServerConfig.password.length() < 8) || ServerConfig.password.length() > IPlayer.MAX_PASS_LENGTH) Log.IO.warn("Passwort muss aus 8-" + IPlayer.MAX_PASS_LENGTH + " Zeichen bestehen, Login wird nicht möglich sein"); } }, "password"); @@ -436,11 +439,11 @@ public final class Server implements IThreadListener { } WorldServer.loadWarps(dim, this.warps); } - if(Config.port >= 0) - this.bind(Config.port); + if(ServerConfig.port >= 0) + this.bind(ServerConfig.port); else Log.SYSTEM.warn("Kein Port definiert, verwende 'sv port <1024-32767>' um einen Hosting-Port festzulegen"); - if(Config.accessRequired && Config.password.length() < 8) + if(ServerConfig.accessRequired && ServerConfig.password.length() < 8) Log.SYSTEM.warn("Kein Passwort definiert, verwende 'sv password <8-" + IPlayer.MAX_PASS_LENGTH + " Zeichen>' um ein Zugangspasswort festzulegen"); Thread con = new Thread(new Runnable() { private final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in))); @@ -512,7 +515,7 @@ public final class Server implements IThreadListener { public void preload(WorldServer world, int bx, int bz) { int done = 0; - int total = Config.distance * 2 + 1; + int total = ServerConfig.distance * 2 + 1; total *= total; Log.TICK.info("Generiere und lade Welt"); // WorldServer world = this.getWorld(Config.spawnDim); @@ -520,8 +523,8 @@ public final class Server implements IThreadListener { bx = bx >> 4; bz = bz >> 4; long last = System.currentTimeMillis(); - for(int x = -Config.distance; x <= Config.distance; x++) { - for(int z = -Config.distance; z <= Config.distance; z++) { + for(int x = -ServerConfig.distance; x <= ServerConfig.distance; x++) { + for(int z = -ServerConfig.distance; z <= ServerConfig.distance; z++) { long time = System.currentTimeMillis(); if(time - last > 1000L) { Log.TICK.info("Bereite Spawnbereich vor" + ": " + (done * 100 / total) + "%"); @@ -607,7 +610,7 @@ public final class Server implements IThreadListener { this.sendPacket(new SPacketPlayerListItem((List)this.getPlayers())); this.pingTimer = 0; } - if(Config.saveInterval > 0 && ++this.saveTimer >= Config.saveInterval) { + if(ServerConfig.saveInterval > 0 && ++this.saveTimer >= ServerConfig.saveInterval) { this.saveAllPlayerData(false); this.saveAllWorlds(false); this.saveTimer = 0; @@ -758,7 +761,7 @@ public final class Server implements IThreadListener { WorldServer world = this.getWorld(origin.getDimension()); world = world == null ? this.space : world; BlockPos pos = origin; - int radius = Config.spawnRadius; + int radius = ServerConfig.spawnRadius; if(radius > 0) { pos = world.getTopSolidOrLiquidBlock(pos.add( ExtMath.clampi(world.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1), 0, @@ -779,10 +782,10 @@ public final class Server implements IThreadListener { Player conn = new Player(this, connection, loginUser); if(tag != null) conn.readTags(tag); - if(Config.compression >= 0) { - connection.sendPacket(new RPacketEnableCompression(Config.compression), new ChannelFutureListener() { + if(ServerConfig.compression >= 0) { + connection.sendPacket(new RPacketEnableCompression(ServerConfig.compression), new ChannelFutureListener() { public void operationComplete(ChannelFuture future) throws Exception { - connection.setCompressionTreshold(Config.compression); + connection.setCompressionTreshold(ServerConfig.compression); } }); } @@ -814,7 +817,7 @@ public final class Server implements IThreadListener { conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null)); conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem)); conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(), - Config.dayCycle, Config.timeFlow)); + ServerConfig.dayCycle, ServerConfig.timeFlow)); // conn.initializeStats(); this.sendPacket(new SPacketPlayerListItem(false, conn)); @@ -945,7 +948,7 @@ public final class Server implements IThreadListener { // this.movePlayerToSpawn(nplayer); } world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4); - if(bed != null ? Config.checkBed : Config.spawnRadius >= 0) { + if(bed != null ? ServerConfig.checkBed : ServerConfig.spawnRadius >= 0) { while(!world.getCollidingBoundingBoxes(nplayer, nplayer.getEntityBoundingBox()).isEmpty() && nplayer.posY < 512.0D) { nplayer.setPosition(nplayer.posX, nplayer.posY + 1.0D, nplayer.posZ); } @@ -1202,7 +1205,7 @@ public final class Server implements IThreadListener { if(this.endpoint != null) this.terminateEndpoint("Wechsele auf Port " + port); // throw new IllegalStateException("Eingangspunkt bereits gesetzt"); - Log.NETWORK.info("Öffne Port %d auf 0.0.0.0 (Timeout %ds)", port, Config.timeout); + Log.NETWORK.info("Öffne Port %d auf 0.0.0.0 (Timeout %ds)", port, ServerConfig.timeout); this.endpoint = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(NioServerSocketChannel.class)).childHandler(new ChannelInitializer() { protected void initChannel(Channel channel) throws Exception { try { @@ -1210,7 +1213,7 @@ public final class Server implements IThreadListener { } catch(ChannelException e) { } - channel.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(Config.timeout))) + channel.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(ServerConfig.timeout))) .addLast((String)"splitter", (ChannelHandler)(new PacketSplitter())) .addLast((String)"decoder", (ChannelHandler)(new PacketDecoder(true))) .addLast((String)"prepender", (ChannelHandler)(new PacketPrepender())) diff --git a/server/src/main/java/server/command/commands/CommandPasswd.java b/server/src/main/java/server/command/commands/CommandPasswd.java index a495505..66bda66 100644 --- a/server/src/main/java/server/command/commands/CommandPasswd.java +++ b/server/src/main/java/server/command/commands/CommandPasswd.java @@ -3,7 +3,6 @@ package server.command.commands; import java.security.MessageDigest; import common.color.TextColor; -import common.init.Config; import common.network.IPlayer; import common.util.EncryptUtil; import server.command.Command; @@ -14,6 +13,7 @@ import server.command.UserPolicy; import server.network.Player; import server.network.User; import server.util.Form; +import server.util.ServerConfig; public class CommandPasswd extends Command { public CommandPasswd() { @@ -39,8 +39,8 @@ public class CommandPasswd extends Command { protected void init() { this.checkField = user != exec ? null : this.addPassword("Aktuelles Passwort", 0, IPlayer.MAX_PASS_LENGTH, ""); - this.passwordField = this.addPassword("Neues Passwort", Config.minPassLength, IPlayer.MAX_PASS_LENGTH, ""); - this.confirmField = this.addPassword("Passwort bestätigen", Config.minPassLength, IPlayer.MAX_PASS_LENGTH, ""); + this.passwordField = this.addPassword("Neues Passwort", ServerConfig.minPassLength, IPlayer.MAX_PASS_LENGTH, ""); + this.confirmField = this.addPassword("Passwort bestätigen", ServerConfig.minPassLength, IPlayer.MAX_PASS_LENGTH, ""); } public String getTitle() { diff --git a/server/src/main/java/server/command/commands/CommandRegister.java b/server/src/main/java/server/command/commands/CommandRegister.java index 48ec952..98ff980 100644 --- a/server/src/main/java/server/command/commands/CommandRegister.java +++ b/server/src/main/java/server/command/commands/CommandRegister.java @@ -1,7 +1,6 @@ package server.command.commands; import common.color.TextColor; -import common.init.Config; import common.network.IPlayer; import common.util.EncryptUtil; import server.command.Command; @@ -11,6 +10,7 @@ import server.command.RunException; import server.network.Player; import server.network.User; import server.util.Form; +import server.util.ServerConfig; public class CommandRegister extends Command { public CommandRegister() { @@ -35,8 +35,8 @@ public class CommandRegister extends Command { private Field confirmField; protected void init() { - this.passwordField = this.addPassword("Passwort", Config.minPassLength, IPlayer.MAX_PASS_LENGTH, ""); - this.confirmField = this.addPassword("Passwort bestätigen", Config.minPassLength, IPlayer.MAX_PASS_LENGTH, ""); + this.passwordField = this.addPassword("Passwort", ServerConfig.minPassLength, IPlayer.MAX_PASS_LENGTH, ""); + this.confirmField = this.addPassword("Passwort bestätigen", ServerConfig.minPassLength, IPlayer.MAX_PASS_LENGTH, ""); } public String getTitle() { diff --git a/server/src/main/java/server/network/LoginHandler.java b/server/src/main/java/server/network/LoginHandler.java index d35af4d..fe13031 100755 --- a/server/src/main/java/server/network/LoginHandler.java +++ b/server/src/main/java/server/network/LoginHandler.java @@ -9,7 +9,6 @@ import java.util.Arrays; import javax.crypto.SecretKey; import common.color.TextColor; -import common.init.Config; import common.log.Log; import common.net.util.concurrent.Future; import common.net.util.concurrent.GenericFutureListener; @@ -28,6 +27,7 @@ import common.packet.RPacketResponse; import common.packet.RPacketServerConfig; import common.util.EncryptUtil; import server.Server; +import server.util.ServerConfig; public class LoginHandler implements ILoginHandler { @@ -100,12 +100,12 @@ public class LoginHandler implements ILoginHandler if(this.server.getPlayer(this.loginUser) != null) return "Nutzername '" + this.loginUser + "' ist bereits vergeben"; User user = this.server.getUser(this.loginUser); - if(Config.authenticate) { + if(ServerConfig.authenticate) { if(user == null) { - if(!Config.register) + if(!ServerConfig.register) return "Anmeldung neuer Accounts ist auf diesem Server deaktiviert (Whitelisted)"; - if(Config.playerLimit > 0 && this.server.getPlayers().size() >= Config.playerLimit) - return String.format("Der Server ist voll (%d/%d)!", this.server.getPlayers().size(), Config.playerLimit); + if(ServerConfig.playerLimit > 0 && this.server.getPlayers().size() >= ServerConfig.playerLimit) + return String.format("Der Server ist voll (%d/%d)!", this.server.getPlayers().size(), ServerConfig.playerLimit); if(this.loginKey != null) { this.server.addUser(user = new User(this.loginUser)); user.setPubkey(this.loginKey); @@ -113,9 +113,9 @@ public class LoginHandler implements ILoginHandler } else { if(this.loginPass == null || this.loginPass.length() == 0) - return "Ein neues Passwort ist erforderlich um diesen Server zu betreten (mindestens " + Config.minPassLength + " Zeichen)"; - if(this.loginPass.length() < Config.minPassLength) - return "Passwort ist zu kurz, mindestens " + Config.minPassLength + " Zeichen"; + return "Ein neues Passwort ist erforderlich um diesen Server zu betreten (mindestens " + ServerConfig.minPassLength + " Zeichen)"; + if(this.loginPass.length() < ServerConfig.minPassLength) + return "Passwort ist zu kurz, mindestens " + ServerConfig.minPassLength + " Zeichen"; this.server.addUser(user = new User(this.loginUser)); user.setPasswordHash(EncryptUtil.hashPassword(this.loginPass)); Log.NETWORK.info(this.loginUser + " registrierte sich mit Passwort"); @@ -129,15 +129,15 @@ public class LoginHandler implements ILoginHandler Log.NETWORK.info(this.loginUser + " loggte sich mit " + (this.loginKey != null ? "Pubkey" : "Passwort") + " ein"); } } - if(Config.playerLimit > 0 && this.server.getPlayers().size() >= Config.playerLimit && (user == null || !user.isAdmin())) - return String.format("Der Server ist voll (%d/%d)!", this.server.getPlayers().size(), Config.playerLimit); + if(ServerConfig.playerLimit > 0 && this.server.getPlayers().size() >= ServerConfig.playerLimit && (user == null || !user.isAdmin())) + return String.format("Der Server ist voll (%d/%d)!", this.server.getPlayers().size(), ServerConfig.playerLimit); return null; } public void sendLoginPacket() { if(this.state != LoginState.INIT) throw new IllegalStateException("Unerwartetes Handshake-Paket"); - if(Config.encrypt) { + if(ServerConfig.encrypt) { this.state = LoginState.ENCRYPT; this.loginToken = new byte[4]; TOKEN_RNG.nextBytes(this.loginToken); @@ -145,7 +145,7 @@ public class LoginHandler implements ILoginHandler } else { this.state = LoginState.PASSWORD; - this.netManager.sendPacket(new RPacketServerConfig(Config.accessRequired, Config.authenticate, Config.authenticate && Config.passwordAuth, false)); + this.netManager.sendPacket(new RPacketServerConfig(ServerConfig.accessRequired, ServerConfig.authenticate, ServerConfig.authenticate && ServerConfig.passwordAuth, false)); } } @@ -166,19 +166,19 @@ public class LoginHandler implements ILoginHandler this.state = LoginState.PASSWORD; this.netManager.sendPacket(new RPacketResponse(packet.getToken(this.server.getPrivateKey())), new GenericFutureListener < Future > () { public void operationComplete(Future u) throws Exception { - LoginHandler.this.netManager.sendPacket(new RPacketServerConfig(Config.accessRequired, Config.authenticate, Config.authenticate && Config.passwordAuth, - Config.authenticate && Config.pubkeyAuth)); + LoginHandler.this.netManager.sendPacket(new RPacketServerConfig(ServerConfig.accessRequired, ServerConfig.authenticate, ServerConfig.authenticate && ServerConfig.passwordAuth, + ServerConfig.authenticate && ServerConfig.pubkeyAuth)); } }); } private boolean checkAccess(String access) { - if(Config.accessRequired) { - if(Config.password.length() < 8) { + if(ServerConfig.accessRequired) { + if(ServerConfig.password.length() < 8) { this.closeConnection("Es ist kein Zugangspasswort für diesen Server konfiguriert"); return false; } - if(!Config.password.equals(access)) { + if(!ServerConfig.password.equals(access)) { this.closeConnection("Falsches Zugangspasswort"); return false; } @@ -192,13 +192,13 @@ public class LoginHandler implements ILoginHandler this.loginUser = packet.getUser(); if(this.loginUser.isEmpty() || !IPlayer.isValidUser(this.loginUser)) throw new IllegalStateException("Ungültiger Nutzername!"); - if(!Config.passwordAuth && Config.authenticate) { - this.closeConnection("Dieser Server " + (Config.pubkeyAuth && Config.encrypt ? "benötigt einen öffentlichen Schlüssel zur Authentifizierung" : "hat keine Authentifizierungsmethode konfiguriert")); + if(!ServerConfig.passwordAuth && ServerConfig.authenticate) { + this.closeConnection("Dieser Server " + (ServerConfig.pubkeyAuth && ServerConfig.encrypt ? "benötigt einen öffentlichen Schlüssel zur Authentifizierung" : "hat keine Authentifizierungsmethode konfiguriert")); return; } if(!this.checkAccess(packet.getAccess())) return; - if(Config.authenticate) + if(ServerConfig.authenticate) this.loginPass = packet.getPassword(); this.state = LoginState.AUTHENTICATED; } @@ -209,13 +209,13 @@ public class LoginHandler implements ILoginHandler this.loginUser = packet.getUser(); if(this.loginUser.isEmpty() || !IPlayer.isValidUser(this.loginUser)) throw new IllegalStateException("Ungültiger Nutzername!"); - if((!Config.pubkeyAuth || !Config.encrypt) && Config.authenticate) { - this.closeConnection("Dieser Server " + (Config.passwordAuth ? "benötigt ein Passwort zur Authentifizierung" : "hat keine Authentifizierungsmethode konfiguriert")); + if((!ServerConfig.pubkeyAuth || !ServerConfig.encrypt) && ServerConfig.authenticate) { + this.closeConnection("Dieser Server " + (ServerConfig.passwordAuth ? "benötigt ein Passwort zur Authentifizierung" : "hat keine Authentifizierungsmethode konfiguriert")); return; } if(!this.checkAccess(packet.getAccess())) return; - if(Config.authenticate) { + if(ServerConfig.authenticate) { this.loginKey = packet.getKey(); this.loginToken = new byte[32]; TOKEN_RNG.nextBytes(this.loginToken); diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 7ddfdd0..12f5c73 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -27,7 +27,6 @@ import common.entity.types.EntityLiving; import common.future.Futures; import common.init.BlockRegistry; import common.init.Blocks; -import common.init.Config; import common.init.EntityRegistry; import common.init.Items; import common.init.SoundEvent; @@ -130,6 +129,7 @@ import server.clipboard.RotationValue; import server.clipboard.Vector; import server.command.Executor; import server.util.Form; +import server.util.ServerConfig; import server.world.ChunkServer; import server.world.Region; import server.world.WorldServer; @@ -274,11 +274,11 @@ public class Player extends User implements ICrafting, Executor, IPlayer public void onEntityDeath() { this.entity.sendDeathMessage(); - if (!Config.keepInventory && Config.playerDrop) + if (!ServerConfig.keepInventory && ServerConfig.playerDrop) { this.entity.inventory.dropAllItems(); } - if(Config.skullDrop) { + if(ServerConfig.skullDrop) { ItemStack stack = new ItemStack(Items.skull, 1, 0); this.entity.dropItem(stack, true, false); } @@ -303,8 +303,8 @@ public class Player extends User implements ICrafting, Executor, IPlayer // this.removeStat(StatRegistry.timeSinceDeathStat); this.entity.resetCombat(); - if(Config.respawnTime > 0) - this.respawnTimer = ExtMath.clampi(Config.respawnTime, 2, 20); + if(ServerConfig.respawnTime > 0) + this.respawnTimer = ExtMath.clampi(ServerConfig.respawnTime, 2, 20); } public boolean isInEditor() { @@ -457,7 +457,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer public void clonePlayer(EntityNPC oldPlayer) { - if(Config.keepInventory) + if(ServerConfig.keepInventory) this.entity.inventory.copyInventory(oldPlayer.inventory); this.entity.experienceLevel = oldPlayer.experienceLevel; this.entity.experienceTotal = oldPlayer.experienceTotal; @@ -2453,7 +2453,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer this.characters.add(new TagObject()); WorldServer world = this.server.getWorld(packetIn.getAuxData()); world = world == null ? this.server.getSpace() : world; - WorldPos origin = new WorldPos(world.rand.range(-Config.originRadius, Config.originRadius), 64, world.rand.range(-Config.originRadius, Config.originRadius), + WorldPos origin = new WorldPos(world.rand.range(-ServerConfig.originRadius, ServerConfig.originRadius), 64, world.rand.range(-ServerConfig.originRadius, ServerConfig.originRadius), world.dimension.getDimensionId()); this.entity.setOrigin(origin); Position pos = this.server.getRandomSpawnPosition(origin); diff --git a/server/src/main/java/server/util/ServerConfig.java b/server/src/main/java/server/util/ServerConfig.java new file mode 100644 index 0000000..af381be --- /dev/null +++ b/server/src/main/java/server/util/ServerConfig.java @@ -0,0 +1,93 @@ +package server.util; + +import common.init.Config; +import common.util.Var; + +public abstract class ServerConfig extends Config { + @Var(name = "tickSpawning") + public static boolean tickSpawn = true; + @Var(name = "genSpawning") + public static boolean genSpawn = true; + @Var(name = "spawnVillagers") + public static boolean spawnVillager = true; + @Var(name = "spawnCagedVillagers") + public static boolean spawnCagedVillager = true; + @Var(name = "spawnHutMages") + public static boolean spawnHutMage = true; + @Var(name = "daylightCycle") + public static boolean dayCycle = true; + @Var(name = "weatherChanges") + public static boolean weather = true; + @Var(name = "dropPlayerSkulls") + public static boolean skullDrop = true; + @Var(name = "checkRespawn") + public static boolean checkBed = true; + @Var(name = "registration") + public static boolean register = true; + @Var(name = "pubkeyAuthentication") + public static boolean pubkeyAuth = true; + @Var(name = "requireAccessPassword") + public static boolean accessRequired = true; + @Var(name = "encryption") + public static boolean encrypt = true; + @Var(name = "requireAuthentication") + public static boolean authenticate = true; + + @Var(name = "snowStacking") + public static boolean snowStack = false; + @Var(name = "passwordAuthentication") + public static boolean passwordAuth = false; + + @Var(name = "randomTickSpeed") + public static int randomTick = 3; + @Var(name = "weatherTickSpeed") + public static int weatherTick = 1; + @Var(name = "lightningChance") + public static int boltChance = 100000; + @Var(name = "igniteChance") + public static int igniteChance = 100; + @Var(name = "spawnRadius") + public static int spawnRadius = 10; + @Var(name = "originRadius", min = 0, max = 262144) + public static int originRadius = 16384; + @Var(name = "respawnTime") + public static int respawnTime = 0; + @Var(name = "spawnGroupCount") + public static int spawnGroups = 3; + @Var(name = "spawnGroupDistance") + public static int spawnGroupDist = 6; + @Var(name = "mobSpawnRadius") + public static int mobSpawnDist = 8; + @Var(name = "mobPlayerDistance") + public static int mobPlayerDist = 24; + @Var(name = "saveInterval") + public static int saveInterval = 900; + @Var(name = "maxPlayers") + public static int playerLimit = 0; + @Var(name = "compressAbove") + public static int compression = 256; + @Var(name = "timeFlow") + public static int timeFlow = 1; + @Var(name = "emptyTicks") + public static int unloadTicks = 1200; + @Var(name = "weatherChance") + public static int weatherChance = 48000; + @Var(name = "viewDistance", min = 2, max = 16) + public static int distance = 8; + @Var(name = "maxSpawns") + public static int maxMobs = 120; + @Var(name = "connectionTimeout", min = 10, max = 300) + public static int timeout = 30; + @Var(name = "passwordMinLength", min = 8, max = 32) + public static int minPassLength = 8; + @Var(name = "port", min = 1024, max = 32767, nonDefault = true) + public static int port = -1; + + @Var(name = "gravity") + public static float gravity = 1.0f; + + @Var(name = "password", nonDefault = true) + public static String password = ""; + @Var(name = "baseSeed", nonDefault = true) + public static String seed = ""; +} diff --git a/server/src/main/java/server/world/Spawner.java b/server/src/main/java/server/world/Spawner.java index bbaea74..046c08c 100755 --- a/server/src/main/java/server/world/Spawner.java +++ b/server/src/main/java/server/world/Spawner.java @@ -8,7 +8,6 @@ import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; import common.entity.types.EntityWaterMob; import common.init.Blocks; -import common.init.Config; import common.rng.Random; import common.rng.WeightedList; import common.util.BlockPos; @@ -17,6 +16,7 @@ import common.util.ExtMath; import common.world.World; import server.biome.GenBiome; import server.biome.RngSpawn; +import server.util.ServerConfig; public abstract class Spawner { private static final int MOB_COUNT_DIV = (int)Math.pow(17.0D, 2.0D); @@ -53,7 +53,7 @@ public abstract class Spawner { // } CHUNKS.clear(); int locs = 0; - int range = Math.max(Config.mobSpawnDist, 1); + int range = Math.max(ServerConfig.mobSpawnDist, 1); for(EntityNPC player : world.players) { // if(Config.spectatorSpawning || !player.isSpectator()) { int x = ExtMath.floord(player.posX / 16.0D); @@ -75,14 +75,14 @@ public abstract class Spawner { } // boolean animals = (time % Math.max(Config.animalSpawnDelay, 1)) == 0; int spawned = 0; - int mobSpread = Math.max(Config.spawnGroupDist, 1); + int mobSpread = Math.max(ServerConfig.spawnGroupDist, 1); // double spawnDist = (double)Config.mobSpawnDistance; - double playerDist = (double)Config.mobPlayerDist; + double playerDist = (double)ServerConfig.mobPlayerDist; // BlockPos spawn = world.isPrimary() ? Server.getSpawnPoint() : null; // for(EnumCreatureType type : EnumCreatureType.values()) { // if((!type.isPeaceful() || peaceful) && (type.isPeaceful() || hostile) && (!type.isAnimal() || animals)) { int cur = world.countEntities(EntityLiving.class); - int max = Config.maxMobs * locs / MOB_COUNT_DIV; + int max = ServerConfig.maxMobs * locs / MOB_COUNT_DIV; if(cur <= max) { typeLabel: for(ChunkPos coord : CHUNKS) { @@ -98,7 +98,7 @@ public abstract class Spawner { if(!block.isNormalCube()) { int group = 0; Object data = null; - for(int n = 0; n < Config.spawnGroups; ++n) { + for(int n = 0; n < ServerConfig.spawnGroups; ++n) { int mx = x; int my = y; int mz = z; diff --git a/server/src/main/java/server/world/WorldServer.java b/server/src/main/java/server/world/WorldServer.java index 4607c2b..4191d72 100755 --- a/server/src/main/java/server/world/WorldServer.java +++ b/server/src/main/java/server/world/WorldServer.java @@ -34,7 +34,6 @@ import common.entity.effect.EntityLightning; import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; import common.init.Blocks; -import common.init.Config; import common.init.SoundEvent; import common.init.UniverseRegistry; import common.item.ItemDoor; @@ -80,6 +79,7 @@ import server.biome.GenBiome; import server.biome.RngSpawn; import server.clipboard.ClipboardBlock; import server.network.Player; +import server.util.ServerConfig; import server.village.VillageCollection; import server.worldgen.BiomeGenLayered; import server.worldgen.BiomeGenPerlin; @@ -180,7 +180,7 @@ public final class WorldServer extends AWorldServer { private long time; public static float clampGravity() { - return ExtMath.clampf(Config.gravity, -10.0f, 10.0f); + return ExtMath.clampf(ServerConfig.gravity, -10.0f, 10.0f); } private BiomeGenerator createBiomeGenerator(Random rand) { @@ -290,8 +290,8 @@ public final class WorldServer extends AWorldServer { this.updateViewRadius(); this.chunkDir = new File(new File("chunk"), dim.getDimensionName()); this.chunkDir.mkdirs(); - if(!Config.seed.isEmpty()) - this.rand.setSeed((long)Config.seed.hashCode() ^ ~((long)dim.getDimensionName().hashCode())); + if(!ServerConfig.seed.isEmpty()) + this.rand.setSeed((long)ServerConfig.seed.hashCode() ^ ~((long)dim.getDimensionName().hashCode())); this.seed = this.rand.longv(); this.dimension.setSeed(this.seed); TagObject tag = null; @@ -321,7 +321,7 @@ public final class WorldServer extends AWorldServer { // ... } else { - Log.TICK.info("Startwert für %s: %d" + (Config.seed.isEmpty() ? "" : " von Basiswert '%s'"), this.dimension.getFormattedName(false), this.seed, Config.seed); + Log.TICK.info("Startwert für %s: %d" + (ServerConfig.seed.isEmpty() ? "" : " von Basiswert '%s'"), this.dimension.getFormattedName(false), this.seed, ServerConfig.seed); } if(this.exterminated) this.weather = Weather.CLEAR; @@ -449,7 +449,7 @@ public final class WorldServer extends AWorldServer { } public void updatePhysics() { - this.setTimeFactor(Config.timeFlow); + this.setTimeFactor(ServerConfig.timeFlow); this.setGravity(clampGravity()); } @@ -457,7 +457,7 @@ public final class WorldServer extends AWorldServer { this.updateWeather(false); this.biomeGen.cleanupCache(); // this.profiler.start("mobSpawner"); - if(this.mobs && Config.mobs && Config.tickSpawn) { + if(this.mobs && ServerConfig.mobs && ServerConfig.tickSpawn) { Spawner.spawn(this); } // this.profiler.next("chunkSource"); @@ -481,7 +481,7 @@ public final class WorldServer extends AWorldServer { // this.info.tick(); this.time += 1L; // this.dataModified = true; - if(Config.dayCycle) // { + if(ServerConfig.dayCycle) // { this.daytime += this.timeFactor; // if(this.dimension.getType().dayCycle) // this.season = this.getSeasonByTime(); @@ -588,7 +588,7 @@ public final class WorldServer extends AWorldServer { } protected void updateBlocks() { - this.setActivePlayerChunksAndCheckLight(Config.distance); + this.setActivePlayerChunksAndCheckLight(ServerConfig.distance); int i = 0; int j = 0; @@ -605,7 +605,7 @@ public final class WorldServer extends AWorldServer { // this.profiler.next("tickChunk"); chunk.update(false); // this.profiler.next("thunder"); - int l2 = Config.boltChance; + int l2 = ServerConfig.boltChance; if(l2 > 0 && this.rand.zrange(l2) == 0 && this.isThundering()) { this.updateLCG = this.updateLCG * 3 + 1013904223; @@ -618,7 +618,7 @@ public final class WorldServer extends AWorldServer { } // this.profiler.next("iceandsnow"); - l2 = Config.weatherTick; + l2 = ServerConfig.weatherTick; for(int z = 0; z < l2; z++) { if(this.rand.zrange(16) == 0) { @@ -631,9 +631,9 @@ public final class WorldServer extends AWorldServer { this.setState(blockpos1, Blocks.ice.getState()); } - if(this.snow && this.isRaining() && this.canSnowAt(blockpos2, true, Config.snowStack)) { - State layer = Config.snowStack ? this.getState(blockpos2) : null; - this.setState(blockpos2, Config.snowStack && layer.getBlock() == Blocks.snow_layer + if(this.snow && this.isRaining() && this.canSnowAt(blockpos2, true, ServerConfig.snowStack)) { + State layer = ServerConfig.snowStack ? this.getState(blockpos2) : null; + this.setState(blockpos2, ServerConfig.snowStack && layer.getBlock() == Blocks.snow_layer ? (Blocks.snow_layer.getState().withProperty(BlockSnow.LAYERS, Math.min(layer.getValue(BlockSnow.LAYERS) + 1, 2))) : Blocks.snow_layer.getState()); } @@ -642,8 +642,8 @@ public final class WorldServer extends AWorldServer { this.getState(blockpos1).getBlock().fillWithRain(this, blockpos1); } - if(Config.igniteChance > 0 && Config.fire && !this.isRaining() && - this.rand.chance(this.hasDownfall() ? Math.max(1, Config.igniteChance / 3) : Config.igniteChance) + if(ServerConfig.igniteChance > 0 && ServerConfig.fire && !this.isRaining() && + this.rand.chance(this.hasDownfall() ? Math.max(1, ServerConfig.igniteChance / 3) : ServerConfig.igniteChance) && this.canPlaceFireAt(blockpos2)) { this.setState(blockpos2, Blocks.fire.getState()); } @@ -651,7 +651,7 @@ public final class WorldServer extends AWorldServer { } // this.profiler.next("tickBlocks"); - l2 = Config.randomTick; + l2 = ServerConfig.randomTick; if(l2 > 0) { this.toTick.addAll(chunk.getStorage()); @@ -754,7 +754,7 @@ public final class WorldServer extends AWorldServer { public void updateEntities() { if(this.players.isEmpty()) { - if(this.emptyTicks++ >= Config.unloadTicks) { + if(this.emptyTicks++ >= ServerConfig.unloadTicks) { return; } } @@ -770,7 +770,7 @@ public final class WorldServer extends AWorldServer { } public boolean shouldUnload() { - return this.emptyTicks >= Config.unloadTicks && this.loaderList.isEmpty(); + return this.emptyTicks >= ServerConfig.unloadTicks && this.loaderList.isEmpty(); } public boolean tickUpdates(boolean p_72955_1_) { @@ -1073,7 +1073,7 @@ public final class WorldServer extends AWorldServer { this.effects.add(entity); this.server.sendNear(entity.posX, entity.posY, entity.posZ, 512.0D, this.dimension.getDimensionId(), new SPacketSpawnGlobalEntity(entity, 1, entity.color)); - if(fire && Config.fire) { + if(fire && ServerConfig.fire) { BlockPos pos = new BlockPos(entity); if(this.isAreaLoaded(pos, 10)) { if(this.getState(pos).getBlock() == Blocks.air && Blocks.fire.canPlaceBlockAt(this, pos)) @@ -1182,9 +1182,9 @@ public final class WorldServer extends AWorldServer { float prevRain = this.rain; float prevFog = this.fog; - if(Config.weather && Config.weatherChance > 0) { + if(ServerConfig.weather && ServerConfig.weatherChance > 0) { // int time = dim.getWeatherTime(); - if(this.rand.chance(Config.weatherChance)) { + if(this.rand.chance(ServerConfig.weatherChance)) { Weather nweather = Weather.pick(this.getBaseTemperature(), this.rand); if(nweather != this.weather) { // dim.setWeatherTime(this.rand.zrange(Config.weatherFlow) + Config.weatherFlow); @@ -1535,7 +1535,7 @@ public final class WorldServer extends AWorldServer { liquid.generate(this, this.grng, pos); } } - if(this.mobs && Config.mobs && Config.genSpawn) { + if(this.mobs && ServerConfig.mobs && ServerConfig.genSpawn) { Spawner.generate(this, biome, bx + 8, bz + 8, 16, 16, this.grng); } // if(this.snow) { @@ -1984,7 +1984,7 @@ public final class WorldServer extends AWorldServer { } public void updateViewRadius() { - int radius = ExtMath.clampi(Config.distance, 3, 128); + int radius = ExtMath.clampi(ServerConfig.distance, 3, 128); if(radius != this.viewRadius) { int diff = radius - this.viewRadius; @@ -2018,7 +2018,7 @@ public final class WorldServer extends AWorldServer { this.viewRadius = radius; } - this.trackDistance = Config.distance * 16 - 16; + this.trackDistance = ServerConfig.distance * 16 - 16; } public void trackEntity(Entity entityIn) { diff --git a/server/src/main/java/server/worldgen/structure/StructureScattered.java b/server/src/main/java/server/worldgen/structure/StructureScattered.java index 2a4b875..0145cb1 100755 --- a/server/src/main/java/server/worldgen/structure/StructureScattered.java +++ b/server/src/main/java/server/worldgen/structure/StructureScattered.java @@ -10,13 +10,13 @@ import common.block.tech.BlockTripWireHook; import common.color.DyeColor; import common.entity.npc.EntityMage; import common.init.Blocks; -import common.init.Config; import common.init.Items; import common.item.RngLoot; import common.rng.Random; import common.tags.TagObject; import common.util.BlockPos; import common.util.Facing; +import server.util.ServerConfig; import server.world.WorldServer; import server.worldgen.LootConstants; @@ -671,7 +671,7 @@ public class StructureScattered } } - if (!this.hasMage && Config.mobs && Config.spawnHutMage) + if (!this.hasMage && ServerConfig.mobs && ServerConfig.spawnHutMage) { int l1 = this.getXWithOffset(2, 5); int i2 = this.getYWithOffset(2); diff --git a/server/src/main/java/server/worldgen/structure/StructureVillage.java b/server/src/main/java/server/worldgen/structure/StructureVillage.java index aa65189..1903edf 100755 --- a/server/src/main/java/server/worldgen/structure/StructureVillage.java +++ b/server/src/main/java/server/worldgen/structure/StructureVillage.java @@ -15,12 +15,12 @@ import common.color.DyeColor; import common.entity.npc.EntityHuman; import common.init.BlockRegistry; import common.init.Blocks; -import common.init.Config; import common.rng.Random; import common.tags.TagObject; import common.util.BlockPos; import common.util.Facing; import common.world.State; +import server.util.ServerConfig; import server.world.WorldServer; import server.worldgen.BiomeGenerator; import server.worldgen.LootConstants; @@ -1604,7 +1604,7 @@ public class StructureVillage protected void spawnVillagers(WorldServer worldIn, StructureBoundingBox p_74893_2_, int p_74893_3_, int p_74893_4_, int p_74893_5_, int p_74893_6_) { - if (this.villagersSpawned < p_74893_6_ && Config.mobs && Config.spawnVillager) + if (this.villagersSpawned < p_74893_6_ && ServerConfig.mobs && ServerConfig.spawnVillager) { for (int i = this.villagersSpawned; i < p_74893_6_; ++i) { @@ -1921,7 +1921,7 @@ public class StructureVillage protected void spawnVillager(WorldServer worldIn, StructureBoundingBox p_74893_2_, int x, int y, int z) { - if (!this.villagerSpawned && Config.mobs && Config.spawnCagedVillager) + if (!this.villagerSpawned && ServerConfig.mobs && ServerConfig.spawnCagedVillager) { int j = this.getXWithOffset(x, z); int k = this.getYWithOffset(y);