mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-19 19:59:37 +00:00
New datatype for Nexus.
Reworked the whole sending pipeline to separate msgs to Rcon and Nexus. Much cleaner and network/IO friendly solution.
This commit is contained in:
1 parent
663d616f21
commit
3cd002769f
9 files changed
+131
-26
No files matched your search
@@ -38,6 +38,7 @@ import mcp.mobius.opis.data.holders.newtypes.DataTileEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTileEntityRender;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTimingMillisecond;
|
||||
import mcp.mobius.opis.data.holders.newtypes.NexusData;
|
||||
import mcp.mobius.opis.data.holders.stats.StatAbstract;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
|
||||
@@ -80,7 +81,8 @@ public enum DataType {
|
||||
DATATIMING (DataTiming.class),
|
||||
DATATIMINGMILLISECOND (DataTimingMillisecond.class),
|
||||
STATABSTRACT (StatAbstract.class),
|
||||
STATSCHUNK (StatsChunk.class);
|
||||
STATSCHUNK (StatsChunk.class),
|
||||
NEXUSDATA (NexusData.class);
|
||||
|
||||
private Class clazz;
|
||||
private static HashBiMap<DataType, Class> bimap = HashBiMap.create(50);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package mcp.mobius.opis.data.holders.newtypes;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialDouble;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialLong;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
||||
public class NexusData implements ISerializable {
|
||||
|
||||
SerialLong packetOutbound;
|
||||
SerialLong packetInbound;
|
||||
SerialInt chunkForced;
|
||||
SerialInt chunkLoaded;
|
||||
DataTiming timingTick;
|
||||
SerialInt amountTileEnts;
|
||||
SerialInt amountEntities;
|
||||
|
||||
|
||||
|
||||
|
||||
public NexusData(SerialLong Packet_Outbound, SerialLong Packet_Inbound, SerialInt Chunk_Forced, SerialInt Chunk_Loaded,
|
||||
DataTiming Timing_Tick, SerialInt Amount_TileEnts, SerialInt Amount_Entities
|
||||
){
|
||||
this.packetOutbound = Packet_Outbound;
|
||||
this.packetInbound = Packet_Inbound;
|
||||
this.chunkForced = Chunk_Forced;
|
||||
this.chunkLoaded = Chunk_Loaded;
|
||||
this.timingTick = Timing_Tick;
|
||||
this.amountTileEnts = Amount_TileEnts;
|
||||
this.amountEntities = Amount_Entities;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteArrayDataOutput stream){
|
||||
this.packetOutbound.writeToStream(stream);
|
||||
this.packetInbound.writeToStream(stream);
|
||||
this.chunkForced.writeToStream(stream);
|
||||
this.chunkLoaded.writeToStream(stream);
|
||||
this.timingTick.writeToStream(stream);
|
||||
this.amountTileEnts.writeToStream(stream);
|
||||
this.amountEntities.writeToStream(stream);
|
||||
}
|
||||
|
||||
public static NexusData readFromStream(ByteArrayDataInput stream){
|
||||
return new NexusData(
|
||||
SerialLong.readFromStream(stream),
|
||||
SerialLong.readFromStream(stream),
|
||||
SerialInt.readFromStream(stream),
|
||||
SerialInt.readFromStream(stream),
|
||||
DataTiming.readFromStream(stream),
|
||||
SerialInt.readFromStream(stream),
|
||||
SerialInt.readFromStream(stream)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package mcp.mobius.opis.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
@@ -12,6 +13,7 @@ import mcp.mobius.opis.data.holders.newtypes.DataPacket;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataPacket250;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataThread;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataTiming;
|
||||
import mcp.mobius.opis.data.holders.newtypes.NexusData;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.data.managers.ChunkManager;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
@@ -26,6 +28,7 @@ import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataValue;
|
||||
import mcp.mobius.opis.network.rcon.RConHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -62,13 +65,26 @@ public enum OpisServerTickHandler{
|
||||
// One second timer
|
||||
if (timer1000.isDone()){
|
||||
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_AMOUNT_UPLOAD, new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).dataAmount)));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_AMOUNT_DOWNLOAD, new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).dataAmount)));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_CHUNK_FORCED, new SerialInt(ChunkManager.INSTANCE.getForcedChunkAmount())));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_CHUNK_LOADED, new SerialInt(ChunkManager.INSTANCE.getLoadedChunkAmount())));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_TIMING_TICK, new DataTiming(((ProfilerTick)ProfilerSection.TICK.getProfiler()).data.getGeometricMean())));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_AMOUNT_TILEENTS, new SerialInt(TileEntityManager.INSTANCE.getAmountTileEntities())));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_AMOUNT_ENTITIES, new SerialInt(EntityManager.INSTANCE.getAmountEntities())));
|
||||
SerialLong amountUpload = new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).dataAmount);
|
||||
SerialLong amountDownload = new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).dataAmount);
|
||||
SerialInt chunkForced = new SerialInt(ChunkManager.INSTANCE.getForcedChunkAmount());
|
||||
SerialInt chunkLoaded = new SerialInt(ChunkManager.INSTANCE.getLoadedChunkAmount());
|
||||
DataTiming timingTick = new DataTiming(((ProfilerTick)ProfilerSection.TICK.getProfiler()).data.getGeometricMean());
|
||||
SerialInt amountTileEnts = new SerialInt(TileEntityManager.INSTANCE.getAmountTileEntities());
|
||||
SerialInt amountEntities = new SerialInt(EntityManager.INSTANCE.getAmountEntities());
|
||||
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_AMOUNT_UPLOAD, amountUpload));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_AMOUNT_DOWNLOAD, amountDownload));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_CHUNK_FORCED, chunkForced));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_CHUNK_LOADED, chunkLoaded));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_TIMING_TICK, timingTick));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_AMOUNT_TILEENTS, amountTileEnts));
|
||||
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.VALUE_AMOUNT_ENTITIES, amountEntities));
|
||||
|
||||
RConHandler.sendToAllNexus(new NetDataValue(Message.NEXUS_DATA,
|
||||
new NexusData(amountUpload, amountDownload, chunkForced, chunkLoaded,
|
||||
timingTick, amountTileEnts, amountEntities)
|
||||
));
|
||||
|
||||
for (EntityPlayerMP player : PlayerTracker.INSTANCE.playersSwing){
|
||||
if (!cachedAccess.containsKey(player) || cachedAccess.get(player) != PlayerTracker.INSTANCE.getPlayerAccessLevel(player)){
|
||||
|
||||
@@ -41,7 +41,7 @@ public enum PlayerTracker{
|
||||
}
|
||||
|
||||
public AccessLevel getPlayerAccessLevel(EntityPlayerMP player){
|
||||
if (player instanceof FakePlayer && RConHandler.fakePlayers.containsKey(player))
|
||||
if (player instanceof FakePlayer && RConHandler.isPriviledge((FakePlayer)player))
|
||||
return AccessLevel.PRIVILEGED;
|
||||
|
||||
return this.getPlayerAccessLevel(player.getGameProfile().getName());
|
||||
|
||||
@@ -222,7 +222,7 @@ public class PacketManager
|
||||
public static void sendToPlayer(PacketBase packet, EntityPlayer player)
|
||||
{
|
||||
if (player instanceof FakePlayer){
|
||||
RConHandler.sendToPlayer(packet, (FakePlayer)player);
|
||||
RConHandler.sendToPlayerRCon(packet, (FakePlayer)player);
|
||||
}
|
||||
else {
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
@@ -255,8 +255,8 @@ public class PacketManager
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
channels.get(SERVER).writeAndFlush(packet);
|
||||
|
||||
for (FakePlayer fakePlayer : RConHandler.fakePlayers.keySet()){
|
||||
RConHandler.sendToPlayer(packet, fakePlayer);
|
||||
for (FakePlayer fakePlayer : RConHandler.fakePlayersRcon.keySet()){
|
||||
RConHandler.sendToPlayerRCon(packet, fakePlayer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,8 @@ public enum Message {
|
||||
CLIENT_HIGHLIGHT_BLOCK,
|
||||
|
||||
SWING_TAB_CHANGED,
|
||||
NEXUS_UUID;
|
||||
NEXUS_UUID,
|
||||
NEXUS_DATA;
|
||||
|
||||
private AccessLevel accessLevel = AccessLevel.NONE;
|
||||
private EnumSet<SelectedTab> tabEnum;
|
||||
|
||||
@@ -3,6 +3,7 @@ package mcp.mobius.opis.network.rcon;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqChunks;
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqData;
|
||||
@@ -18,7 +19,8 @@ import com.google.common.io.ByteStreams;
|
||||
|
||||
public class RConHandler {
|
||||
public static BiMap<Byte, Class> packetTypes = HashBiMap.create();
|
||||
public static BiMap<FakePlayer, ChannelHandlerContext> fakePlayers = HashBiMap.create();
|
||||
public static BiMap<FakePlayer, ChannelHandlerContext> fakePlayersRcon = HashBiMap.create();
|
||||
public static BiMap<FakePlayer, ChannelHandlerContext> fakePlayersNexus = HashBiMap.create();
|
||||
|
||||
static {
|
||||
packetTypes.put((byte)0, PacketReqChunks.class);
|
||||
@@ -29,11 +31,32 @@ public class RConHandler {
|
||||
packetTypes.put((byte)5, PacketChunks.class);
|
||||
}
|
||||
|
||||
public static void sendToPlayer(PacketBase packet, FakePlayer player)
|
||||
public static void sendToAllNexus(PacketBase packet){
|
||||
for (FakePlayer player : fakePlayersNexus.keySet())
|
||||
sendToPlayerNexus(packet, player);
|
||||
}
|
||||
|
||||
public static void sendToAllRCon(PacketBase packet){
|
||||
for (FakePlayer player : fakePlayersRcon.keySet())
|
||||
sendToPlayerRCon(packet, player);
|
||||
}
|
||||
|
||||
public static void sendToPlayerNexus(PacketBase packet, FakePlayer player)
|
||||
{
|
||||
ByteArrayDataOutput output = ByteStreams.newDataOutput();
|
||||
ChannelHandlerContext ctx = RConHandler.fakePlayers.get(player);
|
||||
ChannelHandlerContext ctx = RConHandler.fakePlayersNexus.get(player);
|
||||
sendToContext(packet, ctx);
|
||||
}
|
||||
|
||||
public static void sendToPlayerRCon(PacketBase packet, FakePlayer player)
|
||||
{
|
||||
ChannelHandlerContext ctx = RConHandler.fakePlayersRcon.get(player);
|
||||
sendToContext(packet, ctx);
|
||||
}
|
||||
|
||||
public static void sendToContext(PacketBase packet, ChannelHandlerContext ctx){
|
||||
modOpis.log.info(String.format("%s", packet.msg));
|
||||
|
||||
ByteArrayDataOutput output = ByteStreams.newDataOutput();
|
||||
packet.encode(output);
|
||||
byte[] data = output.toByteArray();
|
||||
|
||||
@@ -47,4 +70,8 @@ public class RConHandler {
|
||||
//modOpis.log.info(String.format("%s", packet.msg));
|
||||
}
|
||||
|
||||
public static boolean isPriviledge(FakePlayer player){
|
||||
return fakePlayersRcon.containsKey(player) || fakePlayersNexus.containsKey(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,12 +34,12 @@ public class NexusInboundHandler extends ChannelInboundHandlerAdapter {
|
||||
UUID fakeUUID = UUID.randomUUID();
|
||||
|
||||
FakePlayer fakePlayer = FakePlayerFactory.get(DimensionManager.getWorld(0), new GameProfile(fakeUUID, ctx.name()));
|
||||
RConHandler.fakePlayers.put(fakePlayer, ctx);
|
||||
RConHandler.fakePlayersNexus.put(fakePlayer, ctx);
|
||||
|
||||
PlayerTracker.INSTANCE.playersSwing.add(fakePlayer);
|
||||
PlayerTracker.INSTANCE.playerTab.put(fakePlayer, SelectedTab.SUMMARY);
|
||||
PacketManager.validateAndSend(new NetDataValue(Message.NEXUS_UUID, new SerialString(NexusClient.instance.uuid)), fakePlayer);
|
||||
PacketManager.validateAndSend(new NetDataValue(Message.STATUS_CURRENT_TIME, new SerialLong(System.currentTimeMillis())), fakePlayer);
|
||||
//PlayerTracker.INSTANCE.playersSwing.add(fakePlayer);
|
||||
//PlayerTracker.INSTANCE.playerTab.put(fakePlayer, SelectedTab.SUMMARY);
|
||||
RConHandler.sendToPlayerNexus(new NetDataValue(Message.NEXUS_UUID, new SerialString(NexusClient.instance.uuid)), 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));
|
||||
|
||||
@@ -32,7 +32,7 @@ class RConInboundHandler extends ChannelInboundHandlerAdapter{
|
||||
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
||||
UUID fakeUUID = UUID.randomUUID();
|
||||
FakePlayer fakePlayer = FakePlayerFactory.get(DimensionManager.getWorld(0), new GameProfile(fakeUUID, ctx.name()));
|
||||
RConHandler.fakePlayers.put(fakePlayer, ctx);
|
||||
RConHandler.fakePlayersRcon.put(fakePlayer, ctx);
|
||||
|
||||
PlayerTracker.INSTANCE.playersSwing.add(fakePlayer);
|
||||
PacketManager.validateAndSend(new NetDataValue(Message.STATUS_CURRENT_TIME, new SerialLong(System.currentTimeMillis())), fakePlayer);
|
||||
@@ -45,7 +45,7 @@ class RConInboundHandler extends ChannelInboundHandlerAdapter{
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||
try {
|
||||
FakePlayer fakePlayer = RConHandler.fakePlayers.inverse().get(ctx);
|
||||
FakePlayer fakePlayer = RConHandler.fakePlayersRcon.inverse().get(ctx);
|
||||
PacketBase packet = (PacketBase) msg;
|
||||
|
||||
//if (packet instanceof PacketReqData)
|
||||
@@ -60,8 +60,8 @@ class RConInboundHandler extends ChannelInboundHandlerAdapter{
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
cause.printStackTrace();
|
||||
FakePlayer fakePlayer = RConHandler.fakePlayers.inverse().get(ctx);
|
||||
RConHandler.fakePlayers.remove(fakePlayer);
|
||||
FakePlayer fakePlayer = RConHandler.fakePlayersRcon.inverse().get(ctx);
|
||||
RConHandler.fakePlayersRcon.remove(fakePlayer);
|
||||
PlayerTracker.INSTANCE.playersSwing.remove(fakePlayer);
|
||||
modOpis.log.info(String.format("Lost connection from %s", fakePlayer.getDisplayName()));
|
||||
ctx.close();
|
||||
|
||||
Reference in new issue
Block a user