diff --git a/src/bungee.yml b/src/bungee.yml
index ba2a898..6cc6e7e 100644
--- a/src/bungee.yml
+++ b/src/bungee.yml
@@ -1,6 +1,6 @@
name: IntaveProxySupport
author: Jpx3
description: Proxy support for Intave AntiCheat. Made with - not only but mostly - my keyboard and some love.
-version: 0.1.6
+version: 0.9.2
main: de.jpx3.ips.IntaveProxySupportPlugin
\ No newline at end of file
diff --git a/src/config.yml b/src/config.yml
index cb31b2a..caa1a5d 100644
--- a/src/config.yml
+++ b/src/config.yml
@@ -1,27 +1,27 @@
### ###
-## Intave Proxy Support 0.1.6 ##
+## Intave Proxy Support 0.9.2 ##
## by Jpx3 ##
### ###
# Connections
connection:
- # Connection between proxy and the database.
+ # Connection between proxy and database.
sql:
enabled: false
connection:
jdbc-service: "mysql"
- host: "a.a.a.a.a.a.org"
+ host: "ich.bin.net"
port: -1
- database: "thetabledancingbar"
- user: "XxX$$rIcHy$$XxX"
- password: "1234"
+ database: "tabledance24"
+ user: "XxX$$R_I_C_H_Y$$XxX"
+ password: "12345678"
create-tables: true
- # Connection between proxy and bukkit.
+ # Connection between our proxy and bukkit (where Intave is running).
bukkit:
enabled: true
@@ -32,4 +32,31 @@ punishment:
# SQL | Punishments are saved in a database and cached
# SQL-NC | Punishments are saved in a database and are not cached
# NONE
- driver: "RUNTIME"
\ No newline at end of file
+ driver: "RUNTIME"
+
+ # Message layout
+ #
+ # Please note that this is not yet working in version 0.9.2
+ #
+ # {expire-short} - Time until expiration (format-example: "13m 23d 13h 22m 19s" or "never")
+ # {expire} - Time until expiration with full annotations (format-example: "13 months, 23 days, 13 hours, 22 minutes & 19 seconds" or "never")
+ # {reason} - Entered reason for punishment
+ message-layout:
+
+ kick-layout: |
+ &4&lYou have been kicked.&r&r
+
+ &fReason: &b&l{reason}&r&r&r
+
+ &r&cPlease contact our staff in case&r&r
+ &cyou have any questions regarding this action.&r
+
+ ban-layout: |
+ &4&lYou have been banned.&r&r
+
+ &fReason: &b&l{reason}&r&r&r
+ &fExpires: &b&l{expire-short}&r&r&r
+
+ &r&cPlease contact our staff in case&r&r
+ &cyou have any questions regarding this action.&r
+
diff --git a/src/de/jpx3/ips/config/ConfigurationService.java b/src/de/jpx3/ips/config/ConfigurationService.java
index a27b911..bd0a1de 100644
--- a/src/de/jpx3/ips/config/ConfigurationService.java
+++ b/src/de/jpx3/ips/config/ConfigurationService.java
@@ -1,13 +1,13 @@
package de.jpx3.ips.config;
import com.google.common.base.Preconditions;
+import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.plugin.Plugin;
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.io.*;
public final class ConfigurationService {
private final Configuration configuration;
@@ -20,13 +20,23 @@ public Configuration configuration() {
return configuration;
}
+ private final static String CONFIGURATION_NAME = "config.yml";
+ private final static String DATAFOLDER_CREATION_ERROR = "Unable to create data folder";
+ private final static String CONFIGURATION_CREATION_ERROR = "Unable to create configuration file";
+
public static ConfigurationService createFrom(Plugin plugin) {
Preconditions.checkNotNull(plugin);
ConfigurationProvider configurationProvider =
ConfigurationProvider.getProvider(YamlConfiguration.class);
- File configurationFile
- = new File(plugin.getDataFolder(), "config.yml");
+
+ File dataFolder = plugin.getDataFolder();
+ File configurationFile = new File(dataFolder, CONFIGURATION_NAME);
+
+ ensureConfigurationExistence(
+ dataFolder,
+ configurationFile
+ );
Configuration configuration;
try {
@@ -37,4 +47,57 @@ public static ConfigurationService createFrom(Plugin plugin) {
return new ConfigurationService(configuration);
}
+
+ private static void ensureConfigurationExistence(File dataFolder,
+ File configurationFile
+ ) {
+ if(!dataFolder.exists()) {
+ if(!dataFolder.mkdir()) {
+ System.out.println(CONFIGURATION_CREATION_ERROR);
+ }
+ }
+
+ if(!configurationFile.exists()) {
+ try {
+ configurationFile.createNewFile();
+
+ moveResourceToFile(
+ CONFIGURATION_NAME,
+ configurationFile
+ );
+
+ } catch (IOException e) {
+ throw new IllegalStateException(DATAFOLDER_CREATION_ERROR, e);
+ }
+ }
+ }
+
+ private final static String RESOURCE_MOVE_TO_FILE_ERROR_LAYOUT = "Unable to move resource %s to %s";
+
+ private static void moveResourceToFile(String resource,
+ File outputFile
+ ) {
+ try {
+ ClassLoader classLoader =
+ ConfigurationService.class.getClassLoader();
+ try (InputStream inputStream =
+ classLoader.getResourceAsStream(resource);
+ OutputStream outputStream =
+ new FileOutputStream(outputFile)) {
+
+ ByteStreams.copy(inputStream, outputStream);
+ }
+ } catch (IOException e) {
+ String errorMessage = String.format(
+ RESOURCE_MOVE_TO_FILE_ERROR_LAYOUT,
+ resource,
+ outputFile.getAbsolutePath()
+ );
+
+ throw new IllegalStateException(
+ errorMessage,
+ e
+ );
+ }
+ }
}
diff --git a/src/de/jpx3/ips/connect/bukkit/MessengerService.java b/src/de/jpx3/ips/connect/bukkit/MessengerService.java
index 8fb7ab0..f9c23af 100644
--- a/src/de/jpx3/ips/connect/bukkit/MessengerService.java
+++ b/src/de/jpx3/ips/connect/bukkit/MessengerService.java
@@ -5,9 +5,8 @@
import net.md_5.bungee.config.Configuration;
public final class MessengerService {
- public final static int PROTOCOL_VERSION = 2;
- public final static String INCOMING_CHANNEL = "ipc-s2p";
- public final static String OUTGOING_CHANNEL = "ipc-p2s";
+ public final static int PROTOCOL_VERSION = 3;
+ public final static String OUTGOING_CHANNEL = "IPC-P2S";
public final static String PROTOCOL_HEADER = "IPC_BEGIN";
public final static String PROTOCOL_FOOTER = "IPC_END";
diff --git a/src/de/jpx3/ips/connect/bukkit/PacketReceiver.java b/src/de/jpx3/ips/connect/bukkit/PacketReceiver.java
index 6f3b704..3c97b69 100644
--- a/src/de/jpx3/ips/connect/bukkit/PacketReceiver.java
+++ b/src/de/jpx3/ips/connect/bukkit/PacketReceiver.java
@@ -34,25 +34,25 @@ public void unset() {
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.LOWEST)
public void onPluginMessageReceive(PluginMessageEvent event) {
- if (isUpstream(event.getSender()) ||
- !isMarkedAsIntaveChannel(event.getTag())
- ) {
+ if (isUpstream(event.getSender())) {
return;
}
- event.setCancelled(true);
- receivePayloadPacket((UserConnection) event.getReceiver(), event.getData());
+ boolean isIntavePacket = receivePayloadPacket((UserConnection) event.getReceiver(), event.getData());
+
+ if(isIntavePacket) {
+ event.setCancelled(true);
+ }
}
- public void receivePayloadPacket(UserConnection player,
- byte[] data
+ public boolean receivePayloadPacket(UserConnection player,
+ byte[] data
) {
ByteArrayDataInput inputData = newByteArrayDataInputFrom(data);
try {
-
String channelName = readChannelName(inputData);
if (!channelName.equalsIgnoreCase(PROTOCOL_HEADER)) {
- return;
+ return false;
}
int protocolVersion = readProtocolVersion(inputData);
@@ -80,7 +80,11 @@ public void receivePayloadPacket(UserConnection player,
player,
constructedPacket
);
- } catch (Exception exception) {
+
+ return true;
+ } catch (IllegalStateException exception) {
+ return false;
+ } catch (IllegalAccessException | InstantiationException exception) {
throw new IllegalStateException("Could not handle incoming packet", exception);
}
}
@@ -128,8 +132,7 @@ private ByteArrayDataInput newByteArrayDataInputFrom(byte[] byteArray) {
}
private boolean isMarkedAsIntaveChannel(String channelTag) {
- return channelTag.equalsIgnoreCase(INCOMING_CHANNEL) ||
- channelTag.equalsIgnoreCase(OUTGOING_CHANNEL);
+ return channelTag.equalsIgnoreCase(OUTGOING_CHANNEL);
}
private boolean isUpstream(Connection connection) {
diff --git a/src/de/jpx3/ips/connect/bukkit/PacketSender.java b/src/de/jpx3/ips/connect/bukkit/PacketSender.java
index 30b8d81..c8a3bd2 100644
--- a/src/de/jpx3/ips/connect/bukkit/PacketSender.java
+++ b/src/de/jpx3/ips/connect/bukkit/PacketSender.java
@@ -76,8 +76,7 @@ private void pushPacketData(
}
private byte[] serialize(AbstractPacket packet) {
- //noinspection UnstableApiUsage
- ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
+ ByteArrayDataOutput dataOutput = newByteArrayDataOutput();
packet.applyTo(dataOutput);
return dataOutput.toByteArray();
}
diff --git a/src/de/jpx3/ips/connect/bukkit/IPacketSubscriber.java b/src/de/jpx3/ips/connect/bukkit/PacketSubscriber.java
similarity index 68%
rename from src/de/jpx3/ips/connect/bukkit/IPacketSubscriber.java
rename to src/de/jpx3/ips/connect/bukkit/PacketSubscriber.java
index 2c947ef..3ef148e 100644
--- a/src/de/jpx3/ips/connect/bukkit/IPacketSubscriber.java
+++ b/src/de/jpx3/ips/connect/bukkit/PacketSubscriber.java
@@ -2,6 +2,6 @@
import net.md_5.bungee.api.connection.ProxiedPlayer;
-public interface IPacketSubscriber
{
+public interface PacketSubscriber
{
void handle(ProxiedPlayer sender, P packet);
}
diff --git a/src/de/jpx3/ips/connect/bukkit/PacketSubscriptionService.java b/src/de/jpx3/ips/connect/bukkit/PacketSubscriptionService.java
index f49cfb3..be29e14 100644
--- a/src/de/jpx3/ips/connect/bukkit/PacketSubscriptionService.java
+++ b/src/de/jpx3/ips/connect/bukkit/PacketSubscriptionService.java
@@ -1,6 +1,7 @@
package de.jpx3.ips.connect.bukkit;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import de.jpx3.ips.IntaveProxySupportPlugin;
@@ -12,7 +13,7 @@
@SuppressWarnings({"rawtypes", "unchecked"})
public final class PacketSubscriptionService {
private IntaveProxySupportPlugin plugin;
- private Map, List> packetSubscriptions;
+ private Map, List> packetSubscriptions = ImmutableMap.of();
private PacketSubscriptionService(IntaveProxySupportPlugin plugin) {
this.plugin = plugin;
@@ -33,7 +34,7 @@ public void reset() {
public void addSubscriber(
Class
type,
- IPacketSubscriber
subscriber
+ PacketSubscriber
subscriber
) {
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(subscriber);
@@ -53,15 +54,15 @@ public
void broadcastPacketToSubscribers(
packetSubscriber.handle(sender, packet));
}
- private List subscriptionsOf(AbstractPacket packet) {
+ private List subscriptionsOf(AbstractPacket packet) {
return subscriptionsOf(packet.getClass());
}
- private List subscriptionsOf(Class extends AbstractPacket> packetClass) {
+ private List subscriptionsOf(Class extends AbstractPacket> packetClass) {
return packetSubscriptions().get(packetClass);
}
- public Map, List> packetSubscriptions() {
+ public Map, List> packetSubscriptions() {
return packetSubscriptions;
}
diff --git a/src/de/jpx3/ips/connect/database/AsyncQueryExecutor.java b/src/de/jpx3/ips/connect/database/AsyncQueryExecutor.java
index ffa7798..a60b116 100644
--- a/src/de/jpx3/ips/connect/database/AsyncQueryExecutor.java
+++ b/src/de/jpx3/ips/connect/database/AsyncQueryExecutor.java
@@ -31,13 +31,16 @@ public void update(String query) {
Preconditions.checkNotNull(query);
ensureStatementPresence();
- pushToExecutor(() -> {
- try {
- statement.execute(query);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- });
+ pushToExecutor(() -> updateBlocking(query));
+ }
+
+ @Override
+ public void updateBlocking(String query) {
+ try {
+ statement.execute(query);
+ } catch (SQLException e) {
+ throw new IllegalStateException(e);
+ }
}
@Override
@@ -49,15 +52,23 @@ public void find(String query,
ensureStatementPresence();
pushToExecutor(() -> {
- try {
- ResultSet resultSet = statement.executeQuery(query);
- lazyReturn.accept(asTableData(resultSet));
- } catch (SQLException e) {
- e.printStackTrace();
- }
+ lazyReturn.accept(findBlocking(query));
});
}
+ @Override
+ public List