Search in sources :

Example 1 with PacketText

use of io.xol.chunkstories.api.net.packets.PacketText in project chunkstories by Hugobros3.

the class TCPServerConnection method handleDatagram.

@Override
public void handleDatagram(LogicalPacketDatagram datagram) throws IOException, PacketProcessingException, IllegalPacketException {
    // (PacketDefinitionImpl) getPacketsContext().getContentTranslator().getPacketForId(datagram.packetTypeId);
    PacketDefinitionImplementation definition = (PacketDefinitionImplementation) datagram.packetDefinition;
    if (definition.getGenre() == PacketGenre.GENERAL_PURPOSE) {
        Packet packet = definition.createNew(true, null);
        packet.process(getRemoteServer(), datagram.getData(), getPacketsContext());
        datagram.dispose();
    } else if (definition.getGenre() == PacketGenre.SYSTEM) {
        Packet packet = definition.createNew(true, null);
        packet.process(getRemoteServer(), datagram.getData(), getPacketsContext());
        if (packet instanceof PacketText) {
            handleSystemRequest(((PacketText) packet).text);
        }
        datagram.dispose();
    } else if (definition.getGenre() == PacketGenre.WORLD) {
        WorldClientRemote world = getPacketsContext().getWorld();
        world.queueDatagram(datagram);
    } else if (definition.getGenre() == PacketGenre.WORLD_STREAMING) {
        WorldClientRemote world = getPacketsContext().getWorld();
        PacketWorldStreaming packet = (PacketWorldStreaming) definition.createNew(true, world);
        packet.process(getRemoteServer(), datagram.getData(), getPacketsContext());
        world.ioHandler().handlePacketWorldStreaming(packet);
        datagram.dispose();
    } else {
        throw new RuntimeException("whut");
    }
}
Also used : Packet(io.xol.chunkstories.api.net.Packet) PacketText(io.xol.chunkstories.api.net.packets.PacketText) PacketWorldStreaming(io.xol.chunkstories.api.net.PacketWorldStreaming) PacketDefinitionImplementation(io.xol.chunkstories.net.PacketDefinitionImplementation) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote)

Example 2 with PacketText

use of io.xol.chunkstories.api.net.packets.PacketText in project chunkstories by Hugobros3.

the class PacketsContextCommon method findIdForPacket.

private short findIdForPacket(Packet packet) throws UnknowPacketException {
    WorldNetworked world = this.getWorld();
    if (world == null) {
        if ((packet instanceof PacketText))
            return 0x00;
        else if ((packet instanceof PacketSendFile))
            return 0x01;
        else
            // Throw an error if sending a packet while not within a world
            throw new UnknowPacketException(0xFF);
    } else {
        PacketDefinition def = world.getContent().packets().getPacketFromInstance(packet);
        if (def == null)
            logger.error("Could not find the definition of packet " + packet);
        short id = (short) world.getContentTranslator().getIdForPacket(def);
        if (id == -1) {
            logger.error("Could not find the id of packet definition " + def.getName());
            // ((AbstractContentTranslator)world.getContentTranslator()).test();
            throw new UnknowPacketException(packet);
        }
        return id;
    }
}
Also used : PacketText(io.xol.chunkstories.api.net.packets.PacketText) PacketSendFile(io.xol.chunkstories.net.packets.PacketSendFile) WorldNetworked(io.xol.chunkstories.api.world.WorldNetworked) PacketDefinition(io.xol.chunkstories.api.net.PacketDefinition) UnknowPacketException(io.xol.chunkstories.api.exceptions.net.UnknowPacketException)

Example 3 with PacketText

use of io.xol.chunkstories.api.net.packets.PacketText in project chunkstories by Hugobros3.

the class Connection method sendTextMessage.

public void sendTextMessage(String string) {
    PacketText packet = new PacketText();
    packet.text = string;
    pushPacket(packet);
}
Also used : PacketText(io.xol.chunkstories.api.net.packets.PacketText)

Example 4 with PacketText

use of io.xol.chunkstories.api.net.packets.PacketText in project chunkstories by Hugobros3.

the class SocketedClientConnection method handleDatagram.

@Override
public void handleDatagram(LogicalPacketDatagram datagram) throws IOException, PacketProcessingException, IllegalPacketException {
    // getPacketsContext().getContentTranslator().getPacketForId(datagram.packetTypeId);
    PacketDefinitionImplementation definition = (PacketDefinitionImplementation) datagram.packetDefinition;
    if (definition.getGenre() == PacketGenre.GENERAL_PURPOSE) {
        Packet packet = definition.createNew(true, null);
        packet.process(packetsProcessor.getInterlocutor(), datagram.getData(), getPacketsContext());
        datagram.dispose();
    } else if (definition.getGenre() == PacketGenre.SYSTEM) {
        Packet packet = definition.createNew(true, null);
        packet.process(packetsProcessor.getInterlocutor(), datagram.getData(), getPacketsContext());
        if (packet instanceof PacketText) {
            handleSystemRequest(((PacketText) packet).text);
        }
        datagram.dispose();
    } else if (definition.getGenre() == PacketGenre.WORLD) {
        // Queue packets for a specific world
        if (player != null) {
            WorldServer world = player.getWorld();
            if (world != null) {
                world.queueDatagram(datagram, player);
            }
        }
    } else if (definition.getGenre() == PacketGenre.WORLD_STREAMING) {
        // Server doesn't expect world streaming updates from the client
        // it does, however, listen to world_user_requests packets to keep
        // track of the client's world data
        WorldServer world = getPacketsContext().getWorld();
        PacketWorldStreaming packet = (PacketWorldStreaming) definition.createNew(false, world);
        packet.process(packetsProcessor.getInterlocutor(), datagram.getData(), getPacketsContext());
        datagram.dispose();
    } else {
        throw new RuntimeException("whut");
    }
}
Also used : Packet(io.xol.chunkstories.api.net.Packet) PacketText(io.xol.chunkstories.api.net.packets.PacketText) PacketWorldStreaming(io.xol.chunkstories.api.net.PacketWorldStreaming) PacketDefinitionImplementation(io.xol.chunkstories.net.PacketDefinitionImplementation) WorldServer(io.xol.chunkstories.world.WorldServer)

Aggregations

PacketText (io.xol.chunkstories.api.net.packets.PacketText)4 Packet (io.xol.chunkstories.api.net.Packet)2 PacketWorldStreaming (io.xol.chunkstories.api.net.PacketWorldStreaming)2 PacketDefinitionImplementation (io.xol.chunkstories.net.PacketDefinitionImplementation)2 UnknowPacketException (io.xol.chunkstories.api.exceptions.net.UnknowPacketException)1 PacketDefinition (io.xol.chunkstories.api.net.PacketDefinition)1 WorldNetworked (io.xol.chunkstories.api.world.WorldNetworked)1 PacketSendFile (io.xol.chunkstories.net.packets.PacketSendFile)1 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)1 WorldServer (io.xol.chunkstories.world.WorldServer)1