mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-20 12:19:50 +00:00
Networking framework up (Thx to SecretDoors).
Readded Client sent packets.
This commit is contained in:
1 parent
c56a5e9f65
commit
699b2e9d05
28 files changed
+519
-332
No files matched your search
@@ -10,6 +10,7 @@ import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import mcp.mobius.opis.data.holders.basetypes.SerialInt;
|
||||
import mcp.mobius.opis.network.PacketManager;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.client.Packet_ReqData;
|
||||
import mcp.mobius.opis.swing.SelectedTab;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mcp.mobius.opis.commands.client;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
@@ -23,7 +23,7 @@ public class CommandClientShowRenderTick extends CommandBase {
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player)
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.CLIENT_SHOW_RENDER_TICK), (Player)icommandsender);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataCommand.create(Message.CLIENT_SHOW_RENDER_TICK), (Player)icommandsender);
|
||||
//((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(NetDataCommand.create(Message.CLIENT_SHOW_RENDER_TICK));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mcp.mobius.opis.commands.client;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
@@ -23,7 +23,7 @@ public class CommandClientStart extends CommandBase {
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] astring) {
|
||||
if (icommandsender instanceof Player)
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.CLIENT_START_PROFILING), (Player)icommandsender);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataCommand.create(Message.CLIENT_START_PROFILING), (Player)icommandsender);
|
||||
//((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(NetDataCommand.create(Message.CLIENT_START_PROFILING));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import javax.swing.JLabel;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.ServerMessageHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
@@ -42,8 +42,8 @@ public class CommandOpis extends CommandBase {
|
||||
PlayerTracker.instance().playersSwing.add((Player)icommandsender);
|
||||
//((EntityPlayerMP)icommandsender).playerNetServerHandler.sendPacketToPlayer(NetDataCommand.create(Message.CLIENT_SHOW_SWING));
|
||||
if (icommandsender instanceof Player)
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.CLIENT_SHOW_SWING), (Player)icommandsender);
|
||||
OpisPacketHandler.sendFullUpdate((Player)icommandsender);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataCommand.create(Message.CLIENT_SHOW_SWING), (Player)icommandsender);
|
||||
OpisPacketHandler_OLD.sendFullUpdate((Player)icommandsender);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,7 +8,7 @@ import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.basetypes.AmountHolder;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
||||
@@ -7,7 +7,7 @@ import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.stats.StatsChunk;
|
||||
import mcp.mobius.opis.data.managers.ChunkManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
||||
@@ -9,7 +9,7 @@ import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataHandler;
|
||||
import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
||||
@@ -10,7 +10,7 @@ import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
import net.minecraft.command.CommandBase;
|
||||
@@ -48,7 +48,7 @@ public class CommandReset extends CommandBase implements IOpisCommand {
|
||||
|
||||
//PacketDispatcher.sendPacketToAllPlayers(NetDataCommand.create(Message.CLIENT_CLEAR_SELECTION));
|
||||
if (icommandsender instanceof Player)
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.CLIENT_CLEAR_SELECTION), (Player)icommandsender);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataCommand.create(Message.CLIENT_CLEAR_SELECTION), (Player)icommandsender);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ import mcp.mobius.opis.data.managers.TickHandlerManager;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataValue;
|
||||
import net.minecraft.command.CommandBase;
|
||||
@@ -54,7 +54,7 @@ public class CommandStart extends CommandBase implements IOpisCommand {
|
||||
modOpis.profilerRun = true;
|
||||
ProfilerSection.activateAll(Side.SERVER);
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_START, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_START, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
icommandsender.sendChatToPlayer(ChatMessageComponent.createFromText(String.format("\u00A7oOpis started with a tick delay %s.", modOpis.profilerDelay)));
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataEntity;
|
||||
import mcp.mobius.opis.data.managers.EntityManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
||||
@@ -7,7 +7,7 @@ import mcp.mobius.opis.commands.IOpisCommand;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataBlockTileEntity;
|
||||
import mcp.mobius.opis.data.managers.TileEntityManager;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataList;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package mcp.mobius.opis.data.holders;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
||||
public interface ISerializable {
|
||||
void writeToStream(DataOutputStream stream) throws IOException;
|
||||
void writeToStream(ByteArrayDataOutput stream);
|
||||
//Object readFromStream(DataInputStream stream) throws IOException;
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package mcp.mobius.opis.data.holders.basetypes;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
@@ -118,14 +123,14 @@ public final class CoordinatesChunk implements ISerializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream stream) throws IOException {
|
||||
public void writeToStream(ByteArrayDataOutput stream){
|
||||
stream.writeInt(this.dim);
|
||||
stream.writeInt(this.chunkX);
|
||||
stream.writeInt(this.chunkZ);
|
||||
stream.writeByte(this.metadata);
|
||||
}
|
||||
|
||||
public static CoordinatesChunk readFromStream(DataInputStream stream) throws IOException {
|
||||
public static CoordinatesChunk readFromStream(ByteArrayDataInput stream){
|
||||
return new CoordinatesChunk(stream.readInt(), stream.readInt(), stream.readInt(), stream.readByte());
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ import mcp.mobius.opis.data.profilers.ProfilerEvent;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerPacket;
|
||||
import mcp.mobius.opis.data.profilers.ProfilerTick;
|
||||
import mcp.mobius.opis.gui.overlay.OverlayStatus;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.AccessLevel;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.server.NetDataCommand;
|
||||
@@ -84,17 +84,17 @@ public enum OpisServerTickHandler implements ITickHandler {
|
||||
// One second timer
|
||||
if (timer1000.isDone()){
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_UPLOAD, new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).dataAmount)));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_DOWNLOAD, new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).dataAmount)));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_CHUNK_FORCED, new SerialInt(ChunkManager.INSTANCE.getForcedChunkAmount())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_CHUNK_LOADED, new SerialInt(ChunkManager.INSTANCE.getLoadedChunkAmount())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_TIMING_TICK, new DataTiming(((ProfilerTick)ProfilerSection.TICK.getProfiler()).data.getGeometricMean())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_TILEENTS, new SerialInt(TileEntityManager.INSTANCE.getAmountTileEntities())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_ENTITIES, new SerialInt(EntityManager.INSTANCE.getAmountEntities())));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_UPLOAD, new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).dataAmount)));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_DOWNLOAD, new SerialLong(((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).dataAmount)));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_CHUNK_FORCED, new SerialInt(ChunkManager.INSTANCE.getForcedChunkAmount())));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_CHUNK_LOADED, new SerialInt(ChunkManager.INSTANCE.getLoadedChunkAmount())));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_TIMING_TICK, new DataTiming(((ProfilerTick)ProfilerSection.TICK.getProfiler()).data.getGeometricMean())));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_TILEENTS, new SerialInt(TileEntityManager.INSTANCE.getAmountTileEntities())));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.VALUE_AMOUNT_ENTITIES, new SerialInt(EntityManager.INSTANCE.getAmountEntities())));
|
||||
|
||||
for (Player player : PlayerTracker.instance().playersSwing){
|
||||
if (!cachedAccess.containsKey(player) || cachedAccess.get(player) != PlayerTracker.instance().getPlayerAccessLevel(player)){
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.STATUS_ACCESS_LEVEL, new SerialInt(PlayerTracker.instance().getPlayerAccessLevel(player).ordinal())), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.STATUS_ACCESS_LEVEL, new SerialInt(PlayerTracker.instance().getPlayerAccessLevel(player).ordinal())), player);
|
||||
cachedAccess.put(player, PlayerTracker.instance().getPlayerAccessLevel(player));
|
||||
}
|
||||
}
|
||||
@@ -103,19 +103,19 @@ public enum OpisServerTickHandler implements ITickHandler {
|
||||
for (Thread t : Thread.getAllStackTraces().keySet()){
|
||||
threads.add(new DataThread().fill(t));
|
||||
}
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_THREADS, threads));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataList.create(Message.LIST_THREADS, threads));
|
||||
|
||||
// Dimension data update.
|
||||
ArrayList<DataDimension> dimData = new ArrayList<DataDimension>();
|
||||
for (int dim : DimensionManager.getIDs()){
|
||||
dimData.add(new DataDimension().fill(dim));
|
||||
}
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_DIMENSION_DATA, dimData));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataList.create(Message.LIST_DIMENSION_DATA, dimData));
|
||||
|
||||
// Profiler update (if running)
|
||||
if (modOpis.profilerRun){
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_RUNNING, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_RUN_UPDATE, new SerialInt(profilerRunningTicks)));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_RUNNING, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_RUN_UPDATE, new SerialInt(profilerRunningTicks)));
|
||||
}
|
||||
|
||||
((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).dataAmount = 0L;
|
||||
@@ -124,18 +124,18 @@ public enum OpisServerTickHandler implements ITickHandler {
|
||||
|
||||
// Two second timer
|
||||
if (timer2000.isDone()){
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PLAYERS, EntityManager.INSTANCE.getAllPlayers()));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataList.create(Message.LIST_PLAYERS, EntityManager.INSTANCE.getAllPlayers()));
|
||||
}
|
||||
|
||||
// Five second timer
|
||||
if (timer5000.isDone()){
|
||||
updatePlayers();
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_OUTBOUND, ((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).data));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_INBOUND, ((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).data));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_OUTBOUND, ((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).data));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_INBOUND, ((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).data));
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_OUTBOUND_250, new ArrayList<DataPacket250>( ((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).data250.values())));
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_INBOUND_250, new ArrayList<DataPacket250>( ((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).data250.values())));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_OUTBOUND_250, new ArrayList<DataPacket250>( ((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).data250.values())));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataList.create(Message.LIST_PACKETS_INBOUND_250, new ArrayList<DataPacket250>( ((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).data250.values())));
|
||||
|
||||
((ProfilerPacket)ProfilerSection.PACKET_OUTBOUND.getProfiler()).startInterval();
|
||||
((ProfilerPacket)ProfilerSection.PACKET_INBOUND.getProfiler()).startInterval();
|
||||
@@ -156,10 +156,10 @@ public enum OpisServerTickHandler implements ITickHandler {
|
||||
modOpis.profilerRun = false;
|
||||
ProfilerSection.desactivateAll(Side.SERVER);
|
||||
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_STOP, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_STOP, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
|
||||
for (Player player : PlayerTracker.instance().playersSwing){
|
||||
OpisPacketHandler.sendFullUpdate(player);
|
||||
OpisPacketHandler_OLD.sendFullUpdate(player);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,14 +182,14 @@ public enum OpisServerTickHandler implements ITickHandler {
|
||||
for (Player player : PlayerTracker.instance().playerOverlayStatus.keySet()){
|
||||
|
||||
if (PlayerTracker.instance().playerOverlayStatus.get(player) == OverlayStatus.CHUNKSTATUS){
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.LIST_CHUNK_LOADED_CLEAR), player);
|
||||
OpisPacketHandler.splitAndSend(Message.LIST_CHUNK_LOADED, ChunkManager.INSTANCE.getLoadedChunks(PlayerTracker.instance().playerDimension.get(player)), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataCommand.create(Message.LIST_CHUNK_LOADED_CLEAR), player);
|
||||
OpisPacketHandler_OLD.splitAndSend(Message.LIST_CHUNK_LOADED, ChunkManager.INSTANCE.getLoadedChunks(PlayerTracker.instance().playerDimension.get(player)), player);
|
||||
}
|
||||
|
||||
if (PlayerTracker.instance().playerOverlayStatus.get(player) == OverlayStatus.MEANTIME){
|
||||
ArrayList<StatsChunk> timingChunks = ChunkManager.INSTANCE.getTopChunks(100);
|
||||
//OpisPacketHandler.validateAndSend(Packet_DataList.create(DataReq.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,29 +10,26 @@ import mcp.mobius.opis.swing.SelectedTab;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import cpw.mods.fml.common.IPlayerTracker;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PlayerTracker implements IPlayerTracker{
|
||||
private static PlayerTracker _instance = new PlayerTracker();
|
||||
public static PlayerTracker instance() {return _instance;}
|
||||
private PlayerTracker(){}
|
||||
|
||||
public HashSet<Player> playersSwing = new HashSet<Player>(); //This is the list of players who have opened the UI
|
||||
public HashSet<EntityPlayerMP> playersSwing = new HashSet<EntityPlayerMP>(); //This is the list of players who have opened the UI
|
||||
//public HashSet<Player> playersOpis = new HashSet<Player>(); //This is the list of players who have opened the UI or used the command line
|
||||
public HashMap<String, Boolean> filteredAmount = new HashMap<String, Boolean>(); //Should the entity amount be filtered or not
|
||||
public HashMap<Player, OverlayStatus> playerOverlayStatus = new HashMap<Player, OverlayStatus>();
|
||||
public HashMap<Player, Integer> playerDimension = new HashMap<Player, Integer>();
|
||||
public HashMap<Player, SelectedTab> playerTab = new HashMap<Player, SelectedTab>();
|
||||
public HashMap<EntityPlayerMP, OverlayStatus> playerOverlayStatus = new HashMap<EntityPlayerMP, OverlayStatus>();
|
||||
public HashMap<EntityPlayerMP, Integer> playerDimension = new HashMap<EntityPlayerMP, Integer>();
|
||||
public HashMap<EntityPlayerMP, SelectedTab> playerTab = new HashMap<EntityPlayerMP, SelectedTab>();
|
||||
private HashSet<String> playerPrivileged = new HashSet<String>();
|
||||
|
||||
public SelectedTab getPlayerSelectedTab(Player player){
|
||||
public SelectedTab getPlayerSelectedTab(EntityPlayerMP player){
|
||||
return this.playerTab.get(player);
|
||||
}
|
||||
|
||||
public AccessLevel getPlayerAccessLevel(Player player){
|
||||
return this.getPlayerAccessLevel(((EntityPlayerMP)player).username);
|
||||
public AccessLevel getPlayerAccessLevel(EntityPlayerMP player){
|
||||
return this.getPlayerAccessLevel(player.getDisplayName());
|
||||
}
|
||||
|
||||
public AccessLevel getPlayerAccessLevel(String name){
|
||||
@@ -68,7 +65,7 @@ public class PlayerTracker implements IPlayerTracker{
|
||||
PlayerTracker.instance().addPrivilegedPlayer(s,false);
|
||||
}
|
||||
|
||||
public boolean isAdmin(Player player){
|
||||
public boolean isAdmin(EntityPlayerMP player){
|
||||
return this.getPlayerAccessLevel(player).ordinal() >= AccessLevel.ADMIN.ordinal();
|
||||
}
|
||||
|
||||
@@ -76,7 +73,7 @@ public class PlayerTracker implements IPlayerTracker{
|
||||
return this.getPlayerAccessLevel(name).ordinal() >= AccessLevel.ADMIN.ordinal();
|
||||
}
|
||||
|
||||
public boolean isPrivileged(Player player){
|
||||
public boolean isPrivileged(EntityPlayerMP player){
|
||||
return this.getPlayerAccessLevel(player).ordinal() >= AccessLevel.PRIVILEGED.ordinal();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ import mcp.mobius.opis.events.OpisServerTickHandler;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.helpers.ModIdentification;
|
||||
import mcp.mobius.opis.network.OpisConnectionHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler;
|
||||
import mcp.mobius.opis.network.OpisPacketHandler_OLD;
|
||||
import mcp.mobius.opis.network.enums.AccessLevel;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.packets.custom.Packet251Extended;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class OpisConnectionHandler implements IConnectionHandler {
|
||||
|
||||
@Override
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) {
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.STATUS_CURRENT_TIME, new SerialLong(System.currentTimeMillis())), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.STATUS_CURRENT_TIME, new SerialLong(System.currentTimeMillis())), player);
|
||||
|
||||
if (manager instanceof MemoryConnection){
|
||||
System.out.printf("Adding SSP player to list of privileged users\n");
|
||||
|
||||
+26
-26
@@ -77,7 +77,7 @@ import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class OpisPacketHandler implements IPacketHandler {
|
||||
public class OpisPacketHandler_OLD implements IPacketHandler {
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
|
||||
@@ -182,21 +182,21 @@ public class OpisPacketHandler implements IPacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateAndSend(NetDataRaw capsule, Player player){
|
||||
public static void validateAndSend(NetDataRaw capsule, EntityPlayerMP player){
|
||||
if (!capsule.msg.isDisplayActive(PlayerTracker.instance().getPlayerSelectedTab(player))) return;
|
||||
|
||||
if (capsule.msg.canPlayerUseCommand(player) && capsule.packet.getPacketSize() < 32000)
|
||||
PacketDispatcher.sendPacketToPlayer(capsule.packet, player);
|
||||
PacketManager.sendPacketToPlayer(capsule.packet, player);
|
||||
else if (capsule.packet.getPacketSize() > 32000)
|
||||
modOpis.log.warning(String.format("Data packet size of type %s too big : %d ! Dropping !", capsule.msg, capsule.packet.getPacketSize()));
|
||||
}
|
||||
|
||||
public static void sendPacketToAllSwing(NetDataRaw capsule){
|
||||
for (Player player : PlayerTracker.instance().playersSwing)
|
||||
OpisPacketHandler.validateAndSend(capsule, player);
|
||||
for (EntityPlayerMP player : PlayerTracker.instance().playersSwing)
|
||||
OpisPacketHandler_OLD.validateAndSend(capsule, player);
|
||||
}
|
||||
|
||||
public static void splitAndSend(Message msg, ArrayList<? extends ISerializable> data, Player player){
|
||||
public static void splitAndSend(Message msg, ArrayList<? extends ISerializable> data, EntityPlayerMP player){
|
||||
int i = 0;
|
||||
while (i < data.size()){
|
||||
validateAndSend(NetDataList.create(msg, data.subList(i, Math.min(i + 500, data.size()))), player);
|
||||
@@ -205,11 +205,11 @@ public class OpisPacketHandler implements IPacketHandler {
|
||||
|
||||
}
|
||||
|
||||
public static void sendChatMsg(String msg, Player player){
|
||||
PacketDispatcher.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(msg)), player);
|
||||
public static void sendChatMsg(String msg, EntityPlayerMP player){
|
||||
PacketManager.sendPacketToPlayer(new Packet3Chat(ChatMessageComponent.createFromText(msg)), player);
|
||||
}
|
||||
|
||||
public static void sendFullUpdate(Player player){
|
||||
public static void sendFullUpdate(EntityPlayerMP player){
|
||||
ArrayList<DataEntity> timingEntities = EntityManager.INSTANCE.getWorses(100);
|
||||
ArrayList<DataBlockTileEntity> timingTileEnts = TileEntityManager.INSTANCE.getWorses(100);
|
||||
ArrayList<DataHandler> timingHandlers = TickHandlerManager.getCumulatedStatsServer();
|
||||
@@ -229,27 +229,27 @@ public class OpisPacketHandler implements IPacketHandler {
|
||||
timingEvents.add(new DataEvent().fill(cell));
|
||||
}
|
||||
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_HANDLERS, timingHandlers), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_ENTITIES, timingEntities), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_TILEENTS, timingTileEnts), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_TILEENTS_PER_CLASS, timingTEsClass), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_EVENTS, timingEvents), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_ENTITIES_PER_CLASS, timingEntsClass), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_TILEENTS, totalTimeTE), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_ENTITIES, totalTimeEnt), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_HANDLERS, totalTimeHandler), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_WORLDTICK, totalWorldTick), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_NETWORK, totalNetwork), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_HANDLERS, timingHandlers), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_ENTITIES, timingEntities), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_TILEENTS, timingTileEnts), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_TILEENTS_PER_CLASS, timingTEsClass), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_EVENTS, timingEvents), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_ENTITIES_PER_CLASS, timingEntsClass), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_TILEENTS, totalTimeTE), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_ENTITIES, totalTimeEnt), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_HANDLERS, totalTimeHandler), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_WORLDTICK, totalWorldTick), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_NETWORK, totalNetwork), player);
|
||||
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_AMOUNT_HANDLERS, new SerialInt(timingHandlers.size())), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_AMOUNT_HANDLERS, new SerialInt(timingHandlers.size())), player);
|
||||
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.STATUS_TIME_LAST_RUN, new SerialLong(ProfilerSection.timeStampLastRun)), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.STATUS_TIME_LAST_RUN, new SerialLong(ProfilerSection.timeStampLastRun)), player);
|
||||
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.STATUS_ACCESS_LEVEL, new SerialInt(PlayerTracker.instance().getPlayerAccessLevel(player).ordinal())), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.STATUS_ACCESS_LEVEL, new SerialInt(PlayerTracker.instance().getPlayerAccessLevel(player).ordinal())), player);
|
||||
|
||||
// This portion is to get the proper filtered amounts depending on the player preferences.
|
||||
String name = ((EntityPlayer)player).getEntityName();
|
||||
String name = player.getDisplayName();
|
||||
boolean filtered = false;
|
||||
if (PlayerTracker.instance().filteredAmount.containsKey(name))
|
||||
filtered = PlayerTracker.instance().filteredAmount.get(name);
|
||||
@@ -257,7 +257,7 @@ public class OpisPacketHandler implements IPacketHandler {
|
||||
|
||||
// Here we send a full update to the player
|
||||
//OpisPacketHandler.validateAndSend(Packet_DataList.create(DataReq.LIST_AMOUNT_ENTITIES, amountEntities), player);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_AMOUNT_ENTITIES, amountEntities), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_AMOUNT_ENTITIES, amountEntities), player);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package mcp.mobius.opis.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataError;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* @author abrarsyed
|
||||
* This is the base packet type for tall the SecretRoomsMod network stuff.
|
||||
* Any class that extends this should have an empty constructor, otherwise the network system will fail.
|
||||
*/
|
||||
public abstract class PacketBase
|
||||
{
|
||||
public abstract void encode(ByteArrayDataOutput output);
|
||||
|
||||
public abstract void decode(ByteArrayDataInput input);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void actionClient(World world, EntityPlayer player){
|
||||
throw new RuntimeException("Packet is not going the right way ! Server side packet seen client side.");
|
||||
}
|
||||
|
||||
public void actionServer(World world, EntityPlayerMP player){
|
||||
throw new RuntimeException("Packet is not going the right way ! Client side packet seen server side.");
|
||||
}
|
||||
|
||||
protected ISerializable dataRead(Class datatype, ByteArrayDataInput istream){
|
||||
if (datatype == null) return new DataError();
|
||||
|
||||
try{
|
||||
Method readFromStream = datatype.getMethod("readFromStream", ByteArrayDataInput.class);
|
||||
|
||||
return (ISerializable)readFromStream.invoke(null, istream);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package mcp.mobius.opis.network;
|
||||
|
||||
import static cpw.mods.fml.relauncher.Side.CLIENT;
|
||||
import static cpw.mods.fml.relauncher.Side.SERVER;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.EnumMap;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqChunks;
|
||||
import mcp.mobius.opis.network.packets.client.PacketReqData;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.Packet;
|
||||
|
||||
@Sharable
|
||||
public class PacketManager extends FMLIndexedMessageToMessageCodec<PacketBase>
|
||||
{
|
||||
private static final PacketManager INSTANCE = new PacketManager();
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final EnumMap<Side, FMLEmbeddedChannel> channels = Maps.newEnumMap(Side.class);
|
||||
|
||||
public static void init()
|
||||
{
|
||||
if (!channels.isEmpty()) // avoid duplicate inits..
|
||||
return;
|
||||
|
||||
INSTANCE.addDiscriminator(0, PacketReqChunks.class);
|
||||
INSTANCE.addDiscriminator(0, PacketReqData.class);
|
||||
//INSTANCE.addDiscriminator(1, PacketShowToggle.class);
|
||||
//INSTANCE.addDiscriminator(2, PacketKey.class);
|
||||
|
||||
channels.putAll(NetworkRegistry.INSTANCE.newChannel("Opis", INSTANCE));
|
||||
}
|
||||
|
||||
// IO METHODS
|
||||
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, PacketBase packet, ByteBuf target) throws Exception
|
||||
{
|
||||
ByteArrayDataOutput output = ByteStreams.newDataOutput();
|
||||
packet.encode(output);
|
||||
target.writeBytes(output.toByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf source, PacketBase packet)
|
||||
{
|
||||
ByteArrayDataInput input = ByteStreams.newDataInput(source.array());
|
||||
input.skipBytes(1); // skip the packet identifier byte
|
||||
packet.decode(input);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||
{
|
||||
actionClient(packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
actionServer(ctx, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void actionClient(PacketBase packet)
|
||||
{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
packet.actionClient(mc.theWorld, mc.thePlayer);
|
||||
}
|
||||
|
||||
private void actionServer(ChannelHandlerContext ctx, PacketBase packet)
|
||||
{
|
||||
EntityPlayerMP player = ((NetHandlerPlayServer)ctx.channel().attr(NetworkRegistry.NET_HANDLER).get()).playerEntity;
|
||||
packet.actionServer(player.worldObj, player);
|
||||
}
|
||||
|
||||
// UTIL SENDING METHODS
|
||||
|
||||
public static void sendToServer(PacketBase packet)
|
||||
{
|
||||
channels.get(CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER);
|
||||
channels.get(CLIENT).writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public static void sendToPlayer(PacketBase packet, EntityPlayer player)
|
||||
{
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
|
||||
channels.get(SERVER).writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public static void sendToAllAround(PacketBase packet, NetworkRegistry.TargetPoint point)
|
||||
{
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point);
|
||||
channels.get(SERVER).writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public static void sendToDimension(PacketBase packet, int dimension)
|
||||
{
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION);
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimension);
|
||||
channels.get(SERVER).writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public static void sendToAll(PacketBase packet)
|
||||
{
|
||||
channels.get(SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
channels.get(SERVER).writeAndFlush(packet);
|
||||
}
|
||||
|
||||
public static Packet toMcPacket(PacketBase packet)
|
||||
{
|
||||
return channels.get(FMLCommonHandler.instance().getEffectiveSide()).generatePacketFrom(packet);
|
||||
}
|
||||
|
||||
// OTHER METHODS
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
|
||||
{
|
||||
LOGGER.log(Level.ERROR, "Error in packet handling!", cause);
|
||||
ctx.fireExceptionCaught(cause); // for the other handlers.
|
||||
}
|
||||
|
||||
@Override
|
||||
public FMLIndexedMessageToMessageCodec<PacketBase> addDiscriminator(int discriminator, Class<? extends PacketBase> type)
|
||||
{
|
||||
// double check it has an empty constructor. or fail early.
|
||||
// This is to gaurd myself against my own stupidity.
|
||||
|
||||
if (!hasEmptyContructor(type))
|
||||
{
|
||||
LOGGER.log(Level.FATAL, type.getName() + "does not have an empty constructor!");
|
||||
}
|
||||
|
||||
return super.addDiscriminator(discriminator, type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static boolean hasEmptyContructor(Class type)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Constructor c : type.getConstructors())
|
||||
{
|
||||
if (c.getParameterTypes().length == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SecurityException e)
|
||||
{
|
||||
// really?
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,8 +10,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.modOpis;
|
||||
@@ -58,8 +56,8 @@ public class ServerMessageHandler {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void handle(Message maintype, ISerializable param1, ISerializable param2, Player player){
|
||||
String name = ((EntityPlayer)player).getEntityName();
|
||||
public void handle(Message maintype, ISerializable param1, ISerializable param2, EntityPlayerMP player){
|
||||
String name = player.getDisplayName();
|
||||
|
||||
if (maintype == Message.OVERLAY_CHUNK_ENTITIES){
|
||||
this.handleOverlayChunkEntities((CoordinatesChunk)param1, player);
|
||||
@@ -67,22 +65,22 @@ public class ServerMessageHandler {
|
||||
|
||||
else if (maintype == Message.OVERLAY_CHUNK_TIMING){
|
||||
ArrayList<StatsChunk> timingChunks = ChunkManager.INSTANCE.getTopChunks(100);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.LIST_CHUNK_TILEENTS){
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_CHUNK_TILEENTS, TileEntityManager.INSTANCE.getTileEntitiesInChunk((CoordinatesChunk)param1)), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_CHUNK_TILEENTS, TileEntityManager.INSTANCE.getTileEntitiesInChunk((CoordinatesChunk)param1)), player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.LIST_CHUNK_ENTITIES){
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_CHUNK_ENTITIES, EntityManager.INSTANCE.getEntitiesInChunk((CoordinatesChunk)param1)), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_CHUNK_ENTITIES, EntityManager.INSTANCE.getEntitiesInChunk((CoordinatesChunk)param1)), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.LIST_CHUNK_LOADED){
|
||||
PlayerTracker.instance().playerOverlayStatus.put(player, OverlayStatus.CHUNKSTATUS);
|
||||
PlayerTracker.instance().playerDimension.put(player, ((SerialInt)param1).value);
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.LIST_CHUNK_LOADED_CLEAR), player);
|
||||
OpisPacketHandler.splitAndSend(Message.LIST_CHUNK_LOADED, ChunkManager.INSTANCE.getLoadedChunks(((SerialInt)param1).value), player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataCommand.create(Message.LIST_CHUNK_LOADED_CLEAR), player);
|
||||
OpisPacketHandler_OLD.splitAndSend(Message.LIST_CHUNK_LOADED, ChunkManager.INSTANCE.getLoadedChunks(((SerialInt)param1).value), player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.LIST_CHUNK_TICKETS){
|
||||
@@ -92,31 +90,31 @@ public class ServerMessageHandler {
|
||||
else if (maintype == Message.LIST_TIMING_TILEENTS){
|
||||
ArrayList<DataBlockTileEntity> timingTileEnts = TileEntityManager.INSTANCE.getWorses(100);
|
||||
DataTiming totalTime = TileEntityManager.INSTANCE.getTotalUpdateTime();
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create (Message.LIST_TIMING_TILEENTS, timingTileEnts), (Player)player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_TILEENTS, totalTime), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create (Message.LIST_TIMING_TILEENTS, timingTileEnts), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_TILEENTS, totalTime), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.LIST_TIMING_ENTITIES){
|
||||
ArrayList<DataEntity> timingEntities = EntityManager.INSTANCE.getWorses(100);
|
||||
DataTiming totalTime = EntityManager.INSTANCE.getTotalUpdateTime();
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_ENTITIES, timingEntities), (Player)player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_ENTITIES, totalTime), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_ENTITIES, timingEntities), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_ENTITIES, totalTime), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.LIST_TIMING_HANDLERS){
|
||||
ArrayList<DataHandler> timingHandlers = TickHandlerManager.getCumulatedStatsServer();
|
||||
DataTiming totalTime = TickHandlerManager.getTotalUpdateTime();
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_HANDLERS, timingHandlers), (Player)player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_HANDLERS, totalTime), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_HANDLERS, timingHandlers), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_HANDLERS, totalTime), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.LIST_TIMING_CHUNK){
|
||||
ArrayList<StatsChunk> timingChunks = ChunkManager.INSTANCE.getTopChunks(100);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_TIMING_CHUNK, timingChunks), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.VALUE_TIMING_WORLDTICK){
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_WORLDTICK, new DataBlockTick().fill()), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.VALUE_TIMING_WORLDTICK, new DataBlockTick().fill()), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.VALUE_TIMING_ENTUPDATE){
|
||||
@@ -128,11 +126,11 @@ public class ServerMessageHandler {
|
||||
filtered = PlayerTracker.instance().filteredAmount.get(name);
|
||||
|
||||
ArrayList<AmountHolder> ents = EntityManager.INSTANCE.getCumulativeEntities(filtered);
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_AMOUNT_ENTITIES, ents), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_AMOUNT_ENTITIES, ents), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.LIST_AMOUNT_TILEENTS){
|
||||
OpisPacketHandler.validateAndSend(NetDataList.create(Message.LIST_AMOUNT_TILEENTS, TileEntityManager.INSTANCE.getCumulativeAmountTileEntities()), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataList.create(Message.LIST_AMOUNT_TILEENTS, TileEntityManager.INSTANCE.getCumulativeAmountTileEntities()), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.COMMAND_FILTERING_TRUE){
|
||||
@@ -152,12 +150,12 @@ public class ServerMessageHandler {
|
||||
MetaManager.reset();
|
||||
modOpis.profilerRun = true;
|
||||
ProfilerSection.activateAll(Side.SERVER);
|
||||
OpisPacketHandler.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_START, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
OpisPacketHandler_OLD.sendPacketToAllSwing(NetDataValue.create(Message.STATUS_START, new SerialInt(modOpis.profilerMaxTicks)));
|
||||
}
|
||||
|
||||
else if (maintype == Message.COMMAND_TELEPORT_BLOCK){
|
||||
EntityManager.INSTANCE.teleportPlayer((CoordinatesBlock)param1, (EntityPlayerMP)player);
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.CLIENT_HIGHLIGHT_BLOCK, param1), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.CLIENT_HIGHLIGHT_BLOCK, param1), (Player)player);
|
||||
}
|
||||
|
||||
else if (maintype == Message.COMMAND_TELEPORT_TO_ENTITY){
|
||||
@@ -189,7 +187,7 @@ public class ServerMessageHandler {
|
||||
}
|
||||
|
||||
else if(maintype == Message.STATUS_TIME_LAST_RUN){
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.STATUS_TIME_LAST_RUN, new SerialLong(ProfilerSection.timeStampLastRun)), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.STATUS_TIME_LAST_RUN, new SerialLong(ProfilerSection.timeStampLastRun)), (Player)player);
|
||||
}
|
||||
|
||||
else if(maintype == Message.COMMAND_KILL_HOSTILES_ALL){
|
||||
@@ -220,7 +218,7 @@ public class ServerMessageHandler {
|
||||
}
|
||||
|
||||
else if(maintype == Message.STATUS_PING){
|
||||
OpisPacketHandler.validateAndSend(NetDataValue.create(Message.STATUS_PING, param1), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataValue.create(Message.STATUS_PING, param1), (Player)player);
|
||||
}
|
||||
|
||||
else if(maintype == Message.SWING_TAB_CHANGED){
|
||||
@@ -229,8 +227,8 @@ public class ServerMessageHandler {
|
||||
}
|
||||
|
||||
else if(maintype == Message.LIST_ORPHAN_TILEENTS){
|
||||
OpisPacketHandler.validateAndSend(NetDataCommand.create(Message.LIST_ORPHAN_TILEENTS_CLEAR), (Player)player);
|
||||
OpisPacketHandler.splitAndSend(Message.LIST_ORPHAN_TILEENTS, TileEntityManager.INSTANCE.getOrphans(), (Player)player);
|
||||
OpisPacketHandler_OLD.validateAndSend(NetDataCommand.create(Message.LIST_ORPHAN_TILEENTS_CLEAR), (Player)player);
|
||||
OpisPacketHandler_OLD.splitAndSend(Message.LIST_ORPHAN_TILEENTS, TileEntityManager.INSTANCE.getOrphans(), (Player)player);
|
||||
}
|
||||
|
||||
else{
|
||||
@@ -238,7 +236,7 @@ public class ServerMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleOverlayChunkEntities(CoordinatesChunk coord, Player player){
|
||||
public void handleOverlayChunkEntities(CoordinatesChunk coord, EntityPlayerMP player){
|
||||
|
||||
HashMap<CoordinatesChunk, ArrayList<DataEntity>> entities = EntityManager.INSTANCE.getAllEntitiesPerChunk();
|
||||
HashMap<CoordinatesChunk, Integer> perChunk = new HashMap<CoordinatesChunk, Integer>();
|
||||
@@ -246,7 +244,7 @@ public class ServerMessageHandler {
|
||||
for (CoordinatesChunk chunk : entities.keySet())
|
||||
perChunk.put(chunk, entities.get(chunk).size());
|
||||
|
||||
PacketDispatcher.sendPacketToPlayer(Packet_DataOverlayChunkEntities.create(perChunk), player);
|
||||
PacketManager.sendPacketToPlayer(Packet_DataOverlayChunkEntities.create(perChunk), player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import static mcp.mobius.opis.network.enums.AccessLevel.*;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.swing.SelectedTab;
|
||||
|
||||
@@ -126,7 +126,7 @@ public enum Message {
|
||||
this.accessLevel = level;
|
||||
}
|
||||
|
||||
public boolean canPlayerUseCommand(Player player){
|
||||
public boolean canPlayerUseCommand(EntityPlayerMP player){
|
||||
return PlayerTracker.instance().getPlayerAccessLevel(player).ordinal() >= this.accessLevel.ordinal();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package mcp.mobius.opis.network.packets.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.enums.AccessLevel;
|
||||
|
||||
public class PacketReqChunks extends PacketBase{
|
||||
|
||||
public int dim;
|
||||
public ArrayList<CoordinatesChunk> chunks = new ArrayList<CoordinatesChunk>();
|
||||
|
||||
public PacketReqChunks()
|
||||
{
|
||||
}
|
||||
|
||||
public PacketReqChunks(int dim, ArrayList<CoordinatesChunk> chunks)
|
||||
{
|
||||
this.dim = dim;
|
||||
this.chunks = chunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteArrayDataOutput output) {
|
||||
output.writeInt(dim);
|
||||
output.writeInt(chunks.size());
|
||||
for(CoordinatesChunk coord : chunks)
|
||||
coord.writeToStream(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteArrayDataInput input) {
|
||||
dim = input.readInt();
|
||||
int nchunks = input.readInt();
|
||||
for (int i = 0; i < nchunks; i++)
|
||||
chunks.add(CoordinatesChunk.readFromStream(input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionServer(World world, EntityPlayerMP player) {
|
||||
if (PlayerTracker.instance().getPlayerAccessLevel(player).ordinal() > AccessLevel.PRIVILEGED.ordinal()){
|
||||
ArrayList<Chunk> list = new ArrayList();
|
||||
|
||||
if (world != null){
|
||||
for (CoordinatesChunk chunk : chunks)
|
||||
list.add(world.getChunkFromChunkCoords(chunk.chunkX, chunk.chunkZ));
|
||||
|
||||
//if (!list.isEmpty()){
|
||||
// Packet_Chunks.send(castedPacket.dim, !world.provider.hasNoSky, list, player);
|
||||
|
||||
|
||||
/*
|
||||
Packet250CustomPayload chunkPacket = Packet_Chunks.create(castedPacket.dim, !world.provider.hasNoSky, list);
|
||||
if (chunkPacket != null)
|
||||
PacketDispatcher.sendPacketToPlayer( chunkPacket, player);
|
||||
*/
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package mcp.mobius.opis.network.packets.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mcp.mobius.opis.data.holders.DataType;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.events.PlayerTracker;
|
||||
import mcp.mobius.opis.network.PacketBase;
|
||||
import mcp.mobius.opis.network.ServerMessageHandler;
|
||||
import mcp.mobius.opis.network.enums.AccessLevel;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.enums.Packets;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
||||
public class PacketReqData extends PacketBase{
|
||||
|
||||
public Message dataReq;
|
||||
public ISerializable param1 = null;
|
||||
public ISerializable param2 = null;
|
||||
|
||||
public PacketReqData(){}
|
||||
|
||||
public PacketReqData(Message dataReq) {
|
||||
this(dataReq, null, null);
|
||||
}
|
||||
|
||||
public PacketReqData(Message dataReq, ISerializable param1) {
|
||||
this(dataReq, param1, null);
|
||||
}
|
||||
|
||||
public PacketReqData(Message dataReq, ISerializable param1, ISerializable param2) {
|
||||
this.dataReq = dataReq;
|
||||
this.param1 = param1;
|
||||
this.param2 = param2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteArrayDataOutput output) {
|
||||
output.writeInt(dataReq.ordinal());
|
||||
|
||||
if (param1 != null){
|
||||
output.writeBoolean(true);
|
||||
//Packet.writeString(param1.getClass().getCanonicalName(), outputStream);
|
||||
output.writeInt(DataType.getForClass(param1.getClass()).ordinal());
|
||||
param1.writeToStream(output);
|
||||
} else {
|
||||
output.writeBoolean(false);
|
||||
}
|
||||
|
||||
if (param2 != null){
|
||||
output.writeBoolean(true);
|
||||
output.writeInt(DataType.getForClass(param2.getClass()).ordinal());
|
||||
param2.writeToStream(output);
|
||||
} else {
|
||||
output.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteArrayDataInput input) {
|
||||
this.dataReq = Message.values()[input.readInt()];
|
||||
|
||||
if (input.readBoolean()){
|
||||
//String datatype = Packet.readString(istream, 255);
|
||||
Class datatype = DataType.getForOrdinal(input.readInt());
|
||||
this.param1 = dataRead(datatype, input);
|
||||
}
|
||||
|
||||
if (input.readBoolean()){
|
||||
Class datatype = DataType.getForOrdinal(input.readInt());
|
||||
this.param2 = dataRead(datatype, input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionServer(World world, EntityPlayerMP player) {
|
||||
String logmsg = String.format("Received request %s from player %s ... ", this.dataReq, player.getDisplayName());
|
||||
|
||||
if (this.dataReq.canPlayerUseCommand(player)){
|
||||
logmsg += "Accepted";
|
||||
ServerMessageHandler.instance().handle(this.dataReq, this.param1, this.param2, player);
|
||||
} else {
|
||||
logmsg += "Rejected";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package mcp.mobius.opis.network.packets.client;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.network.enums.Packets;
|
||||
|
||||
public class Packet_ReqChunks {
|
||||
|
||||
public byte header;
|
||||
public int dim;
|
||||
public ArrayList<CoordinatesChunk> chunks = new ArrayList<CoordinatesChunk>();
|
||||
|
||||
public Packet_ReqChunks(Packet250CustomPayload packet) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
try{
|
||||
this.header = inputStream.readByte();
|
||||
this.dim = inputStream.readInt();
|
||||
int nchunks = inputStream.readInt();
|
||||
for (int i = 0; i < nchunks; i++)
|
||||
chunks.add(CoordinatesChunk.readFromStream(inputStream));
|
||||
|
||||
} catch (IOException e){}
|
||||
}
|
||||
|
||||
public static Packet250CustomPayload create(int dim, ArrayList<CoordinatesChunk> chunks){
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1);
|
||||
DataOutputStream outputStream = new DataOutputStream(bos);
|
||||
|
||||
try{
|
||||
outputStream.writeByte(Packets.REQ_CHUNKS);
|
||||
outputStream.writeInt(dim);
|
||||
outputStream.writeInt(chunks.size());
|
||||
for(CoordinatesChunk coord : chunks)
|
||||
coord.writeToStream(outputStream);
|
||||
|
||||
}catch(IOException e){}
|
||||
|
||||
packet.channel = "Opis";
|
||||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package mcp.mobius.opis.network.packets.client;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import mcp.mobius.opis.data.holders.DataType;
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock;
|
||||
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
||||
import mcp.mobius.opis.data.holders.basetypes.TargetEntity;
|
||||
import mcp.mobius.opis.data.holders.newtypes.DataError;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.enums.Packets;
|
||||
|
||||
public class Packet_ReqData {
|
||||
|
||||
public byte header;
|
||||
public Message dataReq;
|
||||
public ISerializable param1 = null;
|
||||
public ISerializable param2 = null;
|
||||
|
||||
public Packet_ReqData(Packet250CustomPayload packet) {
|
||||
DataInputStream istream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
try{
|
||||
this.header = istream.readByte();
|
||||
this.dataReq = Message.values()[istream.readInt()];
|
||||
|
||||
if (istream.readBoolean()){
|
||||
//String datatype = Packet.readString(istream, 255);
|
||||
Class datatype = DataType.getForOrdinal(istream.readInt());
|
||||
this.param1 = dataRead(datatype, istream);
|
||||
}
|
||||
|
||||
if (istream.readBoolean()){
|
||||
Class datatype = DataType.getForOrdinal(istream.readInt());
|
||||
this.param2 = dataRead(datatype, istream);
|
||||
}
|
||||
|
||||
} catch (IOException e){}
|
||||
}
|
||||
|
||||
public static Packet250CustomPayload create(Message dataReq){
|
||||
return Packet_ReqData.create(dataReq, null, null) ;
|
||||
}
|
||||
|
||||
public static Packet250CustomPayload create(Message dataReq, ISerializable param1){
|
||||
return Packet_ReqData.create(dataReq, param1, null) ;
|
||||
}
|
||||
|
||||
public static Packet250CustomPayload create(Message dataReq, ISerializable param1, ISerializable param2){
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1);
|
||||
DataOutputStream outputStream = new DataOutputStream(bos);
|
||||
|
||||
try{
|
||||
outputStream.writeByte(Packets.REQ_DATA);
|
||||
outputStream.writeInt(dataReq.ordinal());
|
||||
|
||||
if (param1 != null){
|
||||
outputStream.writeBoolean(true);
|
||||
//Packet.writeString(param1.getClass().getCanonicalName(), outputStream);
|
||||
outputStream.writeInt(DataType.getForClass(param1.getClass()).ordinal());
|
||||
param1.writeToStream(outputStream);
|
||||
} else {
|
||||
outputStream.writeBoolean(false);
|
||||
}
|
||||
|
||||
if (param2 != null){
|
||||
outputStream.writeBoolean(true);
|
||||
outputStream.writeInt(DataType.getForClass(param2.getClass()).ordinal());
|
||||
param2.writeToStream(outputStream);
|
||||
} else {
|
||||
outputStream.writeBoolean(false);
|
||||
}
|
||||
|
||||
}catch(IOException e){}
|
||||
|
||||
packet.channel = "Opis";
|
||||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
private ISerializable dataRead(Class datatype, DataInputStream istream){
|
||||
if (datatype == null) return new DataError();
|
||||
|
||||
try{
|
||||
Method readFromStream = datatype.getMethod("readFromStream", DataInputStream.class);
|
||||
|
||||
return (ISerializable)readFromStream.invoke(null, istream);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package mcp.mobius.opis.network.packets.custom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mcp.mobius.opis.data.holders.ISerializable;
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
public class Packet250Metadata extends Packet250CustomPayload {
|
||||
|
||||
public Message dataReq;
|
||||
public ISerializable dataValue;
|
||||
public ArrayList<? extends ISerializable> dataList;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package mcp.mobius.opis.network.packets.custom;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
public class Packet251Extended extends Packet250CustomPayload {
|
||||
|
||||
public Packet251Extended() {}
|
||||
|
||||
public Packet251Extended(String par1Str, byte[] par2ArrayOfByte)
|
||||
{
|
||||
this.channel = par1Str;
|
||||
this.data = par2ArrayOfByte;
|
||||
|
||||
if (par2ArrayOfByte != null)
|
||||
this.length = par2ArrayOfByte.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readPacketData(DataInput par1DataInput) throws IOException
|
||||
{
|
||||
this.channel = readString(par1DataInput, 20);
|
||||
this.length = par1DataInput.readInt();
|
||||
|
||||
this.data = new byte[this.length];
|
||||
par1DataInput.readFully(this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacketData(DataOutput par1DataOutput) throws IOException
|
||||
{
|
||||
writeString(this.channel, par1DataOutput);
|
||||
par1DataOutput.writeInt(this.length);
|
||||
|
||||
if (this.data != null)
|
||||
par1DataOutput.write(this.data);
|
||||
}
|
||||
|
||||
public int getPacketSize()
|
||||
{
|
||||
return 2 + this.channel.length() * 2 + 4 + this.length;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user