Search in sources :

Example 1 with ServerPlayer

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());
    }
}
Also used : ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer)

Example 2 with ServerPlayer

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);
}
Also used : Player(io.xol.chunkstories.api.player.Player) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer) PlayerLoginEvent(io.xol.chunkstories.api.events.player.PlayerLoginEvent)

Example 3 with ServerPlayer

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);
    }
}
Also used : ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer)

Example 4 with ServerPlayer

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();
    }
}
Also used : PacketProcessingException(io.xol.chunkstories.api.exceptions.PacketProcessingException) Packet(io.xol.chunkstories.api.net.Packet) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer) PacketDefinitionImplementation(io.xol.chunkstories.net.PacketDefinitionImplementation) IOException(java.io.IOException) LogicalPacketDatagram(io.xol.chunkstories.net.LogicalPacketDatagram) PacketWorld(io.xol.chunkstories.api.net.PacketWorld) IOException(java.io.IOException) PacketProcessingException(io.xol.chunkstories.api.exceptions.PacketProcessingException)

Example 5 with ServerPlayer

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();
}
Also used : PacketTime(io.xol.chunkstories.api.net.packets.PacketTime) Player(io.xol.chunkstories.api.player.Player) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer)

Aggregations

ServerPlayer (io.xol.chunkstories.server.player.ServerPlayer)6 Player (io.xol.chunkstories.api.player.Player)2 PlayerLoginEvent (io.xol.chunkstories.api.events.player.PlayerLoginEvent)1 PacketProcessingException (io.xol.chunkstories.api.exceptions.PacketProcessingException)1 Packet (io.xol.chunkstories.api.net.Packet)1 PacketWorld (io.xol.chunkstories.api.net.PacketWorld)1 PacketTime (io.xol.chunkstories.api.net.packets.PacketTime)1 LogicalPacketDatagram (io.xol.chunkstories.net.LogicalPacketDatagram)1 PacketDefinitionImplementation (io.xol.chunkstories.net.PacketDefinitionImplementation)1 IOException (java.io.IOException)1