use of com.github.dirtpowered.dirtmv.network.client.ClientSession in project DirtMultiversion by DirtPowered.
the class ServerSession method channelInactive.
@Override
public void channelInactive(ChannelHandlerContext ctx) {
disconnect();
// notify other sessions
MinecraftVersion server = main.getConfiguration().getServerVersion();
MinecraftVersion client = userData.getClientVersion();
// call #onDisconnect only in user protocols
main.getTranslatorRegistry().getAllProtocolsBetween(server, client).forEach(t -> t.onDisconnect(this));
ClientSession clientSession = getClientSession();
if (clientSession != null) {
clientSession.disconnectRemote();
}
}
use of com.github.dirtpowered.dirtmv.network.client.ClientSession in project DirtMultiversion by DirtPowered.
the class ServerSession method sendPacket.
/**
* Translates and sends packet to server
*
* @param packet {@link PacketData} Packet
* @param direction {@link PacketDirection} sending direction (client/server)
* @param from Version to start from
*/
public void sendPacket(PacketData packet, PacketDirection direction, MinecraftVersion from) {
MinecraftVersion version = main.getConfiguration().getServerVersion();
if (from != null && from != version) {
version = from;
}
List<ServerProtocol> protocols = main.getTranslatorRegistry().findProtocol(userData, version);
boolean flag = direction == PacketDirection.TO_CLIENT;
if (!flag) {
Collections.reverse(protocols);
}
PacketData target = packet;
for (ServerProtocol protocol : protocols) {
boolean isNetty = userData.getClientVersion().isNettyProtocol();
ProtocolState state = isNetty ? userData.getProtocolState() : ProtocolState.PRE_NETTY;
if (target == null) {
return;
}
// packet queue workaround
state = packet.getNettyState() != null ? packet.getNettyState() : state;
if (!protocol.getFrom().isNettyProtocol()) {
state = ProtocolState.PRE_NETTY;
}
PacketTranslator translator = protocol.getTranslatorFor(target.getOpCode(), state, direction);
if (translator != null) {
if (from == null || from != protocol.getFrom()) {
try {
target = translator.translate(this, target);
} catch (IOException e) {
disconnect(e.getMessage());
return;
}
if (target.getOpCode() == -1) {
return;
}
}
}
}
if (flag) {
sendPacket(target);
} else {
ClientSession clientSession = getClientSession();
if (target.getOpCode() == 2 && /* handshake */
!hasServerPingProtocol()) {
connectToServer();
}
if (clientSession != null && clientSession.getChannel().isActive()) {
clientSession.sendPacket(target);
return;
}
// queued packets are always login packets
target.setNettyState(ProtocolState.LOGIN);
initialPacketQueue.add(target);
}
}
Aggregations