Advertisement
Guest User

Untitled

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