From 81bd27cded4e10b8cdacf2f2aeebd43938c5752c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 25 Feb 2020 16:07:07 +0100 Subject: [PATCH 1/2] Registration process for new website --- src/de/steamwar/bungeecore/BungeeCore.java | 3 +- .../bungeecore/commands/WebpwCommand.java | 33 ---------- .../commands/WebregisterCommand.java | 63 +++++++++++++++++++ src/de/steamwar/bungeecore/sql/SQL.java | 23 +------ .../steamwar/bungeecore/sql/SteamwarUser.java | 4 -- 5 files changed, 66 insertions(+), 60 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/commands/WebpwCommand.java create mode 100644 src/de/steamwar/bungeecore/commands/WebregisterCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 8ef9bbb1..7afbdeac 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -71,7 +71,7 @@ public class BungeeCore extends Plugin { new MsgCommand(); new RCommand(); new PingCommand(); - new WebpwCommand(); + new WebregisterCommand(); new AlertCommand(); new KickCommand(); new JoinmeCommand(); @@ -196,7 +196,6 @@ public class BungeeCore extends Plugin { SQL.connect( config.getString("db.url"), - config.getString("db.weburl"), config.getString("db.username"), config.getString("db.password") ); diff --git a/src/de/steamwar/bungeecore/commands/WebpwCommand.java b/src/de/steamwar/bungeecore/commands/WebpwCommand.java deleted file mode 100644 index 072d58f9..00000000 --- a/src/de/steamwar/bungeecore/commands/WebpwCommand.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.steamwar.bungeecore.commands; - -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.SteamwarUser; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -public class WebpwCommand extends BasicCommand { - - public WebpwCommand() { - super("webpw", ""); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer player = (ProxiedPlayer) sender; - if(args.length != 2){ - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "/webpw [Passwort] [Passwort wiederholen]"); - return; - }else if(!args[0].equals(args[1])){ - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDie Passwörter stimmen nicht überein!"); - return; - }else if(args[0].length() < 6){ - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDas Passwort muss mindestens 6 Zeichen lang sein!"); - return; - } - - SteamwarUser.get(player.getUniqueId()).setWebpw(args[0]); - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Webpasswort gesetzt!"); - } - } -} diff --git a/src/de/steamwar/bungeecore/commands/WebregisterCommand.java b/src/de/steamwar/bungeecore/commands/WebregisterCommand.java new file mode 100644 index 00000000..ed464a5b --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/WebregisterCommand.java @@ -0,0 +1,63 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.SWException; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class WebregisterCommand extends BasicCommand { + + public WebregisterCommand() { + super("webregister", null, "web"); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if(!(sender instanceof ProxiedPlayer)) + return; + + ProxiedPlayer player = (ProxiedPlayer) sender; + if(args.length != 1){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "/webregister [E-Mail]"); + return; + } + + ProcessBuilder pb = new ProcessBuilder("php", "/var/www/register.php", player.getName(), args[0]); + try { + Process regProcess = pb.start(); + BufferedReader reader = new BufferedReader(new InputStreamReader(regProcess.getInputStream())); + String errorLine; + boolean error = false; + while((errorLine = reader.readLine()) != null){ + switch(errorLine){ + case "username_exists": + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu hast bereits einen Webaccount."); + break; + case "email_exists": + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDie E-Mail hast du bereits für einen anderen Account verwendet..."); + SWException.log("Bungee", "Duplicate E-Mail", player.getName() + " " + args[0]); + break; + case "invalid_email": + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§c[E-Mail], nicht [Freitext]!"); + break; + default: + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cEin interner Fehler ist aufgetreten, bitte wende dich an einen Developer."); + SWException.log("Bungee", "Unknown Wordpress User Creation Error", errorLine); + } + error = true; + } + + if(error) + return; + + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aEine E-Mail zum Setzen des Passworts wurde gesendet."); + } catch (IOException e) { + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cEin interner Fehler ist aufgetreten, bitte wende dich an einen Developer."); + throw new SecurityException("Could not create webaccount", e); + } + } +} diff --git a/src/de/steamwar/bungeecore/sql/SQL.java b/src/de/steamwar/bungeecore/sql/SQL.java index 5a04413e..feadde20 100644 --- a/src/de/steamwar/bungeecore/sql/SQL.java +++ b/src/de/steamwar/bungeecore/sql/SQL.java @@ -10,20 +10,16 @@ public class SQL { private SQL(){} private static Connection con; - private static Connection webcon; private static String url; - private static String weburl; private static String user; private static String password; - public static void connect(String url, String weburl, String user, String password) { + public static void connect(String url, String user, String password) { SQL.url = url; - SQL.weburl = weburl; SQL.user = user; SQL.password = password; try { con = DriverManager.getConnection(url + "?autoreconnect=true", user, password); - webcon = DriverManager.getConnection(weburl + "?autoreconnect=true", user, password); }catch (SQLException e) { ProxyServer.getInstance().stop(); throw new SecurityException("Could not start SQL-Exception", e); @@ -34,8 +30,6 @@ public class SQL { try { if(con != null) con.close(); - if(webcon != null) - webcon.close(); }catch (SQLException e) { BungeeCore.log("Could not close SQL-Connection", e); } @@ -54,19 +48,6 @@ public class SQL { } } - static void webupdate(String qry, Object... objects) { - try { - prepare(webcon, qry, objects).executeUpdate(); - } catch (SQLException e) { - sqlException(); - try { - prepare(webcon, qry, objects).executeUpdate(); - } catch (SQLException ex) { - throw new SecurityException("Could not execute update statement", ex); - } - } - } - static ResultSet select(String qry, Object... objects){ try{ return prepare(con, qry, objects).executeQuery(); @@ -90,6 +71,6 @@ public class SQL { private static void sqlException(){ close(); - connect(url, weburl, user, password); + connect(url, user, password); } } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index edea5352..2447fd8c 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -94,10 +94,6 @@ public class SteamwarUser { usersByUUID.clear(); } - public void setWebpw(String password){ - SQL.webupdate("INSERT INTO User (UID, WebPassword) VALUES (?, password(?)) ON DUPLICATE KEY UPDATE WebPassword = VALUES(WebPassword)", id, password); - } - public void setTeam(int team){ this.team = team; SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id); From 7a7d9065084c165162458dbcd70f2e1852f7d2f3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 26 Feb 2020 18:23:40 +0100 Subject: [PATCH 2/2] Add webpw for historic reasons --- src/de/steamwar/bungeecore/commands/WebregisterCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/WebregisterCommand.java b/src/de/steamwar/bungeecore/commands/WebregisterCommand.java index ed464a5b..260872fa 100644 --- a/src/de/steamwar/bungeecore/commands/WebregisterCommand.java +++ b/src/de/steamwar/bungeecore/commands/WebregisterCommand.java @@ -12,7 +12,7 @@ import java.io.InputStreamReader; public class WebregisterCommand extends BasicCommand { public WebregisterCommand() { - super("webregister", null, "web"); + super("webregister", null, "web", "webpw"); } @Override