Advertisement
Guest User

Untitled

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