Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.America10Ultra.BotAttack;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.net.HttpURLConnection;
- import java.net.InetSocketAddress;
- import java.net.Socket;
- import java.net.URL;
- import java.net.URLEncoder;
- import javax.net.ssl.HttpsURLConnection;
- public class Bot
- implements Runnable
- {
- private String username;
- private String password;
- private String server;
- private int port;
- private String[] session;
- private String auth;
- private String spam;
- private Socket socket;
- private DataOutputStream dos;
- private DataInputStream dis;
- public Bot(String s, String s1, String s2, String s3, int i)
- {
- this.username = s;
- this.password = s1;
- this.spam = s2;
- this.server = s3;
- this.port = i;
- }
- public void run()
- {
- try
- {
- System.out.println("Running...");
- setupBot();
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- }
- public void setupBot()
- {
- System.out.println("Setting up the bot...");
- try
- {
- createSocket();
- if (this.socket.isConnected())
- {
- String s = "user=" + URLEncoder.encode(this.username, "UTF-8") + "&password=" + URLEncoder.encode(this.password, "UTF-8") + "&version=" + 13;
- authenticateLogin(s);
- Thread.sleep(20L);
- sendHandshake();
- Thread.sleep(90L);
- sendLogin();
- Thread.sleep(60L);
- sendChat("Hello");
- Thread.sleep(20L);
- sendDisconnect();
- Thread.sleep(40L);
- this.socket.close();
- this.dis.close();
- this.dos.close();
- }
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- }
- public void createSocket()
- {
- try
- {
- System.out.println("Creating socket...");
- this.socket = new Socket();
- connect();
- this.dos = new DataOutputStream(this.socket.getOutputStream());
- this.dis = new DataInputStream(this.socket.getInputStream());
- }
- catch (IOException ioexception)
- {
- ioexception.printStackTrace();
- }
- }
- public void connect()
- {
- try
- {
- System.out.println("Connecting to: " + this.server + ":" + this.port);
- this.socket.connect(new InetSocketAddress(this.server, this.port));
- }
- catch (IOException ioexception)
- {
- ioexception.printStackTrace();
- }
- catch (Exception exception) {}
- }
- public void sendHandshake()
- {
- try
- {
- this.dos.writeByte(2);
- String s = new StringBuilder().append(this.username).append(";").toString() + new StringBuilder().append(this.server).append(":").toString() + this.port;
- writeString(s);
- int i = this.dis.read();
- System.out.println("Num: " + i);
- this.auth = read(this.dis);
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- System.out.println("Sending Handshake...");
- }
- public void sendLogin()
- {
- try
- {
- joinServer();
- this.dos.writeByte(1);
- this.dos.writeInt(29);
- writeString(this.username);
- writeString("");
- this.dos.writeInt(0);
- this.dos.writeInt(0);
- this.dos.writeByte(0);
- this.dos.writeByte(0);
- this.dos.writeByte(0);
- Thread.sleep(20L);
- createSession();
- }
- catch (IOException ioexception)
- {
- ioexception.printStackTrace();
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- System.out.println("Logging in...");
- }
- protected void keepAlive(DataOutputStream dataoutputstream)
- {
- try
- {
- dataoutputstream.writeByte(0);
- dataoutputstream.writeInt(0);
- System.out.println("Bot is still alive!");
- }
- catch (IOException ioexception)
- {
- ioexception.printStackTrace();
- }
- }
- public void sendChat(String s)
- {
- try
- {
- this.dos.writeByte(3);
- writeString(s);
- }
- catch (IOException ioexception)
- {
- ioexception.printStackTrace();
- }
- System.out.println("Spamming...");
- }
- public void sendDisconnect()
- {
- try
- {
- this.dos.writeByte(255);
- writeString("Quitting");
- this.dos.close();
- this.dis.close();
- this.socket.close();
- System.out.println("Disconnecting...");
- }
- catch (IOException ioexception)
- {
- ioexception.printStackTrace();
- }
- }
- public void writeString(String s)
- {
- try
- {
- this.dos.writeShort(s.length());
- this.dos.writeChars(s);
- }
- catch (IOException ioexception)
- {
- ioexception.printStackTrace();
- }
- }
- protected String read(DataInputStream datainputstream)
- throws IOException
- {
- StringBuilder stringbuilder = new StringBuilder();
- short word0 = datainputstream.readShort();
- System.out.println("Read integer: " + word0);
- for (int i = 0; i < word0; i++) {
- stringbuilder.append(datainputstream.readChar());
- }
- return stringbuilder.toString();
- }
- private void createSession()
- {
- try
- {
- URL url = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + URLEncoder.encode(this.username, "UTF-8") + "&sessionId=" + URLEncoder.encode(this.session[3], "UTF-8") + "&serverId=" + URLEncoder.encode(this.auth, "UTF-8"));
- BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(url.openStream()));
- String s = bufferedreader.readLine();
- bufferedreader.close();
- if (s.equalsIgnoreCase("ok")) {
- System.out.println("http://session.minecraft.net/: Logged in as: " + this.username);
- } else {
- System.out.println("http://session.minecraft.net/: Bad Login");
- }
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- System.out.println("Session created.");
- }
- private void authenticateLogin(String s)
- {
- HttpsURLConnection httpsurlconnection = null;
- try
- {
- URL url = new URL("https://login.minecraft.net/");
- httpsurlconnection = (HttpsURLConnection)url.openConnection();
- httpsurlconnection.setRequestMethod("GET");
- httpsurlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- httpsurlconnection.setRequestProperty("Content-Type", Integer.toString(s.getBytes().length));
- httpsurlconnection.setRequestProperty("Content-Language", "en-US");
- httpsurlconnection.setUseCaches(false);
- httpsurlconnection.setDoInput(true);
- httpsurlconnection.setDoOutput(true);
- httpsurlconnection.connect();
- DataOutputStream dataoutputstream = new DataOutputStream(httpsurlconnection.getOutputStream());
- dataoutputstream.writeBytes(s);
- dataoutputstream.flush();
- dataoutputstream.close();
- InputStream inputstream = httpsurlconnection.getInputStream();
- BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
- StringBuffer stringbuffer = new StringBuffer();
- String s1;
- while ((s1 = bufferedreader.readLine()) != null)
- {
- stringbuffer.append(s1);
- stringbuffer.append('\r');
- }
- bufferedreader.close();
- String s2 = stringbuffer.toString();
- this.session = s2.split(":");
- System.out.println("https://login.mineccraft.net/: " + s2);
- System.out.println("Session ID: " + this.session[3]);
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- finally
- {
- if (httpsurlconnection != null) {
- httpsurlconnection.disconnect();
- }
- }
- System.out.println("Bot Authenticated.");
- }
- public void joinServer()
- throws Exception
- {
- HttpURLConnection httpurlconnection = null;
- URL url = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + this.username + "&sessionId=" + this.session[3] + "&serverId=" + this.auth);
- httpurlconnection = (HttpURLConnection)url.openConnection();
- httpurlconnection.setUseCaches(false);
- httpurlconnection.setConnectTimeout(16000);
- httpurlconnection.setReadTimeout(16000);
- BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream()));
- StringBuffer stringbuffer = new StringBuffer();
- String s;
- while ((s = bufferedreader.readLine()) != null)
- {
- stringbuffer.append(s);
- stringbuffer.append('\r');
- }
- String s1 = stringbuffer.toString();
- String s2 = s1.replaceAll("null", "").trim();
- if (!s2.equals("OK"))
- {
- System.out.println(s2);
- throw new Exception();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement