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
|
package NET.worlds.scape;
import NET.worlds.console.Console;
import NET.worlds.console.Main;
import NET.worlds.core.IniFile;
import NET.worlds.core.ServerTableManager;
import NET.worlds.network.ObjID;
import NET.worlds.network.URL;
import NET.worlds.network.WorldServer;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
public class HoloDrone extends Drone implements HoloCallback {
private WObject _avatar;
private WObject _realAvatar = null;
private boolean _isConstructing = false;
private Hologram _proxyHCnewImage = null;
private boolean _proxyHCok = false;
private static int _debugLevel = IniFile.gamma().getIniInt("dronedebug", 0);
private boolean permitAnyAvatar = IniFile.gamma().getIniInt("permitAnyAvatar", 0) != 0;
private static String[] permittedList;
private static String[] humanList;
private static Hashtable permittedHash;
private static Hashtable humanHash;
private static Object classCookie;
static {
if (_debugLevel > 0) {
System.out.println("DRONE DEBUGGING LEVEL = " + _debugLevel);
}
permittedList = ServerTableManager.instance().getTable("permittedHoloList");
humanList = ServerTableManager.instance().getTable("humanHoloList");
permittedHash = new Hashtable();
humanHash = new Hashtable();
for (int i = 0; i < permittedList.length; i += 2) {
if (permittedList[i + 1] != null) {
permittedHash.put(permittedList[i], permittedList[i + 1]);
} else {
permittedHash.put(permittedList[i], permittedList);
}
}
for (int ix = 0; ix < humanList.length; ix++) {
humanHash.put(humanList[ix], humanList[ix]);
}
classCookie = new Object();
}
public HoloDrone() {
}
public HoloDrone(ObjID objID, WorldServer serv) {
super(objID, serv);
assert Main.isMainThread();
if (this._proxyHCnewImage != null) {
this.holoCallback(this._proxyHCnewImage, this._proxyHCok);
this._proxyHCnewImage = null;
}
}
public static String[] getPermittedList() {
String[] result = new String[permittedList.length / 2];
for (int i = 0; i < result.length; i++) {
result[i] = permittedList[2 * i];
}
return result;
}
static URL permission(URL url) {
String name = url.getAbsolute().toLowerCase();
if (name.startsWith("avatar:") && name.endsWith(".mov")) {
name = name.substring(7, name.length() - 4);
Object newName = permittedHash.get(name);
if (newName == null) {
return null;
} else {
return newName instanceof String ? URL.make((String)newName) : url;
}
} else {
return null;
}
}
public static URL getHuman(URL url) {
if (!url.endsWith(".mov")) {
return PosableShape.getHuman(url);
} else if (permission(url) == null) {
return URL.make("avatar:holden.mov");
} else {
String s = url.getAbsolute().toLowerCase();
int len = s.length();
for (int i = 7; i < len; i++) {
if ("0123456789.".indexOf(s.charAt(i)) >= 0) {
if (humanHash.get(s.substring(7, i)) != null) {
return url;
}
return URL.make(IniFile.override().getIniString("defaultHumanAv", "avatar:holden.mov"));
}
}
return url;
}
}
@Override
public Drone setAvatarNow(URL url) {
if (!this.shouldBeMuted() && url.endsWith(".mov")) {
if (this.shouldBeForcedHuman()) {
url = getHuman(url);
}
url = PosableShape.getPermitted(url, this.getWorld());
if (url.equals(this.getSourceURL())) {
return this;
} else {
this.setSourceURL(url);
URL replacementURL = permission(url);
if (replacementURL != null) {
url = replacementURL;
} else if (!this.permitAnyAvatar) {
url = Console.getDefaultURL();
}
this._realAvatar = this.makeAvatar(url);
if (this._proxyHCnewImage != null) {
if ((_debugLevel & 1) > 0) {
System.out.println("Holo.stAvNow(" + url + "): doing proxy");
}
this.holoCallback(this._proxyHCnewImage, this._proxyHCok);
this._proxyHCnewImage = null;
}
return this;
}
} else {
return super.setAvatarNow(url);
}
}
public WObject makeAvatar(URL url) {
if ((_debugLevel & 1) > 0) {
System.out.println("HoloDrone.makeAvatar(" + url + ")");
}
this._isConstructing = true;
WObject bgAvatar = new Hologram(url, this);
this._isConstructing = false;
bgAvatar.setVisible(true);
bgAvatar.setBumpable(false);
return bgAvatar;
}
@Override
public void holoCallback(Hologram newImage, boolean ok) {
if ((_debugLevel & 1) > 0) {
System.out.println("HoloDrone.holoCallback(" + newImage + "," + ok + ")");
}
if (this._isConstructing) {
assert this._proxyHCnewImage == null;
this._proxyHCnewImage = newImage;
this._proxyHCok = ok;
if ((_debugLevel & 1) > 0) {
System.out.println("holoCallback: requesting proxy");
}
} else if (this._realAvatar == this._avatar) {
if ((_debugLevel & 1) > 0) {
System.out.println("holoCb: real avatar already loaded");
}
} else if (!ok) {
if (newImage == this._realAvatar) {
this._realAvatar = null;
}
if ((_debugLevel & 1) > 0) {
System.out.println("holoCb: not ok");
}
} else {
if ((_debugLevel & 1) > 0) {
System.out.println("holoCb: swapping avatars");
}
if (this._avatar != null) {
this._avatar.detach();
}
float avatarW = newImage.getW();
float avatarH = newImage.getH();
float factor;
if (avatarH < avatarW) {
factor = (float)Math.sqrt(25600.0F / (avatarW * avatarH));
} else {
factor = 160.0F / avatarH;
}
avatarH *= factor;
avatarW *= factor;
float heightAdj = 0.0F;
if (newImage == this._avatar) {
heightAdj = -this._avatar.getZ();
}
this._avatar = (WObject)newImage.scale(factor).raise(avatarH / 2.0F + heightAdj);
this.add(this._avatar);
this.avatarHeightChangedTo(avatarH);
}
}
@Override
public float getMinXYExtent() {
return this._avatar == null ? 0.0F : this._avatar.getMinXYExtent();
}
@Override
public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
Object ret = null;
int var10000 = index - offset;
return super.properties(index, offset + 0, mode, value);
}
@Override
public void saveState(Saver s) throws IOException {
s.saveVersion(0, classCookie);
super.saveState(s);
}
@Override
public void restoreState(Restorer r) throws IOException, TooNewException {
switch (r.restoreVersion(classCookie)) {
case 0:
super.restoreState(r);
Enumeration e = this.getContents();
while (e.hasMoreElements()) {
WObject w = (WObject)e.nextElement();
if (w instanceof Hologram) {
Hologram h = (Hologram)w;
if (h.getMovieName() != null) {
this._avatar = h;
}
}
}
return;
default:
throw new TooNewException();
}
}
}
|