Advertisement
Guest User

Untitled

a guest
Jul 9th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 KB | None | 0 0
  1. package com.climaxcraft.xenfororegister.bungee;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.DataInputStream;
  5. import java.net.HttpURLConnection;
  6. import java.net.URL;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9.  
  10. import java.util.regex.Pattern;
  11.  
  12. import org.json.JSONObject;
  13.  
  14. import com.climaxcraft.xenfororegister.util.PasswordSecurity;
  15.  
  16. import net.md_5.bungee.api.ChatColor;
  17. import net.md_5.bungee.api.CommandSender;
  18. import net.md_5.bungee.api.ProxyServer;
  19. import net.md_5.bungee.api.connection.ProxiedPlayer;
  20. import net.md_5.bungee.api.plugin.Command;
  21.  
  22. public class RegisterCommand extends Command {
  23.  
  24. String prefix = "§4§lM.A.D. §8| ";
  25.  
  26. protected RegisterCommand() {
  27. super("forum");
  28. }
  29.  
  30. public static boolean isRegistered(ProxiedPlayer p) throws SQLException {
  31. // User ist in der ForenDB
  32. String statement = "SELECT COUNT(*) FROM `xf_user` WHERE username = '" + p.getName() + "';";
  33. ResultSet rs = XenforoRegister.instance.db.executeQueryWithResults(statement);
  34. if (rs.first()) {
  35. if (rs.getInt("COUNT(*)") == 1) {
  36. return true;
  37. } else {
  38. return false;
  39. }
  40. }
  41. return false;
  42. }
  43.  
  44. public static boolean samePassword(String string, String password) throws SQLException {
  45. //User ist in der ForenDB
  46. String statement = "SELECT DISTINCT password FROM `authme` WHERE username = '" + string + "';";
  47. ResultSet rs = XenforoRegister.instance.login.executeQueryWithResults(statement);
  48. if (rs.first()) {
  49. String passworddb = rs.getString("password");
  50. if(PasswordSecurity.comparePassword(passworddb, password)) {
  51. return true;
  52. } else {
  53. return false;
  54. }
  55. }
  56. return false;
  57. }
  58.  
  59. @SuppressWarnings("deprecation")
  60. public void execute(CommandSender commandSender, final String[] strings) {
  61. try {
  62. if (XenforoRegister.configObj.getString("apiKey").equalsIgnoreCase("xxxxxx")) {
  63. commandSender.sendMessage(ChatColor.DARK_RED
  64. + "Configuration for plugin not set up - please refer this message to an administrator.");
  65. return;
  66. }
  67. } catch (Exception e3) {
  68. e3.printStackTrace();
  69. if ((commandSender instanceof ProxiedPlayer)) {
  70. final ProxiedPlayer p = (ProxiedPlayer) commandSender;
  71. if (strings.length == 2) {
  72. ProxyServer.getInstance().getScheduler().runAsync(XenforoRegister.instance, new Runnable() {
  73. public void run() {
  74. String password = strings[1];
  75. String email = strings[0];
  76. String[] emailproviderarray = email.split(Pattern.quote("@"));
  77. String emailprovider = "*" + emailproviderarray[1];
  78. try {
  79. if (XenforoRegister.configObj.getBoolean("enforceMaxRegistrations")) {
  80. String statement = "SELECT COUNT(*) FROM `xf_ban_email` WHERE banned_email = '"
  81. + emailprovider + "';";
  82. ResultSet rs = XenforoRegister.instance.db.executeQueryWithResults(statement);
  83. if ((rs.first()) && (rs.getInt("COUNT(*)") == 1)) {
  84. p.sendMessage(RegisterCommand.this.prefix
  85. + "§cBitte verwende eine richtige Emailadresse. Keine Trash-EMail!");
  86. return;
  87. }
  88. if (samePassword(p.getName(), password)) {
  89. p.sendMessage(RegisterCommand.this.prefix
  90. + "§cBitte verwende ein anderes Passwort als dein InGame-Passwort!");
  91. return;
  92. }
  93. }
  94. } catch (Exception e) {
  95. e.printStackTrace();
  96. }
  97. try {
  98. URL api = new URL(XenforoRegister.configObj.getString("apiLoc")
  99. + "?action=register&hash=" + XenforoRegister.configObj.getString("apiKey")
  100. + "&username=" + p.getName() + "&password=" + password + "&email=" + email
  101. + "&user_state="
  102. + XenforoRegister.configObj.getString("default_user_state"));
  103. HttpURLConnection conn = (HttpURLConnection) api.openConnection();
  104. conn.setInstanceFollowRedirects(true);
  105. DataInputStream result;
  106. if (conn.getResponseCode() == 400) {
  107. result = new DataInputStream(new BufferedInputStream(conn.getErrorStream()));
  108. } else {
  109. result = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
  110. }
  111. String json = result.readLine();
  112. if (json == null) {
  113. p.sendMessage(RegisterCommand.this.prefix + ChatColor.RED
  114. + "Das hat nicht geklappt :/ - Bitte an einen Admin wenden!");
  115. }
  116. JSONObject obj = new JSONObject(json);
  117. if (!obj.has("error")) {
  118. p.sendMessage(RegisterCommand.this.prefix
  119. + "§6Fertig! §aDu hast dich erfolgreich in unserem Forum registriert. Forum: http://www.mad-gamble.net/forum");
  120.  
  121. XenforoRegister.instance.getLogger().info(RegisterCommand.this.prefix + "User "
  122. + p.getName() + " has registered on the site.");
  123. } else {
  124. p.sendMessage(RegisterCommand.this.prefix
  125. + "§cDu hast dich bereits im Forum registriert!");
  126. }
  127. } catch (Exception e) {
  128. p.sendMessage(RegisterCommand.this.prefix
  129. + "§cDas hat nicht geklappt :/ Bitte an einen Admin wenden!");
  130. e.printStackTrace();
  131. }
  132. }
  133. });
  134. } else {
  135. p.sendMessage(this.prefix + ChatColor.RED
  136. + "Verwende: /forum <Email> <Passwort> um dich zu registrieren.");
  137. }
  138. } else {
  139. commandSender.sendMessage(this.prefix + ChatColor.RED + "Dieser Befehl ist nur für Spieler.");
  140. }
  141. }
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement