Skip to content

Commit

Permalink
Fix some things, make MySQL bootable
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-i-martin committed Oct 18, 2023
1 parent b687532 commit 26ad0eb
Show file tree
Hide file tree
Showing 32 changed files with 529 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private RedisConnector(AESCryptor cryptor, PacketOrigin origin, InetSocketAddres
@Override
public RedisConnection connect() throws ConnectException {
this.connection = new RedisConnection(
origin,
origin,
this.toClientBuilder(),
this.cryptor
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public DependencyInjector.DI2<RedisConnector, MySQLStorage> connectors(Dependenc
messenger.connect();
MessengerConnection connection = messenger.connection().orElseThrow();
connection.startListening(dependencies.d2(), dependencies.d3(), handlers);
bootOutput.add(Component.text("Finished booting CMessenger.", NamedTextColor.GREEN));
bootOutput.add(Component.text("Finished booting Messenger.", NamedTextColor.GREEN));

MySQLStorage storage = MySQLStorage.create(
config.getMysql_address(),
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendRequest;
import group.aelysium.rustyconnector.plugin.velocity.lib.friends.FriendsService;
import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang;
import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer;
import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer;
import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer;
import group.aelysium.rustyconnector.plugin.velocity.lib.whitelist.Whitelist;
import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.WebhookAlertFlag;
import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.WebhookEventManager;
import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.DiscordWebhookMessage;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

public class OnPlayerChooseInitialServer {
/**
Expand Down Expand Up @@ -69,7 +66,7 @@ public EventTask onPlayerChooseInitialServer(PlayerChooseInitialServerEvent even
// Check for active friend requests
try {
FriendsService friendsService = api.services().friendsService().orElseThrow();
List<FriendRequest> requests = friendsService.findRequestsToTarget(FakePlayer.from(player));
List<FriendRequest> requests = friendsService.findRequestsToTarget(ResolvablePlayer.from(player));

if(requests.size() == 0) throw new NoOutputException();

Expand All @@ -79,7 +76,7 @@ public EventTask onPlayerChooseInitialServer(PlayerChooseInitialServerEvent even
// Check for online friends
try {
FriendsService friendsService = api.services().friendsService().orElseThrow();
List<FakePlayer> friends = friendsService.findFriends(player).orElseThrow();
List<ResolvablePlayer> friends = friendsService.findFriends(player).orElseThrow();

if(friends.size() == 0) throw new NoOutputException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import group.aelysium.rustyconnector.plugin.velocity.lib.lang.VelocityLang;
import group.aelysium.rustyconnector.plugin.velocity.lib.parties.Party;
import group.aelysium.rustyconnector.plugin.velocity.lib.parties.PartyService;
import group.aelysium.rustyconnector.plugin.velocity.lib.players.FakePlayer;
import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer;
import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer;
import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.WebhookAlertFlag;
import group.aelysium.rustyconnector.plugin.velocity.lib.webhook.WebhookEventManager;
Expand Down Expand Up @@ -66,7 +66,7 @@ public EventTask onPlayerDisconnect(DisconnectEvent event) {
FriendsService friendsService = api.services().friendsService().orElseThrow();
if(!friendsService.settings().allowMessaging()) throw new NoOutputException();

List<FakePlayer> friends = friendsService.findFriends(player).orElseThrow();
List<ResolvablePlayer> friends = friendsService.findFriends(player).orElseThrow();

if(friends.size() == 0) throw new NoOutputException();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package group.aelysium.rustyconnector.plugin.velocity.lib.family;

import group.aelysium.rustyconnector.plugin.velocity.central.Tinder;
import group.aelysium.rustyconnector.plugin.velocity.lib.family.bases.BaseServerFamily;

import java.util.Objects;
import java.util.Optional;

public record ResolvableFamily(String name) {
public Optional<BaseServerFamily<?>> resolve() {
BaseServerFamily<?> potentialFamily = Tinder.get().services().familyService().find(this.name);
if(potentialFamily == null) return Optional.empty();
return Optional.of(potentialFamily);
}

@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;

ResolvableFamily that = (ResolvableFamily) object;
return this.name.equals(that.name());
}
public static ResolvableFamily from(BaseServerFamily<?> family) {
return new ResolvableFamily(family.name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public abstract class BaseServerFamily<S extends PlayerServer> {
protected final String name;
Expand All @@ -27,6 +28,7 @@ public String name() {
* @return A found server or `null` if there's no match.
*/
abstract public S findServer(@NotNull ServerInfo serverInfo);
abstract public S findServer(@NotNull UUID uuid);

/**
* Add a server to the family.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ public PlayerServer findServer(@NotNull ServerInfo serverInfo) {
).findFirst().orElse(null);
}

@Override
public PlayerServer findServer(@NotNull UUID uuid) {
return this.registeredServers().stream()
.filter(server -> server.id().equals(uuid)
).findFirst().orElse(null);
}

@Override
public List<Player> allPlayers(int max) {
List<Player> players = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ public class FamiliesConfig extends YAML {
private Boolean rootFamily_catchDisconnectingPlayers = false;
private List<String> scalar = new ArrayList<>();
private List<String> staticF = new ArrayList<>();
private String staticFamilyStorage = "";

public FamiliesConfig(File configPointer) {
super(configPointer);
}
}d .

public String rootFamilyName() {
return this.rootFamily_name;
Expand All @@ -37,10 +36,6 @@ public List<String> staticFamilies() {
return this.staticF;
}

public String staticFamilyStorage() {
return this.staticFamilyStorage;
}

@SuppressWarnings("unchecked")
public void register() throws IllegalStateException, NoOutputException {
PluginLogger logger = Tinder.get().logger();
Expand Down Expand Up @@ -87,12 +82,6 @@ public void register() throws IllegalStateException, NoOutputException {
this.scalar.remove(this.rootFamily_name);
this.staticF.remove(this.rootFamily_name);
}


// MySQL
if(this.staticF.size() > 0) {
this.staticFamilyStorage = this.getNode(this.data, "static-family-storage", String.class);
}
}

private boolean doDuplicatesExist() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.velocitypowered.api.proxy.Player;
import group.aelysium.rustyconnector.core.lib.model.LiquidTimestamp;
import group.aelysium.rustyconnector.plugin.velocity.lib.family.ResolvableFamily;
import group.aelysium.rustyconnector.plugin.velocity.lib.players.ResolvablePlayer;
import group.aelysium.rustyconnector.plugin.velocity.lib.server.PlayerServer;
import group.aelysium.rustyconnector.plugin.velocity.lib.storage.MySQLStorage;
import group.aelysium.rustyconnector.plugin.velocity.lib.storage.StorageRoot;
Expand All @@ -24,7 +26,10 @@ public Optional<ServerResidence> fetch(Player player, StaticServerFamily family)
StorageRoot root = (StorageRoot) this.storage.root();

Optional<ServerResidence> serverResidence = root.residence().stream()
.filter(residence -> residence.player().equals(player) && residence.family().equals(family))
.filter(residence ->
residence.rawPlayer().equals(ResolvablePlayer.from(player)) &&
residence.rawFamily().equals(ResolvableFamily.from(family))
)
.findAny();

return serverResidence;
Expand All @@ -48,7 +53,10 @@ public void delete(Player player, StaticServerFamily family) {
StorageRoot root = (StorageRoot) this.storage.root();

List<ServerResidence> residences = root.residence();
residences.removeIf(residence -> residence.player().equals(player) && residence.family().equals(family));
residences.removeIf(residence ->
residence.rawPlayer().equals(ResolvablePlayer.from(player)) &&
residence.rawFamily().equals(ResolvableFamily.from(family))
);

this.storage.store(residences);
}
Expand All @@ -68,7 +76,10 @@ protected void purgeExpired(StaticServerFamily family) {
StorageRoot root = (StorageRoot) this.storage.root();

List<ServerResidence> residenceList = root.residence();
residenceList.removeIf(serverResidence -> serverResidence.expiration() < Instant.EPOCH.getEpochSecond() && serverResidence.family().equals(family));
residenceList.removeIf(serverResidence ->
serverResidence.expiration() < Instant.EPOCH.getEpochSecond() &&
serverResidence.rawFamily().equals(ResolvableFamily.from(family))
);

this.storage.store(residenceList);
}
Expand All @@ -83,7 +94,7 @@ protected void updateNullExpirations(StaticServerFamily family) {

List<ServerResidence> residenceList = root.residence();
residenceList.forEach(serverResidence -> {
if(!serverResidence.family().equals(family)) return;
if(!serverResidence.rawFamily().equals(ResolvableFamily.from(family))) return;
serverResidence.expiration(null);
});

Expand All @@ -100,7 +111,7 @@ protected void updateValidExpirations(StaticServerFamily family) {

List<ServerResidence> residenceList = root.residence();
residenceList.forEach(serverResidence -> {
if(!serverResidence.family().equals(family)) return;
if(!serverResidence.rawFamily().equals(ResolvableFamily.from(family))) return;
serverResidence.expiration(family.homeServerExpiration());
});

Expand Down
Loading

0 comments on commit 26ad0eb

Please sign in to comment.