Advertisement
Guest User

TPWinXP.java

a guest
Aug 9th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.34 KB | None | 0 0
  1. package TPU;
  2. import java.net.*;
  3. import java.awt.*;
  4. import java.awt.event.KeyEvent;
  5. import java.awt.event.MouseEvent;
  6. import java.io.*;
  7. import java.lang.reflect.Field;
  8. import java.lang.reflect.Modifier;
  9. import java.util.LinkedList;
  10.  
  11. /**
  12.  *
  13.  * @author Laptop
  14.  */
  15. public class TPWinXP {
  16.     static String pass = "oauth:ucq1bt9ymd14kp0b90ewhn2vsovwm4";
  17.     static String username = "razorsharpfang";
  18.     static double restart = 100;
  19.     static double nRestart = 150;
  20.     static long keyTD = 500;
  21.     static Robot robot;
  22.     // default keyTime
  23.     static int autoDelay = 20;
  24.     // default auto delay of robot
  25.     public static void main(String[] args) {
  26.         while(true) {
  27.             try {
  28.                 TPMC();
  29.             }
  30.             catch(Exception e) {
  31.                 System.out.println("Whoops.");
  32.                 System.out.println(e);
  33.             }
  34.         }
  35.     }
  36.    
  37.     public static void TPMC() throws Exception {
  38.         Socket socket = null;
  39.         BufferedWriter output = null;
  40.         LineNumberReader input = null;
  41.         String command = null;
  42.         String user = null;
  43.         robot = null;
  44.         //long restartTime = System.currentTimeMillis();
  45.         long pingTime = System.currentTimeMillis();
  46.        
  47.         LinkedList<KeyDuration> keyList = new LinkedList();
  48.        
  49.         //double speed = 100;
  50.         try {
  51.             robot = new Robot();
  52.             socket = new Socket(InetAddress.getByName("irc.twitch.tv"),6667);
  53.             //socket.connect(socket.getRemoteSocketAddress());
  54.             //System.out.println("We have created a socket!");
  55.             output = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
  56.             input = new LineNumberReader(new InputStreamReader(socket.getInputStream()));
  57.             //System.out.println("We have allocated our writers and readers");
  58.             output.write("PASS "+pass+"\n\r");
  59.             output.write("NICK "+username+"\n\r");
  60.             output.write("JOIN #razorsharpfang\n\r");
  61.             output.flush();
  62.             //System.out.println("We have passed our credentials!");
  63.             output.write("PRIVMSG #razorsharpfang :TPWinXP Bot ONLINE!!\n\r");
  64.             output.flush();
  65.         }
  66.         catch(Exception e) {
  67.             System.out.println("We had trouble setting up....");
  68.             System.out.println(e.getMessage());
  69.             Thread.sleep(1000);
  70.             return;
  71.         }
  72.         robot.setAutoDelay(autoDelay);
  73.         long previous = System.currentTimeMillis();
  74.         //long delta;
  75.         Point p = MouseInfo.getPointerInfo().getLocation();
  76.         int mouseX=0;
  77.         int mouseY=0;
  78.         // these two variables hold the amount that the mouse needs to move
  79.         while(true) {
  80.             //10 milliseconds is desired.
  81.             if(System.currentTimeMillis() < previous + 10) {
  82.                 Thread.sleep(10 - (System.currentTimeMillis() - previous));
  83.             }
  84.             //delta = System.currentTimeMillis() - previous;
  85.             previous = System.currentTimeMillis();
  86.             try {
  87.                 // this should release any keys that are scheduled to be released
  88.                 for(KeyDuration kd : keyList) {
  89.                     if(System.currentTimeMillis() > kd.time) {
  90.                         robot.keyRelease(kd.keycode);
  91.                         keyList.remove(kd);
  92.                     }
  93.                 }
  94.                
  95.                 // move the mouse 20% of the distance between it and the destination
  96.                 p = MouseInfo.getPointerInfo().getLocation();
  97.                 if((Math.abs(mouseX) <= 1) && (Math.abs(mouseY) <= 1)) {
  98.                     //robot.mouseMove(p.x + mouseX, p.y + mouseY);
  99.                     //mouseX = 0;
  100.                     //mouseY = 0;
  101.                 }
  102.                 else {
  103.                     int dX = (int)Math.ceil(mouseX*0.05);
  104.                     int dY = (int)Math.ceil(mouseY*0.05);
  105.                     mouseX -= dX;
  106.                     mouseY -= dY;
  107.                     robot.mouseMove(dX + p.x,p.y + dY);
  108.                 }
  109.                 //System.out.printf("[%d,%d,%d]\n",mouseX,mouseY,delta);
  110.                 if(System.currentTimeMillis() > pingTime + 300000) {
  111.                     output.write("PRIVMSG #RAZORSHARPFANG :Bot is unsure if it's online.\n\r");
  112.                     output.flush();
  113.                     pingTime = System.currentTimeMillis();
  114.                 }
  115.                 if(socket.isConnected()) {
  116.                     //System.out.println("We are connected...");
  117.                     if(input.ready()) {
  118.                         while(input.ready()) {
  119.                             command = input.readLine();
  120.                             if(command.contains("PING")) {
  121.                                 output.write("PONG :"+command.split(":")[1]+"\n\r");
  122.                                 System.out.println("PONG :"+command.split(":")[1]);
  123.                                 output.flush();
  124.                                 pingTime = System.currentTimeMillis();
  125.                             }
  126.                             if(command.contains("PRIVMSG")) { // ignore this.
  127.                                 user = command.split(":")[1];
  128.                                 user = user.split("!")[0];
  129.                                 command = command.toUpperCase();
  130.                                 command = command.substring(command.indexOf(":")+1);
  131.                                 command = command.substring(command.indexOf(":")+1);
  132.                                 if(command.indexOf('!') == 0) {
  133.                                     // This is a command, parse it as a command.
  134.                                     command = command.substring(1);
  135.                                     System.out.print(user + ": ");
  136.                                     try {
  137.                                         String[] commands = command.split(" ");
  138.                                        
  139.                                         if(commands[0].equals("KEY")) {
  140.                                             // Keyboard command
  141.                                             System.out.print("KEY ");
  142.                                             if(commands[1].equals("PRESS")) {
  143.                                                 // Press a key for a tiny duration
  144.                                                 System.out.print("PRESS "+commands[2]);
  145.                                                 int key = GetKey(commands[2]);
  146.                                                 robot.keyPress(key);
  147.                                                 try {
  148.                                                     long duration = Long.parseLong(commands[3]);
  149.                                                     KeyDuration kD = new KeyDuration(key,duration + System.currentTimeMillis());
  150.                                                     keyList.add(kD);
  151.                                                     System.out.print(duration);
  152.                                                 }
  153.                                                 catch(Exception e) {
  154.                                                     robot.keyRelease(key);
  155.                                                 }
  156.                                             }
  157.                                             else if(commands[1].equals("DOWN")) {
  158.                                                 // Hold down a key
  159.                                                 System.out.print("DOWN "+commands[2]);
  160.                                                 int key = GetKey(commands[2]);
  161.                                                 robot.keyPress(key);
  162.                                             }
  163.                                             else if(commands[1].equals("UP")) {
  164.                                                 // Release a held key
  165.                                                
  166.                                                 System.out.print("UP "+commands[2]);
  167.                                                 if(commands[2].equals("ALL")) {
  168.                                                     Field[] fields = KeyEvent.class.getDeclaredFields();
  169.                                                     for(Field field : fields) {
  170.                                                         try {
  171.                                                             if(Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()))
  172.                                                                 robot.keyRelease(field.getInt(null));
  173.                                                         }
  174.                                                         catch(Exception e) {
  175.                                                             ;// catch and throw away
  176.                                                         }
  177.                                                     }
  178.                                                 }
  179.                                                 else {
  180.                                                     int key = GetKey(commands[2]);
  181.                                                     robot.keyRelease(key);
  182.                                                 }
  183.                                             }
  184.                                             else {
  185.                                                 throw new Exception("Invalid argument, must be one of the following: { press, down, up }");
  186.                                             }
  187.                                         }
  188.                                         else if(commands[0].equals("MOUSE")) {
  189.                                             System.out.print("MOUSE ");
  190.                                             // Mouse command
  191.                                             if(commands[1].equals("MOVE")) {
  192.                                                 System.out.print("MOVE ");
  193.                                                 int distance;
  194.                                                 if(commands[2].equals("UP")) {
  195.                                                     System.out.print("UP");
  196.                                                     if(commands.length > 3) {
  197.                                                         distance = Integer.parseInt(commands[3]);
  198.                                                     }
  199.                                                     else {
  200.                                                         distance = 50;
  201.                                                     }
  202.                                                     mouseY += -distance;
  203.                                                 }
  204.                                                 else if(commands[2].equals("DOWN")) {
  205.                                                     System.out.print("DOWN");
  206.                                                     if(commands.length > 3) {
  207.                                                         distance = Integer.parseInt(commands[3]);
  208.                                                     }
  209.                                                     else {
  210.                                                         distance = 50;
  211.                                                     }
  212.                                                     mouseY += distance;
  213.                                                 }
  214.                                                 else if(commands[2].equals("LEFT")) {
  215.                                                     System.out.print("LEFT");
  216.                                                     if(commands.length > 3) {
  217.                                                         distance = Integer.parseInt(commands[3]);
  218.                                                     }
  219.                                                     else {
  220.                                                         distance = 50;
  221.                                                     }
  222.                                                     mouseX += -distance;
  223.                                                 }
  224.                                                 else if(commands[2].equals("RIGHT")) {
  225.                                                     System.out.print("RIGHT");
  226.                                                     if(commands.length > 3) {
  227.                                                         distance = Integer.parseInt(commands[3]);
  228.                                                     }
  229.                                                     else {
  230.                                                         distance = 50;
  231.                                                     }
  232.                                                     mouseX += distance;
  233.                                                 }
  234.                                                 else {
  235.                                                     throw new Exception("Direction required, must be one of the following: { up, down, left, right }");
  236.                                                 }
  237.                                             }
  238.                                             else if(commands[1].equals("BUTTON")) {
  239.                                                 System.out.print("BUTTON ");
  240.                                                 if(commands[2].equals("CLICK")) {
  241.                                                     System.out.print("CLICK ");
  242.                                                     if(commands[3].equals("LEFT")) {
  243.                                                         System.out.print("LEFT ");
  244.                                                         robot.mousePress(MouseEvent.BUTTON1_MASK);
  245.                                                         robot.mouseRelease(MouseEvent.BUTTON1_MASK);
  246.                                                     }
  247.                                                     else if(commands[3].equals("RIGHT")) {
  248.                                                         System.out.print("RIGHT ");
  249.                                                         robot.mousePress(MouseEvent.BUTTON3_MASK);
  250.                                                         robot.mouseRelease(MouseEvent.BUTTON3_MASK);
  251.                                                     }
  252.                                                     else if(commands[3].equals("MIDDLE")) {
  253.                                                         System.out.print("MIDDLE");
  254.                                                         robot.mousePress(MouseEvent.BUTTON2_MASK);
  255.                                                         robot.mouseRelease(MouseEvent.BUTTON2_MASK);
  256.                                                     }
  257.                                                     else {
  258.                                                         throw new Exception("Invalid argument for mouse button, must be one of these: { left, middle, right }");
  259.                                                     }
  260.                                                 }
  261.                                                 else if(commands[2].equals("DOWN")) {
  262.                                                     System.out.print("CLICK ");
  263.                                                     if(commands[3].equals("LEFT")) {
  264.                                                         System.out.print("LEFT ");
  265.                                                         robot.mousePress(MouseEvent.BUTTON1_MASK);
  266.                                                     }
  267.                                                     else if(commands[3].equals("RIGHT")) {
  268.                                                         System.out.print("RIGHT ");
  269.                                                         robot.mousePress(MouseEvent.BUTTON3_MASK);
  270.                                                     }
  271.                                                     else if(commands[3].equals("MIDDLE")) {
  272.                                                         System.out.print("MIDDLE");
  273.                                                         robot.mousePress(MouseEvent.BUTTON2_MASK);
  274.                                                     }
  275.                                                     else {
  276.                                                         throw new Exception("Invalid argument for mouse button, must be one of these: { left, middle, right }");
  277.                                                     }
  278.                                                 }
  279.                                                 else if(commands[2].equals("UP")) {
  280.                                                     System.out.print("UP ");
  281.                                                     if(commands[3].equals("LEFT")) {
  282.                                                         System.out.print("LEFT ");
  283.                                                         robot.mouseRelease(MouseEvent.BUTTON1_MASK);
  284.                                                     }
  285.                                                     else if(commands[3].equals("RIGHT")) {
  286.                                                         System.out.print("RIGHT ");
  287.                                                         robot.mouseRelease(MouseEvent.BUTTON3_MASK);
  288.                                                     }
  289.                                                     else if(commands[3].equals("MIDDLE")) {
  290.                                                         System.out.print("MIDDLE");
  291.                                                         robot.mouseRelease(MouseEvent.BUTTON2_MASK);
  292.                                                     }
  293.                                                     else {
  294.                                                         throw new Exception("Invalid argument for mouse button, must be one of these: { left, middle, right }");
  295.                                                     }
  296.                                                 }
  297.                                                 else {
  298.                                                     throw new Exception("Invalid argument for mouse button action, must be one of these: { click, down, up }");
  299.                                                 }
  300.                                             }
  301.                                             else if(commands[1].equals("SCROLL")) {
  302.                                                 System.out.print("SCROLL ");
  303.                                                 if(commands[2].equals("UP")) {
  304.                                                     System.out.print("UP");
  305.                                                     robot.mouseWheel(-1);
  306.                                                 }
  307.                                                 else if(commands[2].equals("DOWN")) {
  308.                                                     System.out.print("DOWN");
  309.                                                     robot.mouseWheel(1);
  310.                                                 }
  311.                                                 else {
  312.                                                     throw new Exception("Invalid argument for scroll action, must be one of the following: { up, down }");
  313.                                                 }
  314.                                             }
  315.                                             else {
  316.                                                 throw new Exception("Invalid argument for mouse : Must be one of the following : { move, button, scroll }");
  317.                                             }
  318.                                         }
  319.                                         else if(commands[0].equals("RESTART")) {
  320.                                             ;
  321.                                         }
  322.                                         else if(commands[0].equals("Y")) {
  323.                                             ;
  324.                                         }
  325.                                         else if(commands[0].equals("N")) {
  326.                                             ;
  327.                                         }
  328.                                         else {
  329.                                             throw new Exception("Not a valid command. Must be one of { key, mouse} ");
  330.                                         }
  331.                                     }
  332.                                     catch(ArrayIndexOutOfBoundsException e) {
  333.                                         output.write("PRIVMSG #RAZORSHARPFANG :@"+user+ ":" +" Not enough arguments for that command.\n\r");
  334.                                         output.flush();
  335.                                         System.out.println("OH DEAR, OUT OF BOUNDS! D:");
  336.                                         System.out.println(e);
  337.                                     }
  338.                                     catch(Exception e) {
  339.                                         output.write("PRIVMSG #RAZORSHARPFANG :@"+user + ":" + e.getMessage()+"\n\r");
  340.                                         output.flush();
  341.                                         System.out.println(e);
  342.                                         System.out.println(e.getMessage());
  343.                                     }
  344.                                     System.out.print(";");
  345.                                     System.out.println();
  346.                                 }
  347.                             }
  348.                         }
  349.                     }
  350.                 }
  351.                 else {
  352.                     System.out.println("Not connected, restarting...");
  353.                     return;
  354.                 }
  355.                 output.flush();
  356.             }
  357.             catch(IOException e) {
  358.                 System.out.println("CRITICAL ERROR!");
  359.                 System.out.println(e);
  360.                 System.out.println("BOT RESTARTING!");
  361.             }
  362.             catch(Exception e) {
  363.                 System.out.println("That didn't work.");
  364.                 System.out.println(e);
  365.             }
  366.         }
  367.     }
  368.    
  369.     static int GetKey(String s) throws Exception {
  370.         int key = 0;
  371.         switch(s) {
  372.             case "ESC":
  373.                 key = KeyEvent.VK_ESCAPE;
  374.             break;
  375.             case "F1":
  376.                 key = KeyEvent.VK_F1;
  377.             break;
  378.             case "F2":
  379.                 key = KeyEvent.VK_F2;
  380.             break;
  381.             case "F3":
  382.                 key = KeyEvent.VK_F3;
  383.             break;
  384.             case "F4":
  385.                 key = KeyEvent.VK_F4;
  386.             break;
  387.             case "F5":
  388.                 key = KeyEvent.VK_F5;
  389.             break;
  390.             case "F6":
  391.                 key = KeyEvent.VK_F6;
  392.             break;
  393.             case "F7":
  394.                 key = KeyEvent.VK_F7;
  395.             break;
  396.             case "F8":
  397.                 key = KeyEvent.VK_F8;
  398.             break;
  399.             case "F9":
  400.                 key = KeyEvent.VK_F9;
  401.             break;
  402.             case "F10":
  403.                 key = KeyEvent.VK_F10;
  404.             break;
  405.             case "F11":
  406.                 key = KeyEvent.VK_F11;
  407.             break;
  408.             case "F12":
  409.                 key = KeyEvent.VK_F12;
  410.             break;
  411.             case "INSERT":
  412.                 key = KeyEvent.VK_INSERT;
  413.             break;
  414.             case "DELETE":
  415.                 key = KeyEvent.VK_DELETE;
  416.             break;
  417.             // first row
  418.            
  419.             case "`":
  420.                 key = KeyEvent.VK_BACK_QUOTE;
  421.             break;
  422.             case "1":
  423.                 key = KeyEvent.VK_1;
  424.             break;
  425.             case "2":
  426.                 key = KeyEvent.VK_2;
  427.             break;
  428.             case "3":
  429.                 key = KeyEvent.VK_3;
  430.             break;
  431.             case "4":
  432.                 key = KeyEvent.VK_4;
  433.             break;
  434.             case "5":
  435.                 key = KeyEvent.VK_5;
  436.             break;
  437.             case "6":
  438.                 key = KeyEvent.VK_6;
  439.             break;
  440.             case "7":
  441.                 key = KeyEvent.VK_7;
  442.             break;
  443.             case "8":
  444.                 key = KeyEvent.VK_8;
  445.             break;
  446.             case "9":
  447.                 key = KeyEvent.VK_9;
  448.             break;
  449.             case "0":
  450.                 key = KeyEvent.VK_0;
  451.             break;
  452.             case "-":
  453.                 key = KeyEvent.VK_SUBTRACT;
  454.             break;
  455.             case "=":
  456.                 key = KeyEvent.VK_EQUALS;
  457.             break;
  458.             case "BACKSPACE":
  459.                 key = KeyEvent.VK_BACK_SPACE;
  460.             break;
  461.            
  462.             // second row
  463.            
  464.             case "TAB":
  465.                 key = KeyEvent.VK_TAB;
  466.             break;
  467.             case "Q":
  468.                 key = KeyEvent.VK_Q;
  469.             break;
  470.             case "W":
  471.                 key = KeyEvent.VK_W;
  472.             break;
  473.             case "E":
  474.                 key = KeyEvent.VK_E;
  475.             break;
  476.             case "R":
  477.                 key = KeyEvent.VK_R;
  478.             break;
  479.             case "T":
  480.                 key = KeyEvent.VK_T;
  481.             break;
  482.             case "Y":
  483.                 key = KeyEvent.VK_Y;
  484.             break;
  485.             case "U":
  486.                 key = KeyEvent.VK_U;
  487.             break;
  488.             case "I":
  489.                 key = KeyEvent.VK_I;
  490.             break;
  491.             case "O":
  492.                 key = KeyEvent.VK_O;
  493.             break;
  494.             case "P":
  495.                 key = KeyEvent.VK_P;
  496.             break;
  497.             case "[":
  498.                 key = KeyEvent.VK_OPEN_BRACKET;
  499.             break;
  500.             case "]":
  501.                 key = KeyEvent.VK_CLOSE_BRACKET;
  502.             break;
  503.             case "\\":
  504.                 key = KeyEvent.VK_BACK_SLASH;
  505.             break;
  506.            
  507.             // third row
  508.            
  509.             case "CAPSLOCK":
  510.                 key = KeyEvent.VK_CAPS_LOCK;
  511.             break;
  512.             case "A":
  513.                 key = KeyEvent.VK_A;
  514.             break;
  515.             case "S":
  516.                 key = KeyEvent.VK_S;
  517.             break;
  518.             case "D":
  519.                 key = KeyEvent.VK_D;
  520.             break;
  521.             case "F":
  522.                 key = KeyEvent.VK_F;
  523.             break;
  524.             case "G":
  525.                 key = KeyEvent.VK_G;
  526.             break;
  527.             case "H":
  528.                 key = KeyEvent.VK_H;
  529.             break;
  530.             case "J":
  531.                 key = KeyEvent.VK_J;
  532.             break;
  533.             case "K":
  534.                 key = KeyEvent.VK_K;
  535.             break;
  536.             case "L":
  537.                 key = KeyEvent.VK_L;
  538.             break;
  539.             case ";":
  540.                 key = KeyEvent.VK_SEMICOLON;
  541.             break;
  542.             case "'":
  543.                 key = KeyEvent.VK_QUOTE;
  544.             break;
  545.             case "ENTER":
  546.                 key = KeyEvent.VK_ENTER;
  547.             break;
  548.            
  549.             //forth row?
  550.            
  551.             case "SHIFT":
  552.                 key = KeyEvent.VK_SHIFT;
  553.             break;
  554.             case "Z":
  555.                 key = KeyEvent.VK_Z;
  556.             break;
  557.             case "X":
  558.                 key = KeyEvent.VK_X;
  559.             break;
  560.             case "C":
  561.                 key = KeyEvent.VK_C;
  562.             break;
  563.             case "V":
  564.                 key = KeyEvent.VK_V;
  565.             break;
  566.             case "B":
  567.                 key = KeyEvent.VK_B;
  568.             break;
  569.             case "N":
  570.                 key = KeyEvent.VK_N;
  571.             break;
  572.             case "M":
  573.                 key = KeyEvent.VK_M;
  574.             break;
  575.             case ",":
  576.                 key = KeyEvent.VK_COMMA;
  577.             break;
  578.             case ".":
  579.                 key = KeyEvent.VK_PERIOD;
  580.             break;
  581.             case "/":
  582.                 key = KeyEvent.VK_SLASH;
  583.             break;
  584.             //NO RIGHT SHIFT KEY
  585.            
  586.             //Fifth row?
  587.            
  588.             case "CONTROL":
  589.                 key = KeyEvent.VK_CONTROL;
  590.             break;
  591.             case "WINDOWS":
  592.                 key = KeyEvent.VK_WINDOWS;
  593.             break;
  594.             case "ALT":
  595.                 key = KeyEvent.VK_ALT;
  596.             break;
  597.             case "SPACE":
  598.                 key = KeyEvent.VK_SPACE;
  599.             break;
  600.             case "UP":
  601.                 key = KeyEvent.VK_UP;
  602.             break;
  603.             case "DOWN":
  604.                 key = KeyEvent.VK_DOWN;
  605.             break;
  606.             case "LEFT":
  607.                 key = KeyEvent.VK_LEFT;
  608.             break;
  609.             case "RIGHT":
  610.                 key = KeyEvent.VK_RIGHT;
  611.             break;
  612.            
  613.             //no repeats
  614.            
  615.             // extras?
  616.            
  617.             case "HOME":
  618.                 key = KeyEvent.VK_HOME;
  619.             break;
  620.             case "END":
  621.                 key = KeyEvent.VK_END;
  622.             break;
  623.             case "PAGEUP":
  624.                 key = KeyEvent.VK_PAGE_UP;
  625.             break;
  626.             case "PAGEDOWN":
  627.                 key = KeyEvent.VK_PAGE_DOWN;
  628.             break;
  629.             case "PRINTSCREEN":
  630.                 key = KeyEvent.VK_PRINTSCREEN;
  631.             break;
  632.             case "BREAK":
  633.                 key = KeyEvent.VK_CANCEL;
  634.             break;
  635.             case "PAUSE":
  636.                 key = KeyEvent.VK_PAUSE;
  637.             break;
  638.             case "SCROLLLOCK":
  639.                 key = KeyEvent.VK_SCROLL_LOCK;
  640.             break;
  641.            
  642.            
  643.             default:
  644.                 throw new Exception("Invalid command, no such key: "+s);
  645.             //break;
  646.         }
  647.        
  648.         return key;
  649.     }
  650. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement