Advertisement
Guest User

Untitled

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