mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-16 18:54:51 +00:00
Fixed packet compression and splitting on TCP connections.
This commit is contained in:
1 parent
7f42cd94e0
commit
4bd5aab59a
2 files changed
+41
-5
No files matched your search
@@ -3,18 +3,45 @@ package codechicken.lib.packet;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
|
||||
import net.minecraft.network.packet.NetHandler;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
public class MetaPacket extends Packet
|
||||
/**
|
||||
* A class that facilitates sending of multiple packets one after the other.
|
||||
* It first sends an empty 250 packet and then it's payloads.
|
||||
*/
|
||||
public class MetaPacket extends Packet250CustomPayload
|
||||
{
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
String fieldName = new ObfMapping("net/minecraft/network/packet/Packet", "packetClassToIdMap", "Ljava/util/Map;").toRuntime().s_name;
|
||||
Field field = Packet.class.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
Map<Class<? extends Packet>, Integer> packetClassToIdMap = (Map<Class<? extends Packet>, Integer>) field.get(null);
|
||||
packetClassToIdMap.put(MetaPacket.class, 250);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Packet> packets = new ArrayList<Packet>();
|
||||
|
||||
public MetaPacket(Packet... packets)
|
||||
{
|
||||
super("", null);
|
||||
|
||||
for(Packet p : packets)
|
||||
this.packets.add(p);
|
||||
}
|
||||
@@ -33,8 +60,14 @@ public class MetaPacket extends Packet
|
||||
@Override
|
||||
public void writePacketData(DataOutput dataout) throws IOException
|
||||
{
|
||||
//send a dummy 250
|
||||
super.writePacketData(dataout);
|
||||
|
||||
for(Packet p : packets)
|
||||
p.writePacketData(dataout);
|
||||
Packet.writePacket(p, dataout);
|
||||
|
||||
//adjust sent size for Packet.writePacket
|
||||
Packet.sentSize-=getPacketSize()-super.getPacketSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,7 +82,7 @@ public class MetaPacket extends Packet
|
||||
{
|
||||
int size = 0;
|
||||
for(Packet p : packets)
|
||||
size+=p.getPacketSize();
|
||||
size+=p.getPacketSize()+1;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user