Skip to content

Commit

Permalink
Merge pull request #75 from Aelysium-Group/v0.8.2
Browse files Browse the repository at this point in the history
V0.8.2
  • Loading branch information
nathan-i-martin authored Oct 7, 2024
2 parents efc82b0 + ba346cd commit 89f8de3
Show file tree
Hide file tree
Showing 34 changed files with 207 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class RedisConnection extends MessengerConnection implements IMessengerConnection {
private final Vector<RedisSubscriber> subscribers = new Vector<>();
private final Map<PacketIdentification, List<PacketListener<? extends Packet.Wrapper>>> listeners = new HashMap<>();
private final RedisPublisher publisher;
private final RedisClient.Builder clientBuilder;
private boolean isAlive = false;
private final AtomicBoolean alive = new AtomicBoolean(false);
private ExecutorService executorService;
private final FailService failService;
private final AESCryptor cryptor;
Expand All @@ -37,7 +38,7 @@ public RedisConnection(RedisClient.Builder clientBuilder, AESCryptor cryptor) {
}

protected void subscribe(IMessageCacheService<?> cache, PluginLogger logger, Packet.Node senderUUID) {
if(!this.isAlive) return;
if(!this.alive.get()) return;

this.executorService.submit(() -> {
try {
Expand All @@ -62,24 +63,28 @@ protected void subscribe(IMessageCacheService<?> cache, PluginLogger logger, Pac
}

public void startListening(IMessageCacheService<?> cache, PluginLogger logger, Packet.Node senderUUID) {
if(this.isAlive) throw new IllegalStateException("The RedisService is already running! You can't start it again! Shut it down with `.kill()` first and then try again!");
if(this.alive.get()) throw new IllegalStateException("The RedisService is already running! You can't start it again! Shut it down with `.kill()` first and then try again!");
this.executorService = Executors.newFixedThreadPool(2);

this.isAlive = true;
this.alive.set(true);

this.subscribe(cache, logger, senderUUID);
}

@Override
public void kill() {
this.isAlive = false;
this.alive.set(false);
this.failService.kill();

for (Iterator<RedisSubscriber> iterator = this.subscribers.elements().asIterator(); iterator.hasNext(); ) {
RedisSubscriber subscriber = iterator.next();
subscriber.shutdown();
}

try {
this.publisher.kill();
} catch (Exception ignore) {}

try {
this.executorService.shutdown();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import group.aelysium.rustyconnector.core.lib.crypt.AESCryptor;
import group.aelysium.rustyconnector.toolkit.core.packet.Packet;
import group.aelysium.rustyconnector.toolkit.core.serviceable.interfaces.Service;
import io.lettuce.core.RedisChannelHandler;
import io.lettuce.core.RedisConnectionStateAdapter;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class RedisPublisher {
public class RedisPublisher implements Service {
private final RedisClient client;
private StatefulRedisPubSubConnection<String, String> connection;
private final AESCryptor cryptor;
private final AtomicBoolean killed = new AtomicBoolean(false);
protected RedisPublisher(RedisClient client, AESCryptor cryptor) {
this.client = client;
this.client.addListener(new RedisPublisherListener());
Expand All @@ -35,6 +38,8 @@ public void shutdown() {
* @throws IllegalStateException If you attempt to send a received RedisMessage.
*/
public void publish(Packet packet) {
if(killed.get()) return;

String signedPacket;
try {
signedPacket = this.cryptor.encrypt(packet.toString());
Expand All @@ -50,6 +55,11 @@ public void publish(Packet packet) {
async.publish(this.client.dataChannel(), signedPacket);
}

public void kill() {
this.killed.set(true);
this.connection.close();
}

static class RedisPublisherListener extends RedisConnectionStateAdapter {
@Override
public void onRedisExceptionCaught(RedisChannelHandler<?, ?> connection, Throwable cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public Session session() {
new MCLoaderMatchPlayer(
player_uuid,
entryObject.get("username").getAsString(),
entryObject.get("schema").getAsString(),
DefaultRankResolver.New().resolve(entryObject.get("rank").getAsJsonObject())
entryObject.get("rank_schema").getAsString(),
DefaultRankResolver.New().resolve(entryObject.get("rank_schema").getAsJsonObject())
)
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected DefaultRankResolver() {}

@Override
public IPlayerRank resolve(JsonObject object) throws IllegalStateException {
String schema = object.get("schema").getAsString();
String schema = object.get("rank_schema").getAsString();

if(schema.equals(RandomizedPlayerRank.schema()))
return RandomizedPlayerRank.New();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String schemaName() {
@Override
public JsonObject toJSON() {
JsonObject object = new JsonObject();
object.add("schema", new JsonPrimitive(this.schemaName()));
object.add("rank_schema", new JsonPrimitive(this.schemaName()));
object.add("elo", new JsonPrimitive(this.elo));
return object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String schemaName() {
@Override
public JsonObject toJSON() {
JsonObject object = new JsonObject();
object.add("schema", new JsonPrimitive(this.schemaName()));
object.add("rank_schema", new JsonPrimitive(this.schemaName()));
object.add("mu", new JsonPrimitive(this.mu));
object.add("sigma", new JsonPrimitive(this.sigma));
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String schemaName() {
@Override
public JsonObject toJSON() {
JsonObject object = new JsonObject();
object.add("schema", new JsonPrimitive(this.schemaName()));
object.add("rank_schema", new JsonPrimitive(this.schemaName()));
return object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String schemaName() {
@Override
public JsonObject toJSON() {
JsonObject object = new JsonObject();
object.add("schema", new JsonPrimitive(this.schemaName()));
object.add("rank_schema", new JsonPrimitive(this.schemaName()));
object.add("wins", new JsonPrimitive(this.wins));
object.add("losses", new JsonPrimitive(this.losses));
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String schemaName() {
@Override
public JsonObject toJSON() {
JsonObject object = new JsonObject();
object.add("schema", new JsonPrimitive(this.schemaName()));
object.add("rank_schema", new JsonPrimitive(this.schemaName()));
object.add("wins", new JsonPrimitive(this.wins));
object.add("losses", new JsonPrimitive(this.losses));
object.add("ties", new JsonPrimitive(this.ties));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ redis:


storage:
#
# The default provider is "SQLITE" and will store all database information on your Velocity server's filesystem.
#
provider: MYSQL


Expand Down
2 changes: 1 addition & 1 deletion plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx4G
java_version = 17

# Plugin Properties
plugin_version = 0.8.0
plugin_version = 0.8.2
maven_group = group.aelysium.rustyconnector
archives_base_name = rustyconnector
config_version = 6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package group.aelysium.rustyconnector.toolkit.velocity.config;

import group.aelysium.rustyconnector.toolkit.velocity.whitelist.IWhitelistPlayerFilter;

import java.util.List;

public interface WhitelistConfig {
boolean getUse_players();
List<Object> getPlayers();
List<IWhitelistPlayerFilter> getPlayers();
boolean getUse_permission();
boolean getUse_country();
List<String> getCountries();
String getMessage();
boolean isStrict();
boolean isInverted();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package group.aelysium.rustyconnector.toolkit.velocity.matchmaking;

import group.aelysium.rustyconnector.toolkit.core.matchmaking.IPlayerRank;
import group.aelysium.rustyconnector.toolkit.velocity.load_balancing.ISortable;
import group.aelysium.rustyconnector.toolkit.velocity.player.IPlayer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package group.aelysium.rustyconnector.toolkit.velocity.matchmaking;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public interface IVelocityPlayerRank extends group.aelysium.rustyconnector.toolkit.core.matchmaking.IPlayerRank {
/**
* Returns the computer used to compute new ranks.
*/
IComputor computor();
@NotNull IComputer computer();

interface IComputor {
interface IComputer {
/**
* Compute the new rank of all the winners and losers.
* @param winners The winners.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ class Send {
} catch (NoSuchElementException e) {
logger.send(ProxyLang.RC_SEND_NO_FAMILY.build(familyName));
} catch (Exception e) {
e.printStackTrace();
logger.send(Component.text("There was an issue using that command! "+e.getMessage(), NamedTextColor.RED));
}
return Command.SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,7 @@ protected void register() throws IllegalStateException, NoOutputException {

this.maxMembers = IYAML.getValue(this.data, "max-members", Integer.class);

try {
this.friendsOnly = IYAML.getValue(this.data, "friends-only", Boolean.class);
if(this.friendsOnly)
Tinder.get().services().friends().orElseThrow();
} catch (Exception ignore) {
Tinder.get().logger().send(ProxyLang.BOXED_MESSAGE_COLORED.build("[friends-only] in `party.yml` is set to true. But the friends module isn't enabled! Ignoring...", NamedTextColor.YELLOW));
this.friendsOnly = false;
}
this.friendsOnly = IYAML.getValue(this.data, "friends-only", Boolean.class);
this.localOnly = IYAML.getValue(this.data, "local-only", Boolean.class);

this.partyLeader_onlyLeaderCanInvite = IYAML.getValue(this.data, "party-leader.only-leader-can-invite", Boolean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ protected void register() throws IllegalStateException {
Tinder api = Tinder.get();
PluginLogger logger = api.logger();

WebhookEventManager.clear();

Boolean enabled = IYAML.getValue(this.data, "enabled", Boolean.class);
if(!enabled) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
import group.aelysium.rustyconnector.plugin.velocity.central.Tinder;
import group.aelysium.rustyconnector.plugin.velocity.lib.config.ConfigService;
import group.aelysium.rustyconnector.plugin.velocity.lib.lang.ProxyLang;
import group.aelysium.rustyconnector.plugin.velocity.lib.whitelist.WhitelistPlayerFilter;
import group.aelysium.rustyconnector.toolkit.core.config.IConfigService;
import group.aelysium.rustyconnector.toolkit.core.config.IYAML;
import group.aelysium.rustyconnector.toolkit.core.lang.LangFileMappings;
import group.aelysium.rustyconnector.toolkit.velocity.whitelist.IWhitelistPlayerFilter;
import net.kyori.adventure.text.format.NamedTextColor;
import org.spongepowered.configurate.serialize.SerializationException;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class WhitelistConfig extends YAML implements group.aelysium.rustyconnector.toolkit.velocity.config.WhitelistConfig {
private boolean use_players = false;
private List<Object> players = new ArrayList<>();
private final List<IWhitelistPlayerFilter> players = new ArrayList<>();

private boolean use_permission = false;

private boolean use_country = false;
private List<String> countries = new ArrayList<>();
private String message = "You aren't whitelisted on this server!";
private boolean strict = false;
private boolean inverted = false;
Expand All @@ -31,22 +32,14 @@ public boolean getUse_players() {
return use_players;
}

public List<Object> getPlayers() {
public List<IWhitelistPlayerFilter> getPlayers() {
return players;
}

public boolean getUse_permission() {
return use_permission;
}

public boolean getUse_country() {
return use_country;
}

public List<String> getCountries() {
return countries;
}

public String getMessage() {
return message;
}
Expand All @@ -71,20 +64,28 @@ protected void register() throws IllegalStateException {
PluginLogger logger = Tinder.get().logger();

this.use_players = IYAML.getValue(this.data,"use-players",Boolean.class);

try {
this.players = (IYAML.getValue(this.data,"players",List.class));
} catch (ClassCastException e) {
IYAML.get(this.data,"players").childrenList().forEach(e -> {
try {
String username = e.node("username").get(String.class);
String uuid = e.node("uuid").get(String.class);
String ip = e.node("ip").get(String.class);
new WhitelistPlayerFilter(
username,
uuid == null ? null : UUID.fromString(uuid),
ip
);
} catch (SerializationException ex) {
throw new RuntimeException(ex);
}
});
} catch (Exception e) {
throw new IllegalStateException("The node [players] in "+this.name()+" is invalid! Make sure you are using the correct type of data!");
}

this.use_permission = IYAML.getValue(this.data,"use-permission",Boolean.class);

this.use_country = IYAML.getValue(this.data,"use-country",Boolean.class);
if(this.use_country)
ProxyLang.BOXED_MESSAGE_COLORED.send(logger, "RustyConnector does not currently support country codes in whitelists. Setting `use-country` to false.", NamedTextColor.YELLOW);
this.use_country = false;
this.countries = new ArrayList<>();

this.message = IYAML.getValue(data,"message",String.class);
if(this.message.equalsIgnoreCase(""))
throw new IllegalStateException("Whitelist kick messages cannot be empty!");
Expand Down
Loading

0 comments on commit 89f8de3

Please sign in to comment.