mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-19 19:59:37 +00:00
Added reconnect to the NexusAuth message.
Added proper handling of the return packets from Nexus.
This commit is contained in:
1 parent
51bb8700da
commit
3ad2c5be55
5 files changed
+27
-7
No files matched your search
@@ -12,15 +12,18 @@ public class NexusAuth implements ISerializable {
|
||||
|
||||
SerialString uuid;
|
||||
SerialString passphrase;
|
||||
boolean reconnect;
|
||||
|
||||
public NexusAuth(String uuid, String passphrase){
|
||||
public NexusAuth(String uuid, String passphrase, boolean reconnect){
|
||||
this.uuid = new SerialString(uuid);
|
||||
this.passphrase = new SerialString(passphrase);
|
||||
this.reconnect = reconnect;
|
||||
}
|
||||
|
||||
public NexusAuth(SerialString uuid, SerialString passphrase){
|
||||
public NexusAuth(SerialString uuid, SerialString passphrase, boolean reconnect){
|
||||
this.uuid = uuid;
|
||||
this.passphrase = passphrase;
|
||||
this.reconnect = reconnect;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,12 +31,14 @@ public class NexusAuth implements ISerializable {
|
||||
public void writeToStream(ByteArrayDataOutput stream){
|
||||
this.uuid.writeToStream(stream);
|
||||
this.passphrase.writeToStream(stream);
|
||||
stream.writeBoolean(reconnect);
|
||||
}
|
||||
|
||||
public static NexusAuth readFromStream(ByteArrayDataInput stream){
|
||||
return new NexusAuth(
|
||||
SerialString.readFromStream(stream),
|
||||
SerialString.readFromStream(stream)
|
||||
SerialString.readFromStream(stream),
|
||||
stream.readBoolean()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class RConHandler {
|
||||
}
|
||||
|
||||
public static void sendToContext(PacketBase packet, ChannelHandlerContext ctx){
|
||||
modOpis.log.info(String.format("%s", packet.msg));
|
||||
//modOpis.log.info(String.format("%s", packet.msg));
|
||||
|
||||
ByteArrayDataOutput output = ByteStreams.newDataOutput();
|
||||
packet.encode(output);
|
||||
|
||||
@@ -54,6 +54,7 @@ public class NexusClient implements Runnable {
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) throws Exception {
|
||||
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc(), NexusClient.instance.host, NexusClient.instance.port));
|
||||
ch.pipeline().addLast(new ReadTimeoutHandler(10));
|
||||
ch.pipeline().addLast(new NexusHandshakeDecoder());
|
||||
ch.pipeline().addLast(new NexusHandshakeHandler());
|
||||
//ch.pipeline().addLast(new JdkZlibDecoder());
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.nettyopis.buffer.ByteBuf;
|
||||
import io.nettyopis.channel.ChannelHandlerContext;
|
||||
import io.nettyopis.channel.ChannelInboundHandlerAdapter;
|
||||
import io.nettyopis.handler.codec.ByteToMessageDecoder;
|
||||
import io.nettyopis.util.ReferenceCountUtil;
|
||||
|
||||
public class NexusInboundHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@@ -39,19 +40,31 @@ public class NexusInboundHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
PlayerTracker.INSTANCE.playersSwing.add(fakePlayer);
|
||||
PlayerTracker.INSTANCE.playerTab.put(fakePlayer, SelectedTab.ALL);
|
||||
RConHandler.sendToPlayerNexus(new NetDataValue(Message.NEXUS_UUID, new NexusAuth(NexusClient.instance.uuid, NexusClient.instance.pass)), fakePlayer);
|
||||
RConHandler.sendToPlayerNexus(new NetDataValue(Message.NEXUS_UUID, new NexusAuth(NexusClient.instance.uuid, NexusClient.instance.pass, false)), fakePlayer);
|
||||
RConHandler.sendToPlayerNexus(new NetDataValue(Message.STATUS_CURRENT_TIME, new SerialLong(System.currentTimeMillis())), fakePlayer);
|
||||
StringCache.INSTANCE.syncCache(fakePlayer);
|
||||
|
||||
modOpis.log.info(String.format("FakePlayer %s with uuid %s created.", ctx.name(), fakeUUID));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||
try {
|
||||
FakePlayer fakePlayer = RConHandler.fakePlayersNexus.inverse().get(ctx);
|
||||
PacketBase packet = (PacketBase) msg;
|
||||
packet.actionServer(null, fakePlayer);
|
||||
} finally {
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
cause.printStackTrace();
|
||||
FakePlayer fakePlayer = RConHandler.fakePlayersNexus.inverse().get(ctx);
|
||||
RConHandler.fakePlayersNexus.remove(fakePlayer);
|
||||
PlayerTracker.INSTANCE.playersSwing.remove(fakePlayer);
|
||||
modOpis.log.info(String.format("Lost connection from %s", fakePlayer.getDisplayName()));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import io.nettyopis.handler.codec.ByteToMessageDecoder;
|
||||
import java.util.List;
|
||||
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqData;
|
||||
import mcp.mobius.opis.network.rcon.RConHandler;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
Reference in new issue
Block a user