use of io.xol.chunkstories.server.player.ServerPlayer in project chunkstories by Hugobros3.
the class ClientsManager method removeClient.
/**
* Used by ClientConnection during the close() method
*/
void removeClient(ClientConnection clientConnection) {
this.clients.remove(clientConnection);
ServerPlayer player = clientConnection.getPlayer();
if (player != null) {
this.players.remove(player.getName());
this.playersByUUID.remove(player.getUUID());
}
}
use of io.xol.chunkstories.server.player.ServerPlayer in project chunkstories by Hugobros3.
the class PlayerLoginHelper method afterLoginValidation.
/**
* Called after the login token has been validated, or in the case of an
* offline-mode server, after the client requested to login.
*/
private void afterLoginValidation() {
// Disallow users from logging in from two places
Player contender = connection.clientsManager.getPlayerByName(name);
if (contender != null) {
connection.disconnect("You are already logged in. (" + contender + "). ");
return;
}
// Creates a player based on the thrusted login information
ServerPlayer player = new ServerPlayer(connection, name);
// Fire the login event
PlayerLoginEvent playerConnectionEvent = new PlayerLoginEvent(player);
connection.clientsManager.getServer().getPluginManager().fireEvent(playerConnectionEvent);
if (playerConnectionEvent.isCancelled()) {
connection.disconnect(playerConnectionEvent.getRefusedConnectionMessage());
return;
}
// Announce player login
connection.clientsManager.getServer().broadcastMessage(playerConnectionEvent.getConnectionMessage());
// Aknowledge the login
logged_in = true;
connection.sendTextMessage("login/ok");
connection.flush();
connection.setPlayer(player);
}
use of io.xol.chunkstories.server.player.ServerPlayer in project chunkstories by Hugobros3.
the class ServerPacketWorldUser method process.
@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException {
super.process(sender, in, processor);
if (type == Type.REGISTER_SUMMARY || type == Type.UNREGISTER_SUMMARY) {
int sizeInRegions = processor.getWorld().getSizeInChunks() / 8;
int filteredX = x % sizeInRegions;
if (filteredX < 0)
filteredX += sizeInRegions;
int filteredZ = z % sizeInRegions;
if (filteredZ < 0)
filteredZ += sizeInRegions;
if (x != filteredX || z != filteredZ) {
// System.out.println("warning: someone forgot to sanitize their region coordinates!");
x = filteredX;
z = filteredZ;
// System.out.println("og: "+x+": "+z);
// System.out.println(filteredX+":"+filteredZ);
}
}
if (sender instanceof ServerPlayer) {
ServerPlayer player = (ServerPlayer) sender;
player.loadingAgent.handleClientRequest(this);
}
}
use of io.xol.chunkstories.server.player.ServerPlayer in project chunkstories by Hugobros3.
the class WorldServer method processIncommingPackets.
public void processIncommingPackets() {
try {
entitiesLock.writeLock().lock();
Iterator<PendingPlayerDatagram> iterator = packetsQueue.iterator();
while (iterator.hasNext()) {
PendingPlayerDatagram incomming = iterator.next();
iterator.remove();
ServerPlayer player = incomming.player;
LogicalPacketDatagram datagram = incomming.datagram;
try {
// this.getContentTranslator().getPacketForId(datagram.packetTypeId);
PacketDefinitionImplementation definition = (PacketDefinitionImplementation) datagram.packetDefinition;
Packet packet = definition.createNew(false, this);
if (definition.getGenre() != PacketGenre.WORLD || !(packet instanceof PacketWorld)) {
logger().error(definition + " isn't a PacketWorld");
} else {
PacketWorld packetWorld = (PacketWorld) packet;
// packetsProcessor.getSender() is equivalent to player here
packetWorld.process(player, datagram.getData(), player.getPlayerConnection().getPacketsContext());
}
} catch (IOException | PacketProcessingException e) {
logger().warn("Networking Exception while processing datagram: " + e.getMessage());
} catch (Exception e) {
logger().warn("Exception while processing datagram: " + e.getMessage());
}
datagram.dispose();
}
} finally {
entitiesLock.writeLock().unlock();
}
}
use of io.xol.chunkstories.server.player.ServerPlayer in project chunkstories by Hugobros3.
the class WorldServer method tick.
@Override
public void tick() {
processIncommingPackets();
super.tick();
// Update client tracking
Iterator<Player> playersIterator = this.getPlayers();
while (playersIterator.hasNext()) {
Player player = playersIterator.next();
// System.out.println("client: "+client);
if (player.hasSpawned()) {
// Update whatever he sees
((ServerPlayer) player).updateTrackedEntities();
}
// Update time & weather
PacketTime packetTime = new PacketTime(this);
packetTime.time = this.getTime();
packetTime.overcastFactor = this.getWeather();
player.pushPacket(packetTime);
}
virtualServerSoundManager.update();
// TODO this should work per-world
this.getServer().getHandler().flushAll();
}
Aggregations