package NET.worlds.console; import NET.worlds.core.IniFile; import NET.worlds.core.Std; import NET.worlds.network.ConnectionWaiter; import NET.worlds.network.DNSLookup; import NET.worlds.network.Galaxy; import NET.worlds.network.InfiniteWaitException; import NET.worlds.network.InvalidServerURLException; import NET.worlds.network.NetworkObject; import NET.worlds.network.OldPropertyList; import NET.worlds.network.PacketTooLargeException; import NET.worlds.network.PropertyList; import NET.worlds.network.PropertySetCmd; import NET.worlds.network.URL; import NET.worlds.network.VarErrorException; import NET.worlds.network.WorldServer; import NET.worlds.network.net2Property; import NET.worlds.scape.Attribute; import NET.worlds.scape.BooleanPropertyEditor; import NET.worlds.scape.Drone; import NET.worlds.scape.FrameEvent; import NET.worlds.scape.FrameHandler; import NET.worlds.scape.HoloDrone; import NET.worlds.scape.HoloPilot; import NET.worlds.scape.InventoryManager; import NET.worlds.scape.LoadedURLSelf; import NET.worlds.scape.NoSuchPropertyException; import NET.worlds.scape.Pilot; import NET.worlds.scape.ProgressiveAdder; import NET.worlds.scape.PropAdder; import NET.worlds.scape.Property; import NET.worlds.scape.Restorer; import NET.worlds.scape.Room; import NET.worlds.scape.Saver; import NET.worlds.scape.StringPropertyEditor; import NET.worlds.scape.SuperRoot; import NET.worlds.scape.TeleportStatus; import NET.worlds.scape.TooNewException; import NET.worlds.scape.URLPropertyEditor; import NET.worlds.scape.URLSelf; import NET.worlds.scape.URLSelfLoader; import NET.worlds.scape.VectorProperty; import NET.worlds.scape.WObject; import NET.worlds.scape.WobLoaded; import NET.worlds.scape.WobLoader; import NET.worlds.scape.World; import java.awt.CardLayout; import java.awt.CheckboxMenuItem; import java.awt.Container; import java.awt.Event; import java.awt.Font; import java.awt.Menu; import java.awt.MenuBar; import java.awt.MenuItem; import java.awt.MenuShortcut; import java.awt.Panel; import java.awt.PopupMenu; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URLConnection; import java.text.MessageFormat; import java.util.Enumeration; import java.util.Hashtable; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Vector; public abstract class Console extends SuperRoot implements URLSelf, MainCallback, NetworkObject, WobLoaded, DialogDisabled, ConnectionWaiter { private static Vector storedLines = new Vector(); protected boolean disableShaperAccess = false; protected boolean disableSingleUserAccess = false; private static Console active; private Panel myCard; private static int nameCounter; private static Font font = new Font(message("MenuFont"), 0, 12); private URL targetAv; private static String activeTeleportURL; private static String lastTeleportURL; private static FrameEvent frameEvent; private static int freezeFrameEvents = 0; private String sleepMode = ""; private int lastUserAction; private Vector parts = new Vector(); private static MenuBar menuBar = new MenuBar(); protected boolean enableMenu = false; protected MenuItem exitItem; private Hashtable menus = new Hashtable(); protected static boolean autoFullVIP = IniFile.override().getIniInt("tieredVIP", 0) == 0; protected static boolean isRedLightWorld = IniFile.override().getIniString("ProductName", "").equalsIgnoreCase("RedLightWorld") || IniFile.override().getIniString("ProductName", "").equalsIgnoreCase("RedLightCenter"); protected static int vip = IniFile.gamma().getIniInt("VIP", 0) != 0 ? (autoFullVIP ? 2 : 1) : 0; protected static int spguest = IniFile.gamma().getIniInt("SPGUEST", 0) != 0 ? 2 : 0; private boolean canBroadcast = false; protected URL lastPilotRequested; public String pendingPilot = ""; protected boolean setFromMenu = false; private String postFix = ""; public static boolean selfCustom = false; protected Vector callbacks = new Vector(); private String defaultAction = ""; protected String tempCarAvatar = ""; protected static String defaultConsole = IniFile.gamma().getIniString("DEFAULTCONSOLE", "NET.worlds.console.DefaultConsole"); private static Hashtable defConsoles = new Hashtable(); private static Console defaultUnshared; private int refcnt = 0; protected Pilot pilotSoulTemplate; protected Drone droneSoulTemplate; protected Pilot pilot; public boolean targetValid = false; private String sleepStr = message("asleep"); protected static GammaFrame frame = new GammaFrame(); protected Galaxy galaxy = null; protected URL _galaxyURL; private Cursor cursor = new Cursor(URL.make("system:WAIT_CURSOR")); private Vector tempArea = new Vector(); private static Object classCookie = new Object(); static { WhisperManager.whisperManager().setParent(frame); } public static synchronized void println(String msg) { if (active != null) { active.printLine(msg); } else { storedLines.addElement(msg); } } public static void printWhisper(String from, String msg) { if (active != null) { active.printWhisperFrom(from, msg); } } public static void printOwnWhisper(String to, String msg) { if (active != null) { active.printWhisperTo(to, msg); } } public static void startWhispering(String to) { if (active != null) { active.startWhisperingTo(to); } } public static synchronized String message(String Id) { Locale currentLocale = Locale.getDefault(); try { String bundlePrefix = IniFile.override().getIniString("BundlePrefix", "MessagesBundle"); ResourceBundle messages = ResourceBundle.getBundle(bundlePrefix, currentLocale); String mess = messages.getString(Id); if (mess.indexOf(123) == -1 && mess.indexOf(125) == -1) { mess = Std.replaceStr(mess, "''", "'"); } if (mess.lastIndexOf(".gif") > 0 || mess.lastIndexOf(".jpg") > 0 || mess.lastIndexOf(".bmp") > 0) { File f = new File(mess); if (!f.exists()) { return Id; } } return mess; } catch (MissingResourceException var6) { if (Galaxy.getDebugLevel() != 0) { System.out.println("MRE: " + var6.getClassName() + " " + var6.getKey()); System.out.println("NO MESSAGE for " + Id); } return Id; } } public static synchronized String parseUnicode(String s) { if (s == null) { return s; } else { int idx; while ((idx = s.indexOf("\\u")) != -1) { if (idx >= s.length() - 5) { return s; } String x = s.substring(idx + 2, idx + 6); char p = (char)Integer.parseInt(x, 16); String tmp = s.substring(0, idx) + p + s.substring(idx + 6); s = tmp; } return s; } } public static synchronized Vector parseUnicode(Vector cc) { for (int i = 0; i < cc.size(); i++) { String s = cc.elementAt(i); String s2 = parseUnicode(s); cc.setElementAt(s2, i); } return cc; } public static synchronized String parseExtended(String s) { String uc = ""; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c > 255) { int ii = c; try { uc = uc + "\\u" + Integer.toHexString(ii); } catch (NumberFormatException var6) { uc = uc + "?"; } } else { uc = uc + c; } } return uc; } public static boolean wasHttpNoSuchFile(String us) { java.net.URL u = null; URLConnection uc = null; try { u = DNSLookup.lookup(new java.net.URL(us)); uc = u.openConnection(); } catch (Exception var5) { return true; } try { return ((HttpURLConnection)uc).getResponseCode() == 404; } catch (Exception var4) { return true; } } protected void printWhisperFrom(String from, String msg) { if (!msg.startsWith("&|+")) { Object[] arguments = new Object[]{new String(from), new String(msg)}; println(MessageFormat.format(message("whispered"), arguments)); } } protected void printWhisperTo(String to, String msg) { if (!msg.startsWith("&|+")) { Object[] arguments = new Object[]{new String(to), new String(msg)}; println(MessageFormat.format(message("You-whispered"), arguments)); } } protected void startWhisperingTo(String to) { Object[] arguments = new Object[]{new String(to)}; println(MessageFormat.format(message("You-want-whisp"), arguments)); } public void printLine(String msg) { System.out.println(msg); } public boolean isShaperAccessDisabled() { return this.disableShaperAccess; } public boolean isSingleUserAccessDisabled() { return this.disableSingleUserAccess; } public static Console getActive() { return active; } public void inventoryChanged() { } public void forPilotOnlyActivate() { if (active != this) { this.myCard = new Panel(); String myCardName = "" + nameCounter++; Container consoleTile = frame.getConsoleTile(); consoleTile.add(myCardName, this.myCard); Console prev = active; this.activate(this.myCard); ((CardLayout)consoleTile.getLayout()).show(consoleTile, myCardName); getFrame().validate(); if (prev != null) { consoleTile.remove(prev.myCard); prev.myCard.removeAll(); } } } protected void setEnableMenu(boolean enable) { this.enableMenu = enable; if (this == active) { enable |= Gamma.shaper != null; boolean enabled = frame.getMenuBar() == menuBar && menuBar != null; if (enable != enabled) { frame.setMenuBar(enable ? menuBar : null); frame.pack(); } } } private static synchronized void setActive(Console active) { Console.active = active; int sz = storedLines.size(); if (sz > 0) { for (int i = 0; i < sz; i++) { active.printLine(storedLines.elementAt(i)); } storedLines.removeAllElements(); } } protected void activate(Container c) { assert this.pilot != null; Console prev = active; if (active != null) { active.deactivate(); } setActive(this); Main.register(this); this.menus.clear(); menuBar = new MenuBar(); this.getMenu("File"); if (Gamma.shaper != null) { Gamma.shaper.activate(this, c, prev); } int len = this.parts.size(); for (int i = 0; i < len; i++) { this.parts.elementAt(i).activate(this, c, prev); } this.exitItem = this.addMenuItem(message("Exit"), "File"); if (activeTeleportURL != null) { teleportNotification("", activeTeleportURL); } this.cursor.activate(); } protected void menuDone() { this.setEnableMenu(this.enableMenu); } protected void deactivate() { if (active == this) { setActive(null); Main.unregister(this); int len = this.parts.size(); for (int i = 0; i < len; i++) { this.parts.elementAt(i).deactivate(); } if (Gamma.shaper != null) { Gamma.shaper.deactivate(); } this.cursor.deactivate(); frame.deactivate(); } } public String getActiveTeleportURL() { return lastTeleportURL == null ? "" : lastTeleportURL; } public static void teleportNotification(String err, String url) { if (err != null && err.length() == 0) { activeTeleportURL = url; lastTeleportURL = url.toString(); } else { activeTeleportURL = null; } if (active != null) { if (active instanceof TeleportStatus) { ((TeleportStatus)active).teleportStatus(err, url); } int len = active.parts.size(); for (int i = 0; i < len; i++) { Object fp = active.parts.elementAt(i); if (fp instanceof TeleportStatus) { ((TeleportStatus)fp).teleportStatus(err, url); } } } } public static void setFreezeFrameEvents(boolean x) { if (x) { freezeFrameEvents++; } else { freezeFrameEvents--; assert freezeFrameEvents >= 0; } } @Override public void mainCallback() { if (frameEvent == null) { frameEvent = new FrameEvent(null, null); } if (freezeFrameEvents <= 0) { frameEvent.newFrameTime(); frameEvent.source = this; this.generateFrameEvents(frameEvent); frameEvent.target = null; frameEvent.receiver = null; frameEvent.source = null; } } public void generateFrameEvents(FrameEvent f) { World.generateFrameEvents(f); int now = Std.getFastTime(); if (Window.getAndResetUserActionCount() != 0) { this.setSleepMode(null); this.lastUserAction = now; } else if (now > this.lastUserAction + 300000) { if (this.lastUserAction == 0) { this.lastUserAction = now; } else { this.goToSleep(); } } int len = this.parts.size(); if (Main.profile != 0) { for (int i = 0; i < len; i++) { FramePart fp = this.parts.elementAt(i); int start = Std.getRealTime(); long startBytes = Runtime.getRuntime().freeMemory(); fp.handle(f); int dur = Std.getRealTime() - start; long used = startBytes - Runtime.getRuntime().freeMemory(); if (dur > Main.profile) { System.out.println("Took " + dur + "ms and " + used + " bytes to call framePart " + fp); } } } else { for (int ix = 0; ix < len; ix++) { this.parts.elementAt(ix).handle(f); } } ProgressiveAdder.get().handle(f); if (this instanceof FrameHandler) { ((FrameHandler)this).handle(f); } if (this.pilot != null) { this.pilot.generateFrameEvents(f); } } public void addPart(FramePart p) { this.parts.addElement(p); } public Enumeration getParts() { return this.parts.elements(); } public boolean action(Event event, Object what) { if (event.target == this.exitItem) { return maybeQuit(); } else if (Gamma.shaper != null && Gamma.shaper.action(event, what)) { return true; } else { int len = this.parts.size(); for (int i = 0; i < len; i++) { if (this.parts.elementAt(i).action(event, what)) { return true; } } return false; } } public boolean handleEvent(Event e) { return e.id == 201 ? maybeQuit() : false; } public boolean okToQuit() { return true; } public static void quit() { if (Gamma.getShaper() != null) { Gamma.getShaper().maybeQuit(); } else { GammaFrameState.saveBorder(); Main.end(); } } public static boolean maybeQuit() { Console c = getActive(); if (c == null || c.okToQuit()) { quit(); } return true; } public static MenuBar getMenuBar() { return menuBar; } public Menu getMenu(String name) { Menu menu = this.menus.get(name); if (menu == null) { if (!name.equals("Help") && !name.equals("Options") && !name.equals("VIP")) { menu = new Menu(name); menuBar.add(menu); } else { menu = new PopupMenu(); } this.menus.put(name, menu); } return menu; } public void addMenuItem(MenuItem item, String menuName) { this.getMenu(menuName).add(item); item.setFont(font); } public MenuItem addMenuItem(String itemName, String menuName) { MenuItem item = new MenuItem(itemName); this.getMenu(menuName).add(item); item.setFont(font); return item; } public MenuItem addMenuItem(String itemName, String menuName, int keyCode, boolean shiftKey) { MenuItem item = new MenuItem(itemName); MenuShortcut shortcut = new MenuShortcut(keyCode, shiftKey); item.setShortcut(shortcut); this.getMenu(menuName).add(item); item.setFont(font); return item; } public CheckboxMenuItem addMenuCheckbox(String itemName, String menuName) { CheckboxMenuItem item = new CheckboxMenuItem(itemName); this.getMenu(menuName).add(item); item.setFont(font); return item; } @Override public void dialogDisable(boolean disable) { int len = this.parts.size(); for (int i = 0; i < len; i++) { FramePart part = this.parts.elementAt(i); if (part instanceof DialogDisabled) { ((DialogDisabled)part).dialogDisable(disable); } } } public static final native String encrypt(String var0); public static final native String decrypt(String var0); public static String encode(String password) { String coded = ""; if (password != null) { char[] cryptChars = encrypt(password).toCharArray(); for (int i = 0; i < cryptChars.length; i++) { String hex = Integer.toHexString(cryptChars[i]); if (hex.length() == 1) { hex = "0" + hex; } coded = coded + hex; } } return coded; } public static String decode(String password) { try { int length = password.length(); if (length != 0 && (length & 1) == 0) { char[] cryptChars = new char[length / 2]; int j = 0; for (int i = 0; i < cryptChars.length; j += 2) { cryptChars[i] = (char)Integer.parseInt(password.substring(j, j + 2), 16); i++; } String ret = decrypt(new String(cryptChars)); if (ret != null && ret.length() != 0) { return ret; } } } catch (NumberFormatException var5) { } return null; } public static final native int getVolumeInfo(); public boolean getVIPAvatars() { return vip > 0 || isRedLightWorld; } public boolean getVIP() { return vip > 0; } public void setVIP(boolean vip) { Console.vip = vip ? 1 : 0; this.checkCourtesyVIP(); IniFile.gamma().setIniInt("VIP", Console.vip); if (autoFullVIP && vip) { Console.vip = 2; } } public boolean getFullVIP() { return vip == 2; } public void setFullVIP(boolean fullVIP) { if (fullVIP) { vip = 2; } IniFile.gamma().setIniInt("VIP", vip); } public boolean getSpecialGuest() { return spguest > 0; } public void setSpecialGuest(boolean spguest) { if (Console.spguest > 1 != spguest) { Console.spguest = spguest ? 1 : 0; IniFile.gamma().setIniInt("SPGUEST", Console.spguest); Console.spguest = Console.spguest + Console.spguest; } } public void checkCourtesyVIP() { int oldVIP = vip; if (vip < 1) { World w = this.getPilot().getWorld(); vip = w != null && w.isHomeWorld() && w.getCourtesyVIP() ? 1 : 0; } if (vip != oldVIP) { if (vip == 1) { println(message("You-VIP")); } else { println(message("You-no-VIP")); } } URL av = this.getDefaultAvatarURL(); if (!av.equals(this.getAvatarName())) { this.setAvatar(av); } } public boolean broadcastEnabled() { return this.canBroadcast; } public void enableBroadcast(boolean enabled) { this.canBroadcast = enabled; } public abstract URL getAvatarName(); public abstract void setChatname(String var1); public void serverStatus(WorldServer serv, VarErrorException ve) { System.out.println("status-- " + serv + ": " + ve.getMsg()); } @Override public void property(OldPropertyList propList) { assert false; } @Override public void propertyUpdate(PropertyList propList) { assert false; } @Override public WorldServer getServer() { URL url = this.getGalaxyURL(); if (url != null && this.galaxy != null) { try { return this.getGalaxy().getServer(url); } catch (InvalidServerURLException var3) { println(">>" + var3.getMessage()); return null; } } else { return null; } } public WorldServer getServerNew() { URL url = this.getGalaxyURL(); if (url != null && this.galaxy != null) { try { return this.getGalaxy().getServer(url); } catch (InvalidServerURLException var3) { println(">>" + var3.getMessage()); return null; } } else { return null; } } @Override public String getLongID() { return this.galaxy.getChatname(); } @Override public void register() { } @Override public void galaxyDisconnected() { this.setChatname(""); this.galaxy.waitForConnection(this); } @Override public void reacquireServer(WorldServer oldServ) { } @Override public void changeChannel(Galaxy g, String oldChannel, String newChannel) { this.pilot.changeChannel(g, oldChannel, newChannel); } protected void handleVAR_BITMAP(String s) { if (s.charAt(0) == 0) { s = s.substring(2); } try { this.loadPilot(new URL(URL.getAvatar(), s)); } catch (MalformedURLException var3) { this.loadPilot(URL.make("error:\"" + s + '"')); } } protected void loadPilot(URL url) { if (!url.equals(this.lastPilotRequested)) { this.lastPilotRequested = url; this.pendingPilot = url.toString(); Pilot.load(url, this); this.setFromMenu = false; } } @Override public void wobLoaded(WobLoader loader, SuperRoot w) { String err = null; if (w == null) { err = message("no-load-pilot"); println(err + " " + loader.getWobName()); } else if (!(w instanceof Pilot)) { err = message("not-pilot"); println(loader.getWobName().toString() + " " + err); } else { try { this.setPilot((Pilot)w); } catch (IllegalPilotException var7) { err = var7.getMessage(); } } if (this.pilot == null && err != null && !this.disableSingleUserAccess) { this.useDefaultPilot(); err = null; } int end = this.callbacks.size(); for (int i = 0; i < end; i++) { LoadedURLSelf callback = this.callbacks.elementAt(i); if (err == null) { callback.loadedURLSelf(this, this.getSourceURL(), null); } else { this.decRef(); callback.loadedURLSelf(null, this.getSourceURL(), err); } } this.callbacks.removeAllElements(); } public static URL getDefaultURL() { String defaultAvatar = IniFile.override().getIniString("DefaultAvatar", "avatar:pengo.mov"); return URL.make(defaultAvatar); } protected void useDefaultPilot() { try { this.setPilot(new HoloPilot(getDefaultURL())); } catch (IllegalPilotException var2) { assert false; } } public abstract void setOnlineState(boolean var1, boolean var2); @Override public void connectionCallback(Object caller, boolean connected) { if (caller instanceof Galaxy) { if (caller != this.galaxy) { return; } if (!connected) { return; } this.setAvatar(this.lastPilotRequested); this.displayAds(); } } public void displayAds() { Pilot p = Pilot.getActive(); if (p != null) { World w = p.getWorld(); if (w != null) { w.setupAdBanner(); } } } public void setDefaultAction(String newda) { this.defaultAction = newda; } public String getDefaultAction() { return this.defaultAction; } public URL getDefaultAvatarURL() { String defAv = getDefaultURL().toString(); String av = IniFile.gamma().getIniString("AVATAR", defAv); String vav = IniFile.gamma().getIniString("VIPAVATAR", ""); boolean isVIPAv = av.toLowerCase().endsWith(".rwg"); if (vav.equals("")) { vav = av; if (isVIPAv) { IniFile.gamma().setIniString("VIPAVATAR", av); } } if (this.tempCarAvatar != "") { av = this.tempCarAvatar; } else if (this.getVIPAvatars()) { av = vav; } else if (isVIPAv) { av = defAv; } return URL.make(av); } public Console() { this.add(this.cursor); this.galaxy = Galaxy.getAnonGalaxy(); this.regWithGalaxy(); this.setServerURL(null); } public Console(URL serverURL) { this.add(this.cursor); this.galaxy = Galaxy.getAnonGalaxy(); this.regWithGalaxy(); this.setServerURL(serverURL); this.templateInit(); } @Override public void loadInit() { this.templateInit(); this.add(this.cursor); } public void addCursor(Cursor c) { this.add(c); } private void templateInit() { this.pilotSoulTemplate = new HoloPilot(); this.droneSoulTemplate = new HoloDrone(); this.add(this.pilotSoulTemplate); this.add(this.droneSoulTemplate); } public static void load(URL url, LoadedURLSelf callback) { if (url != null && url.endsWith(".console")) { new ConsoleLoader(url, callback); } else { Console c; if (url == null) { c = defaultUnshared; } else { c = defConsoles.get(url); } if (c != null && c.galaxy == null) { if (c.getGalaxyURL() == null) { c.galaxy = Galaxy.getAnonGalaxy(); } else { try { c.galaxy = Galaxy.getGalaxy(c.getGalaxyURL()); } catch (InvalidServerURLException var5) { System.out.println("Illegal ServerURL = " + c.getGalaxyURL()); c.galaxy = Galaxy.getAnonGalaxy(); c.setServerURL(null); } } c.regWithGalaxy(); c.regPilot(); } assert c == null || c.galaxy != null; if (c == null) { try { Class cl = Class.forName(defaultConsole); c = (Console)cl.newInstance(); } catch (Exception var4) { System.out.println("Can't use class " + defaultConsole + ", using DefaultConsole instead."); var4.printStackTrace(System.out); c = new DefaultConsole(); } assert c != null; if (c.galaxy == null) { c.galaxy = Galaxy.getAnonGalaxy(); c.regWithGalaxy(); c.regPilot(); } assert c.galaxy != null; c.loadInit(); c.setServerURL(url); if (url == null) { c.setName("unshared"); defaultUnshared = c; } else { defConsoles.put(c.getGalaxyURL(), c); } } c.incRef(); c.initPilot(url, callback); } } protected void initPilot(URL pilotURL, LoadedURLSelf callback) { this.loadPilot(this.getDefaultAvatarURL()); if (this.pilot == null) { this.useDefaultPilot(); } callback.loadedURLSelf(this, pilotURL, null); } @Override public void incRef() { this.refcnt++; } @Override public void decRef() { if (--this.refcnt == 0) { if (this.galaxy != null) { this.unregWithGalaxy(); this.unregPilot(); this.galaxy.decWorldCount(); Galaxy oldGalaxy = this.galaxy; this.galaxy = null; } this.pilot = null; URL url = this.getSourceURL(); if (url != null) { if (url.endsWith(".console")) { URLSelfLoader.unload(this); } else { defConsoles.remove(url); } } } } @Override public String toString() { return super.toString() + "[" + this.getSourceURL() + "]"; } public Pilot getPilotSoulTemplate() { return this.pilotSoulTemplate; } public Drone getDroneSoulTemplate() { return this.droneSoulTemplate; } public Pilot getPilot() { return this.pilot; } public boolean isValidAv() { if (this.targetAv == null) { return false; } else if (!InventoryManager.getInventoryManager().inventoryInitialized()) { return true; } else { String av = this.targetAv.getAbsolute(); int len = av.length(); for (int i = 1; i < len; i++) { if (av.charAt(i - 1) == '_') { char firstChar = av.charAt(i); if (Character.isLowerCase(firstChar)) { StringBuffer item = new StringBuffer(); item.append(Character.toUpperCase(firstChar)); while (++i < len) { char c = av.charAt(i); if (!Character.isLowerCase(c)) { break; } item.append(c); } if (InventoryManager.getInventoryManager().checkInventoryFor(item.toString()) <= 0) { return false; } } } } return true; } } public void resetAvatar() { this.setAvatar(this.targetAv); } public void setAvatar(URL url) { if (url != null) { BlackBox.getInstance().submitEvent(new BBDroneBitmapCommand("@Pilot", url.toString())); this.targetAv = url; this.targetValid = true; if (url.getAbsolute().length() > 220) { println(message("av-too-complex")); url = URL.make("avatar:holden.mov"); this.targetValid = false; } else if (!this.isValidAv()) { println(message("av-has-inventory")); url = URL.make("avatar:holden.mov"); this.targetValid = false; } this.loadPilot(url); WorldServer serv = this.getServerNew(); if (serv != null) { assert serv.getVersion() >= 18; PropertyList propList = new PropertyList(); propList.addProperty(new net2Property(5, 64, 1, url.getAbsolute())); try { serv.sendNetworkMsg(new PropertySetCmd(propList)); } catch (PacketTooLargeException var5) { assert url.getAbsolute().length() < 220; assert false; } catch (InfiniteWaitException var6) { } } } } public static void wake() { if (active != null) { active.setSleepMode(null); } } public void goToSleep() { this.setSleepMode(this.sleepStr); Window.getAndResetUserActionCount(); } public boolean isSleeping() { return !this.sleepMode.equals(""); } protected void setSleepMode(String mode) { if (mode == null) { mode = ""; this.lastUserAction = Std.getFastTime(); } if (this.pilot != null) { this.pilot.setSleepMode(mode); } if (!mode.equals(this.sleepMode)) { WorldServer serv = this.getServerNew(); if (serv != null) { PropertyList propList = new PropertyList(); propList.addProperty(new net2Property(23, 64, 1, mode)); try { serv.sendNetworkMsg(new PropertySetCmd(propList)); } catch (PacketTooLargeException var5) { assert false; } catch (InfiniteWaitException var6) { } this.sleepMode = mode; } } } public void setPilot(Pilot a) throws IllegalPilotException { assert a != null; Room prevRoom = null; if (this.pilot != null) { prevRoom = this.pilot.getRoom(); this.unregPilot(); } this.pilot = a; this.pilot.getSharer().createDynamicFromNet(); this.pilot.setConsole(this); this.regPilot(); if (active == this) { Pilot.changeActiveRoom(prevRoom); } this.pilot.setSleepMode(this.sleepMode); if (this instanceof DefaultConsole) { ((DefaultConsole)this).resetCamera(); } } public static GammaFrame getFrame() { return frame; } public Galaxy getGalaxy() { assert this.galaxy != null; return this.galaxy; } public URL getGalaxyURL() { return this._galaxyURL; } public void setServerURL(URL serverURL) { try { if (serverURL != null) { this._galaxyURL = URL.make("worldserver://" + getServerHost(serverURL) + "/"); } } catch (InvalidServerURLException var5) { println(">>" + var5.getMessage()); assert false; this._galaxyURL = null; } Galaxy oldGalaxy = this.galaxy; this.unregWithGalaxy(); this.unregPilot(); if (this._galaxyURL != null) { try { this.galaxy = Galaxy.getGalaxy(this._galaxyURL); } catch (InvalidServerURLException var4) { println(">>" + var4.getMessage()); this.galaxy = Galaxy.getAnonGalaxy(); } } else { this.galaxy = Galaxy.getAnonGalaxy(); } assert this.galaxy != null; this.regWithGalaxy(); this.regPilot(); if (oldGalaxy != null) { oldGalaxy.decWorldCount(); if (oldGalaxy != this.galaxy) { oldGalaxy.forceObjectRereg(); } } } private void regWithGalaxy() { assert this.galaxy != null; this.galaxy.addConsole(this); this.galaxy.waitForConnection(this); } private void unregWithGalaxy() { assert this.galaxy != null; this.galaxy.delConsole(this); } protected void regPilot() { if (this.pilot != null) { this.pilot.getSharer().adjustShare(); } } public static String getServerHost(URL url) throws InvalidServerURLException { String s = url.unalias(); int len = s.length(); if (len > 14 && s.startsWith("worldserver://")) { if (s.charAt(len - 1) == '/') { len--; } s = s.substring(14, len); if (s.equals("209.67.68.214:6650")) { s = "www.3dcd.com:6650"; } return s; } else { throw new InvalidServerURLException("Bad worldserver:// URL format"); } } public static URL makeServerURL(String host) { assert host != null && host.length() > 0; return URL.make("worldserver://" + host + "/"); } protected void unregPilot() { if (this.pilot != null) { this.pilot.getSharer().adjustShare(); } } public Cursor getCursor() { return this.cursor; } public String getScriptServer() { String Fred = "Fred"; String override = IniFile.override().getIniString("ScriptServer", Fred); if (!override.equals(Fred)) { return new String(override); } else { WorldServer server = this.getServerNew(); if (server != null) { String sname = server.getScriptServer(); if (sname != null) { return new String(sname); } } return new String("http://www-dynamic.us.worlds.net/cgi-bin/"); } } public String getSmtpServer() { WorldServer server = this.getServerNew(); if (server != null) { String sname = server.getSmtpServer(); if (sname != null) { return sname; } } return "www.3dcd.com:25"; } public String getMailDomain() { WorldServer server = this.getServerNew(); if (server != null) { String dname = server.getMailDomain(); if (dname != null) { return dname; } } return "3dcd.com"; } @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 = URLPropertyEditor.make(new Property(this, index, "Server URL").allowSetNull(), null); } else if (mode == 1) { ret = this.getGalaxyURL(); } else if (mode == 2) { if (value == null) { this.setServerURL(null); } else { URL u = (URL)value; if (u != null && !u.unalias().startsWith("worldserver:")) { println(message("server-URL")); } else { this.setServerURL(u); } } } break; case 1: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Enable Menu Bar"), "No", "Yes"); } else if (mode == 1) { ret = new Boolean(this.enableMenu); } else if (mode == 2) { this.setEnableMenu((Boolean)value); } break; case 2: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Disable Shaper Access (irreversible!)"), "No", "Yes"); } else if (mode == 1) { ret = new Boolean(this.disableShaperAccess); } else if (mode == 2) { this.disableShaperAccess = (Boolean)value; } break; case 3: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Disable Single-user Access"), "No", "Yes"); } else if (mode == 1) { ret = new Boolean(this.disableSingleUserAccess); } else if (mode == 2) { this.disableSingleUserAccess = (Boolean)value; } break; case 4: if (mode == 0) { ret = new Property(this, index, "Pilot Soul Template"); } else if (mode == 1) { ret = this.pilotSoulTemplate; } break; case 5: if (mode == 0) { ret = new Property(this, index, "Drone Soul Template"); } else if (mode == 1) { ret = this.droneSoulTemplate; } break; case 6: if (mode == 0) { ret = new Property(this, index, "Cursor"); } else if (mode == 1) { ret = this.getCursor(); } break; case 7: if (mode == 0) { ret = PropAdder.make(new VectorProperty(this, index, "Temporary Area")); } else if (mode == 1) { ret = this.tempArea.clone(); } else if (mode == 4) { this.tempArea.removeElement(value); ((SuperRoot)value).detach(); } else if (mode == 3) { this.tempArea.addElement(value); this.add((SuperRoot)value); if (value instanceof Console) { Console c = (Console)value; if (c.pilotSoulTemplate == null) { c.loadInit(); } } } else if (mode == 5 && value instanceof SuperRoot && !(value instanceof Room)) { ret = value; } break; case 8: if (mode == 0) { ret = StringPropertyEditor.make(new Property(this, index, "Default Action")); } else if (mode == 1) { ret = this.getDefaultAction(); } else if (mode == 2) { this.setDefaultAction((String)value); } break; default: ret = super.properties(index, offset + 9, mode, value); } return ret; } @Override public void saveState(Saver s) throws IOException { s.saveVersion(4, classCookie); super.saveState(s); URL.save(s, this.getGalaxyURL()); s.saveBoolean(this.enableMenu); s.saveBoolean(this.disableShaperAccess); s.saveString(this.defaultAction); s.save(this.pilotSoulTemplate); s.save(this.droneSoulTemplate); s.save(this.cursor); } private static URL restoreOldURL(Restorer r) throws IOException { String s = r.restoreString(); return s != null && !s.equals("UNSHARED") ? makeServerURL(s) : null; } @Override public void restoreState(Restorer r) throws IOException, TooNewException { int vers = r.restoreVersion(classCookie); switch (vers) { case 0: case 1: WObject w = new WObject(); w.restoreState(r); this.setName(w.getName()); this.templateInit(); Enumeration e = w.getAttributes(); while (e.hasMoreElements()) { Attribute a = e.nextElement(); a.setAttrID(a.getForwardAttrID()); } Pilot.copySoul(w, this.pilotSoulTemplate); this.setServerURL(restoreOldURL(r)); this.enableMenu = r.restoreBoolean(); this.disableShaperAccess = r.restoreBoolean(); if (vers == 1) { this.cursor = (Cursor)r.restore(); } break; case 2: super.restoreState(r); this.setServerURL(restoreOldURL(r)); this.enableMenu = r.restoreBoolean(); this.disableShaperAccess = r.restoreBoolean(); this.pilotSoulTemplate = (Pilot)r.restore(); this.add(this.pilotSoulTemplate); this.droneSoulTemplate = (Drone)r.restore(); this.add(this.droneSoulTemplate); this.cursor = (Cursor)r.restore(); break; case 3: super.restoreState(r); this.setServerURL(restoreOldURL(r)); this.enableMenu = r.restoreBoolean(); this.disableShaperAccess = r.restoreBoolean(); this.defaultAction = r.restoreString(); this.pilotSoulTemplate = (Pilot)r.restore(); this.add(this.pilotSoulTemplate); this.droneSoulTemplate = (Drone)r.restore(); this.add(this.droneSoulTemplate); this.cursor = (Cursor)r.restore(); break; case 4: super.restoreState(r); this.setServerURL(URL.restore(r)); this.enableMenu = r.restoreBoolean(); this.disableShaperAccess = r.restoreBoolean(); this.defaultAction = r.restoreString(); this.pilotSoulTemplate = (Pilot)r.restore(); this.add(this.pilotSoulTemplate); this.droneSoulTemplate = (Drone)r.restore(); this.add(this.droneSoulTemplate); this.cursor = (Cursor)r.restore(); break; default: throw new TooNewException(); } this.add(this.cursor); } }