Dieser Commit ist enthalten in:
Commit
77efb4a97f
@ -272,12 +272,6 @@ public class BungeeCore extends Plugin {
|
||||
Persistent.setChatPrefix(CHAT_PREFIX);
|
||||
Persistent.setLobbyServer(LOBBY_SERVER);
|
||||
|
||||
Statement.connect(
|
||||
config.getString("db.url"),
|
||||
config.getString("db.username"),
|
||||
config.getString("db.password")
|
||||
);
|
||||
|
||||
if (config.contains("discord")) {
|
||||
SteamwarDiscordBotConfig.loadConfig(config.getSection("discord"));
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.bungeecore;
|
||||
|
||||
import de.steamwar.bungeecore.sql.SWException;
|
||||
import de.steamwar.bungeecore.sql.Statement;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
@ -63,7 +62,7 @@ public class ErrorLogger extends Handler {
|
||||
SWException.log("Bungee", "DDOS", ddosRate + "");
|
||||
}
|
||||
return;
|
||||
} else if (!Statement.connectionStable()) {
|
||||
} else if (stacktrace.contains("ErrorLogger")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -85,13 +84,10 @@ public class ErrorLogger extends Handler {
|
||||
|
||||
static {
|
||||
List<String> contains = new ArrayList<>();
|
||||
contains.add("ServerConnector");
|
||||
contains.add("InitialHandler");
|
||||
contains.add("UpstreamBridge");
|
||||
contains.add("DownstreamBridge");
|
||||
contains.add(" took ");
|
||||
contains.add("No client connected for pending server!");
|
||||
contains.add("Error authenticating ");
|
||||
contains.add("read timed out");
|
||||
contains.add("Connection reset by peer");
|
||||
contains.add("No client connected for pending server");
|
||||
ignoreContains = Collections.unmodifiableList(contains);
|
||||
}
|
||||
}
|
||||
|
@ -59,11 +59,11 @@ public class EventStarter implements Runnable {
|
||||
|
||||
EventFight next;
|
||||
while((next = nextFight(fights)) != null){
|
||||
if(!BungeeCore.EVENT_MODE && Event.get(next.getEventID()).spectateSystem())
|
||||
break; //Don't start EventServer if not the event bungee
|
||||
|
||||
Team blue = Team.get(next.getTeamBlue());
|
||||
Team red = Team.get(next.getTeamRed());
|
||||
|
||||
//Don't start EventServer if not the event bungee
|
||||
if(BungeeCore.EVENT_MODE || !Event.get(next.getEventID()).spectateSystem()) {
|
||||
ServerStarter starter = new ServerStarter().event(next);
|
||||
|
||||
ProxiedPlayer leiter = ProxyServer.getInstance().getPlayer(SteamwarUser.get(next.getKampfleiter()).getUuid());
|
||||
@ -76,6 +76,10 @@ public class EventStarter implements Runnable {
|
||||
eventServer.put(red.getTeamId(), subserver);
|
||||
Message.broadcast("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER",
|
||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/event " + blue.getTeamKuerzel()), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName());
|
||||
} else {
|
||||
Message.broadcast("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER",
|
||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/spectate"), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
@ -93,9 +94,13 @@ public class SteamwarDiscordBot {
|
||||
EventManager.update();
|
||||
SchematicsManager.update();
|
||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||
try {
|
||||
activity();
|
||||
EventManager.update();
|
||||
SchematicsManager.update();
|
||||
} catch (ErrorResponseException e) {
|
||||
//ignored
|
||||
}
|
||||
}, 30, 30, TimeUnit.SECONDS);
|
||||
DiscordRolesMessage.sendMessage();
|
||||
DiscordRulesMessage.sendMessage();
|
||||
|
@ -36,6 +36,7 @@ import net.md_5.bungee.config.Configuration;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
@ -127,15 +128,22 @@ public class CheckCommand extends BasicCommand {
|
||||
|
||||
for (SchematicNode schematic : schematicList) {
|
||||
CheckSession current = currentSchems.get(schematic.getId());
|
||||
long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime();
|
||||
String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "§c" : "§e") : "§a";
|
||||
long hours = waitedMillis / 3600000;
|
||||
long minutes = (waitedMillis - hours * 3600000) / 60000;
|
||||
String waitTime = color + Message.parse("CHECK_LIST_WAIT", player, hours, (minutes < 10) ? "0" + minutes : minutes);
|
||||
if (current == null) {
|
||||
Message.sendPrefixless("CHECK_LIST_TO_CHECK", player,
|
||||
Message.parse("CHECK_LIST_TO_CHECK_HOVER", player),
|
||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getId()),
|
||||
waitTime,
|
||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName());
|
||||
} else {
|
||||
Message.sendPrefixless("CHECK_LIST_CHECKING", player,
|
||||
Message.parse("CHECK_LIST_CHECKING_HOVER", player),
|
||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()),
|
||||
waitTime,
|
||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.getName());
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ package de.steamwar.bungeecore.comms;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.comms.handlers.*;
|
||||
import de.steamwar.bungeecore.comms.packets.FightEndsPacket;
|
||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@ -46,7 +47,7 @@ public class SpigotReceiver extends BasicListener {
|
||||
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||
Byte handler = in.readByte();
|
||||
handlerMap.get(handler).handle(in, ((Server) event.getSender()).getInfo());
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> handlerMap.get(handler).handle(in, ((Server) event.getSender()).getInfo()));
|
||||
}
|
||||
|
||||
public static void registerHandler(Byte id, SpigotHandler handler) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bungeecore.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.sql.BannedUserIPs;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
@ -40,6 +41,8 @@ public class BanListener extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(LoginEvent event) {
|
||||
event.registerIntent(BungeeCore.get());
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
||||
SteamwarUser user = SteamwarUser.getOrCreate(event.getConnection());
|
||||
if (user.isPunished(Punishment.PunishmentType.Ban)) {
|
||||
user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress());
|
||||
@ -89,5 +92,7 @@ public class BanListener extends BasicListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
event.completeIntent(BungeeCore.get());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class ChatListener extends BasicListener {
|
||||
return;
|
||||
|
||||
e.setCancelled(true);
|
||||
publicChat(user, sender, e.getMessage());
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> publicChat(user, sender, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ public class ChatListener extends BasicListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){
|
||||
private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message) {
|
||||
String name = UserElo.getEmblem(user) + sender.getDisplayName();
|
||||
String chatcolor = user.getUserGroup().getChatColorCode();
|
||||
|
||||
|
@ -19,8 +19,10 @@
|
||||
|
||||
package de.steamwar.bungeecore.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.sql.Session;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@ -40,7 +42,8 @@ public class SessionManager extends BasicListener {
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerDisconnectEvent e){
|
||||
Timestamp timestamp = sessions.remove(e.getPlayer());
|
||||
if(timestamp != null)
|
||||
Session.insertSession(SteamwarUser.get(e.getPlayer()).getId(), timestamp);
|
||||
if(timestamp != null) {
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> Session.insertSession(SteamwarUser.get(e.getPlayer()).getId(), timestamp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,128 +21,167 @@ package de.steamwar.bungeecore.sql;
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Statement implements AutoCloseable {
|
||||
|
||||
private static final Logger logger = BungeeCore.get().getLogger();
|
||||
|
||||
private static final List<Statement> statements = new ArrayList<>();
|
||||
private static final Deque<Connection> connections = new ArrayDeque<>();
|
||||
|
||||
private static Connection con;
|
||||
private static String url;
|
||||
private static String user;
|
||||
private static String password;
|
||||
private static final String URL;
|
||||
private static final String USER;
|
||||
private static final String PASSWORD;
|
||||
|
||||
public static void connect(String url, String user, String password) {
|
||||
Statement.url = url;
|
||||
Statement.user = user;
|
||||
Statement.password = password;
|
||||
static {
|
||||
File file = new File(BungeeCore.get().getDataFolder(), "MySQL.yml");
|
||||
Configuration config;
|
||||
try {
|
||||
con = DriverManager.getConnection(url + "?autoReconnect=true&useServerPrepStmts=true", user, password);
|
||||
} catch (SQLException e) {
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||
} catch (IOException e) {
|
||||
ProxyServer.getInstance().stop();
|
||||
throw new SecurityException("Could not start SQL-Connection", e);
|
||||
}
|
||||
throw new SecurityException("Could not load SQL connection", e);
|
||||
}
|
||||
|
||||
private static void reset() {
|
||||
closeAll();
|
||||
connect(url, user, password);
|
||||
try {
|
||||
for (Statement statement : statements) {
|
||||
statement.init();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not reprepare SQL statements", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
BungeeCore.get().getLogger().log(Level.INFO, "Could not close statement", e);
|
||||
}
|
||||
statements.remove(this);
|
||||
URL = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE");
|
||||
USER = config.getString("USER");
|
||||
PASSWORD = config.getString("PASSWORD");
|
||||
}
|
||||
|
||||
public static void closeAll() {
|
||||
synchronized (connections) {
|
||||
for(Connection connection : connections) {
|
||||
try {
|
||||
synchronized (statements) {
|
||||
for (Statement statement : statements) {
|
||||
try {
|
||||
statement.st.close();
|
||||
statements.forEach(statement -> statement.close(connection));
|
||||
}
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
BungeeCore.get().getLogger().log(Level.INFO, "Could not close statement", e);
|
||||
logger.log(Level.INFO, "Could not close SQL connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
BungeeCore.get().getLogger().log(Level.INFO, "Could not close SQL connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean connectionStable() {
|
||||
try {
|
||||
return !con.isClosed();
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
connections.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private final String sql;
|
||||
private PreparedStatement st;
|
||||
private final Map<Connection, PreparedStatement> cachedStatements = new HashMap<>();
|
||||
|
||||
public Statement(String sql) {
|
||||
this.sql = sql;
|
||||
synchronized (statements) {
|
||||
statements.add(this);
|
||||
try {
|
||||
init();
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not init SQL statement", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void init() throws SQLException {
|
||||
st = con.prepareStatement(sql);
|
||||
}
|
||||
|
||||
public <T> T select(ResultSetUser<T> user, Object... objects) {
|
||||
synchronized (statements) {
|
||||
return prepare(() -> {
|
||||
return withConnection(st -> {
|
||||
ResultSet rs = st.executeQuery();
|
||||
T result = user.use(rs);
|
||||
rs.close();
|
||||
return result;
|
||||
}, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(Object... objects) {
|
||||
synchronized (statements) {
|
||||
prepare(st::executeUpdate, objects);
|
||||
}
|
||||
withConnection(PreparedStatement::executeUpdate, objects);
|
||||
}
|
||||
|
||||
private <T> T prepare(SQLRunnable<T> runnable, Object... objects) {
|
||||
private <T> T withConnection(SQLRunnable<T> runnable, Object... objects) {
|
||||
Connection connection = aquireConnection();
|
||||
|
||||
T result;
|
||||
try {
|
||||
setObjects(objects);
|
||||
return runnable.run();
|
||||
result = tryWithConnection(connection, runnable, objects);
|
||||
} catch (SQLException e) {
|
||||
reset();
|
||||
throw new SecurityException("Could not execute SQL statement", e);
|
||||
closeConnection(connection);
|
||||
connection = aquireConnection();
|
||||
try {
|
||||
result = tryWithConnection(connection, runnable, objects);
|
||||
} catch (SQLException ex) {
|
||||
closeConnection(connection);
|
||||
throw new SecurityException("Could not execute statement", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void setObjects(Object... objects) throws SQLException {
|
||||
synchronized (connections) {
|
||||
connections.push(connection);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> T tryWithConnection(Connection connection, SQLRunnable<T> runnable, Object... objects) throws SQLException {
|
||||
PreparedStatement st = cachedStatements.get(connection);
|
||||
if(st == null) {
|
||||
st = connection.prepareStatement(sql);
|
||||
cachedStatements.put(connection, st);
|
||||
}
|
||||
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
st.setObject(i + 1, objects[i]);
|
||||
}
|
||||
|
||||
return runnable.run(st);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
cachedStatements.values().forEach(st -> closeStatement(st, false));
|
||||
cachedStatements.clear();
|
||||
synchronized (statements) {
|
||||
statements.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void close(Connection connection) {
|
||||
PreparedStatement st = cachedStatements.remove(connection);
|
||||
if(st != null)
|
||||
closeStatement(st, true);
|
||||
}
|
||||
|
||||
private static Connection aquireConnection() {
|
||||
synchronized (connections) {
|
||||
if(!connections.isEmpty())
|
||||
return connections.pop();
|
||||
}
|
||||
try {
|
||||
return DriverManager.getConnection(URL + "?autoReconnect=true&useServerPrepStmts=true", USER, PASSWORD);
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not open connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeConnection(Connection connection) {
|
||||
synchronized (statements) {
|
||||
for (Statement statement : statements) {
|
||||
statement.close(connection);
|
||||
}
|
||||
}
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
logger.log(Level.INFO, "Could not close connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeStatement(PreparedStatement st, boolean silent) {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
if(!silent)
|
||||
logger.log(Level.INFO, "Could not close statement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ResultSetUser<T> {
|
||||
@ -150,6 +189,6 @@ public class Statement implements AutoCloseable {
|
||||
}
|
||||
|
||||
private interface SQLRunnable<T> {
|
||||
T run() throws SQLException;
|
||||
T run(PreparedStatement st) throws SQLException;
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,12 @@ import java.util.stream.Collectors;
|
||||
|
||||
public enum UserGroup {
|
||||
|
||||
Admin("§4", "§e", "Obererzieher", true, true, true, true),
|
||||
Developer("§3", "§f", "Seelsorger", true, true, true, true),
|
||||
Moderator("§c", "§f", "Schichtleiter", true, true, true, true),
|
||||
Supporter("§9", "§f", "Kindergärtner", false, true, true, true),
|
||||
Builder("§2", "§f", "Hausmeister", false, true, false, true),
|
||||
YouTuber("§5", "§f", "Reporter", false, false, false, true),
|
||||
Admin("§4", "§e", "Admin", true, true, true, true),
|
||||
Developer("§3", "§f", "Dev", true, true, true, true),
|
||||
Moderator("§c", "§f", "Mod", true, true, true, true),
|
||||
Supporter("§9", "§f", "Sup", false, true, true, true),
|
||||
Builder("§2", "§f", "Arch", false, true, false, true),
|
||||
YouTuber("§5", "§f", "YT", false, false, false, true),
|
||||
Member("§7", "§7", "", false, false, false, false);
|
||||
|
||||
private final String colorCode;
|
||||
|
@ -245,9 +245,10 @@ CHECK_HELP_NEXT=§8/§7check next §8- §7Nächste Prüffrage§8/§7freigeben
|
||||
CHECK_HELP_DECLINE=§8/§7check decline §8[§eGrund§8] - §7Schematic ablehnen
|
||||
CHECK_HELP_CANCEL=§8/§7check cancel §8- §7Bricht den Prüfvorgang ab
|
||||
CHECK_LIST_HEADER=§e§lZu prüfen sind {0} Schematics
|
||||
CHECK_LIST_TO_CHECK=§8{0} §7{1} §e{2}
|
||||
CHECK_LIST_TO_CHECK={0} §8{1} §7{2} §e{3}
|
||||
CHECK_LIST_WAIT={0}:{1}
|
||||
CHECK_LIST_TO_CHECK_HOVER=§eSchematic prüfen
|
||||
CHECK_LIST_CHECKING=§8{0} §7{1} §e{2} §7wird geprüft von §e{3}
|
||||
CHECK_LIST_CHECKING={0} §8{1} §7{2} §e{3} §7wird geprüft von §e{4}
|
||||
CHECK_LIST_CHECKING_HOVER=§eZum Prüfer
|
||||
CHECK_SCHEMATIC_ALREADY_CHECKING=§cDu prüfst schon eine Schematic!
|
||||
CHECK_SCHEMATIC_OWN=§cDu kannst nicht deine eigenen Schematics prüfen.
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren