Advertisement
Guest User

Untitled

a guest
May 15th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.88 KB | None | 0 0
  1.  
  2. /**
  3.  * vBulletin class
  4.  * @author Mad Turnip
  5.  */
  6.  
  7. import java.sql.*;
  8.  
  9. public class vBulletin implements Runnable {
  10.    
  11.    
  12.     private Connection connection = null;
  13.     private Statement statement = null;
  14.     private static Thread thread = null;
  15.    
  16.     public enum Type {
  17.         myBB,
  18.         SMF,
  19.         IPB,
  20.         vBulletin,
  21.         phpBB,
  22.     }
  23.  
  24.     private String[] tableNames = new String[6];
  25.     private void setTables(){
  26.         if(forum == Type.myBB){
  27.             tableNames = new String[] {"mybb_users","username","password","salt","usergroupid",};
  28.         } else if(forum == Type.SMF){
  29.        
  30.         } else if(forum == Type.IPB){
  31.        
  32.         } else if(forum == Type.vBulletin){//vbulletin
  33.             tableNames = new String[] {"user","username","password","salt","usergroupid",};
  34.         } else if(forum == Type.phpBB){//phpBB
  35.             tableNames = new String[] {"users","username","user_password","user_password","group_id",};
  36.         }
  37.     }
  38.    
  39.     public vBulletin(String url,String database,String username,String password,Type t){
  40.         this.hostAddress = "jdbc:mysql://"+url+"/"+database;
  41.         this.username = username;
  42.         this.password = password;
  43.         this.forum = t;
  44.         try {
  45.             //connect();
  46.             thread = new Thread(this);
  47.             thread.start();
  48.         } catch(Exception e){
  49.             connection = null;
  50.             e.printStackTrace();
  51.         }
  52.     }
  53.    
  54.     private final String hostAddress;
  55.     private final String username;
  56.     private final String password;
  57.     private final Type forum;
  58.    
  59.     private void connect(){
  60.         try {
  61.             Class.forName("com.mysql.jdbc.Driver");
  62.         } catch(Exception e2){
  63.             System.out.println("Cannot find mySql Driver.");
  64.             return;
  65.         }
  66.         try {
  67.             connection = DriverManager.getConnection(hostAddress, username,password);
  68.             statement = connection.createStatement();
  69.         } catch(Exception e){
  70.             System.out.println("Connetion rejected, Wrong username or password, or ip is banned, or host is down.");
  71.             connection = null;
  72.             e.printStackTrace();
  73.         }
  74.     }
  75.     private void ping(){
  76.         try{
  77.             ResultSet results = null;
  78.             String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[2]+" LIKE 'null312'";
  79.             results = statement.executeQuery(query);
  80.         } catch(Exception e){
  81.             connection = null;
  82.             connect();
  83.             e.printStackTrace();
  84.         }
  85.     }
  86.    
  87.     public void run(){
  88.         boolean allowRun = true;
  89.         while(allowRun){
  90.             try {
  91.                 if(connection == null) {
  92.                     setTables();
  93.                     connect();
  94.                 } else {
  95.                     ping();
  96.                 }
  97.                 thread.sleep(10000);
  98.             } catch(Exception e){
  99.             }
  100.         }
  101.     }
  102.     /**
  103.      * returns 2 integers, the return code and the usergroup of the player
  104.      */
  105.    
  106.     public int[] checkUser(String name,String password){
  107.         int i = 0;
  108.         int[] returnCodes = {0,0};//return code for client, group id
  109.  
  110.         try{
  111.             ResultSet results = null;
  112.             String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[1]+" LIKE '"+name+"'";
  113.             try {
  114.             if(statement == null)
  115.                 statement = connection.createStatement();
  116.             } catch(Exception e5){
  117.                 statement = null;
  118.                 connection = null;
  119.                 connect();
  120.                 statement = connection.createStatement();
  121.             }
  122.             results = statement.executeQuery(query);
  123.             if(results.next()){
  124.                 String salt = results.getString(tableNames[3]);
  125.                 String pass = results.getString(tableNames[2]);
  126.                 int group = results.getInt(tableNames[4]);
  127.                 returnCodes[1] = group;
  128.                 String pass2 = "";
  129.                 if(forum == Type.myBB){
  130.                     pass2 = MD5.MD5(salt);
  131.                     pass2 = MD5.MD5(pass2+password);
  132.                 } else if(forum == Type.vBulletin){
  133.                     pass2 = MD5.MD5(password);
  134.                     pass2 = MD5.MD5(pass2+salt);
  135.                 } else if(forum == Type.phpBB){
  136.                     pass2 = MD5.MD5(password);
  137.                 }
  138.                 //System.out.println(""+pass2+" : "+pass);
  139.                 if(pass.equals(pass2)){
  140.                     returnCodes[0] = 2;
  141.                     return returnCodes;
  142.                 } else {
  143.                     returnCodes[0] = 3;
  144.                     return returnCodes;
  145.                 }
  146.             } else {
  147.                 //no user exists
  148.                 returnCodes[0] = 12;
  149.                 return returnCodes;
  150.             }
  151.         } catch(Exception e){
  152.             statement = null;
  153.             returnCodes[0] = 8;
  154.             return returnCodes;
  155.         }
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement