Hakens

ZegarBot

Dec 10th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.10 KB | None | 0 0
  1. public class Zegar {
  2.     static String IP_Adrr="";
  3.     static  String Log="";
  4.     static String Pass="";
  5.     static String Nick="";
  6.     static String ID1="";
  7.     static String ID2="";
  8.     static String ID3="";
  9.     static String ID4="";
  10.     static String Port="";
  11.     static String Id_Rangi_Bota="";
  12.     static String HOST = "";
  13.     static int PORT_e;
  14.     static String FROM = "";
  15.     static String PASSWORD = "";
  16.     static String TO = "";
  17.     static String SUBJECT = "";
  18.     static String CONTENT = "";
  19.     static String Port1="";
  20.     static String Z_CONTENT="";
  21.     public static void main(String[] args) {
  22.        
  23.         Properties prop = new Properties();
  24.        
  25.         try {
  26.            
  27.  
  28.            
  29.             prop.setProperty("IP", "xxx.xxx.xxx.xxx");
  30.             prop.setProperty("Login", "xxxx");
  31.             prop.setProperty("Pass", "xxxxx");
  32.             prop.setProperty("Nick", "xxxxx");
  33.             prop.setProperty("Port", "xxxxx");
  34.             prop.setProperty("1ID", "xxx");
  35.             prop.setProperty("2ID", "xxx");
  36.             prop.setProperty("3ID", "xxx");
  37.             prop.setProperty("4ID", "xxx");
  38.             prop.setProperty("Id_Rangi_Bota", "xxx");//<-Id rangi query
  39.             prop.setProperty("Email_HOST", "xxx");
  40.             prop.setProperty("Email_PORT", "xxx");
  41.             prop.setProperty("Email_FROM", "xxx");
  42.             prop.setProperty("Email_PASSWORD", "xxx");
  43.             prop.setProperty("Email_TO", "xxx");
  44.             prop.setProperty("Email_SUBJECT", "DDoS Serwera");
  45.             prop.setProperty("Email_CONTENT", "\"Atak DDos IP: \"+{IP_Adrr}");//<- zmienna w pliku konfiguracyjnym musi byc w klamrach
  46.            
  47.             File f = new File("server.properties");
  48.             if(!f.exists()){
  49.                 PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8")), true);
  50.                     prop.store(out, "Autoconfig, generated by ZegarBot");
  51.            
  52.             }
  53.  
  54.         } catch (Exception io) {
  55.             io.printStackTrace();
  56.         }
  57.         try {
  58.             BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("server.properties"), "UTF8"));
  59.             prop.load(in);
  60.              IP_Adrr=prop.getProperty("IP");
  61.              Log=prop.getProperty("Login");
  62.              Pass=prop.getProperty("Pass");
  63.              Nick=prop.getProperty("Nick");
  64.              ID1=prop.getProperty("1ID");
  65.              ID2=prop.getProperty("2ID");
  66.              ID3=prop.getProperty("3ID");
  67.              ID4=prop.getProperty("4ID");
  68.              Port=prop.getProperty("Port");
  69.              Id_Rangi_Bota=prop.getProperty("Id_Rangi_Bota");
  70.              HOST   =prop.getProperty("Email_HOST");
  71.              Port1=prop.getProperty("Email_PORT");
  72.              PORT_e=Integer.parseInt(Port1);
  73.              FROM=prop.getProperty("Email_FROM");
  74.              PASSWORD=prop.getProperty("Email_PASSWORD");
  75.              TO =prop.getProperty("Email_TO");
  76.              SUBJECT=prop.getProperty("Email_SUBJECT");
  77.              CONTENT    =prop.getProperty("Email_CONTENT");
  78.              Z_CONTENT = CONTENT.replaceAll("\\{IP_Adrr\\}", IP_Adrr);
  79.         } catch (IOException  | NumberFormatException e) {
  80.             System.err.println("Utworzono plik konfiguracyjny, edytuj jego wartości na poprawne.");
  81.         }
  82.        
  83.          
  84.         final TS3Config config = new TS3Config();
  85.         final TS3Query query = new TS3Query(config);
  86.         final TS3Api api = query.getApi();
  87.     try {
  88.         config.setHost((IP_Adrr));
  89.         config.setQueryPort(Integer.parseInt(Port));
  90.         config.setDebugLevel(Level.SEVERE);
  91.         config.setFloodRate(FloodRate.UNLIMITED);
  92.         query.connect();
  93.         api.login((Log), (Pass));
  94.         api.selectVirtualServerById(1);
  95.         api.setNickname((Nick));
  96.         api.registerAllEvents();
  97.  
  98.     } catch(NumberFormatException e) {
  99.             System.err.println("Uruchom ponownie po edycji zmiennych");
  100.       }
  101.          
  102.        
  103.        
  104.  
  105.        
  106.        
  107.         ScheduledExecutorService ses2 = Executors.newSingleThreadScheduledExecutor();
  108.         ses2.scheduleAtFixedRate(new Runnable() {
  109.             @Override
  110.            public void run() {
  111.      String[][] czcionka ={{"▄▀▀▀█─", "─█─", "─▀▀▀█─", "─▀▀▀█─", "▄───█─", "▄▀▀▀▀─", "▄▀▀▀▀─", "▄▀▀▀█─", "▄▀▀▀█─", "▄▀▀▀█─", "────"},
  112.                            {"█───█─", "─█─", "▄▄▄▄█─", "─▄▄▄█─", "█▄▄▄█─", "█▄▄▄▄─", "█▄▄▄▄─", "────█─", "█▄▄▄█─", "█▄▄▄█─", "─▀──"},
  113.                            {"█───█─", "─█─", "█─────", "────█─", "────█─", "────█─", "█───█─", "────█─", "█───█─", "────█─", "─▄──"},
  114.                            {"▀▀▀▀──", "─▀─", "▀▀▀▀──", "▀▀▀▀──", "────▀─", "▀▀▀▀──", "▀▀▀▀──", "────▀─", "▀▀▀▀──", "▀▀▀▀──", "────"}};
  115.        
  116.        
  117.        
  118.        
  119.        
  120.        
  121.         Calendar teraz = Calendar.getInstance();
  122.         int hours = teraz.get(Calendar.HOUR_OF_DAY);
  123.         int minutes = teraz.get(Calendar.MINUTE);
  124.         String[] linie= {"", "", "", ""};
  125.        
  126.         for(int i = 0; i<4;i++) {
  127.             linie[i]="[cspacer]-";
  128.             if(hours>=10) {
  129.                 linie[i] +=czcionka[i][(int) Math.floor(hours / 10)];
  130.             }
  131.             linie[i]+=czcionka[i][hours % 10];
  132.             linie[i]+=czcionka[i][10];
  133.             linie[i]+=czcionka[i][(int) Math.floor(minutes / 10)];
  134.             linie[i]+=czcionka[i][minutes%10];
  135.            
  136.            
  137.            
  138.            
  139.         }
  140.        
  141.         final HashMap<ChannelProperty, String> zegar1 = new HashMap<>();
  142.         final HashMap<ChannelProperty, String> zegar2 = new HashMap<>();
  143.         final HashMap<ChannelProperty, String> zegar3 = new HashMap<>();
  144.         final HashMap<ChannelProperty, String> zegar4 = new HashMap<>();
  145.         zegar1.put(ChannelProperty.CHANNEL_NAME, linie[0]);
  146.         zegar2.put(ChannelProperty.CHANNEL_NAME, linie[1]);
  147.         zegar3.put(ChannelProperty.CHANNEL_NAME, linie[2]);
  148.         zegar4.put(ChannelProperty.CHANNEL_NAME, linie[3]);
  149.         api.editChannel(Integer.parseInt(ID1), zegar1);
  150.         api.editChannel(Integer.parseInt((ID2)), zegar2);
  151.         api.editChannel(Integer.parseInt((ID3)), zegar3);
  152.         api.editChannel(Integer.parseInt((ID4)), zegar4);
  153.             }
  154.         }, 0, 1, TimeUnit.MINUTES);
  155.        
  156.         System.err.println("Zegarynka Dziala");
  157.          
  158.        
  159.        
  160.        
  161.        
  162.        
  163.        
  164.        
  165.        
  166.        
  167.        
  168.        
  169.         api.addTS3Listeners(new TS3Listener() {
  170.            
  171.            
  172.             @Override
  173.             public void onTextMessage(TextMessageEvent e) {
  174.                
  175.            
  176.             }
  177.  
  178.             @Override
  179.             public void onServerEdit(ServerEditedEvent e) {
  180.                
  181.             }
  182.  
  183.             @Override
  184.             public void onClientMoved(ClientMovedEvent e) {
  185.                
  186.                
  187.             }
  188.             @Override
  189.             public void onClientLeave(ClientLeaveEvent e) {
  190.                 double packet=api.getServerInfo().getTotalPacketloss();
  191.                 if(packet>=30.0) {
  192.                     if(api.getClientInfo(e.getClientId()).isInServerGroup(Integer.parseInt(Id_Rangi_Bota))!=true) {
  193.                        
  194.                        
  195.                         try {
  196.                                new Zegar().send();
  197.                               } catch (MessagingException e1) {
  198.                                e1.printStackTrace();
  199.                               }
  200.                    
  201.                 }
  202.                 }
  203.             }
  204.  
  205.             @Override
  206.             public void onClientJoin(ClientJoinEvent e) {
  207.                 // ...
  208.             }
  209.  
  210.             @Override
  211.             public void onChannelEdit(ChannelEditedEvent e) {
  212.                 // ...
  213.             }
  214.  
  215.             @Override
  216.             public void onChannelDescriptionChanged(ChannelDescriptionEditedEvent e) {
  217.                 // ...
  218.             }
  219.  
  220.             @Override
  221.             public void onChannelCreate(ChannelCreateEvent e) {
  222.                 // ...
  223.             }
  224.  
  225.             @Override
  226.             public void onChannelDeleted(ChannelDeletedEvent e) {
  227.                 // ...
  228.             }
  229.  
  230.             @Override
  231.             public void onChannelMoved(ChannelMovedEvent e) {
  232.                 // ...
  233.             }
  234.  
  235.             @Override
  236.             public void onChannelPasswordChanged(ChannelPasswordChangedEvent e) {
  237.                 // ...
  238.             }
  239.  
  240.             @Override
  241.             public void onPrivilegeKeyUsed(PrivilegeKeyUsedEvent e) {
  242.                 // ...
  243.             }
  244.         });
  245.     }
  246.    
  247.     public void send() throws MessagingException {
  248.  
  249.    
  250.           Properties props = new Properties();
  251.           props.put("mail.transport.protocol", "smtp");
  252.           props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
  253.           props.put("mail.smtp.starttls.enable", "true");
  254.           Session mailSession = Session.getDefaultInstance(props);
  255.           MimeMessage message = new MimeMessage(mailSession);
  256.           message.setSubject(SUBJECT);
  257.           message.setContent(Z_CONTENT, "text/plain; charset=ISO-8859-2");
  258.           message.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
  259.           Transport transport = mailSession.getTransport();
  260.           transport.connect(HOST, PORT_e, FROM, PASSWORD);
  261.           transport.sendMessage(message, message
  262.             .getRecipients(Message.RecipientType.TO));
  263.           transport.close();
  264.          
  265.          }
  266. }
Advertisement
Add Comment
Please, Sign In to add comment