AmountHolder is now using a CachedString

Added PlayerLogging datatype (just a player name + online status).
Simplification of the TickHandler. Added checks for 0 players. Sending TEs & Ent count on a 5s timer
Sending log in/off packet on player logging/off events.
New message for PlayerOnline thingy
Added a new separate Netty version as dep in gradle. The package is called nettyopis. Let me use the 4.0.23 nifty things.
This commit is contained in:
ProfMobius committed 2014-10-21 18:16:55 +02:00
1 parent cab5ecef8b
commit be53815b57
21 files changed
+155 -105

No files matched your search

@@ -40,6 +40,7 @@ import mcp.mobius.opis.data.holders.newtypes.DataTiming;
import mcp.mobius.opis.data.holders.newtypes.DataTimingMillisecond;
import mcp.mobius.opis.data.holders.newtypes.NexusAuth;
import mcp.mobius.opis.data.holders.newtypes.NexusData;
import mcp.mobius.opis.data.holders.newtypes.PlayerLogging;
import mcp.mobius.opis.data.holders.stats.StatAbstract;
import mcp.mobius.opis.data.holders.stats.StatsChunk;
@@ -84,7 +85,8 @@ public enum DataType {
STATABSTRACT (StatAbstract.class),
STATSCHUNK (StatsChunk.class),
NEXUSDATA (NexusData.class),
NEXUSAUTH (NexusAuth.class);
NEXUSAUTH (NexusAuth.class),
PLAYERLOGGING (PlayerLogging.class);
private Class clazz;
private static HashBiMap<DataType, Class> bimap = HashBiMap.create(50);
@@ -8,28 +8,31 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import mcp.mobius.opis.data.holders.ISerializable;
import mcp.mobius.opis.data.holders.newtypes.CachedString;
import mcp.mobius.opis.network.PacketManager;
public class AmountHolder implements ISerializable {
public String key = null;
public CachedString key = null;
public Integer value = 0;
public AmountHolder(String key, Integer value){
this.key = key;
this.key = new CachedString(key);
this.value = value;
}
public AmountHolder(CachedString key, Integer value){
this.key = key;
this.value = value;
}
@Override
public void writeToStream(ByteArrayDataOutput stream){
stream.writeUTF(this.key);
this.key.writeToStream(stream);
stream.writeInt(this.value);
}
public static AmountHolder readFromStream(ByteArrayDataInput istream){
String key = istream.readUTF();
Integer value = istream.readInt();
return new AmountHolder(key, value);
return new AmountHolder(CachedString.readFromStream(istream), istream.readInt());
}
}
@@ -8,6 +8,7 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import mcp.mobius.opis.data.holders.ISerializable;
import mcp.mobius.opis.data.holders.newtypes.CachedString;
public class SerialString implements ISerializable {
@@ -0,0 +1,37 @@
package mcp.mobius.opis.data.holders.newtypes;
import mcp.mobius.opis.data.holders.ISerializable;
import mcp.mobius.opis.data.holders.basetypes.SerialString;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
public class PlayerLogging implements ISerializable {
CachedString name;
boolean status;
public PlayerLogging(String name, boolean status){
this.name = new CachedString(name);
this.status = status;
}
public PlayerLogging(CachedString name, boolean status){
this.name = name;
this.status = status;
}
@Override
public void writeToStream(ByteArrayDataOutput stream){
this.name.writeToStream(stream);
stream.writeBoolean(this.status);
}
public static PlayerLogging readFromStream(ByteArrayDataInput stream){
return new PlayerLogging(
CachedString.readFromStream(stream),
stream.readBoolean()
);
}
}
@@ -6,6 +6,7 @@ import java.util.HashMap;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.DimensionManager;
import mcp.mobius.opis.modOpis;
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
import mcp.mobius.opis.data.holders.basetypes.SerialLong;
import mcp.mobius.opis.data.holders.newtypes.DataDimension;
@@ -64,25 +65,22 @@ public enum OpisServerTickHandler{
StringCache.INSTANCE.syncNewCache();
// One second timer
if (timer1000.isDone()){
if (timer1000.isDone() && PlayerTracker.INSTANCE.playersSwing.size() > 0){
// Summary panel
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());
SerialInt amountPlayers = new SerialInt(FMLCommonHandler.instance().getMinecraftServerInstance().getCurrentPlayerCount());
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.NEXUS_DATA,
new NexusData(amountUpload, amountDownload, chunkForced, chunkLoaded,
timingTick, amountTileEnts, amountEntities, amountPlayers)
));
new NexusData(
new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).dataAmount),
new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).dataAmount),
new SerialInt(ChunkManager.INSTANCE.getForcedChunkAmount()),
new SerialInt(ChunkManager.INSTANCE.getLoadedChunkAmount()),
new DataTiming(((ProfilerTick)ProfilerSection.TICK.getProfiler()).data.getGeometricMean()),
new SerialInt(TileEntityManager.INSTANCE.getAmountTileEntities()),
new SerialInt(EntityManager.INSTANCE.getAmountEntities()),
new SerialInt(FMLCommonHandler.instance().getMinecraftServerInstance().getCurrentPlayerCount())
)));
// End of summary update
for (EntityPlayerMP player : PlayerTracker.INSTANCE.playersSwing){
if (!cachedAccess.containsKey(player) || cachedAccess.get(player) != PlayerTracker.INSTANCE.getPlayerAccessLevel(player)){
PacketManager.validateAndSend(new NetDataValue(Message.STATUS_ACCESS_LEVEL, new SerialInt(PlayerTracker.INSTANCE.getPlayerAccessLevel(player).ordinal())), player);
@@ -114,12 +112,15 @@ public enum OpisServerTickHandler{
}
// Two second timer
if (timer2000.isDone()){
if (timer2000.isDone() && PlayerTracker.INSTANCE.playersSwing.size() > 0){
PacketManager.sendPacketToAllSwing(new NetDataList(Message.LIST_PLAYERS, EntityManager.INSTANCE.getAllPlayers()));
}
// Five second timer
if (timer5000.isDone()){
if (timer5000.isDone() && PlayerTracker.INSTANCE.playersSwing.size() > 0){
PacketManager.sendPacketToAllSwing(new NetDataList(Message.LIST_AMOUNT_ENTITIES, EntityManager.INSTANCE.getCumulativeEntities(false)));
PacketManager.sendPacketToAllSwing(new NetDataList(Message.LIST_AMOUNT_TILEENTS, TileEntityManager.INSTANCE.getCumulativeAmountTileEntities()));
updatePlayers();
PacketManager.sendPacketToAllSwing(new NetDataList(Message.LIST_PACKETS_OUTBOUND, new ArrayList<DataPacket>( ((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).data.values())));
@@ -9,6 +9,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import mcp.mobius.opis.modOpis;
import mcp.mobius.opis.data.holders.basetypes.SerialLong;
import mcp.mobius.opis.data.holders.newtypes.PlayerLogging;
import mcp.mobius.opis.data.managers.StringCache;
import mcp.mobius.opis.gui.overlay.OverlayStatus;
import mcp.mobius.opis.network.PacketManager;
@@ -104,7 +105,8 @@ public enum PlayerTracker{
this.playerOverlayStatus.remove(event.player);
this.playerDimension.remove(event.player);
//this.playersOpis.remove(player);
this.playersSwing.remove(event.player);
this.playersSwing.remove(event.player);
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.PLAYER_ONLINE_CHANGED, new PlayerLogging(event.player.getGameProfile().getName(), false)));
}
@SubscribeEvent
@@ -118,6 +120,7 @@ public enum PlayerTracker{
}
*/
StringCache.INSTANCE.syncCache((EntityPlayerMP)event.player);
StringCache.INSTANCE.syncCache((EntityPlayerMP)event.player);
PacketManager.sendPacketToAllSwing(new NetDataValue(Message.PLAYER_ONLINE_CHANGED, new PlayerLogging(event.player.getGameProfile().getName(), true)));
}
}
@@ -127,7 +127,7 @@ public class ServerMessageHandler {
else if (maintype == Message.LIST_AMOUNT_TILEENTS){
PacketManager.validateAndSend(new NetDataList(Message.LIST_AMOUNT_TILEENTS, TileEntityManager.INSTANCE.getCumulativeAmountTileEntities()), player);
}
}
else if (maintype == Message.COMMAND_FILTERING_TRUE){
PlayerTracker.INSTANCE.filteredAmount.put(name, true);
@@ -97,8 +97,9 @@ public enum Message {
CLIENT_HIGHLIGHT_BLOCK,
SWING_TAB_CHANGED,
NEXUS_UUID,
NEXUS_DATA;
NEXUS_UUID, // Login data for the nexus system
NEXUS_DATA, // Data blob with everything needed to update the summary screen in realtime
PLAYER_ONLINE_CHANGED; // Sent when the online/offline status of a player changes
private AccessLevel accessLevel = AccessLevel.NONE;
private EnumSet<SelectedTab> tabEnum;
@@ -1,7 +1,7 @@
package mcp.mobius.opis.network.rcon;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import net.minecraftforge.common.util.FakePlayer;
import mcp.mobius.opis.modOpis;
import mcp.mobius.opis.network.PacketBase;
@@ -1,21 +1,21 @@
package mcp.mobius.opis.network.rcon.nexus;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.handler.timeout.WriteTimeoutHandler;
import io.nettyopis.bootstrap.Bootstrap;
import io.nettyopis.bootstrap.ServerBootstrap;
import io.nettyopis.channel.ChannelFuture;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.channel.ChannelInitializer;
import io.nettyopis.channel.ChannelOption;
import io.nettyopis.channel.EventLoopGroup;
import io.nettyopis.channel.nio.NioEventLoopGroup;
import io.nettyopis.channel.socket.SocketChannel;
import io.nettyopis.channel.socket.nio.NioServerSocketChannel;
import io.nettyopis.channel.socket.nio.NioSocketChannel;
import io.nettyopis.handler.ssl.SslContext;
import io.nettyopis.handler.ssl.util.InsecureTrustManagerFactory;
import io.nettyopis.handler.ssl.util.SelfSignedCertificate;
import io.nettyopis.handler.timeout.ReadTimeoutHandler;
import io.nettyopis.handler.timeout.WriteTimeoutHandler;
import java.io.File;
import java.io.FileInputStream;
@@ -2,9 +2,9 @@ package mcp.mobius.opis.network.rcon.nexus;
import java.util.List;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.handler.codec.ByteToMessageDecoder;
public class NexusHandshakeDecoder extends ByteToMessageDecoder {
@@ -1,13 +1,13 @@
package mcp.mobius.opis.network.rcon.nexus;
import mcp.mobius.opis.modOpis;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.ssl.SslHandler;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.channel.Channel;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.channel.ChannelInboundHandlerAdapter;
import io.nettyopis.handler.ssl.SslHandler;
import io.nettyopis.util.concurrent.Future;
import io.nettyopis.util.concurrent.GenericFutureListener;
import io.nettyopis.channel.Channel;
public class NexusHandshakeHandler extends ChannelInboundHandlerAdapter {
@@ -23,10 +23,10 @@ import mcp.mobius.opis.network.packets.server.NetDataValue;
import mcp.mobius.opis.network.rcon.RConHandler;
import mcp.mobius.opis.network.rcon.server.RConServer;
import mcp.mobius.opis.swing.SelectedTab;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.channel.ChannelInboundHandlerAdapter;
import io.nettyopis.handler.codec.ByteToMessageDecoder;
public class NexusInboundHandler extends ChannelInboundHandlerAdapter {
@@ -1,8 +1,8 @@
package mcp.mobius.opis.network.rcon.nexus;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.handler.codec.ByteToMessageDecoder;
import java.util.List;
@@ -1,8 +1,8 @@
package mcp.mobius.opis.network.rcon.server;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.handler.codec.ByteToMessageDecoder;
import java.util.List;
@@ -15,12 +15,12 @@ import net.minecraftforge.common.util.FakePlayerFactory;
import com.mojang.authlib.GameProfile;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.compression.JdkZlibDecoder;
import io.netty.handler.codec.compression.JdkZlibEncoder;
import io.netty.util.ReferenceCountUtil;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.channel.ChannelInboundHandlerAdapter;
import io.nettyopis.handler.codec.compression.JdkZlibDecoder;
import io.nettyopis.handler.codec.compression.JdkZlibEncoder;
import io.nettyopis.util.ReferenceCountUtil;
public class RConHandshakeHandler extends ChannelInboundHandlerAdapter {
@@ -18,10 +18,10 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.channel.ChannelInboundHandlerAdapter;
import io.nettyopis.util.ReferenceCountUtil;
class RConInboundHandler extends ChannelInboundHandlerAdapter{
// One object of this type is created by connection
@@ -7,9 +7,9 @@ import com.google.common.io.ByteStreams;
import mcp.mobius.opis.modOpis;
import mcp.mobius.opis.network.PacketBase;
import mcp.mobius.opis.network.rcon.RConHandler;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.handler.codec.ByteToMessageDecoder;
public class RConMsgDecoder extends ByteToMessageDecoder {
@@ -26,28 +26,28 @@ import mcp.mobius.opis.network.packets.server.NetDataList;
import mcp.mobius.opis.network.packets.server.NetDataValue;
import mcp.mobius.opis.network.packets.server.PacketChunks;
import mcp.mobius.opis.network.rcon.RConHandler;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.compression.JdkZlibDecoder;
import io.netty.handler.codec.compression.JdkZlibEncoder;
import io.netty.handler.codec.compression.ZlibCodecFactory;
import io.netty.handler.codec.compression.ZlibDecoder;
import io.netty.handler.codec.compression.ZlibWrapper;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.ReferenceCountUtil;
import io.nettyopis.bootstrap.ServerBootstrap;
import io.nettyopis.buffer.ByteBuf;
import io.nettyopis.channel.Channel;
import io.nettyopis.channel.ChannelFuture;
import io.nettyopis.channel.ChannelHandlerContext;
import io.nettyopis.channel.ChannelInboundHandlerAdapter;
import io.nettyopis.channel.ChannelInitializer;
import io.nettyopis.channel.ChannelOption;
import io.nettyopis.channel.EventLoopGroup;
import io.nettyopis.channel.nio.NioEventLoopGroup;
import io.nettyopis.channel.socket.SocketChannel;
import io.nettyopis.channel.socket.nio.NioServerSocketChannel;
import io.nettyopis.handler.codec.compression.JdkZlibDecoder;
import io.nettyopis.handler.codec.compression.JdkZlibEncoder;
import io.nettyopis.handler.codec.compression.ZlibCodecFactory;
import io.nettyopis.handler.codec.compression.ZlibDecoder;
import io.nettyopis.handler.codec.compression.ZlibWrapper;
import io.nettyopis.handler.ssl.SslContext;
import io.nettyopis.handler.ssl.util.SelfSignedCertificate;
import io.nettyopis.handler.timeout.IdleStateHandler;
import io.nettyopis.handler.timeout.ReadTimeoutHandler;
import io.nettyopis.util.ReferenceCountUtil;
public class RConServer implements Runnable {
@@ -29,7 +29,7 @@ public class ActionAmountEntities implements ActionListener, ItemListener {
AmountHolder data = (AmountHolder)table.getTableData().get(indexData);
if (e.getSource() == panel.getBtnKillAll()){
PacketManager.sendToServer(new PacketReqData(Message.COMMAND_KILLALL, new SerialString(data.key)));
PacketManager.sendToServer(new PacketReqData(Message.COMMAND_KILLALL, new SerialString(data.key.str)));
PacketManager.sendToServer(new PacketReqData(Message.LIST_AMOUNT_ENTITIES));
}