Archiviert
1
0

Merge branch 'master' into schem_aleart

Dieser Commit ist enthalten in:
Lixfel 2021-05-09 07:48:09 +02:00
Commit 588ecebb3f
12 geänderte Dateien mit 180 neuen und 82 gelöschten Zeilen

Datei anzeigen

@ -84,6 +84,7 @@ public class BungeeCore extends Plugin {
new CheckListener();
new ModLoaderBlocker();
new WorldDownloader();
new BrandListener();
commands.put("/b", null);
commands.put("/gs", null);

Datei anzeigen

@ -28,8 +28,10 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.logging.Level;
public class SubserverSystem {
private SubserverSystem(){}
@ -41,13 +43,13 @@ public class SubserverSystem {
private static final String SERVER_PATH = BACKBONE + "server/";
private static final String EVENT_PATH = BACKBONE + "event/";
private static final int firstArenaPort;
private static final int FIRST_ARENA_PORT;
static {
if(BungeeCore.EVENT_MODE)
firstArenaPort = 6000;
FIRST_ARENA_PORT = 6000;
else
firstArenaPort = 2500;
FIRST_ARENA_PORT = 2500;
}
/**
@ -89,13 +91,13 @@ public class SubserverSystem {
*/
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, int prepareSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
//Generate missing parameters
int port = freePort(firstArenaPort);
int port = freePort(FIRST_ARENA_PORT);
if(serverName == null){
if(ranked)
serverName = "Ranked" + (port - firstArenaPort);
serverName = "Ranked" + (port - FIRST_ARENA_PORT);
else
serverName = modus.getDisplayName() + (port - firstArenaPort);
serverName = modus.getDisplayName() + (port - FIRST_ARENA_PORT);
}
if(mapName == null)
mapName = serverName;
@ -109,8 +111,11 @@ public class SubserverSystem {
//Copy world
try {
new ProcessBuilder("cp", "-r", SERVER_PATH + modus.getFolder() + "/arenas/" + map, worldDir + mapName).start().waitFor();
} catch (IOException | InterruptedException e) {
} catch (IOException e) {
throw new SecurityException("Could not copy folder", e);
} catch (InterruptedException e) {
ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Interrupted while copying folder", e);
Thread.currentThread().interrupt();
}
List<String> cmd = serverStartCommand(
@ -125,8 +130,8 @@ public class SubserverSystem {
"ranked=" + ranked,
"checkSchemID=" + checkSchemID,
"prepareSchemID=" + prepareSchemID,
player1 != null && eventFightID != -1 ? "blueLeader=" + player1.toString() : null,
player2 != null ? "redLeader=" + player2.toString() : null);
player1 != null && eventFightID != -1 ? "blueLeader=" + player1 : null,
player2 != null ? "redLeader=" + player2 : null);
//Start server
ProcessBuilder process = new ProcessBuilder(cmd);
@ -134,26 +139,26 @@ public class SubserverSystem {
String finalMapName = mapName;
if(eventFightID == -1)
return new Bauserver(serverName, player1, port, process, () -> {
try {
new ProcessBuilder("rm", "-r", ARENA_PATH + finalMapName).start().waitFor();
} catch (IOException | InterruptedException e) {
throw new SecurityException("Could not clean up folder", e);
}
});
return new Bauserver(serverName, player1, port, process, () -> deleteFolder(ARENA_PATH + finalMapName));
else
return new Subserver(Servertype.ARENA, serverName, port, process, () -> {
if(eventFightID > 0)
return;
try {
new ProcessBuilder("rm", "-r", ARENA_PATH + finalMapName).start().waitFor();
} catch (IOException | InterruptedException e) {
throw new SecurityException("Could not clean up folder", e);
}
deleteFolder(ARENA_PATH + finalMapName);
});
}
public static void deleteFolder(String worldName){
try {
new ProcessBuilder("rm", "-r", worldName).start().waitFor();
} catch (IOException e) {
throw new SecurityException("Could not clean up folder", e);
} catch (InterruptedException e) {
ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Interrupted while deleting folder", e);
Thread.currentThread().interrupt();
}
}
public static Subserver startEventArena(EventFight eventFight, String serverName){
return startArena(
eventFight.getSpielmodus(),
@ -172,50 +177,44 @@ public class SubserverSystem {
startArena(m, map, -1, checkSchemId, prepareSchemId, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null, false).sendPlayer(p);
}
public static void sendToBauServer(ProxiedPlayer p, UUID owner){
private static void sendToBau(ProxiedPlayer p, UUID owner, String prototype, String worldFolder, String serverJar, String worldDir, String worldName, String xmx, String serverName){
if(bauRunning(p, owner))
return;
SteamwarUser user = SteamwarUser.get(owner);
copyBauweltIfRequired(p, BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER + owner.toString());
copyBauweltIfRequired(p, prototype, worldFolder + worldName);
int port = freePort(4000);
List<String> cmd = serverStartCommand(
"spigot-1.12.2.jar",
"/home/minecraft/userworlds",
owner.toString(),
serverJar,
worldDir,
worldName,
port,
"256M",
"logPath=" + owner.toString());
xmx,
"logPath=" + worldName);
//Start server
ProcessBuilder process = new ProcessBuilder(cmd);
process.directory(new File(SERVER_PATH, "UserBau"));
process.directory(new File(SERVER_PATH, serverName));
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
}
public static void sendToBau15(ProxiedPlayer p, UUID owner){
if(bauRunning(p, owner))
return;
public static void sendToBauServer(ProxiedPlayer p, UUID owner){
sendToBau(p, owner, BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER, "spigot-1.12.2.jar", "/home/minecraft/userworlds", owner.toString(), "256M", "UserBau");
}
private static void sendToBau15(ProxiedPlayer p, UUID owner, String serverJar){
SteamwarUser user = SteamwarUser.get(owner);
copyBauweltIfRequired(p, BungeeCore.BAUWELT15, BungeeCore.USERWORLDS15 + user.getId());
int port = freePort(4000);
sendToBau(p, owner, BungeeCore.BAUWELT15, BungeeCore.USERWORLDS15, serverJar, "/home/minecraft/userworlds15", String.valueOf(user.getId()), "512M", "Bau15");
}
List<String> cmd = serverStartCommand(
"spigot-1.15.2.jar",
"/home/minecraft/userworlds15",
String.valueOf(user.getId()),
port,
"512M",
"logPath=" + user.getId());
public static void sendToBau15(ProxiedPlayer p, UUID owner){
sendToBau15(p, owner, "spigot-1.15.2.jar");
}
//Start server
ProcessBuilder process = new ProcessBuilder(cmd);
process.directory(new File(SERVER_PATH, "Bau15"));
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
public static void sendToBau15paper(ProxiedPlayer p, UUID owner){
sendToBau15(p, owner, "paper-1.15.2.jar");
}
public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){
@ -274,11 +273,7 @@ public class SubserverSystem {
File w = new File(targetPath);
if (!w.exists() || !w.isDirectory()){
try {
Process pr;
ProcessBuilder pb = new ProcessBuilder(
"cp", "-r", sourcePath, targetPath);
pr = pb.start();
pr.waitFor();
new ProcessBuilder("cp", "-r", sourcePath, targetPath).start().waitFor();
} catch (IOException e) {
Message.send("SERVER_WORLD_ERROR", p);
throw new SecurityException("Could not create Bauwelt", e);
@ -298,7 +293,7 @@ public class SubserverSystem {
port++;
isFree = true;
for(Subserver server : Subserver.getServerList()){
if(server.getServer().getAddress().getPort() == port){
if(((InetSocketAddress)server.getServer().getSocketAddress()).getPort() == port){
isFree = false;
break;
}

Datei anzeigen

@ -42,7 +42,7 @@ public class BanCommand extends BasicCommand {
return;
}
SteamwarUser target = user(sender, args[0]);
SteamwarUser target = unsafeUser(sender, args[0]);
if(target == null)
return;

Datei anzeigen

@ -53,10 +53,17 @@ abstract class BasicCommand extends Command implements TabExecutor {
return new ArrayList<>();
}
protected SteamwarUser user(CommandSender sender, String arg){
protected SteamwarUser existingUser(CommandSender sender, String arg){
SteamwarUser target = SteamwarUser.get(arg);
if(target == null)
Message.send("UNKNOWN_PLAYER", sender);
return target;
}
protected SteamwarUser unsafeUser(CommandSender sender, String arg){
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(arg);
if(target == null)
Message.send("UNKNOWN_PLAYER", sender);
return target;
}
}

Datei anzeigen

@ -28,8 +28,6 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
import java.io.File;
public class BauCommand {
private BauCommand(){}
@ -70,6 +68,9 @@ public class BauCommand {
case "1.15":
SubserverSystem.sendToBau15(p, p.getUniqueId());
break;
case "paper":
SubserverSystem.sendToBau15paper(p, p.getUniqueId());
break;
case "addmember":
addmember(p, command);
break;
@ -251,8 +252,7 @@ public class BauCommand {
break;
}
}
File directory = new File(world);
del(directory);
SubserverSystem.deleteFolder(world);
});
}
@ -318,19 +318,4 @@ public class BauCommand {
Message.send("BAU_MEMBER_TOGGLE_OFF", p, what);
}
}
private static void del(File dir){
if (dir.isDirectory()){
String[] entries = dir.list();
assert entries != null;
for (String entry : entries) {
File aktFile = new File(dir.getPath(), entry);
del(aktFile);
}
dir.delete();
}
else{
dir.delete();
}
}
}

Datei anzeigen

@ -38,7 +38,7 @@ public class MuteCommand extends BasicCommand {
return;
}
SteamwarUser target = user(sender, args[0]);
SteamwarUser target = unsafeUser(sender, args[0]);
if(target == null)
return;

Datei anzeigen

@ -179,6 +179,7 @@ public class TeamCommand extends BasicCommand {
Team.create(args[1], args[2], user);
user.setTeam(Team.get(args[1]).getTeamId());
user.setLeader(true);
Message.send("TEAM_CREATE_CREATED", player, args[2]);
}
@ -255,7 +256,7 @@ public class TeamCommand extends BasicCommand {
user.setTeam(0);
if(user.isLeader() && team.size() > 0){
team.disband();
team.disband(user);
}
Message.send("TEAM_LEAVE_LEFT", player);

Datei anzeigen

@ -39,7 +39,7 @@ public class UnbanCommand extends BasicCommand {
return;
}
SteamwarUser target = user(sender, args[0]);
SteamwarUser target = existingUser(sender, args[0]);
if(target == null)
return;

Datei anzeigen

@ -0,0 +1,65 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.listeners;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.SteamwarUser;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
import net.md_5.bungee.protocol.packet.PluginMessage;
import java.util.concurrent.TimeUnit;
public class BrandListener extends BasicListener {
@EventHandler
public void onServerSwitch(PluginMessageEvent event) {
if(event.getTag().equals("minecraft:brand") || event.getTag().equals("MC|Brand")) {
return;
}
if(event.getReceiver().getAddress().getHostName().contains("localhost")) {
return;
}
BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> {
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
String channel = player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand";
StringBuilder serverBrand = new StringBuilder();
for (byte b:event.getData()) {
serverBrand.append((char) b);
}
String brandString = Message.parse("STEAMWAR_BRAND", player, BungeeCore.get().getProxy().getName(), player.getServer().getInfo().getName(), serverBrand.substring(1));
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString(brandString, brand);
player.sendData(channel, DefinedPacket.toArray(brand));
brand.release();
}, 50, TimeUnit.MILLISECONDS);
}
}

Datei anzeigen

@ -19,10 +19,15 @@
package de.steamwar.bungeecore.sql;
import com.google.gson.JsonParser;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.WebregisterCommand;
import de.steamwar.bungeecore.listeners.ConnectionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.PendingConnection;
@ -38,6 +43,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class SteamwarUser {
private final int id;
private final UUID uuid;
@ -51,6 +57,8 @@ public class SteamwarUser {
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
private static final InetAddress LIXFEL_DE;
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
private static final JsonParser jsonParser = new JsonParser();
static {
try {
@ -85,8 +93,7 @@ public class SteamwarUser {
user.userName = userName;
}
}else{
SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')", connection.getUniqueId().toString(), connection.getName());
user = dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", connection.getUniqueId().toString()));
user = SteamwarUser.createUserInDatabase(connection.getUniqueId(), connection.getName());
if(user == null)
throw new SecurityException("user == null");
ConnectionListener.newPlayer(user.uuid);
@ -97,6 +104,25 @@ public class SteamwarUser {
return user;
}
public static SteamwarUser getOrCreateOfflinePlayer(String name){
SteamwarUser user = SteamwarUser.get(name);
if (user != null) {
return user;
}
UUID uuid = SteamwarUser.loadUUID(name);
if (uuid == null) {
return null;
}
return SteamwarUser.createUserInDatabase(uuid, name);
}
private static SteamwarUser createUserInDatabase(UUID uuid, String name) {
SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')", uuid.toString(), name);
return dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", uuid.toString()));
}
public static SteamwarUser get(String userName){
userName = userName.toLowerCase();
if(usersByName.containsKey(userName))
@ -126,6 +152,22 @@ public class SteamwarUser {
usersByUUID.clear();
}
public static UUID loadUUID(String playerName) {
try {
final URL url = new URL(API_URL + playerName);
return getUniqueIdFromString(jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static UUID getUniqueIdFromString(String uuid) {
return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
}
public void setTeam(int team){
this.team = team;
SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id);

Datei anzeigen

@ -53,7 +53,6 @@ public class Team {
}
public static void create(String kuerzel, String name, SteamwarUser user){
user.setLeader(true);
SQL.update("INSERT INTO Team (TeamKuerzel, TeamName) VALUES (?, ?)", kuerzel, name);
}
@ -154,8 +153,9 @@ public class Team {
}
}
public void disband(){
SQL.update("UPDATE Team SET TeamDeleted = 1, TeamLeader = NULL WHERE TeamID = ?", teamId);
public void disband(SteamwarUser user){
user.setLeader(false);
SQL.update("UPDATE Team SET TeamDeleted = 1", teamId);
teamCache.remove(this);
}

Datei anzeigen

@ -7,6 +7,8 @@ UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht.
UNKNOWN_TEAM=§cDieses Team gibt es nicht.
INVALID_TIME=§cUngültige Zeitangabe.
STEAMWAR_BRAND=§eSteam§8War.de §7({0}) §r<- §e{1} §7({2})§r
#ModLoader blocker
MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten.
MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten.