SteamWar/BungeeCore
Archiviert
13
2

Merge branch 'webPW' of SteamWar/BungeeCore into master

Dieser Commit ist enthalten in:
Lixfel 2020-02-26 19:06:32 +01:00 committet von Gitea
Commit 9f741e8d18
5 geänderte Dateien mit 66 neuen und 60 gelöschten Zeilen

Datei anzeigen

@ -71,7 +71,7 @@ public class BungeeCore extends Plugin {
new MsgCommand(); new MsgCommand();
new RCommand(); new RCommand();
new PingCommand(); new PingCommand();
new WebpwCommand(); new WebregisterCommand();
new AlertCommand(); new AlertCommand();
new KickCommand(); new KickCommand();
new JoinmeCommand(); new JoinmeCommand();
@ -196,7 +196,6 @@ public class BungeeCore extends Plugin {
SQL.connect( SQL.connect(
config.getString("db.url"), config.getString("db.url"),
config.getString("db.weburl"),
config.getString("db.username"), config.getString("db.username"),
config.getString("db.password") config.getString("db.password")
); );

Datei anzeigen

@ -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!");
}
}
}

Datei anzeigen

@ -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", "webpw");
}
@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);
}
}
}

Datei anzeigen

@ -10,20 +10,16 @@ public class SQL {
private SQL(){} private SQL(){}
private static Connection con; private static Connection con;
private static Connection webcon;
private static String url; private static String url;
private static String weburl;
private static String user; private static String user;
private static String password; 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.url = url;
SQL.weburl = weburl;
SQL.user = user; SQL.user = user;
SQL.password = password; SQL.password = password;
try { try {
con = DriverManager.getConnection(url + "?autoreconnect=true", user, password); con = DriverManager.getConnection(url + "?autoreconnect=true", user, password);
webcon = DriverManager.getConnection(weburl + "?autoreconnect=true", user, password);
}catch (SQLException e) { }catch (SQLException e) {
ProxyServer.getInstance().stop(); ProxyServer.getInstance().stop();
throw new SecurityException("Could not start SQL-Exception", e); throw new SecurityException("Could not start SQL-Exception", e);
@ -34,8 +30,6 @@ public class SQL {
try { try {
if(con != null) if(con != null)
con.close(); con.close();
if(webcon != null)
webcon.close();
}catch (SQLException e) { }catch (SQLException e) {
BungeeCore.log("Could not close SQL-Connection", 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){ static ResultSet select(String qry, Object... objects){
try{ try{
return prepare(con, qry, objects).executeQuery(); return prepare(con, qry, objects).executeQuery();
@ -90,6 +71,6 @@ public class SQL {
private static void sqlException(){ private static void sqlException(){
close(); close();
connect(url, weburl, user, password); connect(url, user, password);
} }
} }

Datei anzeigen

@ -94,10 +94,6 @@ public class SteamwarUser {
usersByUUID.clear(); 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){ public void setTeam(int team){
this.team = team; this.team = team;
SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id); SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id);