Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. package server.players;
  2.  
  3. import java.sql.*;
  4.  
  5. public class vBulletin implements Runnable {
  6.  
  7.  
  8. private static Connection connection = null;
  9. private static 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 static 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[] {"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.  
  50. private final String hostAddress;
  51. private final String username;
  52. private final String password;
  53. private final Type forum;
  54.  
  55. private void connect(){
  56. try {
  57. Class.forName("com.mysql.jdbc.Driver");
  58. } catch(Exception e2){
  59. System.out.println("Cannot find mySql Driver.");
  60. return;
  61. }
  62. try {
  63. connection = DriverManager.getConnection(hostAddress, username,password);
  64. statement = connection.createStatement();
  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. private void ping(){
  72. try{
  73. ResultSet results = null;
  74. String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[2]+" LIKE 'null312'";
  75. results = statement.executeQuery(query);
  76. } catch(Exception e){
  77. connection = null;
  78. connect();
  79. e.printStackTrace();
  80. }
  81. }
  82.  
  83. public void run(){
  84. boolean allowRun = true;
  85. while(allowRun){
  86. try {
  87. if(connection == null) {
  88. setTables();
  89. connect();
  90. } else {
  91. ping();
  92. }
  93. thread.sleep(10000);
  94. } catch(Exception e){
  95. }
  96. }
  97. }
  98. /**
  99. * returns 2 integers, the return code and the usergroup of the player
  100. */
  101.  
  102. public static int[] checkUser(String name,String password){
  103. int i = 0;
  104. int[] returnCodes = {0,0};//return code for client, group id
  105.  
  106. try{
  107. ResultSet results = null;
  108. String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[1]+" LIKE '"+name+"'";
  109. try {
  110. if(statement == null)
  111. statement = connection.createStatement();
  112. } catch(Exception e5){
  113. statement = null;
  114. connection = null;
  115. connect();
  116. statement = connection.createStatement();
  117. }
  118. results = statement.executeQuery(query);
  119. if(results.next()){
  120. String salt = results.getString(tableNames[3]);
  121. String pass = results.getString(tableNames[2]);
  122. int group = results.getInt(tableNames[4]);
  123. returnCodes[1] = group;
  124. String pass2 = "";
  125. if(forum == Type.myBB){
  126. pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
  127. } else if(forum == Type.vBulletin){
  128. pass2 = MD5.MD5(password);
  129. pass2 = MD5.MD5(pass2+salt);
  130. } else if(forum == Type.SMF){
  131. pass2 = MD5.SHA((name.toLowerCase())+password);
  132. } else if(forum == Type.phpBB){
  133. pass2 = MD5.MD5(password);
  134. } else if(forum == Type.IPB){
  135. pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
  136. }
  137. if(pass.equals(pass2)){
  138. returnCodes[0] = 2;
  139. return returnCodes;
  140. } else {
  141. returnCodes[0] = 3;
  142. return returnCodes;
  143. }
  144. } else {
  145. //no user exists
  146. returnCodes[0] = 12;
  147. return returnCodes;
  148. }
  149. } catch(Exception e){
  150. statement = null;
  151. returnCodes[0] = 8;
  152. return returnCodes;
  153. }
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement