public static void main(String[] args) { // Script Engine instantiation using ServiceProvider - this will // look in the classpath for a file // /META-INF/services/javax.script.ScriptEngineFactory // where the AbclScriptEngineFactory is registered ScriptEngine lispEngine = new ScriptEngineManager().getEngineByExtension("lisp"); // Alternatively, you can directly instantiate the script engine: // ScriptEngineManager scriptManager = new ScriptEngineManager(); // scriptManager.registerEngineExtension("lisp", new AbclScriptEngineFactory()); // ScriptEngine lispEngine = scriptManager.getEngineByExtension("lisp"); // (thanks to Peter Tsenter for suggesting this) // Accessing variables System.out.println(); System.out.println("*package* = " + lispEngine.get("*package*")); Object someValue = new Object(); lispEngine.put("someVariable", someValue); System.out.println("someVariable = " + lispEngine.get("someVariable")); try { // Interpretation (also from streams) lispEngine.eval("(defun hello (arg) (print (list arg someVariable)) (terpri))"); // Direct function invocation ((Invocable) lispEngine).invokeFunction("hello", "world"); // Implementing a Java interface in Lisp lispEngine.eval("(defun compare-to (&rest args) 42)"); Comparable c = ((Invocable) lispEngine).getInterface(java.lang.Comparable.class); System.out.println("compareTo: " + c.compareTo(null)); // Compilation! lispEngine.eval( "(defmacro slow-compiling-macro (arg) (dotimes (i 1000000) (incf i)) `(print ,arg))"); long millis = System.currentTimeMillis(); lispEngine.eval("(slow-compiling-macro 42)"); millis = System.currentTimeMillis() - millis; System.out.println("interpretation took " + millis); millis = System.currentTimeMillis(); CompiledScript cs = ((Compilable) lispEngine).compile("(slow-compiling-macro 42)"); millis = System.currentTimeMillis() - millis; System.out.println("compilation took " + millis); millis = System.currentTimeMillis(); cs.eval(); millis = System.currentTimeMillis() - millis; System.out.println("evaluation took " + millis); millis = System.currentTimeMillis(); cs.eval(); millis = System.currentTimeMillis() - millis; System.out.println("evaluation took " + millis); // Ecc. ecc. } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (ScriptException e) { e.printStackTrace(); } }
private DarkBotMCSpambot( DarkBot darkBot, String server, String username, String password, String sessionId, String loginProxy, String proxy, String owner) { synchronized (bots) { bots.add(this); // slotsTaken.incrementAndGet(); synchronized (slotsTaken) { slotsTaken.notifyAll(); } } MinecraftBotData.Builder builder = MinecraftBotData.builder(); // botData.nickname = ""; // for(int i = 0; i < 10; i++) // botData.nickname += alphas[random.nextInt(alphas.length)]; if (proxy != null && !proxy.isEmpty()) { int port = 80; ProxyType type = ProxyType.SOCKS; if (proxy.contains(":")) { String[] parts = proxy.split(":"); proxy = parts[0]; port = Integer.parseInt(parts[1]); if (parts.length > 2) type = ProxyType.values()[Integer.parseInt(parts[2]) - 1]; } builder.withSocksProxy(new ProxyData(proxy, port, type)); this.proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxy, port)); } if (loginProxy != null && !loginProxy.isEmpty()) { int port = 80; if (loginProxy.contains(":")) { String[] parts = loginProxy.split(":"); loginProxy = parts[0]; port = Integer.parseInt(parts[1]); } builder.withHttpProxy(new ProxyData(loginProxy, port, ProxyType.HTTP)); this.loginProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(loginProxy, port)); } builder.withUsername(username); if (sessionId != null) builder.withSessionId(sessionId); else builder.withPassword(password); if (server != null && !server.isEmpty()) { int port = 25565; if (server.contains(":")) { String[] parts = server.split(":"); server = parts[0]; port = Integer.parseInt(parts[1]); } builder.withServer(server).withPort(port); } else throw new IllegalArgumentException("Unknown server!"); this.owner = owner; MinecraftBotData botData = builder.build(); System.setProperty("socksProxyHost", ""); System.setProperty("socksProxyPort", ""); System.out.println("[" + username + "] Connecting..."); bot = new MinecraftBot(darkBot, botData); bot.setMovementDisabled(true); connectionHandler = bot.getConnectionHandler(); Session session = bot.getSession(); // System.gc(); System.out.println("[" + username + "] Done! (" + amountJoined.incrementAndGet() + ")"); bot.getEventManager().registerListener(this); bot.getGameHandler().registerListener(this); long lastShoutTime = System.currentTimeMillis(); while (bot.isConnected()) { if (die) { connectionHandler.sendPacket(new Packet255KickDisconnect("Goodbye")); return; } try { Thread.sleep(3000 + random.nextInt(1000)); } catch (InterruptedException exception) { exception.printStackTrace(); } if (!bot.hasSpawned()) continue; connectionHandler.sendPacket(new Packet0KeepAlive(random.nextInt())); if (spamMessage == null || !canSpam) continue; String message = spamMessage; if (message.contains("%skill")) message = message.replace("%skill", skills[nextSkill++]); if (nextSkill >= skills.length) nextSkill = 0; if (message.contains("%bot")) { synchronized (bots) { message = message.replace( "%bot", bots.get(nextBot > bots.size() ? (nextBot = 0) * 0 : nextBot++) .bot .getSession() .getUsername()); } } if (message.contains("%spamlist")) message = message.replace("%spamlist", spamList[nextSpamList++]); if (nextSpamList >= spamList.length) nextSpamList = 0; if (message.contains("%rnd")) { int length = 1; int index = message.indexOf("%rnd") + "%rnd".length(); int lastIndex; for (lastIndex = index; lastIndex < message.length(); lastIndex++) if (Character.isDigit(message.charAt(lastIndex))) lastIndex++; else break; if (lastIndex > message.length()) lastIndex--; try { System.out.println(index + "," + lastIndex + "," + message.length()); length = Integer.parseInt(message.substring(index, lastIndex)); } catch (Exception exception) { } String randomChars = ""; for (int i = 0; i < length; i++) randomChars += alphas[random.nextInt(alphas.length)]; message = message.replace("%rnd", randomChars); } if (message.contains("%msg")) message = "/msg " + msgChars[nextMsgChar++] + " " + message.replace("%msg", ""); if (message.contains("%ernd")) { message = message.replace("%ernd", ""); int extraMessageLength = 15 + random.nextInt(6); message = message.substring(0, Math.min(100 - extraMessageLength, message.length())) + " ["; extraMessageLength -= 3; for (int i = 0; i < extraMessageLength; i++) message += alphas[random.nextInt(alphas.length)]; message += "]"; } else message = message.substring(0, Math.min(100, message.length())); connectionHandler.sendPacket(new Packet3Chat(message)); } synchronized (bots) { bots.remove(this); } amountJoined.decrementAndGet(); slotsTaken.decrementAndGet(); synchronized (slotsTaken) { slotsTaken.notifyAll(); } }