change port, config and version mechanisms
This commit is contained in:
parent
f879b060e8
commit
adc81d56d2
14 changed files with 122 additions and 74 deletions
|
@ -24,6 +24,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import common.Version;
|
||||
import common.collect.Lists;
|
||||
import common.collect.Maps;
|
||||
import common.color.TextColor;
|
||||
|
@ -153,20 +154,19 @@ public final class Server implements IThreadListener {
|
|||
long time = System.currentTimeMillis();
|
||||
Util.checkOs();
|
||||
Registry.setup("Server thread");
|
||||
Log.SYSTEM.info("Starte " + Config.NAME + " Server Version " + Config.VERSION);
|
||||
Log.SYSTEM.info("Starte " + Version.NAME + " Server Version " + Util.VERSION + " (Protokoll #" + Util.PROTOCOL + ")");
|
||||
GenBiome.setAsProvider();
|
||||
UniverseRegistry.register();
|
||||
RotationRegistry.register();
|
||||
ReorderRegistry.register();
|
||||
boolean debug = System.getProperty("server.debug", null) != null;
|
||||
int port = Integer.parseInt(System.getProperty("server.port", "" + Config.PORT));
|
||||
final Server server = new Server(debug);
|
||||
Registry.addShutdownHook(new Runnable() {
|
||||
public void run() {
|
||||
server.stopServer();
|
||||
}
|
||||
});
|
||||
server.run(time, port);
|
||||
server.run(time);
|
||||
Region.killIO();
|
||||
Log.flushLog();
|
||||
}
|
||||
|
@ -175,10 +175,12 @@ public final class Server implements IThreadListener {
|
|||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setLong("Time", time);
|
||||
data.setLong("LastAccess", System.currentTimeMillis());
|
||||
data.setString("Version", Config.VERSION);
|
||||
data.setString("Version", Util.VERSION);
|
||||
NBTTagCompound cfg = new NBTTagCompound();
|
||||
for(String cvar : Config.VARS.keySet()) {
|
||||
cfg.setString(cvar, Config.VARS.get(cvar).getValue());
|
||||
Config.Value value = Config.VARS.get(cvar);
|
||||
if(!value.noDef || !value.def.equals(value.getValue()))
|
||||
cfg.setString(cvar, value.getValue());
|
||||
}
|
||||
data.setTag("Config", cfg);
|
||||
data.setTag("Universe", UniverseRegistry.saveNbt());
|
||||
|
@ -245,6 +247,11 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
}
|
||||
}, "viewDistance");
|
||||
Config.setCallback(new Runnable() {
|
||||
public void run() {
|
||||
Server.this.bind(Config.port);
|
||||
}
|
||||
}, "port");
|
||||
this.keyPair = EncryptUtil.generateKeyPair();
|
||||
}
|
||||
|
||||
|
@ -356,14 +363,16 @@ public final class Server implements IThreadListener {
|
|||
Config.Value cvar = entry.getValue();
|
||||
String v = cvar.getValue();
|
||||
String comp = TextColor.YELLOW + entry.getKey() + TextColor.GRAY + " = ";
|
||||
if(entry.getKey().equals("password") && !v.isEmpty())
|
||||
if(cvar.noDef && cvar.def.equals(v))
|
||||
comp += TextColor.DGRAY + "[ - ]";
|
||||
else if(entry.getKey().equals("password") && !v.isEmpty())
|
||||
comp += TextColor.NEON + "'****'";
|
||||
else if(cvar.type == ValueType.STRING)
|
||||
comp += TextColor.NEON + "'" + v + "'";
|
||||
else
|
||||
comp += ((cvar.type == ValueType.BOOLEAN ? (v.equals("true") ? TextColor.GREEN : TextColor.RED) : TextColor.BLUE)) + v;
|
||||
if(!cvar.def.equals(v)) {
|
||||
comp += TextColor.GRAY + " (" + TextColor.BROWN + cvar.def + TextColor.GRAY + ")";
|
||||
comp += TextColor.GRAY + " (" + (cvar.noDef ? TextColor.DGRAY + "[ - ]" : TextColor.BROWN + cvar.def) + TextColor.GRAY + ")";
|
||||
}
|
||||
exec.logConsole(comp);
|
||||
}
|
||||
|
@ -381,12 +390,14 @@ public final class Server implements IThreadListener {
|
|||
return false;
|
||||
String v = cfg.getValue();
|
||||
String comp = TextColor.YELLOW + args[0] + TextColor.GRAY + " = ";
|
||||
if(cfg.type == ValueType.STRING)
|
||||
if(cfg.noDef && cfg.def.equals(v))
|
||||
comp += TextColor.DGRAY + "[ - ]";
|
||||
else if(cfg.type == ValueType.STRING)
|
||||
comp += TextColor.NEON + "'" + v + "'";
|
||||
else
|
||||
comp += ((cfg.type == ValueType.BOOLEAN ? (v.equals("true") ? TextColor.GREEN : TextColor.RED) : TextColor.BLUE)) + v;
|
||||
if(!cfg.def.equals(v))
|
||||
comp += TextColor.GRAY + " (" + TextColor.BROWN + cfg.def + TextColor.GRAY + ")";
|
||||
comp += TextColor.GRAY + " (" + (cfg.noDef ? TextColor.DGRAY + "[ - ]" : TextColor.BROWN + cfg.def) + TextColor.GRAY + ")";
|
||||
exec.logConsole(comp);
|
||||
// break;
|
||||
// default:
|
||||
|
@ -434,7 +445,7 @@ public final class Server implements IThreadListener {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void run(long time, int port) {
|
||||
public void run(long time) {
|
||||
if(!this.debug) {
|
||||
Converter.convert();
|
||||
long wtime = loadServerConfig();
|
||||
|
@ -489,8 +500,10 @@ public final class Server implements IThreadListener {
|
|||
WorldServer.loadWarps(dim, this.warps);
|
||||
}
|
||||
}
|
||||
if(port >= 0)
|
||||
this.bind(port);
|
||||
if(Config.port >= 0)
|
||||
this.bind(Config.port);
|
||||
else
|
||||
Log.SYSTEM.warn("Kein Port definiert, verwende 'port <1024-32767>' um einen Hosting-Port festzulegen");
|
||||
Thread con = new Thread(new Runnable() {
|
||||
private final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in)));
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import server.command.commands.CommandOfflinetp;
|
|||
import server.command.commands.CommandPasswd;
|
||||
import server.command.commands.CommandPlayers;
|
||||
import server.command.commands.CommandPotion;
|
||||
import server.command.commands.CommandRebind;
|
||||
import server.command.commands.CommandRegister;
|
||||
import server.command.commands.CommandRemove;
|
||||
import server.command.commands.CommandRevoke;
|
||||
|
@ -276,7 +275,6 @@ public class CommandEnvironment {
|
|||
this.registerExecutable(new CommandKick());
|
||||
this.registerExecutable(new CommandMessage());
|
||||
this.registerExecutable(new CommandShutdown());
|
||||
this.registerExecutable(new CommandRebind());
|
||||
this.registerExecutable(new CommandPasswd());
|
||||
this.registerExecutable(new CommandPlayers());
|
||||
this.registerExecutable(new CommandSave());
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package server.command.commands;
|
||||
|
||||
import server.command.Command;
|
||||
import server.command.CommandEnvironment;
|
||||
import server.command.Executor;
|
||||
|
||||
public class CommandRebind extends Command {
|
||||
public CommandRebind() {
|
||||
super("rebind");
|
||||
|
||||
this.addInt("port", 1024, 65535);
|
||||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, int port) {
|
||||
env.getServer().bind(port);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package server.network;
|
||||
|
||||
import common.init.Config;
|
||||
import common.network.IHandshakeHandler;
|
||||
import common.network.NetConnection;
|
||||
import common.network.NetHandler;
|
||||
import common.network.PacketRegistry;
|
||||
import common.packet.HPacketHandshake;
|
||||
import common.packet.RPacketDisconnect;
|
||||
import common.util.Util;
|
||||
import server.Server;
|
||||
|
||||
public class HandshakeHandler extends NetHandler implements IHandshakeHandler
|
||||
|
@ -31,13 +31,13 @@ public class HandshakeHandler extends NetHandler implements IHandshakeHandler
|
|||
return;
|
||||
}
|
||||
this.networkManager.setConnectionState(PacketRegistry.LOGIN);
|
||||
if (packetIn.getProtocolVersion() != Config.PROTOCOL)
|
||||
if (packetIn.getProtocolVersion() != Util.PROTOCOL)
|
||||
{
|
||||
String comp;
|
||||
if(packetIn.getProtocolVersion() < Config.PROTOCOL)
|
||||
comp = "Der Server nutzt eine neuere Version: " + Config.VERSION;
|
||||
if(packetIn.getProtocolVersion() < Util.PROTOCOL)
|
||||
comp = "Der Server nutzt eine neuere Version: " + Util.VERSION;
|
||||
else
|
||||
comp = "Der Server nutzt eine ältere Version: " + Config.VERSION;
|
||||
comp = "Der Server nutzt eine ältere Version: " + Util.VERSION;
|
||||
this.networkManager.sendPacket(new RPacketDisconnect(comp));
|
||||
this.networkManager.closeChannel(comp);
|
||||
}
|
||||
|
|
|
@ -2044,7 +2044,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
|
|||
return Lists.newArrayList();
|
||||
if(v.type == ValueType.BOOLEAN)
|
||||
return Boolean.parseBoolean(v.getValue()) ? Lists.newArrayList("false", "true") : Lists.newArrayList("true", "false");
|
||||
else if(v.type == ValueType.INTEGER || v.type == ValueType.FLOAT)
|
||||
else if(!v.noDef && (v.type == ValueType.INTEGER || v.type == ValueType.FLOAT))
|
||||
return Lists.newArrayList(v.def);
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue