Search in sources :

Example 11 with NetworkSession

use of org.lanternpowered.server.network.NetworkSession in project LanternServer by LanternPowered.

the class HandlerPlayInRequestStatistics method handle.

@Override
public void handle(NetworkContext context, MessagePlayInRequestStatistics message) {
    final NetworkSession session = context.getSession();
    session.send(session.getPlayer().getStatisticMap().createStatisticsMessage());
}
Also used : NetworkSession(org.lanternpowered.server.network.NetworkSession)

Example 12 with NetworkSession

use of org.lanternpowered.server.network.NetworkSession in project LanternServer by LanternPowered.

the class LanternChannelRegistrar method sendPayload.

void sendPayload(Player player, String channel, Consumer<ByteBuffer> payload) {
    checkNotNull(player, "player");
    checkNotNull(payload, "payload");
    final NetworkSession session = ((LanternPlayer) player).getConnection();
    if (session.getRegisteredChannels().contains(channel)) {
        final ByteBuffer buf = ByteBufferAllocator.unpooled().buffer();
        payload.accept(buf);
        session.send(new MessagePlayInOutChannelPayload(channel, buf));
    }
}
Also used : NetworkSession(org.lanternpowered.server.network.NetworkSession) MessagePlayInOutChannelPayload(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 13 with NetworkSession

use of org.lanternpowered.server.network.NetworkSession in project LanternServer by LanternPowered.

the class LanternChannelRegistrar method unbindChannel.

@Override
public void unbindChannel(ChannelBinding channel) {
    final LanternChannelBinding binding = (LanternChannelBinding) checkNotNull(channel, "channel");
    if (binding.bound) {
        binding.bound = false;
        this.bindings.remove(channel.getName());
        final MessagePlayInOutUnregisterChannels message = new MessagePlayInOutUnregisterChannels(Collections.singleton(channel.getName()));
        for (Player player : this.server.getOnlinePlayers()) {
            ((NetworkSession) player.getConnection()).send(message);
        }
    }
}
Also used : MessagePlayInOutUnregisterChannels(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutUnregisterChannels) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Player(org.spongepowered.api.entity.living.player.Player) NetworkSession(org.lanternpowered.server.network.NetworkSession)

Example 14 with NetworkSession

use of org.lanternpowered.server.network.NetworkSession in project LanternServer by LanternPowered.

the class HandlerForgeHandshakeInModList method handle.

@Override
public void handle(NetworkContext context, MessageForgeHandshakeInOutModList message) {
    final NetworkSession session = context.getSession();
    final Attribute<ForgeServerHandshakePhase> phase = context.getChannel().attr(ForgeHandshakePhase.PHASE);
    if (phase.get() != ForgeServerHandshakePhase.HELLO) {
        session.disconnect(t("Retrieved unexpected forge handshake modList message."));
        return;
    }
    // We don't need to validate the mods for now, maybe in the future, just poke back
    session.getInstalledMods().addAll(message.getEntries().keySet());
    // Just use a empty map for now
    session.send(new MessageForgeHandshakeInOutModList(new HashMap<>()));
    phase.set(ForgeServerHandshakePhase.WAITING_ACK);
    Lantern.getLogger().info("{}: Forge handshake -> Received modList message.", session.getGameProfile().getName().get());
}
Also used : ForgeServerHandshakePhase(org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase) NetworkSession(org.lanternpowered.server.network.NetworkSession) HashMap(java.util.HashMap) MessageForgeHandshakeInOutModList(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutModList)

Aggregations

NetworkSession (org.lanternpowered.server.network.NetworkSession)14 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)4 ForgeServerHandshakePhase (org.lanternpowered.server.network.forge.handshake.ForgeServerHandshakePhase)4 UUID (java.util.UUID)3 LanternGameProfile (org.lanternpowered.server.profile.LanternGameProfile)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 InetSocketAddress (java.net.InetSocketAddress)2 HashMap (java.util.HashMap)2 MessagePlayInOutRegisterChannels (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels)2 Player (org.spongepowered.api.entity.living.player.Player)2 Text (org.spongepowered.api.text.Text)2 Gson (com.google.gson.Gson)1 CodecException (io.netty.handler.codec.CodecException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigInteger (java.math.BigInteger)1 InetAddress (java.net.InetAddress)1 SocketException (java.net.SocketException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 MessageDigest (java.security.MessageDigest)1