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/ObjID.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/network/ObjID.java')
| -rw-r--r-- | NET/worlds/network/ObjID.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/NET/worlds/network/ObjID.java b/NET/worlds/network/ObjID.java new file mode 100644 index 0000000..d8ad62c --- /dev/null +++ b/NET/worlds/network/ObjID.java @@ -0,0 +1,66 @@ +package NET.worlds.network; + +import java.io.IOException; + +public class ObjID { + private int _shortObjID; + private String _longObjID; + + public ObjID(int id) { + this._shortObjID = id; + this._longObjID = null; + } + + public ObjID(String id) { + this._shortObjID = 0; + if (id.startsWith("!")) { + id = id.substring(1); + } + + this._longObjID = id; + } + + public ObjID() { + this._shortObjID = 0; + this._longObjID = null; + } + + public int shortID() { + return this._shortObjID; + } + + public String longID() { + return this._longObjID; + } + + void parseNetData(ServerInputStream data) throws IOException { + this._shortObjID = data.readUnsignedByte(); + if (this._shortObjID == 0) { + this._longObjID = data.readUTF(); + } + } + + int packetSize() { + return this._longObjID != null ? 2 + ServerOutputStream.utfLength(this._longObjID) : 1; + } + + void send(ServerOutputStream o) throws IOException { + if (this._longObjID != null) { + o.writeByte(0); + o.writeUTF(this._longObjID); + } else { + assert this._shortObjID == 1 || this._shortObjID >= 253; + + o.writeByte(this._shortObjID); + } + } + + public String toString(WorldServer serv) { + return this._longObjID != null ? this._longObjID : Integer.toString(this._shortObjID) + "[" + serv.getLongID(this) + "]"; + } + + @Override + public String toString() { + return this._longObjID != null ? this._longObjID : "[#" + Integer.toString(this._shortObjID) + "]"; + } +} |