diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/network/netPacket.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/network/netPacket.java')
| -rw-r--r-- | NET/worlds/network/netPacket.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/NET/worlds/network/netPacket.java b/NET/worlds/network/netPacket.java new file mode 100644 index 0000000..bc430a3 --- /dev/null +++ b/NET/worlds/network/netPacket.java @@ -0,0 +1,58 @@ +package NET.worlds.network; + +import NET.worlds.console.StatNetMUNode; +import java.io.IOException; + +public abstract class netPacket { + protected ObjID _objID; + protected int _commandType; + + public netPacket(ObjID id, int cmd) { + if (id != null) { + this._objID = id; + } else { + this._objID = new ObjID(1); + } + + this._commandType = cmd; + } + + public netPacket() { + this._objID = new ObjID(1); + } + + public int msgID() { + return this._commandType; + } + + int packetSize() { + return 2 + this._objID.packetSize(); + } + + public String toString(WorldServer serv) { + return new Integer(this._commandType).toString(); + } + + void send(ServerOutputStream o) throws IOException { + int packetsize = this.packetSize(); + if (packetsize >= 256 && o.getVersion() <= 24) { + throw new PacketTooLargeException(); + } else { + StatNetMUNode netStat = StatNetMUNode.getNode(); + netStat.addBytesSent(packetsize); + netStat.addPacketsSent(1); + + assert this._commandType > 0; + + if (packetsize >= 128 && o.getVersion() > 24) { + o.writeByte(128 + packetsize / 256); + o.writeByte(packetsize & 0xFF); + } else { + o.writeByte(packetsize); + } + + this._objID.send(o); + o.writeByte(this._commandType); + } + } +} |