Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
115
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. private static Type forum;
  12. private static Type hostAddress;
  13. private static Type username;
  14. private static Type password;
  15. public enum Type {
  16. myBB,
  17. SMF,
  18. IPB,
  19. vBulletin,
  20. phpBB,
  21. }
  22.  
  23. private static String[] tableNames = new String[6];
  24. private static void setTables(){
  25. if(forum == Type.myBB){
  26. tableNames = new String[] {"mybb_users","username","password","salt","usergroupid",};
  27. } else if(forum == Type.SMF){
  28. tableNames = new String[] {"smf_","username","password","password","usergroupid",};
  29. } else if(forum == Type.IPB){
  30. tableNames = new String[] {"members","name","converge_pass_hash","converge_pass_salt","mgroup",};
  31. } else if(forum == Type.vBulletin){//vbulletin
  32. tableNames = new String[] {"user","username","password","salt","usergroupid",};
  33. } else if(forum == Type.phpBB){//phpBB
  34. tableNames = new String[] {"users","username","user_password","user_password","group_id",};
  35. }
  36. }
  37.  
  38. public vBulletin(String url,String database,String username,String password,Type t){
  39. this.hostAddress = "jdbc:mysql://"+url+"/"+database;
  40. this.username = username;
  41. this.password = password;
  42. this.forum = t;
  43. try {
  44. //connect();
  45. thread = new Thread(this);
  46. thread.start();
  47. } catch(Exception e){
  48. connection = null;
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53.  
  54. private static 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. } catch(Exception e){
  65. System.out.println("Connetion rejected, Wrong username or password, or ip is banned, or host is down.");
  66. connection = null;
  67. e.printStackTrace();
  68. }
  69. }
  70. private void ping(){
  71. try{
  72. ResultSet results = null;
  73. String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[2]+" LIKE 'null312'";
  74. results = statement.executeQuery(query);
  75. } catch(Exception e){
  76. connection = null;
  77. connect();
  78. e.printStackTrace();
  79. }
  80. }
  81.  
  82. public void run(){
  83. boolean allowRun = true;
  84. while(allowRun){
  85. try {
  86. if(connection == null) {
  87. setTables();
  88. connect();
  89. } else {
  90. ping();
  91. }
  92. thread.sleep(10000);
  93. } catch(Exception e){
  94. }
  95. }
  96. }
  97. /**
  98. * returns 2 integers, the return code and the usergroup of the player
  99. */
  100.  
  101. public static int[] checkUser(String name,String password){
  102. int i = 0;
  103. int[] returnCodes = {0,0};//return code for client, group id
  104.  
  105. try{
  106. ResultSet results = null;
  107. String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[1]+" LIKE '"+name+"'";
  108. try {
  109. if(statement == null)
  110. statement = connection.createStatement();
  111. } catch(Exception e5){
  112. statement = null;
  113. connection = null;
  114. connect();
  115. statement = connection.createStatement();
  116. }
  117. results = statement.executeQuery(query);
  118. if(results.next()){
  119. String salt = results.getString(tableNames[3]);
  120. String pass = results.getString(tableNames[2]);
  121. int group = results.getInt(tableNames[4]);
  122. returnCodes[1] = group;
  123. String pass2 = "";
  124. if(forum == Type.myBB){
  125. pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
  126. } else if(forum == Type.vBulletin){
  127. pass2 = MD5.MD5(password);
  128. pass2 = MD5.MD5(pass2+salt);
  129. } else if(forum == Type.SMF){
  130. pass2 = MD5.SHA((name.toLowerCase())+password);
  131. } else if(forum == Type.phpBB){
  132. pass2 = MD5.MD5(password);
  133. } else if(forum == Type.IPB){
  134. pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
  135. }
  136. if(pass.equals(pass2)){
  137. returnCodes[0] = 2;
  138. return returnCodes;
  139. } else {
  140. returnCodes[0] = 3;
  141. return returnCodes;
  142. }
  143. } else {
  144. //no user exists
  145. returnCodes[0] = 12;
  146. return returnCodes;
  147. }
  148. } catch(Exception e){
  149. statement = null;
  150. returnCodes[0] = 8;
  151. return returnCodes;
  152. }
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement