split server
This commit is contained in:
parent
b0dc368ef7
commit
3ab017888b
25 changed files with 458 additions and 482 deletions
|
@ -14,7 +14,6 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Date;
|
||||
|
@ -406,7 +405,6 @@ public class Game implements IThreadListener {
|
|||
|
||||
private ServerProcess server;
|
||||
private String serverInfo;
|
||||
private int lastServerTick;
|
||||
private AudioInterface audio;
|
||||
private long start;
|
||||
private boolean cfgDirty;
|
||||
|
@ -414,6 +412,10 @@ public class Game implements IThreadListener {
|
|||
private boolean waitingForFile;
|
||||
private boolean refreshing;
|
||||
|
||||
public String message;
|
||||
public int total;
|
||||
public int progress = -1;
|
||||
|
||||
private final int[] tickTimes = new int[240];
|
||||
private final long[] frames = new long[240];
|
||||
private int tickIndex;
|
||||
|
@ -437,7 +439,7 @@ public class Game implements IThreadListener {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void connect(String address, int port, String user, String pass, String access, byte[] local) {
|
||||
public void connect(String address, int port, String user, String pass, String access) {
|
||||
Log.JNI.info("Verbinde zu " + (address == null ? "localhost" : address) + ":" + port);
|
||||
NetConnection connection = null;
|
||||
try
|
||||
|
@ -445,7 +447,7 @@ public class Game implements IThreadListener {
|
|||
connection = NetConnection.createNetworkManagerAndConnect(address == null ? InetAddress.getLoopbackAddress() : InetAddress.getByName(IDN.toASCII(address)), port);
|
||||
connection.setNetHandler(new ClientLoginHandler(connection, this));
|
||||
connection.sendPacket(new HPacketHandshake(Config.PROTOCOL));
|
||||
connection.sendPacket(new LPacketPasswordResponse(user, access, pass, local));
|
||||
connection.sendPacket(new LPacketPasswordResponse(user, access, pass));
|
||||
}
|
||||
catch (UnknownHostException u)
|
||||
{
|
||||
|
@ -1606,11 +1608,6 @@ public class Game implements IThreadListener {
|
|||
this.serverInfo = info;
|
||||
}
|
||||
|
||||
public void setLastTick(int tick) {
|
||||
this.lastTicked = System.currentTimeMillis();
|
||||
this.lastServerTick = tick;
|
||||
}
|
||||
|
||||
public void updatePlayerMoveState()
|
||||
{
|
||||
this.moveStrafe = 0.0F;
|
||||
|
@ -2078,7 +2075,7 @@ public class Game implements IThreadListener {
|
|||
return;
|
||||
this.frameWait = 50000000L - ((n - (this.frameLast + this.frameWait)) < 50000000L ? (n - (this.frameLast + this.frameWait)) : 0L);
|
||||
this.frameLast = n;
|
||||
this.tickTimes[this.tickIndex++] = this.lastServerTick;
|
||||
this.tickTimes[this.tickIndex++] = this.server == null ? 0 : this.server.getLastTick();
|
||||
if(this.tickIndex == 240) {
|
||||
this.tickIndex = 0;
|
||||
}
|
||||
|
@ -2163,6 +2160,7 @@ public class Game implements IThreadListener {
|
|||
|
||||
Log.SYSTEM.info("Beende ...");
|
||||
unload(false);
|
||||
this.stopServer(false);
|
||||
this.getSoundManager().unload();
|
||||
Region.killIO();
|
||||
this.renderGlobal.stopChunkBuilders();
|
||||
|
@ -2341,46 +2339,23 @@ public class Game implements IThreadListener {
|
|||
Timing.tick_update = rtime();
|
||||
}
|
||||
|
||||
public boolean isRemote() {
|
||||
return this.theWorld != null && server == null;
|
||||
}
|
||||
|
||||
public void unload(boolean loading) {
|
||||
if(this.theWorld != null) {
|
||||
if(server != null)
|
||||
this.performAction(Action.SHUTDOWN);
|
||||
if(server == null && this.getNetHandler() != null)
|
||||
if(this.getNetHandler() != null)
|
||||
this.getNetHandler().getNetworkManager().closeChannel("Quitting");
|
||||
this.unloadWorld();
|
||||
// if(server != null)
|
||||
// server.shutdown();
|
||||
}
|
||||
if(server != null) {
|
||||
if(loading) {
|
||||
this.displayGuiScreen(GuiLoading.makeSaveTask(server));
|
||||
}
|
||||
else {
|
||||
while(!server.isStopped()) {
|
||||
try {
|
||||
Thread.sleep(10L);
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
}
|
||||
server = null;
|
||||
this.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
}
|
||||
|
||||
public void startServer(File dir, String user) {
|
||||
byte[] key = new byte[256];
|
||||
new SecureRandom().nextBytes(key);
|
||||
server = new ServerProcess(dir, 1024, 4096, this.port, this.renderDistance, key);
|
||||
public void startServer(File dir) {
|
||||
if(this.server != null)
|
||||
return;
|
||||
server = new ServerProcess(dir, 1024, 4096, this.port);
|
||||
server.start();
|
||||
this.displayGuiScreen(GuiLoading.makeLoadTask(server, user, key));
|
||||
this.displayGuiScreen(GuiLoading.makeLoadTask(server));
|
||||
// while(server != null && !server.isStarted()) {
|
||||
// try {
|
||||
// Thread.sleep(10L);
|
||||
|
@ -2392,9 +2367,32 @@ public class Game implements IThreadListener {
|
|||
// }
|
||||
}
|
||||
|
||||
public void stopServer(boolean display) {
|
||||
if(server != null) {
|
||||
server.shutdown();
|
||||
if(display) {
|
||||
this.displayGuiScreen(GuiLoading.makeSaveTask(server));
|
||||
}
|
||||
else {
|
||||
while(!server.isStopped()) {
|
||||
try {
|
||||
Thread.sleep(10L);
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
server = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isServerRunning() {
|
||||
return this.server != null;
|
||||
}
|
||||
|
||||
public void waitForServer() {
|
||||
if(this.server != null)
|
||||
this.displayGuiScreen(GuiLoading.makeIntermittentTask(this.server));
|
||||
// if(this.server != null)
|
||||
this.displayGuiScreen(GuiLoading.makeWaitTask("Lade Welt ..."));
|
||||
}
|
||||
|
||||
private void startSound(boolean load) {
|
||||
|
@ -2436,8 +2434,6 @@ public class Game implements IThreadListener {
|
|||
public void distance(int distance) {
|
||||
if(this.renderGlobal != null)
|
||||
this.renderGlobal.setDisplayListEntitiesDirty();
|
||||
if(this.server != null && this.thePlayer != null)
|
||||
this.thePlayer.sendQueue.addToSendQueue(new CPacketAction(Action.SET_VIEWDIST, distance));
|
||||
}
|
||||
|
||||
private void registerDebug(Keysym key, String help, DebugRunner runner) {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package game;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
|
@ -64,6 +67,7 @@ import game.packet.SPacketTimeUpdate;
|
|||
import game.packet.SPacketWorld;
|
||||
import game.potion.PotionEffect;
|
||||
import game.util.ExtMath;
|
||||
import game.util.Tuple;
|
||||
import game.util.Util;
|
||||
import game.world.BlockPos;
|
||||
import game.world.PortalType;
|
||||
|
@ -108,11 +112,9 @@ public final class Server implements IThreadListener {
|
|||
private final CommandEnvironment scriptEnv = new CommandEnvironment(this);
|
||||
private final boolean debug;
|
||||
private final boolean ipcpipe;
|
||||
private final String token;
|
||||
|
||||
private WorldServer space;
|
||||
private ChannelFuture endpoint;
|
||||
private String localUser;
|
||||
|
||||
private boolean running = true;
|
||||
private boolean stopped;
|
||||
|
@ -137,24 +139,23 @@ public final class Server implements IThreadListener {
|
|||
public static void main(String[] args) {
|
||||
Util.checkOs();
|
||||
Registry.setup("Server thread");
|
||||
boolean debug = Boolean.parseBoolean(System.getProperty("server.debug", "false"));
|
||||
boolean ipc = debug || Boolean.parseBoolean(System.getProperty("server.pipe", "false"));;
|
||||
String token = System.getProperty("server.token", null);
|
||||
boolean debug = System.getProperty("server.debug", null) != null;
|
||||
boolean ipc = debug || System.getProperty("server.pipe", null) != null;
|
||||
int port = Integer.parseInt(System.getProperty("server.port", "" + Config.PORT));
|
||||
int distance = Integer.parseInt(System.getProperty("server.distance", "" + 0));
|
||||
final Server server = new Server(debug, ipc, token);
|
||||
final Server server = new Server(debug, ipc);
|
||||
Registry.addShutdownHook(new Runnable() {
|
||||
public void run() {
|
||||
server.stopServer();
|
||||
}
|
||||
});
|
||||
server.run(port, distance);
|
||||
server.run(port);
|
||||
Region.killIO();
|
||||
Log.flushLog();
|
||||
}
|
||||
|
||||
private Server(boolean debug, boolean ipc, String token) {
|
||||
private Server(boolean debug, boolean ipc) {
|
||||
this.debug = debug;
|
||||
this.ipcpipe = ipc;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public CommandEnvironment getScriptEnvironment() {
|
||||
|
@ -177,13 +178,9 @@ public final class Server implements IThreadListener {
|
|||
return list;
|
||||
}
|
||||
|
||||
public void setLocalUser(String user) {
|
||||
this.localUser = user;
|
||||
}
|
||||
|
||||
public void saveWorldInfo() {
|
||||
if(!this.debug) {
|
||||
Region.saveWorldInfo(null, this.space.getDayTime(), this.localUser);
|
||||
Region.saveWorldInfo(null, this.space.getDayTime());
|
||||
WorldServer.saveWarps(this.warps);
|
||||
}
|
||||
}
|
||||
|
@ -254,14 +251,12 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
}
|
||||
|
||||
public void run(int port, int distance) {
|
||||
public void run(int port) {
|
||||
long time = System.currentTimeMillis();
|
||||
Log.JNI.info("Starte Server Version " + Config.VERSION);
|
||||
if(!this.debug) {
|
||||
this.setMessage("Welt wird erstellt und geladen");
|
||||
FolderInfo info = Region.loadWorldInfo(null);
|
||||
if(distance > 0)
|
||||
Config.set("viewDistance", "" + distance, null);
|
||||
// if(dtime == -1L) // {
|
||||
// dtime = World.START_TIME;
|
||||
//// Config.set("spawnDim", "1", null);
|
||||
|
@ -300,8 +295,6 @@ public final class Server implements IThreadListener {
|
|||
Config.set("weatherChanges", "false", null);
|
||||
Config.set("mobSpawning", "false", null);
|
||||
Config.set("spawnRadius", "0", null);
|
||||
if(distance > 0)
|
||||
Config.set("viewDistance", "" + distance, null);
|
||||
this.worlds.add(this.space = new WorldServer(this, World.START_TIME,
|
||||
Space.INSTANCE, true));
|
||||
this.dimensions.put(this.space.dimension.getDimensionId(), this.space);
|
||||
|
@ -317,6 +310,32 @@ public final class Server implements IThreadListener {
|
|||
if(port >= 0)
|
||||
this.bind(port);
|
||||
}
|
||||
Thread con = new Thread(new Runnable() {
|
||||
private final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in)));
|
||||
|
||||
public void run() {
|
||||
while(true) {
|
||||
String line;
|
||||
try {
|
||||
line = this.reader.readLine();
|
||||
}
|
||||
catch(IOException e) {
|
||||
line = null;
|
||||
}
|
||||
if(line == null)
|
||||
break;
|
||||
if(line.startsWith("#")) {
|
||||
line = line.substring(1);
|
||||
Tuple<String, String> data = Util.getKeyValue(line);
|
||||
if(data.first.equals("end"))
|
||||
Server.this.shutdown();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "Server console handler");
|
||||
con.setDaemon(true);
|
||||
con.start();
|
||||
Log.JNI.info("Server gestartet in " + String.format("%.1f", (double)(System.currentTimeMillis() - time) / 1000.0) + " Sekunden");
|
||||
while(this.running) {
|
||||
this.currentTime = System.nanoTime() / 1000L;
|
||||
|
@ -365,12 +384,18 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
}
|
||||
|
||||
public void preload(WorldServer world, int bx, int bz) {
|
||||
public void preload(WorldServer world, int bx, int bz, Player callback) {
|
||||
int done = 0;
|
||||
int total = Config.distance * 2 + 1;
|
||||
total *= total;
|
||||
this.setMessage("Landschaft wird generiert");
|
||||
this.startProgress(false, total);
|
||||
if(callback != null) {
|
||||
callback.displayLoading("Lade Welt ...");
|
||||
callback.sendTask("Landschaft wird generiert", total);
|
||||
}
|
||||
else {
|
||||
this.setMessage("Landschaft wird generiert");
|
||||
this.startProgress(false, total);
|
||||
}
|
||||
// WorldServer world = this.getWorld(Config.spawnDim);
|
||||
// world = world == null ? this.space : world;
|
||||
bx = bx >> 4;
|
||||
|
@ -380,17 +405,25 @@ public final class Server implements IThreadListener {
|
|||
for(int z = -Config.distance; z <= Config.distance; z++) {
|
||||
long time = System.currentTimeMillis();
|
||||
if(time - last >= 10L) {
|
||||
this.setProgress(done);
|
||||
if(time - last > 1000L) {
|
||||
Log.JNI.info("Bereite Spawnbereich vor" + ": " + (done * 100 / total) + "%");
|
||||
last = time;
|
||||
if(callback != null) {
|
||||
callback.sendProgress(done);
|
||||
}
|
||||
else {
|
||||
this.setProgress(done);
|
||||
if(time - last > 1000L) {
|
||||
Log.JNI.info("Bereite Spawnbereich vor" + ": " + (done * 100 / total) + "%");
|
||||
last = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
++done;
|
||||
world.loadChunk(bx + x, bz + z);
|
||||
}
|
||||
}
|
||||
this.setProgress(-1);
|
||||
if(callback != null)
|
||||
callback.sendProgress(-1);
|
||||
else
|
||||
this.setProgress(-1);
|
||||
}
|
||||
|
||||
// public void resetProgress() {
|
||||
|
@ -476,6 +509,7 @@ public final class Server implements IThreadListener {
|
|||
if(this.perfTimer == 100) {
|
||||
this.perfTimer = 0;
|
||||
}
|
||||
this.sendPipeIPC("tick", this.getLastTick());
|
||||
}
|
||||
|
||||
public WorldServer getSpace() {
|
||||
|
@ -642,7 +676,7 @@ public final class Server implements IThreadListener {
|
|||
conn.readFromNBT(tag);
|
||||
if(Config.playerLimit > 0 && this.players.size() >= Config.playerLimit && !conn.isAdmin())
|
||||
return String.format("Der Server ist voll (%d/%d)!", this.players.size(), Config.playerLimit);
|
||||
if(!connection.isLocalChannel() && Config.auth) {
|
||||
if(/* !connection.isLocalChannel() && */ Config.auth) {
|
||||
if(conn.getPassword() == null) {
|
||||
if(!Config.register)
|
||||
return "Anmeldung neuer Accounts ist auf diesem Server deaktiviert (Whitelisted)";
|
||||
|
@ -688,8 +722,8 @@ public final class Server implements IThreadListener {
|
|||
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": "
|
||||
+ String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? "Charakter-Editor" : "'" + player.getCommandName() + "'") + ")");
|
||||
|
||||
if(Config.preloadLocal && conn.isLocal() && this.players.size() == 1)
|
||||
this.preload(world, (int)player.posX, (int)player.posZ);
|
||||
if(Config.preload && /* conn.isLocal() && */ this.players.size() == 1)
|
||||
this.preload(world, (int)player.posX, (int)player.posZ, conn);
|
||||
|
||||
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null));
|
||||
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
|
||||
|
@ -1040,8 +1074,7 @@ public final class Server implements IThreadListener {
|
|||
|
||||
private void unsetLanEndpoint() {
|
||||
for(Player conn : Lists.newArrayList(this.players)) {
|
||||
if(!conn.isLocal())
|
||||
conn.disconnect();
|
||||
conn.disconnect();
|
||||
}
|
||||
this.terminateEndpoint();
|
||||
}
|
||||
|
@ -1137,15 +1170,15 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
|
||||
public void shutdown() {
|
||||
Futures.getUnchecked(this.schedule(new Runnable() {
|
||||
public void run() {
|
||||
for(Player conn : Lists.newArrayList(Server.this.players)) { // = Server.this.getPlayer(Server.this.owner);
|
||||
// if(conn != null)
|
||||
if(conn.isLocal())
|
||||
Server.this.removePlayer(conn);
|
||||
}
|
||||
}
|
||||
}));
|
||||
// Futures.getUnchecked(this.schedule(new Runnable() {
|
||||
// public void run() {
|
||||
// for(Player conn : Lists.newArrayList(Server.this.players)) { // = Server.this.getPlayer(Server.this.owner);
|
||||
// // if(conn != null)
|
||||
// if(conn.isLocal())
|
||||
// Server.this.removePlayer(conn);
|
||||
// }
|
||||
// }
|
||||
// }));
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
|
@ -1155,7 +1188,9 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
|
||||
private void sendPipeIPC(String key, Object value) {
|
||||
System.out.println("#" + key + (value == null ? "" : " " + String.valueOf(value)));
|
||||
System.out.flush();
|
||||
if(this.ipcpipe) {
|
||||
System.out.println("#" + key + (value == null ? "" : " " + String.valueOf(value)));
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@ import java.io.BufferedOutputStream;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import game.log.Log;
|
||||
import game.util.Tuple;
|
||||
|
@ -17,25 +19,37 @@ public class ServerProcess {
|
|||
private final ProcessBuilder builder;
|
||||
|
||||
private Process process;
|
||||
private BufferedWriter writer;
|
||||
private PrintWriter writer;
|
||||
private boolean running;
|
||||
private String message;
|
||||
private int total;
|
||||
private int progress = -1;
|
||||
private int lastTick;
|
||||
|
||||
public ServerProcess(File dir, int minMem, int maxMem, int port, int distance, byte[] key) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int z = 0; z < key.length; z++) {
|
||||
sb.append(String.format("%02x", key[z] & 255));
|
||||
}
|
||||
public ServerProcess(File dir, int minMem, int maxMem, int port) {
|
||||
File jar = new File("game.jar");
|
||||
this.builder = new ProcessBuilder("java", "-Xms" + minMem + "M", "-Xmx" + maxMem + "M", "-cp", jar.exists() ? jar.getAbsolutePath() : new File("../bin").getAbsolutePath(),
|
||||
"-Dserver.port=" + port, "-Dserver.distance=" + distance, "-Dserver.token=" + sb.toString(), dir == null ? "-Dserver.debug" : "-Dserver.pipe", "game.Server")
|
||||
String path;
|
||||
if(jar.exists()) {
|
||||
path = jar.getAbsolutePath();
|
||||
}
|
||||
else {
|
||||
path = new File("../bin").getAbsolutePath() + File.pathSeparator + new File("../data").getAbsolutePath();
|
||||
for(File file : new File("../lib").listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().endsWith(".jar") && !pathname.getName().endsWith("-sources.jar");
|
||||
}
|
||||
})) {
|
||||
path += File.pathSeparator + file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
this.builder = new ProcessBuilder("java", "-Xms" + minMem + "M", "-Xmx" + maxMem + "M", "-cp", path,
|
||||
"-Dserver.port=" + port, dir == null ? "-Dserver.debug" : "-Dserver.pipe", "game.Server")
|
||||
.directory(dir).redirectErrorStream(true);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.builder.directory().mkdirs();
|
||||
if(this.builder.directory() != null)
|
||||
this.builder.directory().mkdirs();
|
||||
try {
|
||||
this.process = this.builder.start();
|
||||
}
|
||||
|
@ -65,13 +79,15 @@ public class ServerProcess {
|
|||
Tuple<String, String> data = Util.getKeyValue(line);
|
||||
if(data.first.equals("running"))
|
||||
ServerProcess.this.running = Boolean.parseBoolean(data.second);
|
||||
if(data.first.equals("message"))
|
||||
else if(data.first.equals("message"))
|
||||
ServerProcess.this.message = data.second;
|
||||
if(data.first.equals("total"))
|
||||
else if(data.first.equals("total"))
|
||||
ServerProcess.this.total = Integer.parseInt(data.second);
|
||||
if(data.first.equals("progress"))
|
||||
else if(data.first.equals("progress"))
|
||||
ServerProcess.this.progress = Integer.parseInt(data.second);
|
||||
Log.SYSTEM.info("server cmd %s -- %s", data.first, data.second);
|
||||
else if(data.first.equals("tick"))
|
||||
ServerProcess.this.lastTick = Integer.parseInt(data.second);
|
||||
Log.SYSTEM.trace("server cmd %s -- %s", data.first, data.second);
|
||||
continue;
|
||||
}
|
||||
System.err.println(line);
|
||||
|
@ -80,11 +96,7 @@ public class ServerProcess {
|
|||
}, "Server console listener");
|
||||
con.setDaemon(true);
|
||||
con.start();
|
||||
this.writer = new BufferedWriter(new OutputStreamWriter(new BufferedOutputStream(this.process.getOutputStream())));
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return this.builder.directory();
|
||||
this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new BufferedOutputStream(this.process.getOutputStream()))), true);
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
|
@ -107,11 +119,15 @@ public class ServerProcess {
|
|||
return this.total;
|
||||
}
|
||||
|
||||
public int getLastTick() {
|
||||
return this.lastTick;
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
try {
|
||||
this.writer.write("end\n");
|
||||
this.writer.println("#end");
|
||||
}
|
||||
catch(IOException e) {
|
||||
catch(Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ public class CommandAdmin extends Command {
|
|||
throw new RunException("Dieser Befehl kann nur von Spielern ausgeführt werden");
|
||||
else if(player == exec)
|
||||
throw new RunException("Du kannst nicht deinen eigenen Admin-Status erneut setzen");
|
||||
else if(player.isLocal())
|
||||
throw new RunException("%s ist der Host-Spieler", player.getUser());
|
||||
else if(player.getAdmin())
|
||||
throw new RunException("%s ist bereits ein Admin", player.getUser());
|
||||
player.setAdmin(true);
|
||||
|
|
|
@ -18,8 +18,6 @@ public class CommandKick extends Command {
|
|||
throw new RunException("Dieser Befehl kann nur von Spielern ausgeführt werden");
|
||||
else if(player == exec)
|
||||
throw new RunException("Du kannst nicht dich nicht selbst vom Server werfen");
|
||||
else if(player.isLocal())
|
||||
throw new RunException("%s ist der Host-Spieler", player.getUser());
|
||||
else if(player.getAdmin())
|
||||
throw new RunException("%s ist ein Admin", player.getUser());
|
||||
player.disconnect();
|
||||
|
|
|
@ -14,12 +14,10 @@ public class CommandRevoke extends Command {
|
|||
}
|
||||
|
||||
public void exec(CommandEnvironment env, Executor exec, Player player) {
|
||||
if(!(exec instanceof Player) || !((Player)exec).isLocal())
|
||||
throw new RunException("Dieser Befehl kann nur vom Host-Spieler ausgeführt werden");
|
||||
if(exec instanceof Player)
|
||||
throw new RunException("Dieser Befehl kann nur der Konsole ausgeführt werden");
|
||||
else if(player == exec)
|
||||
throw new RunException("Du kannst nicht deinen eigenen Admin-Status entfernen");
|
||||
else if(player.isLocal())
|
||||
throw new RunException("%s ist der Host-Spieler", player.getUser());
|
||||
else if(!player.getAdmin())
|
||||
throw new RunException("%s ist kein Admin", player.getUser());
|
||||
player.setAdmin(false);
|
||||
|
|
|
@ -18,17 +18,14 @@ public class GuiLoading extends Gui {
|
|||
private Bar progressBar1;
|
||||
private Bar progressBar2;
|
||||
|
||||
public static GuiLoading makeLoadTask(final ServerProcess server, final String user, final byte[] key) {
|
||||
return new GuiLoading("Lade Welt ...", new Callback() {
|
||||
public static GuiLoading makeLoadTask(final ServerProcess server) {
|
||||
return new GuiLoading("Starte Server ...", new Callback() {
|
||||
boolean started = false;
|
||||
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
if(!this.started && server.isStarted()) {
|
||||
this.started = true;
|
||||
// gm.displayGuiScreen(null);
|
||||
gm.debugWorld = server.getFolder() == null;
|
||||
gm.connect(null, gm.port, user, "", "", key);
|
||||
// return;
|
||||
gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
}
|
||||
int progress = server.getProgress();
|
||||
if(progress < 0) {
|
||||
|
@ -43,26 +40,6 @@ public class GuiLoading extends Gui {
|
|||
});
|
||||
}
|
||||
|
||||
public static GuiLoading makeIntermittentTask(final ServerProcess server) {
|
||||
return new GuiLoading("Lade Welt ...", new Callback() {
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
int progress = server.getProgress();
|
||||
// if(progress == -2) {
|
||||
// gm.displayGuiScreen(null);
|
||||
// return;
|
||||
// }
|
||||
if(progress < 0) {
|
||||
gui.resetBar();
|
||||
}
|
||||
else {
|
||||
gui.setBar(null, "Chunks", Math.max(1, server.getTotal()));
|
||||
gui.setProgress(progress);
|
||||
}
|
||||
gui.setTask(server.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GuiLoading makeSaveTask(final ServerProcess server) {
|
||||
return new GuiLoading("Speichere Welt ...", new Callback() {
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
|
@ -83,6 +60,29 @@ public class GuiLoading extends Gui {
|
|||
});
|
||||
}
|
||||
|
||||
public static GuiLoading makeServerTask(String message) {
|
||||
return new GuiLoading(message, new Callback() {
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
int progress = gm.progress;
|
||||
if(progress < 0) {
|
||||
gui.resetBar();
|
||||
}
|
||||
else {
|
||||
gui.setBar(null, "Chunks", Math.max(1, gm.total));
|
||||
gui.setProgress(progress);
|
||||
}
|
||||
gui.setTask(gm.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GuiLoading makeWaitTask(String message) {
|
||||
return new GuiLoading(message, new Callback() {
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public GuiLoading(String message, Callback callback) {
|
||||
this.message = message;
|
||||
this.callback = callback;
|
||||
|
|
|
@ -61,11 +61,14 @@ public class GuiMenu extends Gui {
|
|||
GuiMenu.this.hacked++;
|
||||
GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!");
|
||||
}
|
||||
else if(GuiMenu.this.gm.isServerRunning()) {
|
||||
GuiMenu.this.gm.stopServer(true);
|
||||
}
|
||||
else {
|
||||
GuiMenu.this.gm.displayGuiScreen(GuiWorlds.INSTANCE);
|
||||
}
|
||||
}
|
||||
}, "Einzelspieler"));
|
||||
}, this.gm.isServerRunning() ? "Server beenden" : "Server hosten"));
|
||||
this.add(new ActButton(0, 28, 400, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(GuiMenu.this.hacked == 8)
|
||||
|
@ -73,7 +76,7 @@ public class GuiMenu extends Gui {
|
|||
else
|
||||
GuiMenu.this.gm.displayGuiScreen(GuiConnect.INSTANCE);
|
||||
}
|
||||
}, "Mehrspieler"));
|
||||
}, "Server beitreten"));
|
||||
this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE);
|
||||
|
@ -118,7 +121,7 @@ public class GuiMenu extends Gui {
|
|||
GuiMenu.this.gm.unload(true);
|
||||
// GuiMenu.this.gm.displayGuiScreen(INSTANCE);
|
||||
}
|
||||
}, this.gm.isRemote() ? "Server verlassen und Verbindung trennen" : "Welt speichern und schließen"));
|
||||
}, "Server verlassen und Verbindung trennen"));
|
||||
this.shift();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class GuiConnect extends Gui implements Textbox.Callback {
|
|||
this.lastPass = pass;
|
||||
this.lastAcc = acc;
|
||||
this.gm.setDirty();
|
||||
this.gm.connect(addr, port, user, pass, acc, null);
|
||||
this.gm.connect(addr, port, user, pass, acc);
|
||||
}
|
||||
|
||||
public void use(Textbox elem, Action value) {
|
||||
|
|
|
@ -10,7 +10,6 @@ import game.gui.element.Label;
|
|||
import game.gui.element.NavButton;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.network.Player;
|
||||
import game.world.Region;
|
||||
|
||||
public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callback
|
||||
|
@ -22,11 +21,9 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba
|
|||
|
||||
private Textbox worldNameField;
|
||||
// private Textbox worldSeedField;
|
||||
private Textbox worldUserField;
|
||||
private ActButton createButton;
|
||||
private Label actionLabel;
|
||||
private Label nameLabel;
|
||||
private Label userLabel;
|
||||
// private Label seed;
|
||||
// private Label decoded;
|
||||
|
||||
|
@ -184,11 +181,10 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba
|
|||
// }
|
||||
this.fileExists = false;
|
||||
String text = this.worldNameField.getText().trim();
|
||||
this.createButton.enabled = !text.isEmpty() && !this.worldUserField.getText().isEmpty();
|
||||
this.createButton.enabled = !text.isEmpty();
|
||||
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
|
||||
this.createButton.enabled = false;
|
||||
this.actionLabel.setText(this.getFolderDesc());
|
||||
this.userLabel.setText(this.getUserDesc());
|
||||
}
|
||||
|
||||
public void init(int width, int height)
|
||||
|
@ -200,10 +196,10 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba
|
|||
this.worldNameField = this.add(new Textbox(20, 40, 284, 24, 256, true, this, GuiWorlds.VALID_FILE, ""));
|
||||
this.worldNameField.setSelected();
|
||||
// this.worldSeedField = this.add(new Textbox(20, 140, 284, 24, 256, true, this, ""));
|
||||
this.worldUserField = this.add(new Textbox(20, 90, 284, 24, Player.MAX_USER_LENGTH, true, this, Player.VALID_USER, ""));
|
||||
// this.worldUserField = this.add(new Textbox(20, 90, 284, 24, Player.MAX_USER_LENGTH, true, this, Player.VALID_USER, ""));
|
||||
this.createButton.enabled = false;
|
||||
this.actionLabel = this.add(new Label(20, 20, 284, 20, this.getFolderDesc(), true));
|
||||
this.userLabel = this.add(new Label(20, 70, 284, 20, this.getUserDesc(), true));
|
||||
// this.userLabel = this.add(new Label(20, 70, 284, 20, this.getUserDesc(), true));
|
||||
// this.seed = this.add(new Label(20, 120, 284, 20, "", true));
|
||||
// this.decoded = this.add(new Label(20, 164, 284, 20, "", true));
|
||||
this.shift();
|
||||
|
@ -241,7 +237,7 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba
|
|||
// Log.IO.error(e, "Konnte Weltdaten nicht speichern");
|
||||
// }
|
||||
// }
|
||||
this.gm.startServer(dir, this.worldUserField.getText());
|
||||
this.gm.startServer(dir);
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -255,7 +251,7 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba
|
|||
+ "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : "");
|
||||
}
|
||||
|
||||
private String getUserDesc() {
|
||||
return (this.worldUserField.getText().isEmpty() ? TextColor.DRED : "") + "Spielername";
|
||||
}
|
||||
// private String getUserDesc() {
|
||||
// return (this.worldUserField.getText().isEmpty() ? TextColor.DRED : "") + "Spielername";
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -12,10 +12,9 @@ import java.util.Set;
|
|||
|
||||
import game.collect.Sets;
|
||||
|
||||
import game.Game;
|
||||
import game.Game.FileMode;
|
||||
import game.color.TextColor;
|
||||
import game.dimension.Dimension;
|
||||
import game.dimension.Space;
|
||||
import game.gui.GuiConfirm;
|
||||
import game.gui.GuiMenu;
|
||||
import game.gui.element.ActButton;
|
||||
|
@ -24,11 +23,9 @@ import game.gui.element.GuiList;
|
|||
import game.gui.element.ListEntry;
|
||||
import game.gui.element.NavButton;
|
||||
import game.gui.world.GuiEdit.Callback;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.log.Log;
|
||||
import game.nbt.NBTLoader;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagList;
|
||||
import game.renderer.Drawing;
|
||||
import game.util.CharValidator;
|
||||
import game.util.FileCallback;
|
||||
|
@ -44,15 +41,15 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
{
|
||||
protected class SaveInfo implements Comparable<SaveInfo>, ListEntry {
|
||||
private final String file;
|
||||
private final String name;
|
||||
private final String dim;
|
||||
private final int dimensions;
|
||||
private final int players;
|
||||
private final long seed;
|
||||
private final FolderInfo info;
|
||||
|
||||
public SaveInfo(String file, String name, String dim, long seed, FolderInfo info) {
|
||||
public SaveInfo(String file, int dimensions, int players, long seed, FolderInfo info) {
|
||||
this.file = file;
|
||||
this.name = name;
|
||||
this.dim = dim;
|
||||
this.dimensions = dimensions;
|
||||
this.players = players;
|
||||
this.seed = seed;
|
||||
this.info = info;
|
||||
}
|
||||
|
@ -61,20 +58,12 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
return this.file;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
public int getDimensions() {
|
||||
return this.dimensions;
|
||||
}
|
||||
|
||||
public String getDim() {
|
||||
return this.dim == null ? "<?>" : this.dim;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return this.info.user == null ? "<?>" : this.info.user;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.info.user;
|
||||
public int getPlayers() {
|
||||
return this.players;
|
||||
}
|
||||
|
||||
public boolean mustConvert() {
|
||||
|
@ -105,28 +94,26 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
{
|
||||
boolean use = !this.isIncompatible();
|
||||
boolean cur = use && !this.mustConvert();
|
||||
GuiWorlds.this.selectButton.setText(!use || !cur ? "Konvertieren" : "Welt spielen");
|
||||
GuiWorlds.this.selectButton.setText(!use || !cur ? "Konvertieren" : "Server starten");
|
||||
GuiWorlds.this.selectButton.enabled = use;
|
||||
GuiWorlds.this.deleteButton.enabled = true;
|
||||
GuiWorlds.this.pruneButton.enabled = cur;
|
||||
GuiWorlds.this.copyButton.enabled = use;
|
||||
GuiWorlds.this.moveButton.enabled = use;
|
||||
GuiWorlds.this.seedButton.enabled = cur;
|
||||
GuiWorlds.this.userButton.enabled = cur;
|
||||
GuiWorlds.this.dupeButton.enabled = cur;
|
||||
|
||||
if (isDoubleClick && use)
|
||||
{
|
||||
GuiWorlds.this.playWorld(null);
|
||||
GuiWorlds.this.playWorld();
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover)
|
||||
{
|
||||
Drawing.drawText((this.isIncompatible() ? TextColor.DRED : "") + this.getFile() + (this.mustConvert() ? "" :
|
||||
(TextColor.GRAY + " - " + TextColor.RESET + this.getUser() + (this.getName() != null ? TextColor.GRAY + " (" + TextColor.RESET + this.getName() + TextColor.GRAY + ")" : ""))),
|
||||
(TextColor.GRAY + " - " + TextColor.RESET + (this.getPlayers() > 0 ? this.getPlayers() + " Spieler" : "Keine Spieler"))),
|
||||
x + 2, y, 0xffffffff);
|
||||
Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : this.getDim())
|
||||
Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : (this.getDimensions() <= 0 ? "Keine Dimensionen" : this.getDimensions() + " Dimension" + (this.getDimensions() != 1 ? "en" : "") + " erschaffen"))
|
||||
, x + 2, y + 18, 0xff808080);
|
||||
Drawing.drawText(this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON + "Kann nicht konvertiert werden!" :
|
||||
"Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") +
|
||||
|
@ -153,8 +140,8 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
private ActButton copyButton;
|
||||
private ActButton moveButton;
|
||||
private ActButton seedButton;
|
||||
private ActButton userButton;
|
||||
private ActButton dupeButton;
|
||||
// private ActButton userButton;
|
||||
// private ActButton dupeButton;
|
||||
private ActButton createButton;
|
||||
|
||||
private GuiWorlds()
|
||||
|
@ -182,44 +169,37 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
continue;
|
||||
FolderInfo info = Region.loadWorldInfo(file);
|
||||
if(info == null)
|
||||
info = Converter.convertMapFormat(file, null);
|
||||
info = Converter.convertMapFormat(file, false);
|
||||
if(info == null) {
|
||||
this.elements.add(new SaveInfo(file.getName(), null, null,
|
||||
0L, new FolderInfo(World.START_TIME, null, file.lastModified(), null, null)));
|
||||
this.elements.add(new SaveInfo(file.getName(), -1, -1,
|
||||
0L, new FolderInfo(World.START_TIME, file.lastModified(), null, null)));
|
||||
continue;
|
||||
}
|
||||
Dimension dim = null;
|
||||
String name = null;
|
||||
if(info.legacy == null && info.user != null) {
|
||||
File dat = new File(new File(new File(Region.SAVE_DIR, file.getName()), "players"), info.user + ".nbt");
|
||||
if(dat.exists() && dat.isFile()) {
|
||||
try {
|
||||
NBTTagCompound tag = NBTLoader.readGZip(dat);
|
||||
int selected = tag.getInteger("selected");
|
||||
NBTTagList list = tag.getTagList("characters", 10);
|
||||
selected = Math.min(selected, list.tagCount() - 1);
|
||||
if(selected >= 0) {
|
||||
NBTTagCompound etag = list.getCompoundTagAt(selected);
|
||||
dim = UniverseRegistry.getDimension(etag.getInteger("Dimension"));
|
||||
if(etag.hasKey("CustomName", 8) && etag.getString("CustomName").length() > 0)
|
||||
name = etag.getString("CustomName");
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
int dims = -1;
|
||||
int players = -1;
|
||||
if(info.legacy == null) {
|
||||
dims = 0;
|
||||
File[] folders = new File(new File(Region.SAVE_DIR, file.getName()), "chunk").listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.isDirectory() && !pathname.getName().equals(Space.INSTANCE.getDimensionName());
|
||||
}
|
||||
});
|
||||
if(folders != null) {
|
||||
for(File sub : folders) {
|
||||
File[] dim = sub.listFiles();
|
||||
if(dim != null && dim.length > 0)
|
||||
dims++;
|
||||
}
|
||||
}
|
||||
File[] plrs = new File(new File(Region.SAVE_DIR, file.getName()), "players").listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().endsWith(".nbt");
|
||||
}
|
||||
});
|
||||
players = plrs == null ? 0 : plrs.length;
|
||||
}
|
||||
if(dim != null) {
|
||||
File dat = new File(new File(new File(new File(Region.SAVE_DIR, file.getName()), "chunk"),
|
||||
dim.getDimensionName()), "data.nbt");
|
||||
try {
|
||||
dim.fromNbt(NBTLoader.readGZip(dat).getCompoundTag("Generator"));
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
}
|
||||
this.elements.add(new SaveInfo(file.getName(), name, dim == null ? null : TextColor.stripCodes(dim.getFormattedName(true)),
|
||||
dim == null ? 0L : dim.getSeed(), info));
|
||||
this.elements.add(new SaveInfo(file.getName(), dims, players,
|
||||
0L, info));
|
||||
}
|
||||
// this.saveList = list;
|
||||
Collections.sort(this.elements);
|
||||
|
@ -233,7 +213,7 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
this.warningMessage = "Welten-Ordner nicht lesbar!";
|
||||
}
|
||||
|
||||
this.add(this.selectButton = new ActButton(width / 2 - 383, height - 56, 150, 24, this, "Welt spielen"));
|
||||
this.add(this.selectButton = new ActButton(width / 2 - 383, height - 56, 150, 24, this, "Server starten"));
|
||||
this.add(this.createButton = new ActButton(width / 2 + 233, height - 56, 150, 24, this,
|
||||
(create ? "" : "" + TextColor.DRED) + (create ? "Neue Welt ..." : "Fehler!")));
|
||||
this.add(this.deleteButton = new ActButton(width / 2 - 229, height - 28, 150, 24, this, "Löschen"));
|
||||
|
@ -241,8 +221,8 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
this.add(this.copyButton = new ActButton(width / 2 - 383, height - 28, 150, 24, this, "Kopieren"));
|
||||
this.add(this.moveButton = new ActButton(width / 2 + 79, height - 28, 150, 24, this, "Verschieben"));
|
||||
this.add(this.seedButton = new ActButton(width / 2 - 75, height - 56, 150, 24, this, "Startwert"));
|
||||
this.add(this.userButton = new ActButton(width / 2 - 229, height - 56, 150, 24, this, "Spieler"));
|
||||
this.add(this.dupeButton = new ActButton(width / 2 + 79, height - 56, 150, 24, this, "Duplizieren"));
|
||||
// this.add(this.userButton = new ActButton(width / 2 - 229, height - 56, 150, 24, this, "Spieler"));
|
||||
// this.add(this.dupeButton = new ActButton(width / 2 + 79, height - 56, 150, 24, this, "Duplizieren"));
|
||||
this.add(new NavButton(width / 2 + 233, height - 28, 150, 24, GuiMenu.INSTANCE, "Abbrechen"));
|
||||
|
||||
this.add(new ActButton(4, 4, 200, 24, new ActButton.Callback() {
|
||||
|
@ -259,7 +239,7 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
}
|
||||
FolderInfo info = Region.loadWorldInfo(file);
|
||||
if(info == null)
|
||||
info = Converter.convertMapFormat(file, null);
|
||||
info = Converter.convertMapFormat(file, false);
|
||||
if(info == null || info.legacy == SaveVersion.RELEASE_1_13) {
|
||||
GuiWorlds.this.warningTimer = 120;
|
||||
GuiWorlds.this.warningMessage = info == null ? "Keine Weltdaten gefunden" : "Weltdaten haben inkompatible Version";
|
||||
|
@ -289,8 +269,6 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
this.copyButton.enabled = false;
|
||||
this.moveButton.enabled = false;
|
||||
this.seedButton.enabled = false;
|
||||
this.userButton.enabled = false;
|
||||
this.dupeButton.enabled = false;
|
||||
this.createButton.enabled = create;
|
||||
}
|
||||
|
||||
|
@ -401,38 +379,19 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
// if(isShiftKeyDown())
|
||||
//
|
||||
// else
|
||||
this.playWorld(null);
|
||||
this.playWorld();
|
||||
}
|
||||
else if (button == this.createButton)
|
||||
{
|
||||
if(GuiWorlds.this.gm.theWorld == null) {
|
||||
if(this.gm.shift()) {
|
||||
// this.gm.displayGuiScreen(null);
|
||||
this.gm.startServer(null, "debug");
|
||||
this.gm.startServer(null);
|
||||
}
|
||||
else {
|
||||
this.gm.displayGuiScreen(GuiCreate.INSTANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (button == this.userButton)
|
||||
{
|
||||
this.gm.displayGuiScreen(new GuiEdit(this.getSelected().getUsername(), true,
|
||||
"Spieler für '" + this.getSaveAt() + "' ändern", "Ändern", "Spielername", new Callback() {
|
||||
public void confirm(String name) {
|
||||
if(name != null)
|
||||
GuiWorlds.this.changeUser(name);
|
||||
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
|
||||
}
|
||||
}));
|
||||
}
|
||||
// else if (button.id == 0)
|
||||
// {
|
||||
// this.gm.displayGuiScreen(this.parentScreen);
|
||||
// }
|
||||
else if (button == this.dupeButton)
|
||||
{
|
||||
|
||||
}
|
||||
else if (button == this.copyButton)
|
||||
{
|
||||
|
@ -530,7 +489,7 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
// this.gm.displayGuiScreen(this);
|
||||
}
|
||||
|
||||
private void playWorld(String user)
|
||||
private void playWorld()
|
||||
{
|
||||
if(GuiWorlds.this.gm.theWorld != null)
|
||||
return;
|
||||
|
@ -539,34 +498,16 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
|
|||
if (!this.starting)
|
||||
{
|
||||
this.starting = true;
|
||||
// int index = this.selectedIndex;
|
||||
if(user == null)
|
||||
user = this.getSelected().getUsername();
|
||||
String dir = this.getSaveAt();
|
||||
File folder = new File(Region.SAVE_DIR, dir);
|
||||
if(folder.isDirectory()) {
|
||||
if(user == null) {
|
||||
this.gm.displayGuiScreen(new GuiEdit("", true,
|
||||
"Spieler für '" + dir + "' festlegen", "Festlegen", "Spielername", new Callback() {
|
||||
public void confirm(String name) {
|
||||
if(name != null)
|
||||
GuiWorlds.this.playWorld(name);
|
||||
else
|
||||
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
|
||||
}
|
||||
}));
|
||||
this.starting = false;
|
||||
}
|
||||
else {
|
||||
if(this.getSelected().mustConvert()) {
|
||||
Game r = this.gm;
|
||||
Converter.convertMapFormat(folder, user);
|
||||
this.starting = false;
|
||||
}
|
||||
else {
|
||||
this.gm.startServer(folder, user);
|
||||
}
|
||||
}
|
||||
if(this.getSelected().mustConvert()) {
|
||||
Converter.convertMapFormat(folder, true);
|
||||
this.starting = false;
|
||||
}
|
||||
else {
|
||||
this.gm.startServer(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -339,8 +339,8 @@ public abstract class Config {
|
|||
public static boolean itemFallDamage = true;
|
||||
@Var(name = "registration")
|
||||
public static boolean register = true;
|
||||
@Var(name = "preload_chunks_local")
|
||||
public static boolean preloadLocal = true;
|
||||
@Var(name = "preload_chunks")
|
||||
public static boolean preload = true;
|
||||
|
||||
@Var(name = "keepInventory")
|
||||
public static boolean keepInventory = false;
|
||||
|
|
|
@ -27,6 +27,7 @@ import game.entity.projectile.EntityProjectile;
|
|||
import game.entity.types.EntityLiving;
|
||||
import game.gui.Gui;
|
||||
import game.gui.GuiConsole;
|
||||
import game.gui.GuiLoading;
|
||||
import game.gui.character.GuiChar;
|
||||
import game.gui.character.GuiCharacters;
|
||||
import game.gui.container.GuiMachine;
|
||||
|
@ -89,12 +90,12 @@ import game.packet.SPacketEntityVelocity;
|
|||
import game.packet.SPacketHeldItemChange;
|
||||
import game.packet.SPacketJoinGame;
|
||||
import game.packet.SPacketKeepAlive;
|
||||
import game.packet.SPacketLoading;
|
||||
import game.packet.SPacketMapChunkBulk;
|
||||
import game.packet.SPacketMessage;
|
||||
import game.packet.SPacketMultiBlockChange;
|
||||
import game.packet.SPacketPlayerPosLook;
|
||||
import game.packet.SPacketRespawn;
|
||||
import game.packet.SPacketServerTick;
|
||||
import game.packet.SPacketSetExperience;
|
||||
import game.packet.SPacketSkin;
|
||||
import game.packet.SPacketSpawnMob;
|
||||
|
@ -795,6 +796,25 @@ public class ClientPlayer extends NetHandler
|
|||
// }
|
||||
}
|
||||
|
||||
public void handleLoading(SPacketLoading packet) {
|
||||
NetHandler.checkThread(packet, this, this.gameController);
|
||||
|
||||
if(packet.getMessage() == null) {
|
||||
if(packet.getTask() != null)
|
||||
this.gameController.message = packet.getTask();
|
||||
if(packet.getTotal() >= 0)
|
||||
this.gameController.total = packet.getTotal();
|
||||
if(packet.getProgress() >= -1)
|
||||
this.gameController.progress = packet.getProgress();
|
||||
}
|
||||
else {
|
||||
this.gameController.message = "";
|
||||
this.gameController.total = 0;
|
||||
this.gameController.progress = -1;
|
||||
this.gameController.displayGuiScreen(GuiLoading.makeServerTask(packet.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
// public void handleMessage(SPacketMessage packetIn)
|
||||
// {
|
||||
// NetHandler.checkThread(packetIn, this, this.gameController);
|
||||
|
@ -1883,11 +1903,6 @@ public class ClientPlayer extends NetHandler
|
|||
this.clientWorldController.dimension.setCustomName(packetIn.getCustomName());
|
||||
}
|
||||
|
||||
public void handleServerTick(SPacketServerTick packet) {
|
||||
NetHandler.checkThread(packet, this, this.gameController);
|
||||
this.gameController.setLastTick(packet.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this the NetworkManager instance registered with this NetworkHandlerPlayClient
|
||||
*/
|
||||
|
|
|
@ -3,11 +3,9 @@ package game.network;
|
|||
import game.Server;
|
||||
import game.color.TextColor;
|
||||
import game.init.Config;
|
||||
import game.init.NameRegistry;
|
||||
import game.log.Log;
|
||||
import game.packet.LPacketPasswordResponse;
|
||||
import game.packet.RPacketDisconnect;
|
||||
import game.rng.Random;
|
||||
|
||||
public class LoginHandler extends NetHandler
|
||||
{
|
||||
|
@ -105,32 +103,15 @@ public class LoginHandler extends NetHandler
|
|||
if(this.state != LoginState.PASSWORD)
|
||||
throw new IllegalStateException("Unerwartetes Passwort-Paket");
|
||||
this.loginUser = packetIn.getUser();
|
||||
if(packetIn.getLocal() != null) {
|
||||
// TODO: key verification
|
||||
this.netManager.setLocal();
|
||||
this.loginPass = "";
|
||||
// this.loginUser = Config.localUser;
|
||||
if(this.loginUser.length() > Player.MAX_USER_LENGTH || (!this.loginUser.isEmpty() && !Player.isValidUser(this.loginUser))) {
|
||||
Random rand = new Random();
|
||||
do {
|
||||
this.loginUser = NameRegistry.FANTASY.generate(rand, rand.range(2, 4)).toLowerCase();
|
||||
}
|
||||
while(this.loginUser.length() > Player.MAX_USER_LENGTH || !Player.isValidUser(this.loginUser)); // || this.server.getPlayer(this.loginUser) != null);
|
||||
// this.server.setVar("local_user", this.loginUser);
|
||||
}
|
||||
this.server.setLocalUser(this.loginUser);
|
||||
}
|
||||
else {
|
||||
this.loginPass = packetIn.getPassword();
|
||||
if(this.loginUser.isEmpty() || !Player.isValidUser(this.loginUser))
|
||||
throw new IllegalStateException("Ungültiger Nutzername!");
|
||||
this.loginPass = packetIn.getPassword();
|
||||
if(this.loginUser.isEmpty() || !Player.isValidUser(this.loginUser))
|
||||
throw new IllegalStateException("Ungültiger Nutzername!");
|
||||
// if(!this.checkConnect(packetIn.getAccess()))
|
||||
// return;
|
||||
if(!Config.password.isEmpty() && !Config.password.equals(packetIn.getAccess())) {
|
||||
this.closeConnection("Falsches Zugangspasswort");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!Config.password.isEmpty() && !Config.password.equals(packetIn.getAccess())) {
|
||||
this.closeConnection("Falsches Zugangspasswort");
|
||||
return;
|
||||
}
|
||||
this.state = LoginState.READY_TO_ACCEPT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,13 +50,11 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet>
|
|||
private NetHandler packetListener;
|
||||
private String terminationReason;
|
||||
private boolean disconnected;
|
||||
private boolean local;
|
||||
|
||||
public void channelActive(ChannelHandlerContext p_channelActive_1_) throws Exception
|
||||
{
|
||||
super.channelActive(p_channelActive_1_);
|
||||
this.channel = p_channelActive_1_.channel();
|
||||
this.local = false; // this.channel instanceof LocalChannel || this.channel instanceof LocalServerChannel;
|
||||
this.socketAddress = this.channel.remoteAddress();
|
||||
|
||||
try
|
||||
|
@ -293,20 +291,6 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet>
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True if this NetworkManager uses a memory connection (single player game). False may imply both an active TCP
|
||||
* connection or simply no active connection at all
|
||||
*/
|
||||
public boolean isLocalChannel()
|
||||
{
|
||||
return this.local;
|
||||
}
|
||||
|
||||
public void setLocal()
|
||||
{
|
||||
this.local = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new NetworkManager from the server host and connect it to the server
|
||||
*
|
||||
|
|
|
@ -42,7 +42,7 @@ public class PacketDecoder extends ByteToMessageDecoder
|
|||
|
||||
// if (Log.isTraceEnabled())
|
||||
// {
|
||||
// Log.debug("EIN: [" + p_decode_1_.channel().attr(NetConnection.ATTR_STATE).get() + ":" + i + "] " + packet.getClass().getName());
|
||||
// Log.SYSTEM.info("EIN: [" + p_decode_1_.channel().attr(NetConnection.ATTR_STATE).get() + ":" + i + "] " + packet.getClass().getName());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,12 +69,12 @@ import game.packet.SPacketEntityVelocity;
|
|||
import game.packet.SPacketHeldItemChange;
|
||||
import game.packet.SPacketJoinGame;
|
||||
import game.packet.SPacketKeepAlive;
|
||||
import game.packet.SPacketLoading;
|
||||
import game.packet.SPacketMapChunkBulk;
|
||||
import game.packet.SPacketMessage;
|
||||
import game.packet.SPacketMultiBlockChange;
|
||||
import game.packet.SPacketPlayerPosLook;
|
||||
import game.packet.SPacketRespawn;
|
||||
import game.packet.SPacketServerTick;
|
||||
import game.packet.SPacketSetExperience;
|
||||
import game.packet.SPacketSkin;
|
||||
import game.packet.SPacketSpawnMob;
|
||||
|
@ -179,7 +179,7 @@ public enum PacketRegistry
|
|||
// this.server(SPacketNotify.class);
|
||||
this.server(SPacketDimensionName.class);
|
||||
this.server(SPacketCharacterList.class);
|
||||
this.server(SPacketServerTick.class);
|
||||
this.server(SPacketLoading.class);
|
||||
|
||||
this.client(CPacketKeepAlive.class);
|
||||
this.client(CPacketMessage.class);
|
||||
|
|
|
@ -96,6 +96,7 @@ import game.packet.SPacketChunkData;
|
|||
import game.packet.SPacketDestroyEntities;
|
||||
import game.packet.SPacketDisconnect;
|
||||
import game.packet.SPacketKeepAlive;
|
||||
import game.packet.SPacketLoading;
|
||||
import game.packet.SPacketMapChunkBulk;
|
||||
import game.packet.SPacketMessage;
|
||||
import game.packet.SPacketMessage.Type;
|
||||
|
@ -167,7 +168,6 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
private final NetConnection connection;
|
||||
private final Server server;
|
||||
private final String user;
|
||||
private final boolean local;
|
||||
private final IntHashMap<Short> transactions = new IntHashMap();
|
||||
private final List<NBTTagCompound> characters = Lists.newArrayList();
|
||||
|
||||
|
@ -239,7 +239,7 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
this.user = user;
|
||||
this.server = server;
|
||||
this.connection = connection;
|
||||
this.local = connection.isLocalChannel();
|
||||
// this.local = connection.isLocalChannel();
|
||||
}
|
||||
|
||||
public EntityNPC createPlayer(WorldServer world, String id) {
|
||||
|
@ -274,7 +274,7 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
this.pingKey = (int)this.lastPingTime;
|
||||
this.sendPacket(new SPacketKeepAlive(this.pingKey));
|
||||
}
|
||||
if(this.local)
|
||||
// if(this.local)
|
||||
|
||||
if(this.respawnTimer > 0) {
|
||||
if(--this.respawnTimer == 0) {
|
||||
|
@ -283,6 +283,18 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
}
|
||||
}
|
||||
|
||||
public void displayLoading(String message) {
|
||||
this.sendPacket(new SPacketLoading(message));
|
||||
}
|
||||
|
||||
public void sendTask(String task, int total) {
|
||||
this.sendPacket(new SPacketLoading(task, total));
|
||||
}
|
||||
|
||||
public void sendProgress(int progress) {
|
||||
this.sendPacket(new SPacketLoading(progress));
|
||||
}
|
||||
|
||||
public void onEntityDeath() {
|
||||
this.entity.sendDeathMessage();
|
||||
|
||||
|
@ -335,16 +347,16 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
return this.user;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return this.local;
|
||||
}
|
||||
// public boolean isLocal() {
|
||||
// return this.local;
|
||||
// }
|
||||
|
||||
public int getLatency() {
|
||||
return this.ping;
|
||||
}
|
||||
|
||||
public boolean isAdmin() {
|
||||
return this.admin || this.local;
|
||||
return this.admin; // || this.local;
|
||||
}
|
||||
|
||||
public boolean getAdmin() {
|
||||
|
@ -955,7 +967,7 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
Iterator<ChunkPos> iterator1 = this.loadedChunks.iterator();
|
||||
List<TileEntity> list1 = Lists.<TileEntity>newArrayList();
|
||||
|
||||
int n = this.local ? 1024 : 10;
|
||||
int n = 10; // TODO: this.local ? 1024 : 10;
|
||||
|
||||
while (iterator1.hasNext() && ((List)list).size() < n)
|
||||
{
|
||||
|
@ -1551,8 +1563,7 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
public void onDisconnect(String reason)
|
||||
{
|
||||
Log.JNI.info(this.user + " wurde getrennt: " + TextColor.stripCodes(reason));
|
||||
if(!this.local)
|
||||
this.server.sendPacket(new SPacketMessage(String.format("%s hat das Spiel verlassen", this.user), Type.FEED));
|
||||
this.server.sendPacket(new SPacketMessage(String.format("%s hat das Spiel verlassen", this.user), Type.FEED));
|
||||
this.server.removePlayer(this);
|
||||
}
|
||||
|
||||
|
@ -1577,8 +1588,7 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
chars.add(this.getCharacterInfo(tag));
|
||||
}
|
||||
this.sendPacket(new SPacketCharacterList(this.selected, chars));
|
||||
if(!this.local)
|
||||
this.server.sendPacket(new SPacketMessage(String.format("%s hat das Spiel betreten", this.user), Type.FEED));
|
||||
this.server.sendPacket(new SPacketMessage(String.format("%s hat das Spiel betreten", this.user), Type.FEED));
|
||||
}
|
||||
|
||||
public void sendPacket(final Packet packet)
|
||||
|
@ -2513,7 +2523,7 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
NetHandler.checkThread(packetIn, this, this.server);
|
||||
|
||||
CPacketAction.Action action = packetIn.getAction();
|
||||
if(action != Action.SET_VIEWDIST && action != Action.SHUTDOWN && (this.charEditor != (action == Action.SET_ALIGN || action == Action.SET_SPECIES || action == Action.SET_CLASS || action == Action.SET_HEIGHT || action == Action.CLOSE_EDITOR))) // {
|
||||
if(this.charEditor != (action == Action.SET_ALIGN || action == Action.SET_SPECIES || action == Action.SET_CLASS || action == Action.SET_HEIGHT || action == Action.CLOSE_EDITOR)) // {
|
||||
// if(this.local && action == Action.CLOSE_EDITOR)
|
||||
// this.server.setDone();
|
||||
return;
|
||||
|
@ -2544,8 +2554,8 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
world.dimension.getDimensionId());
|
||||
this.entity.setOrigin(origin);
|
||||
Position pos = this.server.getRandomSpawnPosition(origin);
|
||||
if(Config.preloadLocal && this.local && this.server.getPlayers().size() == 1)
|
||||
this.server.preload(world, (int)pos.x, (int)pos.z);
|
||||
if(Config.preload && /* this.local && */ this.server.getPlayers().size() == 1)
|
||||
this.server.preload(world, (int)pos.x, (int)pos.z, this);
|
||||
this.entity.teleport(pos);
|
||||
this.sendPacket(new SPacketCharacterList(this.selected, this.selected, new PlayerCharacter(this.entity.getCustomNameTag(), this.entity.getDescription(), this.entity.getAlignment(), this.entity.worldObj.dimension.getFormattedName(false), this.entity.getPosition(), EntityRegistry.getEntityName(EntityRegistry.getEntityString(this.entity)), this.entity.experienceLevel)));
|
||||
// if(this.local)
|
||||
|
@ -2877,7 +2887,7 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
break;
|
||||
|
||||
case WARP_MODE:
|
||||
if(this.isLocal()) {
|
||||
if(this.isAdmin()) {
|
||||
this.server.schedule(new Runnable() {
|
||||
public void run() {
|
||||
Player.this.server.setTpsTarget(Player.this.server.getTpsTarget() < 10000.0f ? 10000.0f : 20.0f);
|
||||
|
@ -2886,16 +2896,6 @@ public class Player extends NetHandler implements ICrafting, Executor
|
|||
}
|
||||
break;
|
||||
|
||||
case SET_VIEWDIST:
|
||||
if(this.isLocal())
|
||||
this.server.setVar("viewDistance", "" + packetIn.getAuxData());
|
||||
break;
|
||||
|
||||
case SHUTDOWN:
|
||||
if(this.isLocal())
|
||||
this.server.shutdown();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Ungültige Aktion!");
|
||||
}
|
||||
|
|
|
@ -94,8 +94,8 @@ public class CPacketAction implements Packet<Player>
|
|||
REPAIR,
|
||||
PERF,
|
||||
MAGNET,
|
||||
SET_VIEWDIST,
|
||||
WARP_MODE,
|
||||
SHUTDOWN;
|
||||
// SET_VIEWDIST,
|
||||
WARP_MODE;
|
||||
// SHUTDOWN;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,18 +12,16 @@ public class LPacketPasswordResponse implements Packet<LoginHandler>
|
|||
private String user;
|
||||
private String access;
|
||||
private String password;
|
||||
private byte[] local;
|
||||
|
||||
public LPacketPasswordResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public LPacketPasswordResponse(String userIn, String accessIn, String passwordIn, byte[] local)
|
||||
public LPacketPasswordResponse(String userIn, String accessIn, String passwordIn)
|
||||
{
|
||||
this.user = userIn;
|
||||
this.access = accessIn;
|
||||
this.password = passwordIn;
|
||||
this.local = local;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,8 +32,6 @@ public class LPacketPasswordResponse implements Packet<LoginHandler>
|
|||
this.user = buf.readStringFromBuffer(Player.MAX_USER_LENGTH);
|
||||
this.access = buf.readStringFromBuffer(Player.MAX_PASS_LENGTH);
|
||||
this.password = buf.readStringFromBuffer(Player.MAX_PASS_LENGTH);
|
||||
this.local = buf.readByteArray();
|
||||
this.local = this.local.length == 0 ? null : this.local;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +42,6 @@ public class LPacketPasswordResponse implements Packet<LoginHandler>
|
|||
buf.writeString(this.user);
|
||||
buf.writeString(this.access);
|
||||
buf.writeString(this.password);
|
||||
buf.writeByteArray(this.local == null ? new byte[0] : this.local);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,9 +66,4 @@ public class LPacketPasswordResponse implements Packet<LoginHandler>
|
|||
{
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public byte[] getLocal()
|
||||
{
|
||||
return this.local;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.util.Map.Entry;
|
|||
import game.collect.Maps;
|
||||
import game.entity.npc.Alignment;
|
||||
import game.entity.npc.PlayerCharacter;
|
||||
import game.log.Log;
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.Player;
|
||||
import game.world.BlockPos;
|
||||
|
@ -25,21 +24,17 @@ public class SPacketCharacterList implements Packet<ClientPlayer> {
|
|||
|
||||
public SPacketCharacterList(int selected) {
|
||||
this.selected = selected;
|
||||
Log.SYSTEM.info("PPPPPPPPPPPPPPPPP selected" + selected);
|
||||
}
|
||||
|
||||
public SPacketCharacterList(int selected, int index, PlayerCharacter conns) {
|
||||
this.players.put(index, conns);
|
||||
this.selected = selected;
|
||||
Log.SYSTEM.info("PPPPPPPPPPPPPPPPP selected " + selected + " @ " + index + " : " + (conns == null ? "[null]" : conns.name + " - " + conns.dim));
|
||||
}
|
||||
|
||||
public SPacketCharacterList(int selected, Iterable<PlayerCharacter> conns) {
|
||||
int pos = 0;
|
||||
Log.SYSTEM.info("PPPPPPPPPPPPPPPPP list selected" + selected);
|
||||
for(PlayerCharacter conn : conns) {
|
||||
this.players.put(pos++, conn);
|
||||
Log.SYSTEM.info("PPPPPPPPPPPPPPPPP list : " + conn.name + " - " + conn.dim);
|
||||
}
|
||||
this.selected = selected;
|
||||
}
|
||||
|
@ -54,6 +49,7 @@ public class SPacketCharacterList implements Packet<ClientPlayer> {
|
|||
continue;
|
||||
}
|
||||
String info = buf.readStringFromBuffer(Player.MAX_INFO_LENGTH);
|
||||
info = info.isEmpty() ? null : info;
|
||||
Alignment align = buf.readEnumValue(Alignment.class);
|
||||
String dim = buf.readStringFromBuffer(256);
|
||||
BlockPos pos = buf.readBlockPos();
|
||||
|
@ -74,7 +70,7 @@ public class SPacketCharacterList implements Packet<ClientPlayer> {
|
|||
continue;
|
||||
}
|
||||
buf.writeString(chr.name);
|
||||
buf.writeString(chr.info);
|
||||
buf.writeString(chr.info == null ? "" : chr.info);
|
||||
buf.writeEnumValue(chr.align);
|
||||
buf.writeString(chr.dim);
|
||||
buf.writeBlockPos(chr.pos);
|
||||
|
|
70
java/src/game/packet/SPacketLoading.java
Normal file
70
java/src/game/packet/SPacketLoading.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package game.packet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class SPacketLoading implements Packet<ClientPlayer> {
|
||||
private String message;
|
||||
private String task;
|
||||
private int total = -1;
|
||||
private int progress = -2;
|
||||
|
||||
public SPacketLoading() {
|
||||
}
|
||||
|
||||
public SPacketLoading(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public SPacketLoading(String task, int total) {
|
||||
this.task = task;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public SPacketLoading(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public void readPacketData(PacketBuffer buf) throws IOException {
|
||||
this.message = buf.readStringFromBuffer(128);
|
||||
this.message = this.message != null && this.message.isEmpty() ? null : this.message;
|
||||
if(this.message == null) {
|
||||
this.task = buf.readStringFromBuffer(128);
|
||||
this.task = this.task != null && this.task.isEmpty() ? null : this.task;
|
||||
this.total = buf.readInt();
|
||||
this.progress = buf.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
public void writePacketData(PacketBuffer buf) throws IOException {
|
||||
buf.writeString(this.message == null ? "" : this.message);
|
||||
if(this.message == null) {
|
||||
buf.writeString(this.task == null ? "" : this.task);
|
||||
buf.writeInt(this.total);
|
||||
buf.writeInt(this.progress);
|
||||
}
|
||||
}
|
||||
|
||||
public void processPacket(ClientPlayer handler) {
|
||||
handler.handleLoading(this);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public String getTask() {
|
||||
return this.task;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return this.progress;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package game.packet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import game.network.ClientPlayer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class SPacketServerTick implements Packet<ClientPlayer> {
|
||||
private int time;
|
||||
|
||||
public SPacketServerTick() {
|
||||
}
|
||||
|
||||
public SPacketServerTick(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public void readPacketData(PacketBuffer buf) throws IOException {
|
||||
this.time = buf.readInt();
|
||||
}
|
||||
|
||||
public void writePacketData(PacketBuffer buf) throws IOException {
|
||||
buf.writeInt(this.time);
|
||||
}
|
||||
|
||||
public void processPacket(ClientPlayer handler) {
|
||||
handler.handleServerTick(this);
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return this.time;
|
||||
}
|
||||
}
|
131
java/src/game/world/Converter.java
Executable file → Normal file
131
java/src/game/world/Converter.java
Executable file → Normal file
|
@ -57,7 +57,6 @@ import game.entity.animal.EntitySquid;
|
|||
import game.entity.animal.EntityWolf;
|
||||
import game.entity.item.EntityBoat;
|
||||
import game.entity.item.EntityMinecart;
|
||||
import game.entity.npc.EntityHuman;
|
||||
import game.gui.GuiLoading;
|
||||
import game.gui.GuiLoading.Callback;
|
||||
import game.gui.world.GuiWorlds;
|
||||
|
@ -1207,12 +1206,12 @@ public final class Converter {
|
|||
return start;
|
||||
}
|
||||
|
||||
public static FolderInfo convertMapFormat(File dir, String user) {
|
||||
public static FolderInfo convertMapFormat(File dir, boolean load) {
|
||||
long cur = System.currentTimeMillis();
|
||||
if(user != null)
|
||||
if(load)
|
||||
Log.JNI.info("Welt '" + dir + "' wird konvertiert");
|
||||
if(new File(dir, "level.nbt").exists()) {
|
||||
if(user != null)
|
||||
if(load)
|
||||
Log.JNI.error("Datei level.nbt existiert bereits");
|
||||
return null;
|
||||
}
|
||||
|
@ -1220,7 +1219,7 @@ public final class Converter {
|
|||
if(!ldat.exists())
|
||||
ldat = new File(dir, "level.dat_old");
|
||||
if(!ldat.exists()) {
|
||||
if(user != null)
|
||||
if(load)
|
||||
Log.JNI.error("Datei level.dat und level.dat_old nicht gefunden");
|
||||
return null;
|
||||
}
|
||||
|
@ -1229,7 +1228,7 @@ public final class Converter {
|
|||
nbt = NBTLoader.readGZip(ldat);
|
||||
}
|
||||
catch(Exception e) {
|
||||
if(user != null)
|
||||
if(load)
|
||||
Log.JNI.error(e, "Fehler beim Lesen von level.dat");
|
||||
return null;
|
||||
}
|
||||
|
@ -1239,13 +1238,13 @@ public final class Converter {
|
|||
// nbt.setBoolean("incompatible", data >= 1400);
|
||||
SaveVersion ver = data >= 1400 ? SaveVersion.RELEASE_1_13 : (data >= 100 ? SaveVersion.RELEASE_1_9 : (version == 19132 || version == 19133 ? SaveVersion.BETA_1_3 : (version == 0 ? SaveVersion.ALPHA_1_0 : null)));
|
||||
if(ver == null) {
|
||||
if(user != null)
|
||||
if(load)
|
||||
Log.IO.error("Version %d ist unbekannt", version);
|
||||
return null;
|
||||
}
|
||||
long wtime = nbt.getLong(nbt.hasKey("DayTime", 99) ? "DayTime" : "Time") + World.START_TIME;
|
||||
if(user == null)
|
||||
return new FolderInfo(wtime, null, nbt.getLong("LastPlayed"), ver, null);
|
||||
if(!load)
|
||||
return new FolderInfo(wtime, nbt.getLong("LastPlayed"), ver, null);
|
||||
// nbt.setString("verdesc", ver);
|
||||
// NBTTagCompound nbt = getLegacyWorldInfo(dir);
|
||||
// if(nbt == null)
|
||||
|
@ -1333,62 +1332,62 @@ public final class Converter {
|
|||
// int id = nbt.getInteger("GameType");
|
||||
// Config.set("defaultNoCreative", "" + (id == 2 || id == 0), false);
|
||||
Log.JNI.info("Speichere neue level.nbt ...");
|
||||
Region.saveWorldInfo(dir, wtime, user);
|
||||
if(tag.hasKey("Player", 10)) {
|
||||
conv.action = "Konvertiere Spielerdaten";
|
||||
NBTTagCompound player = tag.getCompoundTag("Player");
|
||||
NBTTagList pos = player.getTagList("Pos", 6);
|
||||
NBTTagList motion = player.getTagList("Motion", 6);
|
||||
NBTTagList rotation = player.getTagList("Rotation", 5);
|
||||
boolean ground = player.getBoolean("OnGround");
|
||||
BlockPos spawn = null;
|
||||
// boolean force = player.getBoolean("OnGround");
|
||||
// int mode = -1;
|
||||
// if(player.hasKey("playerGameType", 99)) {
|
||||
// mode = player.getInteger("playerGameType");
|
||||
// mode = mode == 0 || mode == 2 ? 0 : (mode == 1 || mode == 3 ? 1 : -1);
|
||||
// }
|
||||
if(player.hasKey("SpawnX", 99) && player.hasKey("SpawnY", 99) && player.hasKey("SpawnZ", 99)) {
|
||||
spawn = new BlockPos(player.getInteger("SpawnX"), player.getInteger("SpawnY"),
|
||||
player.getInteger("SpawnZ"));
|
||||
// force = player.getBoolean("SpawnForced");
|
||||
}
|
||||
player.getKeySet().clear();
|
||||
player.setTag("Pos", pos);
|
||||
player.setTag("Motion", motion);
|
||||
player.setTag("Rotation", rotation);
|
||||
player.setBoolean("OnGround", ground);
|
||||
player.setInteger("Dimension", 1);
|
||||
player.setString("id", EntityRegistry.getEntityString(EntityHuman.class));
|
||||
if(spawn != null) {
|
||||
player.setInteger("SpawnX", spawn.getX());
|
||||
player.setInteger("SpawnY", spawn.getY());
|
||||
player.setInteger("SpawnZ", spawn.getZ());
|
||||
player.setInteger("SpawnDim", 1);
|
||||
// player.setBoolean("SpawnForced", force);
|
||||
}
|
||||
player.setInteger("OriginX", tag.getInteger("SpawnX"));
|
||||
player.setInteger("OriginY", tag.getInteger("SpawnY"));
|
||||
player.setInteger("OriginZ", tag.getInteger("SpawnZ"));
|
||||
player.setInteger("OriginDim", 1);
|
||||
player.setString("CustomName", user.substring(0, 1).toUpperCase() + user.substring(1));
|
||||
NBTTagCompound plr = new NBTTagCompound();
|
||||
plr.setInteger("selected", 0);
|
||||
NBTTagList list = new NBTTagList();
|
||||
list.appendTag(player);
|
||||
plr.setTag("characters", list);
|
||||
// if(mode >= 0)
|
||||
// player.setBoolean("creative", mode == 1);
|
||||
Log.JNI.info("Speichere neue Spielerdaten " + user.toLowerCase() + ".nbt ...");
|
||||
File pdat = new File(new File(dir, "players"), user.toLowerCase() + ".nbt");
|
||||
try {
|
||||
pdat.getParentFile().mkdirs();
|
||||
NBTLoader.writeGZip(plr, pdat);
|
||||
}
|
||||
catch(Exception e) {
|
||||
Log.JNI.error(e, "Fehler beim Schreiben von " + pdat);
|
||||
}
|
||||
}
|
||||
Region.saveWorldInfo(dir, wtime);
|
||||
// if(tag.hasKey("Player", 10)) {
|
||||
// conv.action = "Konvertiere Spielerdaten";
|
||||
// NBTTagCompound player = tag.getCompoundTag("Player");
|
||||
// NBTTagList pos = player.getTagList("Pos", 6);
|
||||
// NBTTagList motion = player.getTagList("Motion", 6);
|
||||
// NBTTagList rotation = player.getTagList("Rotation", 5);
|
||||
// boolean ground = player.getBoolean("OnGround");
|
||||
// BlockPos spawn = null;
|
||||
// // boolean force = player.getBoolean("OnGround");
|
||||
// // int mode = -1;
|
||||
// // if(player.hasKey("playerGameType", 99)) {
|
||||
// // mode = player.getInteger("playerGameType");
|
||||
// // mode = mode == 0 || mode == 2 ? 0 : (mode == 1 || mode == 3 ? 1 : -1);
|
||||
// // }
|
||||
// if(player.hasKey("SpawnX", 99) && player.hasKey("SpawnY", 99) && player.hasKey("SpawnZ", 99)) {
|
||||
// spawn = new BlockPos(player.getInteger("SpawnX"), player.getInteger("SpawnY"),
|
||||
// player.getInteger("SpawnZ"));
|
||||
// // force = player.getBoolean("SpawnForced");
|
||||
// }
|
||||
// player.getKeySet().clear();
|
||||
// player.setTag("Pos", pos);
|
||||
// player.setTag("Motion", motion);
|
||||
// player.setTag("Rotation", rotation);
|
||||
// player.setBoolean("OnGround", ground);
|
||||
// player.setInteger("Dimension", 1);
|
||||
// player.setString("id", EntityRegistry.getEntityString(EntityHuman.class));
|
||||
// if(spawn != null) {
|
||||
// player.setInteger("SpawnX", spawn.getX());
|
||||
// player.setInteger("SpawnY", spawn.getY());
|
||||
// player.setInteger("SpawnZ", spawn.getZ());
|
||||
// player.setInteger("SpawnDim", 1);
|
||||
// // player.setBoolean("SpawnForced", force);
|
||||
// }
|
||||
// player.setInteger("OriginX", tag.getInteger("SpawnX"));
|
||||
// player.setInteger("OriginY", tag.getInteger("SpawnY"));
|
||||
// player.setInteger("OriginZ", tag.getInteger("SpawnZ"));
|
||||
// player.setInteger("OriginDim", 1);
|
||||
// player.setString("CustomName", user.substring(0, 1).toUpperCase() + user.substring(1));
|
||||
// NBTTagCompound plr = new NBTTagCompound();
|
||||
// plr.setInteger("selected", 0);
|
||||
// NBTTagList list = new NBTTagList();
|
||||
// list.appendTag(player);
|
||||
// plr.setTag("characters", list);
|
||||
// // if(mode >= 0)
|
||||
// // player.setBoolean("creative", mode == 1);
|
||||
// Log.JNI.info("Speichere neue Spielerdaten " + user.toLowerCase() + ".nbt ...");
|
||||
// File pdat = new File(new File(dir, "players"), user.toLowerCase() + ".nbt");
|
||||
// try {
|
||||
// pdat.getParentFile().mkdirs();
|
||||
// NBTLoader.writeGZip(plr, pdat);
|
||||
// }
|
||||
// catch(Exception e) {
|
||||
// Log.JNI.error(e, "Fehler beim Schreiben von " + pdat);
|
||||
// }
|
||||
// }
|
||||
Weather weather = tag.getBoolean("thundering") ? Weather.THUNDER : (tag.getBoolean("raining") ? Weather.RAIN : Weather.CLEAR);
|
||||
if(weather != Weather.CLEAR) {
|
||||
conv.action = "Konvertiere Dimensionsdaten";
|
||||
|
@ -1411,7 +1410,7 @@ public final class Converter {
|
|||
});
|
||||
}
|
||||
}, "Converter Thread").start();
|
||||
return new FolderInfo(wtime, user, System.currentTimeMillis(), null, Config.VERSION);
|
||||
return new FolderInfo(wtime, System.currentTimeMillis(), null, Config.VERSION);
|
||||
}
|
||||
|
||||
// public static NBTTagCompound getLegacyWorldInfo(File worldDir) {
|
||||
|
|
|
@ -36,14 +36,12 @@ import game.world.Converter.SaveVersion;
|
|||
public class Region {
|
||||
public static class FolderInfo {
|
||||
public final long time;
|
||||
public final String user;
|
||||
public final long lastPlayed;
|
||||
public final SaveVersion legacy;
|
||||
public final String version;
|
||||
|
||||
public FolderInfo(long time, String user, long lastPlayed, SaveVersion legacy, String version) {
|
||||
public FolderInfo(long time, long lastPlayed, SaveVersion legacy, String version) {
|
||||
this.time = time;
|
||||
this.user = user;
|
||||
this.lastPlayed = lastPlayed;
|
||||
this.legacy = legacy;
|
||||
this.version = version;
|
||||
|
@ -666,7 +664,7 @@ public class Region {
|
|||
killed = true;
|
||||
}
|
||||
|
||||
public static void saveWorldInfo(File worldDir, long time, String owner) {
|
||||
public static void saveWorldInfo(File worldDir, long time) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setLong("Time", time);
|
||||
data.setLong("LastAccess", System.currentTimeMillis());
|
||||
|
@ -692,8 +690,6 @@ public class Region {
|
|||
}
|
||||
data.setTag("Config", cfg);
|
||||
data.setTag("Universe", UniverseRegistry.saveNbt());
|
||||
if(owner != null)
|
||||
data.setString("Owner", owner);
|
||||
if(worldDir != null)
|
||||
worldDir.mkdirs();
|
||||
File nfile = new File(worldDir, "level.nbt.tmp");
|
||||
|
@ -731,12 +727,10 @@ public class Region {
|
|||
UniverseRegistry.loadNbt(tag.getCompoundTag("Universe"));
|
||||
// tag.getInteger("Version");
|
||||
long lastPlayed = tag.getLong("LastAccess");
|
||||
String user = tag.hasKey("Owner", 8) ? tag.getString("Owner") : null;
|
||||
user = user != null && user.isEmpty() ? null : user;
|
||||
String version = tag.hasKey("Version", 8) ? tag.getString("Version") : null;
|
||||
version = version != null && version.isEmpty() ? null : version;
|
||||
long time = tag.hasKey("Time", 4) ? tag.getLong("Time") : World.START_TIME;
|
||||
return new FolderInfo(time, user, lastPlayed, null, version);
|
||||
return new FolderInfo(time, lastPlayed, null, version);
|
||||
}
|
||||
catch(Exception e) {
|
||||
Log.JNI.error(e, "Fehler beim Lesen von " + file);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue