split server
This commit is contained in:
parent
b0dc368ef7
commit
3ab017888b
25 changed files with 458 additions and 482 deletions
|
@ -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
|
||||
|
@ -292,21 +290,7 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet>
|
|||
this.terminationReason = message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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!");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue