Advertisement
Guest User

Untitled

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