summaryrefslogtreecommitdiff
path: root/NET/worlds/network/netPacket.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/network/netPacket.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/network/netPacket.java')
-rw-r--r--NET/worlds/network/netPacket.java58
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);
+ }
+ }
+}