fix dev mode, add @ cmd
This commit is contained in:
parent
53a4f5f1a8
commit
06517a0d34
13 changed files with 238 additions and 395 deletions
|
@ -19,6 +19,7 @@ import java.util.Collections;
|
|||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -96,7 +97,7 @@ import server.biome.GenBiome;
|
|||
import server.clipboard.ReorderRegistry;
|
||||
import server.clipboard.RotationRegistry;
|
||||
import server.command.CommandEnvironment;
|
||||
import server.command.FixedExecutor;
|
||||
import server.command.Executor;
|
||||
import server.network.HandshakeHandler;
|
||||
import server.network.Player;
|
||||
import server.network.User;
|
||||
|
@ -106,7 +107,7 @@ import server.world.Converter;
|
|||
import server.world.Region;
|
||||
import server.world.WorldServer;
|
||||
|
||||
public final class Server implements IThreadListener {
|
||||
public final class Server implements IThreadListener, Executor {
|
||||
private static final LazyLoader<NioEventLoopGroup> SERVER_NIO_EVENTLOOP = new LazyLoader<NioEventLoopGroup>() {
|
||||
protected NioEventLoopGroup load() {
|
||||
return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build());
|
||||
|
@ -156,15 +157,21 @@ public final class Server implements IThreadListener {
|
|||
public static void main(String[] args) {
|
||||
long time = System.currentTimeMillis();
|
||||
Util.checkPlatform();
|
||||
Thread.currentThread().setName("Server thread");
|
||||
Locale.setDefault(Locale.ROOT);
|
||||
Util.setupHandlers();
|
||||
Log.init();
|
||||
Registry.setup("Server thread");
|
||||
Log.SYSTEM.info("Starte " + Version.NAME + " Server Version " + Util.VERSION + " (Protokoll #" + Util.PROTOCOL + ")");
|
||||
Log.SYSTEM.info("Java " + System.getProperty("java.version"));
|
||||
Log.SYSTEM.info("Starte " + Version.NAME + " Server " + Util.VERSION + " (Protokoll #" + Util.PROTOCOL + ")");
|
||||
if(Util.DEVMODE)
|
||||
Log.SYSTEM.warn("Entwicklungsmodus aktiv - Debugging-Features sind verfügbar");
|
||||
Registry.register();
|
||||
GenBiome.setAsProvider();
|
||||
UniverseRegistry.register();
|
||||
RotationRegistry.register();
|
||||
ReorderRegistry.register();
|
||||
final Server server = new Server();
|
||||
Registry.addShutdownHook(new Runnable() {
|
||||
Util.addShutdownHook(new Runnable() {
|
||||
public void run() {
|
||||
server.stopServer();
|
||||
Log.flushLog();
|
||||
|
@ -224,7 +231,7 @@ public final class Server implements IThreadListener {
|
|||
String version = tag.hasString("Version") ? tag.getString("Version") : null;
|
||||
version = version != null && version.isEmpty() ? "<unbekannt>" : version;
|
||||
long time = tag.hasLong("Time") ? tag.getLong("Time") : World.START_TIME;
|
||||
Log.IO.info("Version: %s", version);
|
||||
Log.IO.info("Config-Version: %s", version);
|
||||
Log.IO.info("Weltzeit: %d Ticks / %d Sekunden", time, time / 20L);
|
||||
Log.IO.info("Zuletzt geladen: %s", new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date(lastPlayed)));
|
||||
if(tag.hasByteArray("PrivateKey") && tag.hasByteArray("PublicKey")) {
|
||||
|
@ -403,35 +410,9 @@ public final class Server implements IThreadListener {
|
|||
this.keyPair = EncryptUtil.createKeypair();
|
||||
}
|
||||
User.loadDatabase(this.users);
|
||||
// if(dtime == -1L) // {
|
||||
// dtime = World.START_TIME;
|
||||
//// Config.set("spawnDim", "1", null);
|
||||
//// }
|
||||
this.worlds.add(this.space = new WorldServer(this, wtime, Space.INSTANCE));
|
||||
this.dimensions.put(this.space.dimension.getDimensionId(), this.space);
|
||||
new File("players").mkdirs();
|
||||
// if(Config.spawnY < 0) {
|
||||
// WorldServer world = this.getWorld(Config.spawnDim);
|
||||
// world = world == null ? this.space : world;
|
||||
// Random rand = new Random(world.getSeed());
|
||||
// int x = 0;
|
||||
// int z = 0;
|
||||
// int count = 0;
|
||||
// while(!(world.getGroundAboveSeaLevel(new BlockPos(x, 0, z)) == Blocks.grass)) {
|
||||
// if(count == 1000) {
|
||||
// SKC.warn("Konnte keine Spawn-Position finden");
|
||||
// break;
|
||||
// }
|
||||
// x += rand.zrange(64) - rand.zrange(64);
|
||||
// z += rand.zrange(64) - rand.zrange(64);
|
||||
// ++count;
|
||||
// }
|
||||
// Config.set("spawnX", "" + x, null);
|
||||
// Config.set("spawnY", "" + world.getSeaLevel(), null);
|
||||
// Config.set("spawnZ", "" + z, null);
|
||||
// Config.set("spawnYaw", "" + (-180.0f + rand.floatv() * 360.0f), null);
|
||||
// Config.set("spawnPitch", "0.0", null);
|
||||
// }
|
||||
this.setTpsTarget(20.0f);
|
||||
for(Dimension dim : UniverseRegistry.getDimensions()) {
|
||||
if(WorldServer.needsLoading(dim)) {
|
||||
|
@ -462,7 +443,7 @@ public final class Server implements IThreadListener {
|
|||
final String cmd = line;
|
||||
Server.this.schedule(new Runnable() {
|
||||
public void run() {
|
||||
Server.this.scriptEnv.execute(cmd, new FixedExecutor(Server.this, "#con", "KONSOLE", null));
|
||||
Server.this.scriptEnv.execute(cmd, Server.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -518,8 +499,6 @@ public final class Server implements IThreadListener {
|
|||
int total = SVars.distance * 2 + 1;
|
||||
total *= total;
|
||||
Log.TICK.info("Generiere und lade Welt");
|
||||
// WorldServer world = this.getWorld(Config.spawnDim);
|
||||
// world = world == null ? this.space : world;
|
||||
bx = bx >> 4;
|
||||
bz = bz >> 4;
|
||||
long last = System.currentTimeMillis();
|
||||
|
@ -535,43 +514,8 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public void resetProgress() {
|
||||
// this.setProgress(-1);
|
||||
// }
|
||||
//
|
||||
// public void setDone() {
|
||||
// this.setProgress(-2);
|
||||
// }
|
||||
|
||||
private void tick() {
|
||||
// boolean pause = this.paused;
|
||||
// this.paused = this.pause;
|
||||
// if(!pause && this.paused) {
|
||||
// if(!this.debug)
|
||||
// Log.info("Speichere und pausiere Spiel...");
|
||||
// this.saveAllPlayerData(true);
|
||||
// this.saveAllWorlds(true);
|
||||
// }
|
||||
// if(this.paused) {
|
||||
// synchronized(this.queue) {
|
||||
// while(!this.queue.isEmpty()) {
|
||||
// FutureTask<?> task = this.queue.poll();
|
||||
// try {
|
||||
// task.run();
|
||||
// task.get();
|
||||
// }
|
||||
// catch(ExecutionException e1) {
|
||||
// if(!(e1.getCause() instanceof ThreadQuickExitException))
|
||||
// Log.error("Fehler beim Ausführen von Pause-Task " + task, e1);
|
||||
// }
|
||||
// catch(InterruptedException e2) {
|
||||
// Log.error("Fehler beim Ausführen von Pause-Task " + task, e2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
long now = System.currentTimeMillis();
|
||||
synchronized(this.queue) {
|
||||
while(!this.queue.isEmpty()) {
|
||||
|
@ -741,22 +685,6 @@ public final class Server implements IThreadListener {
|
|||
return Thread.currentThread() == this.serverThread;
|
||||
}
|
||||
|
||||
// private void movePlayerToSpawn(EntityNPC player) {
|
||||
// BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ);
|
||||
// int radius = Config.spawnRadius;
|
||||
// if(radius > 0) {
|
||||
// pos = ((WorldServer)player.worldObj).getTopSolidOrLiquidBlock(pos.add(
|
||||
// ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1), 0,
|
||||
// ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1)));
|
||||
// }
|
||||
// player.moveToBlockPosAndAngles(pos, radius > 0 ? (-180.0f + player.worldObj.rand.floatv() * 360.0f) : Config.spawnYaw,
|
||||
// radius > 0 ? 0.0f : Config.spawnPitch);
|
||||
// while(radius >= 0 && !player.worldObj.getCollidingBoundingBoxes(player, player.getEntityBoundingBox()).isEmpty()
|
||||
// && player.posY < 511.0D) {
|
||||
// player.setPosition(player.posX, player.posY + 1.0D, player.posZ);
|
||||
// }
|
||||
// }
|
||||
|
||||
public Position getRandomSpawnPosition(WorldPos origin) {
|
||||
WorldServer world = this.getWorld(origin.getDimension());
|
||||
world = world == null ? this.space : world;
|
||||
|
@ -806,9 +734,8 @@ public final class Server implements IThreadListener {
|
|||
player.readTags(tag);
|
||||
else
|
||||
player.onInitialSpawn(null);
|
||||
// player.setWorld(world);
|
||||
if(tag == null)
|
||||
/* this.movePlayerToSpawn(player); */ player.moveToBlockPosAndAngles(new BlockPos(0, 16384, 0), 0.0f, 0.0f);
|
||||
player.moveToBlockPosAndAngles(new BlockPos(0, 16384, 0), 0.0f, 0.0f);
|
||||
|
||||
Log.NETWORK.info(loginUser + "[" + connection.getCutAddress() + "] hat sich mit Objekt-ID "
|
||||
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": "
|
||||
|
@ -818,7 +745,6 @@ public final class Server implements IThreadListener {
|
|||
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
|
||||
conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(),
|
||||
SVars.dayCycle, SVars.timeFlow));
|
||||
// conn.initializeStats();
|
||||
this.sendPacket(new SPacketPlayerListItem(false, conn));
|
||||
|
||||
world.spawnEntityInWorld(player);
|
||||
|
@ -945,7 +871,6 @@ public final class Server implements IThreadListener {
|
|||
else {
|
||||
Position rpos = this.getRandomSpawnPosition(origin);
|
||||
nplayer.setLocationAndAngles(rpos.x(), rpos.y(), rpos.z(), rpos.yaw(), rpos.pitch());
|
||||
// this.movePlayerToSpawn(nplayer);
|
||||
}
|
||||
world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4);
|
||||
if(bed != null ? SVars.checkBed : SVars.spawnRadius >= 0) {
|
||||
|
@ -981,20 +906,17 @@ public final class Server implements IThreadListener {
|
|||
oldWorld.untrackEntity(old);
|
||||
oldWorld.removePlayer(old);
|
||||
oldWorld.removePlayerEntityDangerously(old);
|
||||
// old.dead = false;
|
||||
|
||||
WorldServer world = tag == null ? this.space : this.getWorld(tag.getInt("Dimension"));
|
||||
world = world == null ? this.space : world;
|
||||
EntityNPC nplayer = conn.createPlayer(world, tag == null ? EntityRegistry.getEntityString(clazz) : tag.getString("id"));
|
||||
// conn.sendPacket(new SPacketRespawn(world.dimension, EntityRegistry.getEntityID(nplayer)));
|
||||
if(tag != null)
|
||||
nplayer.readTags(tag);
|
||||
else
|
||||
nplayer.onInitialSpawn(null);
|
||||
// nplayer.clonePlayer(old);
|
||||
nplayer.setId(old.getId());
|
||||
if(tag == null)
|
||||
/* this.movePlayerToSpawn(nplayer); */ nplayer.moveToBlockPosAndAngles(new BlockPos(0, 16384, 0), 0.0f, 0.0f);
|
||||
nplayer.moveToBlockPosAndAngles(new BlockPos(0, 16384, 0), 0.0f, 0.0f);
|
||||
world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4);
|
||||
world.addPlayer(nplayer);
|
||||
world.spawnEntityInWorld(nplayer);
|
||||
|
@ -1002,7 +924,6 @@ public final class Server implements IThreadListener {
|
|||
conn.sendPacket(new SPacketSkin(nplayer.getId(), nplayer.getSkin())); // , nplayer.getModel()));
|
||||
conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch);
|
||||
conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel));
|
||||
// conn.initializeStats();
|
||||
conn.addSelfToInternalCraftingInventory();
|
||||
nplayer.setHealth(nplayer.getHealth());
|
||||
this.updateTimeAndWeatherForPlayer(conn, world);
|
||||
|
@ -1016,7 +937,6 @@ public final class Server implements IThreadListener {
|
|||
|
||||
public void transferToDimension(EntityNPC player, int dimension, BlockPos pos, float yaw, float pitch, PortalType portal) {
|
||||
WorldServer oldWorld = (WorldServer)player.getServerWorld(); // this.getWorld(player.dimension);
|
||||
// player.dimension = dimension;
|
||||
WorldServer newWorld = this.getWorld(dimension);
|
||||
player.connection.sendPacket(new SPacketRespawn(newWorld.dimension, EntityRegistry.getEntityID(player), player.connection.isInEditor()));
|
||||
oldWorld.removePlayerEntityDangerously(player);
|
||||
|
@ -1031,7 +951,6 @@ public final class Server implements IThreadListener {
|
|||
player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, pos != null ? yaw : player.rotYaw, pos != null ? pitch : player.rotPitch);
|
||||
if(pos != null)
|
||||
player.setRotationYawHead(yaw);
|
||||
// player.interactManager.setWorld(newWorld);
|
||||
this.updateTimeAndWeatherForPlayer((Player)player.connection, newWorld);
|
||||
this.syncPlayerInventory(player);
|
||||
for(PotionEffect effect : player.getEffects()) {
|
||||
|
@ -1181,10 +1100,6 @@ public final class Server implements IThreadListener {
|
|||
public Map<String, Position> getWarps() {
|
||||
return this.warps;
|
||||
}
|
||||
//
|
||||
// public void start() {
|
||||
// this.serverThread.start();
|
||||
// }
|
||||
|
||||
private void stopServer() {
|
||||
if(!this.stopped) {
|
||||
|
@ -1204,7 +1119,6 @@ public final class Server implements IThreadListener {
|
|||
try {
|
||||
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, SVars.timeout);
|
||||
this.endpoint = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(NioServerSocketChannel.class)).childHandler(new ChannelInitializer<Channel>() {
|
||||
protected void initChannel(Channel channel) throws Exception {
|
||||
|
@ -1246,10 +1160,6 @@ public final class Server implements IThreadListener {
|
|||
"Geladen: " + this.getWorlds().size() + " Welten, " + WorldServer.getLoadedInfo(this);
|
||||
}
|
||||
|
||||
public void logConsole(String message) {
|
||||
Log.CONSOLE.info(message);
|
||||
}
|
||||
|
||||
public PublicKey getPublicKey() {
|
||||
return this.keyPair.getPublic();
|
||||
}
|
||||
|
@ -1257,4 +1167,20 @@ public final class Server implements IThreadListener {
|
|||
public PrivateKey getPrivateKey() {
|
||||
return this.keyPair.getPrivate();
|
||||
}
|
||||
|
||||
public void logConsole(String msg) {
|
||||
Log.CONSOLE.info(msg);
|
||||
}
|
||||
|
||||
public Position getExecPos() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Entity getPointedEntity() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public BlockPos getPointedPosition() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue