private String ask(String cmd) { BufferedWriter out = null; BufferedReader in = null; Socket sock = null; String ret = ""; try { System.out.println(server); sock = new Socket(server, ServerListener.PORT); out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); out.write(cmd, 0, cmd.length()); out.flush(); in = new BufferedReader(new InputStreamReader(sock.getInputStream())); int inr = in.read(); while (inr != ';') { ret += Character.toString((char) inr); inr = in.read(); } } catch (IOException io) { io.printStackTrace(); } finally { try { out.close(); in.close(); sock.close(); } catch (IOException io) { io.printStackTrace(); } } return ret; }
@EventHandler public void onTick(TickEvent event) { if (!bot.hasSpawned() || !bot.isConnected()) return; if (tickDelay > 0) { tickDelay--; return; } MainPlayerEntity player = bot.getPlayer(); if (player == null || !bot.hasSpawned() || spamMessage == null) return; if (nextMessage > 0) { nextMessage--; return; } try { String message = spamMessage; MessageFormatter formatter = new MessageFormatter(); synchronized (bots) { if (bots.size() > 0) { DarkBotMCSpambot bot = bots.get(++nextBot >= bots.size() ? nextBot = 0 : nextBot); if (bot != null && bot.bot != null && bot.bot.getSession() != null) formatter.setVariable("bot", bot.bot.getSession().getUsername()); } } if (spamList.length > 0) { formatter.setVariable( "spamlist", spamList[++nextSpamList >= spamList.length ? nextSpamList = 0 : nextSpamList]); } formatter.setVariable("rnd", Util.generateRandomString(15 + random.nextInt(6))); formatter.setVariable( "msg", Character.toString( msgChars[++nextMsgChar >= msgChars.length ? nextMsgChar = 0 : nextMsgChar])); message = formatter.format(message); bot.say(message); } catch (Exception e) { e.printStackTrace(); } nextMessage = messageDelay; }