use of net.glowstone.net.protocol.PlayProtocol in project Glowstone by GlowstoneMC.
the class GlowSession method disconnect.
/**
* Disconnects the session with the specified reason.
*
* <p>This causes a KickMessage to be sent. When it has been delivered, the channel is closed.
*
* @param reason The reason for disconnection.
* @param overrideKick Whether to skip the kick event.
*/
public void disconnect(String reason, boolean overrideKick) {
if (player != null && !overrideKick) {
PlayerKickEvent event = EventFactory.getInstance().onPlayerKick(player, reason);
if (event.isCancelled()) {
return;
}
reason = event.getReason();
if (player.isOnline() && event.getLeaveMessage() != null) {
server.broadcastMessage(event.getLeaveMessage());
}
}
// log that the player was kicked
if (player != null) {
GlowServer.logger.info(player.getName() + " kicked: " + reason);
} else {
GlowServer.logger.info("[" + address + "] kicked: " + reason);
}
// perform the kick, sending a kick message if possible
if (isActive() && (getProtocol() instanceof LoginProtocol || getProtocol() instanceof PlayProtocol)) {
// channel is both currently connected and in a protocol state allowing kicks
ChannelFuture future = sendWithFuture(new KickMessage(reason));
if (future != null) {
future.addListener(ChannelFutureListener.CLOSE);
}
} else {
getChannel().close();
}
}
use of net.glowstone.net.protocol.PlayProtocol in project Glowstone by GlowstoneMC.
the class GlowSession method idle.
/**
* Notify that the session is currently idle.
*/
public void idle() {
if (pingMessageId == 0 && getProtocol() instanceof PlayProtocol) {
pingMessageId = System.currentTimeMillis();
send(new PingMessage(pingMessageId));
} else {
disconnect("Timed out");
}
}
use of net.glowstone.net.protocol.PlayProtocol in project Dragonet-Legacy by DragonetMC.
the class BaseProtocolTest method testProtocol.
@Test
public void testProtocol() throws Exception {
Map<Class<? extends Message>, Codec.CodecRegistration> inboundMap = getField(inboundCodecs, CodecLookupService.class, "messages");
Map<Class<? extends Message>, Codec.CodecRegistration> outboundMap = getField(outboundCodecs, CodecLookupService.class, "messages");
Set<Class<? extends Message>> inboundSet = new HashSet<>(inboundMap.keySet());
Set<Class<? extends Message>> outboundSet = new HashSet<>(outboundMap.keySet());
for (Message message : testMessages) {
boolean any = false;
Class<? extends Message> clazz = message.getClass();
// test inbound
Codec.CodecRegistration registration = inboundCodecs.find(clazz);
if (registration != null) {
inboundSet.remove(clazz);
checkCodec(registration, message);
any = true;
}
// test outbound
registration = outboundCodecs.find(clazz);
if (registration != null) {
outboundSet.remove(clazz);
checkCodec(registration, message);
any = true;
}
assertTrue("Codec missing for: " + message, any);
}
// special case: HeldItemMessage is excluded from tests
inboundSet.remove(HeldItemMessage.class);
outboundSet.remove(HeldItemMessage.class);
assertTrue("Did not test inbound classes: " + inboundSet, inboundSet.isEmpty());
// todo: enable the outbound check for PlayProtocol
if (!(protocol instanceof PlayProtocol)) {
assertTrue("Did not test outbound classes: " + outboundSet, outboundSet.isEmpty());
}
}
use of net.glowstone.net.protocol.PlayProtocol in project Glowstone by GlowstoneMC.
the class BaseProtocolTest method testProtocol.
@Test
public void testProtocol() throws Exception {
Map<Class<? extends Message>, Codec.CodecRegistration> inboundMap = getField(inboundCodecs, CodecLookupService.class, "messages");
Map<Class<? extends Message>, Codec.CodecRegistration> outboundMap = getField(outboundCodecs, CodecLookupService.class, "messages");
Set<Class<? extends Message>> inboundSet = new HashSet<>(inboundMap.keySet());
Set<Class<? extends Message>> outboundSet = new HashSet<>(outboundMap.keySet());
for (Message message : testMessages) {
boolean any = false;
Class<? extends Message> clazz = message.getClass();
// test inbound
Codec.CodecRegistration registration = inboundCodecs.find(clazz);
if (registration != null) {
inboundSet.remove(clazz);
checkCodec(registration, message);
any = true;
}
// test outbound
registration = outboundCodecs.find(clazz);
if (registration != null) {
outboundSet.remove(clazz);
checkCodec(registration, message);
any = true;
}
assertThat("Codec missing for: " + message, any, is(true));
}
// special case: HeldItemMessage is excluded from tests
inboundSet.remove(HeldItemMessage.class);
outboundSet.remove(HeldItemMessage.class);
assertThat("Did not test inbound classes: " + inboundSet, inboundSet.isEmpty(), is(true));
// todo: enable the outbound check for PlayProtocol
if (!(protocol instanceof PlayProtocol)) {
assertThat("Did not test outbound classes: " + outboundSet, outboundSet.isEmpty(), is(true));
}
}
Aggregations