Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. package dragonkk.rs2rsps.net;
  2.  
  3. import java.sql.*;
  4.  
  5. public class vBulletin implements Runnable {
  6.  
  7. private static Connection connection = null;
  8. private static Statement statement = null;
  9. private static Thread thread = null;
  10.  
  11. public enum Type {
  12.  
  13. myBB,
  14. SMF,
  15. IPB,
  16. vBulletin,
  17. phpBB,
  18. }
  19. private String[] tableNames = new String[6];
  20.  
  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[]{"smf_", "username", "password", "password", "usergroupid",};
  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.username = username;
  38. this.password = password;
  39. this.forum = t;
  40. try {
  41. //connect();
  42. thread = new Thread(this);
  43. thread.start();
  44. } catch (Exception e) {
  45. connection = null;
  46. e.printStackTrace();
  47. }
  48. }
  49. private final String hostAddress;
  50. private final String username;
  51. private final String password;
  52. private final Type forum;
  53.  
  54. private void connect() {
  55. try {
  56. Class.forName("com.mysql.jdbc.Driver");
  57. } catch (Exception e2) {
  58. System.out.println("Cannot find mySql Driver.");
  59. return;
  60. }
  61. try {
  62. connection = DriverManager.getConnection(hostAddress, username, password);
  63. statement = connection.createStatement();
  64. System.out.println("Connected to SQL");
  65. } catch (Exception e) {
  66. System.out.println("Connetion rejected, Wrong username or password, or ip is banned, or host is down.");
  67. connection = null;
  68. e.printStackTrace();
  69. }
  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. /**
  101. * returns 2 integers, the return code and the usergroup of the player
  102. */
  103. public int[] checkUser(String name, String password) {
  104. int i = 0;
  105. int[] returnCodes = {0, 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. }
  114. } catch (Exception e5) {
  115. statement = null;
  116. connection = null;
  117. connect();
  118. statement = connection.createStatement();
  119. }
  120. results = statement.executeQuery(query);
  121. if (results.next()) {
  122. String salt = results.getString(tableNames[3]);
  123. String pass = results.getString(tableNames[2]);
  124. int group = results.getInt(tableNames[4]);
  125. String mgroup = results.getString("membergroupids");
  126. returnCodes[1] = group;
  127. String pass2 = "";
  128. if (forum == Type.myBB) {
  129. pass2 = MD5.MD5(MD5.MD5(salt) + MD5.MD5(password));
  130. } else if (forum == Type.vBulletin) {
  131. pass2 = MD5.MD5(password);
  132. pass2 = MD5.MD5(pass2 + salt);
  133. } else if (forum == Type.SMF) {
  134. pass2 = MD5.SHA((name.toLowerCase()) + password);
  135. } else if (forum == Type.phpBB) {
  136. pass2 = MD5.MD5(password);
  137. } else if (forum == Type.IPB) {
  138. pass2 = MD5.MD5(MD5.MD5(salt) + MD5.MD5(password));
  139. }
  140. if (mgroup.contains("10"))
  141. returnCodes[2] = 1;
  142. if (mgroup.contains("11"))
  143. returnCodes[2] = 2;
  144. if (pass.equals(pass2)) {
  145. returnCodes[0] = 2;
  146. return returnCodes;
  147. } else {
  148. returnCodes[0] = 3;
  149. return returnCodes;
  150. }
  151. } else {
  152. //no user exists
  153. returnCodes[0] = 12;
  154. return returnCodes;
  155. }
  156. } catch (Exception e) {
  157. statement = null;
  158. returnCodes[0] = 8;
  159. return returnCodes;
  160. }
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement