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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue