SteamWar/BungeeCore
Archiviert
13
2

WepPW Command
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
Chaoscaot 2023-12-17 18:28:53 +01:00
Ursprung b024d24a93
Commit 18dfcf5025
5 geänderte Dateien mit 10 neuen und 145 gelöschten Zeilen

@ -1 +1 @@
Subproject commit b66c18b8b3f1faa3fe97fd8c3f16ce19259dc0d2
Subproject commit e83ab4762d77567a01b0b71bdf12b65bf2aca3bd

Datei anzeigen

@ -66,7 +66,7 @@ public class PunishmentCommand {
return null;
}
return SteamwarUser.getOrCreate(uuid, name, u -> {}, (o, n) -> {});
return SteamwarUser.getOrCreate(uuid, name, u -> {});
}
private static UUID getUUIDofOfflinePlayer(String playerName) {

Datei anzeigen

@ -1,116 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.command.SWCommand;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Token;
import lombok.SneakyThrows;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.security.MessageDigest;
import java.util.Base64;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class TokensCommand extends SWCommand {
public TokensCommand() {
super("tokens", null, "token");
}
private static final Random random = new Random();
@SneakyThrows
private static String generateCode() {
byte[] hash = new byte[16];
for(int i = 0; i < hash.length; i++) {
hash[i] = (byte) (random.nextInt(256) - 128);
}
return Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-1").digest(hash));
}
@SneakyThrows
private static String generateHash(String code) {
MessageDigest md = MessageDigest.getInstance("SHA-512");
return Base64.getEncoder().encodeToString(md.digest(code.getBytes()));
}
@Register
public void genericCommand(ProxiedPlayer p) {
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
List<Token> tokens = Token.listUser(user);
List<SWListInv.SWListEntry<Token>> entries = tokens
.stream()
.map(token -> new SWListInv.SWListEntry<>(new SWItem("STONE", token.getName()), token))
.collect(Collectors.toList());
SWListInv<Token> inv = new SWListInv<>(p, Message.parse("TOKENS_TITLE", p), entries, (click, element) -> {
SWInventory deleteInv = new SWInventory(p, 9, Message.parse("TOKENS_DELETE", p));
deleteInv.addItem(0, new SWItem(Message.parse("TOKENS_DELETE_CONFIRM", p), 2), deleteClick -> {
Token.delete(element);
Message.send("TOKENS_DELETED", p);
deleteInv.close();
});
deleteInv.addItem(8, new SWItem(Message.parse("TOKENS_DELETE_CANCEL", p), 1), deleteClick -> {
deleteInv.close();
});
deleteInv.open();
});
inv.open();
}
@Register("create")
public void createToken(ProxiedPlayer p, String name) {
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
if(name.length() > 32) {
Message.send("TOKENS_NAME_TOO_LONG", p);
return;
}
if(name.length() < 3) {
Message.send("TOKENS_NAME_TOO_SHORT", p);
return;
}
if(Token.listUser(user).stream().anyMatch(token -> token.getName().equalsIgnoreCase(name))) {
Message.send("TOKENS_NAME_ALREADY_EXISTS", p);
return;
}
String code = generateCode();
String hash = generateHash(code);
Token token = Token.create(name, user, hash);
Message.send("TOKENS_NAME_CREATED", p, "TOKENS_NAME_CREATED_HOVER", new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, code));
}
}

Datei anzeigen

@ -19,8 +19,11 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.command.SWCommand;
import de.steamwar.messages.ChatSender;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Token;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.BufferedReader;
@ -41,33 +44,11 @@ public class WebpasswordCommand extends SWCommand {
return;
}
ProcessBuilder pb = new ProcessBuilder("php", "/var/www/register.php", player.getName(), password);
pb.redirectErrorStream(true);
try {
Process regProcess = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(regProcess.getInputStream()));
String errorLine;
if((errorLine = reader.readLine()) != null) {
if ("updated".equals(errorLine)) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
user.setPassword(password);
Token.listUser(user).stream().filter(token -> token.getName().startsWith("Website: ")).forEach(token -> token.delete());
ChatSender.of(player).system("WEB_UPDATED");
return;
} else {
throw new SecurityException("Could not create webaccount " + errorLine);
}
}
ChatSender.of(player).system("WEB_CREATED");
} catch (IOException e) {
throw new SecurityException("Could not create webaccount", e);
}
}
public static void changeUsername(String oldUsername, String newUsername){
ProcessBuilder pb = new ProcessBuilder("php", "/var/www/changename.php", oldUsername, newUsername);
try {
pb.start();
} catch (IOException e) {
throw new SecurityException("Could not change username", e);
}
}
}

Datei anzeigen

@ -46,7 +46,7 @@ public class BanListener extends BasicListener {
event.registerIntent(BungeeCore.get());
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
PendingConnection connection = event.getConnection();
SteamwarUser user = SteamwarUser.getOrCreate(connection.getUniqueId(), connection.getName(), ConnectionListener::newPlayer, WebpasswordCommand::changeUsername);
SteamwarUser user = SteamwarUser.getOrCreate(connection.getUniqueId(), connection.getName(), ConnectionListener::newPlayer);
if (user.isPunished(Punishment.PunishmentType.Ban)) {
event.setCancelled(true);
BannedUserIPs.banIP(user.getId(), connection.getAddress().getAddress().getHostAddress());