summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/Attribute.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/scape/Attribute.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/Attribute.java')
-rw-r--r--NET/worlds/scape/Attribute.java383
1 files changed, 383 insertions, 0 deletions
diff --git a/NET/worlds/scape/Attribute.java b/NET/worlds/scape/Attribute.java
new file mode 100644
index 0000000..12d2304
--- /dev/null
+++ b/NET/worlds/scape/Attribute.java
@@ -0,0 +1,383 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.network.InfiniteWaitException;
+import NET.worlds.network.NetworkObject;
+import NET.worlds.network.ObjID;
+import NET.worlds.network.PacketTooLargeException;
+import NET.worlds.network.WorldServer;
+import NET.worlds.network.propReqCmd;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Vector;
+
+public abstract class Attribute extends Sensor {
+ public int _shorthandVersion = this.getMaxShorthandVersion();
+ int _attrID;
+ byte[] _serverData;
+ boolean _waitingForFeedback;
+ byte[] _outgoing;
+ boolean loaded;
+ Vector<LoadedAttribute> callbacks;
+ private Attribute _to;
+ private int _storedForwardAttrID = -1;
+ protected int _propertyFlags = 208;
+ protected int _accessFlags = 0;
+ private static Object classCookie = new Object();
+
+ public int getMaxShorthandVersion() {
+ return 0;
+ }
+
+ public void load(LoadedAttribute callback) {
+ if (this.loaded) {
+ if (callback != null) {
+ callback.loadedAttribute(this, null);
+ }
+ } else {
+ Sharer s = (Sharer)this.getOwner();
+ if (s != null && s.isShared()) {
+ if (callback != null) {
+ if (this.callbacks == null) {
+ this.callbacks = new Vector<LoadedAttribute>();
+ }
+
+ this.callbacks.addElement(callback);
+ }
+
+ Attribute f = this.getForwardAttribute();
+ if (f != null) {
+ f.load(null);
+ } else {
+ assert (s.getMode() & 1) == 0;
+
+ Object served = s.getOwner();
+
+ try {
+ WorldServer servr;
+ String id;
+ if (served instanceof Room) {
+ servr = ((Room)served).getServer();
+ id = ((Room)served).getNetworkRoom().getLongID();
+ } else {
+ servr = ((NetworkObject)served).getServer();
+ id = ((NetworkObject)served).getLongID();
+ }
+
+ servr.sendNetworkMsg(new propReqCmd(new ObjID(id), this._attrID));
+ } catch (InfiniteWaitException var7) {
+ } catch (PacketTooLargeException var8) {
+ assert false;
+ }
+ }
+ } else {
+ if (callback != null) {
+ callback.loadedAttribute(this, "unshared");
+ }
+ }
+ }
+ }
+
+ public int getAttrID() {
+ return this._attrID;
+ }
+
+ public Attribute(int attrID) {
+ this._attrID = attrID;
+ }
+
+ public Attribute() {
+ }
+
+ public void setAttrID(int newID) {
+ this.flushBuffers();
+ Sharer sharer = (Sharer)this.getOwner();
+ if (sharer == null) {
+ this._attrID = newID;
+ } else {
+ sharer.resetAttributeID(this, newID);
+ }
+ }
+
+ private void flushBuffers() {
+ this._serverData = null;
+ this._waitingForFeedback = false;
+ this._outgoing = null;
+ }
+
+ public int getForwardAttrID() {
+ return this._to != null ? this._to._attrID : this._storedForwardAttrID;
+ }
+
+ public void unforward() {
+ if (this._to != null) {
+ this._storedForwardAttrID = this._to.getAttrID();
+ Sharer s = (Sharer)this._to.getOwner();
+ if (s != null) {
+ s.removeAttribute(this._to);
+ }
+ }
+
+ this.flushBuffers();
+ }
+
+ public boolean isForwarded() {
+ return this._to != null;
+ }
+
+ public Attribute getForwardAttribute() {
+ return this._to;
+ }
+
+ public void setForwardAttrID(int newID) {
+ if (this._to != null) {
+ this._to.setAttrID(newID);
+ } else {
+ this._storedForwardAttrID = newID;
+ }
+ }
+
+ public void noteChange() {
+ Sharer sharer = (Sharer)this.getOwner();
+ if (sharer != null) {
+ sharer.noteChange(this, this.actions.size() > 0);
+ }
+ }
+
+ public void addForwarding() {
+ if (!this.isForwarded()) {
+ Sharer s = (Sharer)this.getOwner();
+
+ assert ((WObject)s.getOwner()).getSharerMode() == 3;
+
+ WObject terminal = ((WObject)s.getOwner()).getServed();
+ if (terminal != null) {
+ if (this.getOwner().getOwner() != terminal) {
+ ForwardAttribute fwd = new ForwardAttribute(this, this._storedForwardAttrID);
+ terminal.addShareableAttribute(fwd);
+ this._to = fwd;
+ }
+ }
+ }
+ }
+
+ public abstract void generateNetData(DataOutputStream var1) throws IOException;
+
+ public abstract void setFromNetData(DataInputStream var1, int var2) throws IOException;
+
+ @Override
+ public void detach() {
+ super.detach();
+ this.unforward();
+ }
+
+ public int getFlags() {
+ return this._propertyFlags;
+ }
+
+ public void setFlag(int flag, boolean onoff) {
+ if (onoff) {
+ this._propertyFlags |= flag;
+ } else {
+ this._propertyFlags &= ~flag;
+ }
+ }
+
+ public void setFinger(boolean onoff) {
+ this.setFlag(32, onoff);
+ }
+
+ public boolean getFinger() {
+ return (this.getFlags() & 32) != 0;
+ }
+
+ public void setAutoUpdate(boolean onoff) {
+ this.setFlag(64, onoff);
+ }
+
+ public boolean getAutoUpdate() {
+ return (this.getFlags() & 64) != 0;
+ }
+
+ public void setDatabase(boolean onoff) {
+ this.setFlag(128, onoff);
+ }
+
+ public boolean getDatabase() {
+ return (this.getFlags() & 128) != 0;
+ }
+
+ public void setBinary(boolean onoff) {
+ this.setFlag(16, onoff);
+ }
+
+ public boolean getBinary() {
+ return (this.getFlags() & 16) != 0;
+ }
+
+ public int getAccessFlags() {
+ return this._accessFlags;
+ }
+
+ public void setAccessFlags(int flags) {
+ this._accessFlags = flags;
+ }
+
+ @Override
+ public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
+ Object ret = null;
+ switch (index - offset) {
+ case 0:
+ if (mode == 0) {
+ ret = IntegerPropertyEditor.make(new Property(this, index, "Attribute ID"));
+ } else if (mode == 1) {
+ ret = new Integer(this._attrID);
+ } else if (mode == 2) {
+ int id = (Integer)value;
+ if (id >= 0 && id <= 255) {
+ this.setAttrID(id);
+ } else {
+ Console.println(Console.message("Attribute-id"));
+ }
+ }
+ break;
+ case 1:
+ if (mode == 0) {
+ ret = BooleanPropertyEditor.make(new Property(this, index, "Fingerable"), "No", "Yes");
+ } else if (mode == 1) {
+ ret = new Boolean(this.getFinger());
+ } else if (mode == 2) {
+ this.setFinger((Boolean)value);
+ }
+ break;
+ case 2:
+ if (mode == 0) {
+ ret = BooleanPropertyEditor.make(new Property(this, index, "Auto Update"), "No", "Yes");
+ } else if (mode == 1) {
+ ret = new Boolean(this.getAutoUpdate());
+ } else if (mode == 2) {
+ this.setAutoUpdate((Boolean)value);
+ }
+ break;
+ case 3:
+ if (mode == 0) {
+ ret = BooleanPropertyEditor.make(new Property(this, index, "Store in Database"), "No", "Yes");
+ } else if (mode == 1) {
+ ret = new Boolean(this.getDatabase());
+ } else if (mode == 2) {
+ this.setDatabase((Boolean)value);
+ }
+ break;
+ case 4:
+ if (mode == 0) {
+ ret = IntegerPropertyEditor.make(new Property(this, index, "Shorthand version"));
+ } else if (mode == 1) {
+ ret = new Integer(this._shorthandVersion);
+ } else if (mode == 2) {
+ int id = (Integer)value;
+ if (id >= 0 && id <= this.getMaxShorthandVersion()) {
+ this._shorthandVersion = id;
+ } else {
+ Console.println(Console.message("Shorthand-version") + " " + this.getMaxShorthandVersion());
+ }
+ }
+ break;
+ case 5:
+ if (mode == 0) {
+ ret = IntegerPropertyEditor.make(new Property(this, index, "Forwarder attrID"));
+ } else if (mode == 1) {
+ ret = new Integer(this.getForwardAttrID());
+ } else if (mode == 2) {
+ int id = (Integer)value;
+ if (id >= 0 && id <= 255) {
+ this.setForwardAttrID(id);
+ } else {
+ Console.println(Console.message("Attribute-id"));
+ }
+ }
+ break;
+ case 6:
+ if (mode == 0) {
+ ret = BooleanPropertyEditor.make(new Property(this, index, "Load Now"), "No", "Yes");
+ } else if (mode == 1) {
+ ret = new Boolean(false);
+ } else if (mode == 2 && (Boolean)value) {
+ this.load(null);
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 7, mode, value);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Object propertyParent() {
+ return this.getOwner().getOwner();
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ s.saveVersion(5, classCookie);
+ super.saveState(s);
+ s.saveInt(this._attrID);
+ s.saveInt(this.getForwardAttrID());
+ s.saveInt(this._propertyFlags);
+ s.saveInt(this._shorthandVersion);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException, TooNewException {
+ switch (r.restoreVersion(classCookie)) {
+ case 0:
+ this._attrID = r.restoreInt();
+ if (r.restoreBoolean()) {
+ this._storedForwardAttrID = r.restoreInt();
+ } else {
+ r.restoreInt();
+ }
+ break;
+ case 1:
+ this._attrID = r.restoreInt();
+ this._storedForwardAttrID = r.restoreInt();
+ break;
+ case 2:
+ this._attrID = r.restoreInt();
+ this._storedForwardAttrID = r.restoreInt();
+ this._propertyFlags = r.restoreInt();
+ break;
+ case 3:
+ this.restoreStateSuperRoot(r);
+ this._attrID = r.restoreInt();
+ this._storedForwardAttrID = r.restoreInt();
+ this._propertyFlags = r.restoreInt();
+ break;
+ case 4:
+ this.restoreStateSuperRoot(r);
+ this._attrID = r.restoreInt();
+ this._storedForwardAttrID = r.restoreInt();
+ this._propertyFlags = r.restoreInt();
+ this._shorthandVersion = r.restoreInt();
+ break;
+ case 5:
+ super.restoreState(r);
+ this._attrID = r.restoreInt();
+ this._storedForwardAttrID = r.restoreInt();
+ this._propertyFlags = r.restoreInt();
+ this._shorthandVersion = r.restoreInt();
+ break;
+ default:
+ throw new TooNewException();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return this.isForwarded() ? super.toString() + "[forwarded to " + this._to.getName() + "]" : super.toString();
+ }
+
+ public void releaseAuxilaryData() {
+ }
+}