1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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() {
}
}
|