- * Simple encoding is used, if java string does not contain - * any characters less, than 0x0020, or greater, than 0x007f. - * Simple encoding adds "/" character to capital letters, i.e. - * "A" is encoded as "/A". Character '\' is encoded as '//', - * '/' is encoded as '\'. - * The constructed string is converted to byte array by truncating the - * highest byte and adding the terminating null character. - *
- * altBase64 encoding is used, if java string does contain at least - * one character less, than 0x0020, or greater, than 0x007f. - * This encoding is marked by setting first two bytes of the - * Windows string to '/!'. The java name is then encoded using - * byteArrayToAltBase64() method from - * Base64 class. - */ - private static byte[] toWindowsName(String javaName) { - StringBuffer windowsName = new StringBuffer(); - for (int i = 0; i < javaName.length(); i++) { - char ch =javaName.charAt(i); - if ((ch < 0x0020)||(ch > 0x007f)) { - // If a non-trivial character encountered, use altBase64 - return toWindowsAlt64Name(javaName); - } - if (ch == '\\') { - windowsName.append("//"); - } else if (ch == '/') { - windowsName.append('\\'); - } else if ((ch >= 'A') && (ch <='Z')) { - windowsName.append("/" + ch); - } else { - windowsName.append(ch); - } - } - return stringToByteArray(windowsName.toString()); - } - - /** - * Converts value's or node's name to its Windows representation - * as a byte-encoded string, using altBase64 encoding. See - * {@link #toWindowsName(String) toWindowsName()} for a detailed - * description of encoding conventions. - */ - private static byte[] toWindowsAlt64Name(String javaName) { - byte[] javaNameArray = new byte[2*javaName.length()]; - // Convert to byte pairs - int counter = 0; - for (int i = 0; i < javaName.length();i++) { - int ch = javaName.charAt(i); - javaNameArray[counter++] = (byte)(ch >>> 8); - javaNameArray[counter++] = (byte)ch; - } - - return javaNameArray; - } - - /** - * Converts value string from its Windows representation - * to java string. See - * {@link #toWindowsValueString(String) toWindowsValueString()} for the - * description of the encoding algorithm. - */ - private static String toJavaValueString(byte[] windowsNameArray) { - // Use modified native2ascii algorithm - String windowsName = byteArrayToString(windowsNameArray); - StringBuffer javaName = new StringBuffer(); - char ch; - for (int i = 0; i < windowsName.length(); i++){ - if ((ch = windowsName.charAt(i)) == '/') { - char next = ' '; - - if (windowsName.length() > i + 1 && - (next = windowsName.charAt(i + 1)) == 'u') { - if (windowsName.length() < i + 6){ - break; - } else { - ch = (char)Integer.parseInt - (windowsName.substring(i + 2, i + 6), 16); - i += 5; - } - } else - if ((windowsName.length() > i + 1) && - ((windowsName.charAt(i+1)) >= 'A') && (next <= 'Z')) { - ch = next; - i++; - } else if ((windowsName.length() > i + 1) && - (next == '/')) { - ch = '\\'; - i++; - } - } else if (ch == '\\') { - ch = '/'; - } - javaName.append(ch); - } - return javaName.toString(); - } - - /** - * Converts value string to it Windows representation. - * as a byte-encoded string. - * Encoding algorithm adds "/" character to capital letters, i.e. - * "A" is encoded as "/A". Character '\' is encoded as '//', - * '/' is encoded as '\'. - * Then encoding scheme similar to jdk's native2ascii converter is used - * to convert java string to a byte array of ASCII characters. - */ - private static byte[] toWindowsValueString(String javaName) { - StringBuffer windowsName = new StringBuffer(); - for (int i = 0; i < javaName.length(); i++) { - char ch =javaName.charAt(i); - if ((ch < 0x0020)||(ch > 0x007f)){ - // write \udddd - windowsName.append("/u"); - String hex = Integer.toHexString(javaName.charAt(i)); - StringBuffer hex4 = new StringBuffer(hex); - hex4.reverse(); - int len = 4 - hex4.length(); - for (int j = 0; j < len; j++){ - hex4.append('0'); - } - for (int j = 0; j < 4; j++){ - windowsName.append(hex4.charAt(3 - j)); - } - } else if (ch == '\\') { - windowsName.append("//"); - } else if (ch == '/') { - windowsName.append('\\'); - } else if ((ch >= 'A') && (ch <='Z')) { - windowsName.append("/" + ch); - } else { - windowsName.append(ch); - } - } - return stringToByteArray(windowsName.toString()); - } - - /** - * Returns native handle for the top Windows node for this node. - */ - private int rootNativeHandle() { - return (isUserNode()? USER_ROOT_NATIVE_HANDLE : - SYSTEM_ROOT_NATIVE_HANDLE); - } - - /** - * Returns this java string as a null-terminated byte array - */ - private static byte[] stringToByteArray(String str) { - byte[] result = new byte[str.length()+1]; - for (int i = 0; i < str.length(); i++) { - result[i] = (byte) str.charAt(i); - } - result[str.length()] = 0; - return result; - } - - /** - * Converts a null-terminated byte array to java string - */ - private static String byteArrayToString(byte[] array) { - StringBuffer result = new StringBuffer(); - for (int i = 0; i < array.length - 1; i++) { - result.append((char)array[i]); - } - return result.toString(); - } - - /** - * Empty, never used implementation of AbstractPreferences.flushSpi(). - */ - protected void flushSpi() throws BackingStoreException { - // assert false; - } - - /** - * Empty, never used implementation of AbstractPreferences.flushSpi(). - */ - protected void syncSpi() throws BackingStoreException { - // assert false; - } - - private static synchronized Logger logger() { - if (logger == null) { - logger = Logger.getLogger("org.parabot.logger"); - } - logger.setLevel(Level.OFF); - return logger; - } -} \ No newline at end of file diff --git a/src/main/java/org/parabot/environment/scripts/Script.java b/src/main/java/org/parabot/environment/scripts/Script.java index 732e5c0..aa33f4b 100644 --- a/src/main/java/org/parabot/environment/scripts/Script.java +++ b/src/main/java/org/parabot/environment/scripts/Script.java @@ -123,10 +123,8 @@ public class Script implements Runnable { this.state = STATE_STOPPED; context.setRunningScript(null); - if (context.getUlirathaClient() != null) { - context.getUlirathaClient().disconnect(); - context.setUlirathaClient(null); - } + Core.verbose("Resetting key bindings..."); + Context.getInstance().getPbKeyListener().resetBindings(); BotUI.getInstance().toggleRun(); Core.verbose("Done."); @@ -156,7 +154,6 @@ public class Script implements Runnable { if(state < 0 || state > 2) { throw new IllegalArgumentException("Illegal state"); } - Core.setBugsnagInformation("Script", "State", String.valueOf(state)); this.state = state; } @@ -181,6 +178,5 @@ public class Script implements Runnable { public void setScriptID(int scriptID){ this.scriptID = scriptID; - Core.setBugsnagInformation("Script", "State", String.valueOf(scriptID)); } } diff --git a/src/main/java/org/parabot/environment/scripts/executers/BDNScriptsExecuter.java b/src/main/java/org/parabot/environment/scripts/executers/BDNScriptsExecuter.java index e29b450..fdfc199 100644 --- a/src/main/java/org/parabot/environment/scripts/executers/BDNScriptsExecuter.java +++ b/src/main/java/org/parabot/environment/scripts/executers/BDNScriptsExecuter.java @@ -8,7 +8,6 @@ import org.parabot.core.ui.utils.UILog; import org.parabot.environment.api.utils.WebUtil; import org.parabot.environment.scripts.Script; import org.parabot.environment.scripts.loader.JavaScriptLoader; -import org.parabot.environment.scripts.uliratha.UlirathaExecuter; import javax.swing.*; import java.lang.reflect.Constructor; @@ -77,9 +76,6 @@ public class BDNScriptsExecuter extends ScriptExecuter { script.setScriptID(this.id); super.finalize(tg, script); - if (manager.getAccount().getApi() != null) { - new UlirathaExecuter(manager.getAccount().getApi()).start(this.id); - } } catch (NoClassDefFoundError | ClassNotFoundException ignored) { UILog.log("Error", "Failed to load BDN script, error: [This server provider does not support this script]", JOptionPane.ERROR_MESSAGE); } catch (Throwable t) { diff --git a/src/main/java/org/parabot/environment/scripts/uliratha/UlirathaClient.java b/src/main/java/org/parabot/environment/scripts/uliratha/UlirathaClient.java deleted file mode 100644 index 0ef0083..0000000 --- a/src/main/java/org/parabot/environment/scripts/uliratha/UlirathaClient.java +++ /dev/null @@ -1,158 +0,0 @@ -package org.parabot.environment.scripts.uliratha; - -import naga.ExceptionObserver; -import naga.NIOService; -import naga.NIOSocket; -import naga.SocketObserver; -import naga.packetreader.RegularPacketReader; -import naga.packetwriter.RegularPacketWriter; -import org.parabot.core.ui.Logger; - -import java.io.*; - -/** - * @author JKetelaar - */ - -public class UlirathaClient extends Thread { - - private String host; - private int port; - private NIOSocket socket; - private boolean connected; - private int scriptID; - private String api; - private boolean valid; - - public UlirathaClient(String host, int port, int scriptID, String api) { - this.host = host; - this.port = port; - this.scriptID = scriptID; - this.api = api; - } - - @Override - public void run() { - connect(); - } - - private void connect() { - try { - NIOService service = new NIOService(); - service.setExceptionObserver(new ExceptionObserver() { - @Override - public void notifyExceptionThrown(Throwable throwable) { - throwable.printStackTrace(); - if (valid) { - reconnect(); - connected = false; - } - } - }); - socket = service.openSocket(host, port); - socket.setPacketReader(new RegularPacketReader(4, true)); - socket.setPacketWriter(new RegularPacketWriter(4, true)); - socket.listen(new SocketObserver() { - public void connectionOpened(NIOSocket nioSocket) { - try { - sendObjects(nioSocket, new Object[]{76, scriptID, api}); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void packetReceived(NIOSocket socket, byte[] packet) { - try { - DataInputStream stream = new DataInputStream(new ByteArrayInputStream(packet)); - int packetID = stream.readInt(); - - switch (packetID){ - case 75: - valid = stream.readBoolean(); - if (valid) { - Logger.addMessage("We're connected with the Uliratha server!", false); - connected = true; - }else{ - socket.close(); - } - break; - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void packetSent(NIOSocket nioSocket, Object o) { - - } - - public void connectionBroken(NIOSocket nioSocket, Exception exception) { - if (valid) { - Logger.addMessage("We lost connection with the Uliratha server, reconnecting...", false); - reconnect(); - connected = false; - }else{ - Logger.addMessage("We're disconnected from the Uliratha server", false); - } - } - }); - while (true) { - service.selectBlocking(); - } - } catch (IOException e) { - if (valid) { - reconnect(); - connected = false; - } - } - } - - private void reconnect() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - connect(); - } - - public boolean isConnected() { - return connected; - } - - public void disconnect(){ - valid = false; - socket.close(); - } - - private void sendObjects(NIOSocket socket, Object[] objects) throws IOException { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - DataOutputStream dataStream = new DataOutputStream(stream); - for (Object o : objects) { - if (o instanceof String) { - dataStream.writeUTF((String) o); - } else if (o instanceof Integer) { - dataStream.writeInt((Integer) o); - } else if (o instanceof byte[]) { - dataStream.write((byte[]) o); - } else if (o instanceof Long) { - dataStream.writeLong((Long) o); - } else if (o instanceof Boolean) { - dataStream.writeBoolean((Boolean) o); - } - } - dataStream.flush(); - final byte[] content = stream.toByteArray(); - dataStream.close(); - socket.write(content); - } - - public void sendMessage(String message){ - try { - sendObjects(socket, new Object[]{83, message}); - } catch (IOException e) { - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/parabot/environment/scripts/uliratha/UlirathaExecuter.java b/src/main/java/org/parabot/environment/scripts/uliratha/UlirathaExecuter.java deleted file mode 100644 index 47cfc5e..0000000 --- a/src/main/java/org/parabot/environment/scripts/uliratha/UlirathaExecuter.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.parabot.environment.scripts.uliratha; - -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; -import org.parabot.core.Context; -import org.parabot.environment.api.utils.WebUtil; - -import java.io.IOException; - -/** - * @author JKetelaar - */ -public class UlirathaExecuter { - - private String api; - private static boolean isVip = true; - - public UlirathaExecuter(String api){ - this.api = api; - } - - public void start(int scriptID){ - if (UlirathaExecuter.isVip) { - String vipUrl = "http://bdn.parabot.org/api/v2/user/" + api + "/vip"; - JSONParser parser = new JSONParser(); - try { - JSONObject vipObject = (JSONObject) parser.parse(WebUtil.getReader(vipUrl)); - - boolean isVip = (boolean) vipObject.get("result"); - if (isVip) { - String serverUrl = "http://bdn.parabot.org/api/v2/clients/server"; - JSONObject serverObject = (JSONObject) parser.parse(WebUtil.getReader(serverUrl)); - JSONObject detailsObject = (JSONObject) serverObject.get("result"); - String host = (String) detailsObject.get("host"); - long port = (long) detailsObject.get("port"); - - UlirathaClient client = new UlirathaClient(host, (int) port, scriptID, api); - client.start(); - Context.getInstance().setUlirathaClient(client); - }else{ - UlirathaExecuter.isVip = false; - } - } catch (IOException | ParseException | ClassCastException e) { - e.printStackTrace(); - } - } - } -} diff --git a/src/main/java/org/parabot/environment/servers/executers/PublicServerExecuter.java b/src/main/java/org/parabot/environment/servers/executers/PublicServerExecuter.java index 7e32445..73723a4 100644 --- a/src/main/java/org/parabot/environment/servers/executers/PublicServerExecuter.java +++ b/src/main/java/org/parabot/environment/servers/executers/PublicServerExecuter.java @@ -54,8 +54,7 @@ public class PublicServerExecuter extends ServerExecuter { final File destination = new File(Directories.getCachePath(), serverProviderInfo.getCRC32() + ".jar"); - final String jarUrl = Configuration.GET_SERVER_PROVIDER - + this.serverName; + final String jarUrl = String.format(Configuration.GET_SERVER_PROVIDER, Configuration.BOT_VERSION.isNightly()); Core.verbose("Downloading: " + jarUrl + " ..."); @@ -63,7 +62,7 @@ public class PublicServerExecuter extends ServerExecuter { Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]"); } else { WebUtil.downloadFile(new URL(jarUrl), destination, - VerboseLoader.get(), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword()); + VerboseLoader.get()); Core.verbose("Server provider downloaded..."); } diff --git a/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java b/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java index f2ac865..290bac9 100644 --- a/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java +++ b/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java @@ -24,8 +24,6 @@ public abstract class ServerExecuter { @Override public void run() { try { - Core.setBugsnagServer(serverName); - Context context = Context.getInstance(provider); context.load(); PaintComponent.getInstance().startPainting(context); diff --git a/src/main/resources/storage/app.properties b/src/main/resources/storage/app.properties deleted file mode 100755 index 1c3dea3..0000000 --- a/src/main/resources/storage/app.properties +++ /dev/null @@ -1 +0,0 @@ -application.version=${project.version} \ No newline at end of file diff --git a/src/main/resources/storage/images/icon.png b/src/main/resources/storage/images/icon.png deleted file mode 100755 index 33ef49f..0000000 Binary files a/src/main/resources/storage/images/icon.png and /dev/null differ diff --git a/src/main/resources/storage/parabot.properties b/src/main/resources/storage/parabot.properties new file mode 100755 index 0000000..263d0ff --- /dev/null +++ b/src/main/resources/storage/parabot.properties @@ -0,0 +1 @@ +application.version=${project.version}${build.version} \ No newline at end of file