Skip to content

Commit

Permalink
Improve layout more
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Martin committed Jul 25, 2024
1 parent 81be8f8 commit 82a645f
Show file tree
Hide file tree
Showing 23 changed files with 452 additions and 223 deletions.
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ jar {
it.isDirectory() ? it : zipTree(it)
}

from(files("LICENSE_rusty-connector"))
from(files("LICENSE"))

exclude("META-INF/*.RSA", "META-INF/*.DSA", "META-INF/*.SF")
}

tasks.register('generatePropertiesFile') {
doLast {
def propertiesFile = file("${buildDir}/version.txt")
propertiesFile.parentFile.mkdirs()
propertiesFile.text = "${version}"
}
}
32 changes: 23 additions & 9 deletions core/src/main/java/group/aelysium/rustyconnector/RC.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import group.aelysium.rustyconnector.proxy.magic_link.MagicLink;
import group.aelysium.rustyconnector.proxy.player.Player;
import group.aelysium.rustyconnector.common.lang.LangLibrary;
import group.aelysium.rustyconnector.proxy.storage.LocalStorage;
import group.aelysium.rustyconnector.proxy.player.Players;

import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

/**
* This interface provides shorthand fetch operations for common requests.
Expand All @@ -39,6 +40,10 @@ static Families Families() throws NoSuchElementException {
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().Families().orElseThrow();
}

static Players Players() throws NoSuchElementException {
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().Players().orElseThrow();
}

static Optional<Whitelist> Whitelist() throws NoSuchElementException {
Optional<Particle.Flux<Whitelist>> whitelistOptional = RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().Whitelist();
if(whitelistOptional.isEmpty()) return Optional.empty();
Expand All @@ -49,12 +54,8 @@ static MagicLink MagicLink() throws NoSuchElementException {
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().MagicLink().orElseThrow();
}

static LocalStorage LocalStorage() throws NoSuchElementException {
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().LocalStorage();
}

static EventManager EventManager() throws NoSuchElementException {
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().EventManager();
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().EventManager().orElseThrow();
}

static ProxyAdapter Adapter() throws NoSuchElementException {
Expand All @@ -74,18 +75,31 @@ static Optional<Family> Family(String id) throws NoSuchElementException {
}

static Optional<Server> Server(UUID uuid) throws NoSuchElementException {
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().LocalStorage().servers().fetch(uuid);
Families families = RC.P.Families();
AtomicReference<Server> server = new AtomicReference<>(null);
for (Particle.Flux<Family> family : families.dump()) {
family.executeNow(f -> {
f.servers().stream().filter(s -> s.uuid().equals(uuid)).findAny().ifPresent(server::set);
});
if(server.get() != null) break;
}
return Optional.ofNullable(server.get());
}

static Optional<Player> Player(UUID uuid) throws NoSuchElementException {
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().LocalStorage().players().fetch(uuid);
return RustyConnector.Toolkit.Proxy().orElseThrow().orElseThrow().Players().orElseThrow().fetch(uuid);
}
}

/**
* The interface containing Server based operations.
*/
interface S {
/**
* Returns the RustyConnector Kernel.
* @return {@link ProxyFlame}
* @throws NoSuchElementException If the kernel cannot be found.
*/
static ServerFlame Kernel() throws NoSuchElementException {
return RustyConnector.Toolkit.Server().orElseThrow().orElseThrow();
}
Expand All @@ -103,7 +117,7 @@ static LangLibrary<ServerLang> Lang() throws NoSuchElementException {
}

static EventManager EventManager() throws NoSuchElementException {
return RustyConnector.Toolkit.Server().orElseThrow().orElseThrow().EventManager();
return RustyConnector.Toolkit.Server().orElseThrow().orElseThrow().EventManager().orElseThrow();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*/
public interface Particle extends AutoCloseable {
/**
* Tinder exists as an ignition point for new Particles.
* @param <P> The Particles that will be launched via this Tinder.
* Tinder is the configuration point for a {@link Particle}.
* Via a {@link Flux}, a single Tinder be deterministic of the {@link Particle} produced.
* @param <P> The Particle type that will be launched via this Tinder.
*/
abstract class Tinder<P extends Particle> {
protected Tinder() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.concurrent.Callable;

public class AESCryptor {
private static SecretKey DEFAULT_AES_KEY;
static {
try {
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256);
DEFAULT_AES_KEY = keyGen.generateKey();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private final SecretKey key;

public AESCryptor(SecretKey key) {
Expand Down Expand Up @@ -47,4 +59,9 @@ public static AESCryptor from(byte[] key) {

return new AESCryptor(secretKey);
}

/**
* The cryptor returned here is effectively worthless because there's no way to retrieve the AES key used.
*/
public static AESCryptor DEFAULT_CRYPTOR = new AESCryptor(DEFAULT_AES_KEY);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package group.aelysium.rustyconnector.common.events;

import group.aelysium.rustyconnector.common.absolute_redundancy.Particle;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Vector;
Expand Down Expand Up @@ -55,4 +56,13 @@ public void close() throws Exception {
this.listeners.clear();
this.executor.shutdown();
}

public static class Tinder extends Particle.Tinder<EventManager> {
@Override
public @NotNull EventManager ignite() throws Exception {
return new EventManager();
}

public static Tinder DEFAULT_CONFIGURATION = new Tinder();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package group.aelysium.rustyconnector.common.lang;

import group.aelysium.rustyconnector.common.absolute_redundancy.Particle;
import group.aelysium.rustyconnector.mc_loader.lang.ServerLang;
import group.aelysium.rustyconnector.proxy.lang.ProxyLang;
import org.jetbrains.annotations.NotNull;

public class LangLibrary<L extends Lang> implements Particle {
Expand Down Expand Up @@ -47,6 +49,15 @@ public Tinder(
this.asciiAlphabet
);
}

public static LangLibrary.Tinder<ProxyLang> DEFAULT_PROXY_CONFIGURATION = new Tinder<>(
new ProxyLang(DEFAULT_ASCII_ALPHABET),
DEFAULT_ASCII_ALPHABET
);
public static LangLibrary.Tinder<ServerLang> DEFAULT_SERVER_CONFIGURATION = new Tinder<>(
new ServerLang(DEFAULT_ASCII_ALPHABET),
DEFAULT_ASCII_ALPHABET
);
}

public static ASCIIAlphabet DEFAULT_ASCII_ALPHABET = new EnglishAlphabet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void close() throws Exception {
this.packetsAwaitingReply.close();
}

/**
* Handles all of the MagicLink/RustyConnector internals of handling MagicLink packets.
* @param rawMessage A AES-256 encrypted MagicLink packet.
*/
public void handleMessage(String rawMessage) {
CacheableMessage cachedMessage = null;
String decryptedMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ public boolean isNodeEquivalentToMe(Target target) {
// If one of the two is of type "ANY_PROXY" and the other is of type "PROXY", return true.
if(
(this.origin == Origin.ANY_PROXY && target.origin == Origin.PROXY) ||
(this.origin == Origin.PROXY && target.origin == Origin.ANY_PROXY) ||
(this.origin == Origin.ANY_PROXY && target.origin == Origin.ANY_PROXY)
(this.origin == Origin.PROXY && target.origin == Origin.ANY_PROXY) ||
(this.origin == Origin.ANY_PROXY && target.origin == Origin.ANY_PROXY)
) return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import group.aelysium.rustyconnector.common.magic_link.packet.Packet;
import group.aelysium.rustyconnector.mc_loader.lang.ServerLang;
import group.aelysium.rustyconnector.mc_loader.magic_link.MagicLink;
import group.aelysium.rustyconnector.proxy.ProxyFlame;
import group.aelysium.rustyconnector.proxy.util.Version;
import group.aelysium.rustyconnector.common.lang.LangLibrary;
import org.jetbrains.annotations.NotNull;

import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.*;

Expand All @@ -21,26 +23,38 @@ public class ServerFlame implements Particle {
private final String displayName;
private final InetSocketAddress address;
private final Flux<MagicLink> magicLink;
private final EventManager eventManager;
private final Flux<EventManager> eventManager;

protected ServerFlame(
@NotNull UUID uuid,
@NotNull Version version,
@NotNull ServerAdapter adapter,
@NotNull Flux<LangLibrary<ServerLang>> lang,
@NotNull String displayName,
@NotNull InetSocketAddress address,
@NotNull Flux<MagicLink> magicLink,
@NotNull EventManager eventManager
@NotNull Flux<EventManager> eventManager
) {
this.uuid = uuid;
this.version = version;
this.adapter = adapter;
this.lang = lang;
this.displayName = displayName;
this.address = address;
this.magicLink = magicLink;
this.eventManager = eventManager;

try {
try (InputStream input = ProxyFlame.class.getClassLoader().getResourceAsStream("version.txt")) {
if (input == null) throw new NullPointerException("Unable to initialize version number from jar.");
String stringVersion = new String(input.readAllBytes());
this.version = new Version(stringVersion);
}

this.lang.access().get();
this.magicLink.access().get();
this.eventManager.access().get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

/**
Expand Down Expand Up @@ -139,7 +153,7 @@ public Flux<LangLibrary<ServerLang>> Lang() {
return this.lang;
}

public EventManager EventManager() {
public Flux<EventManager> EventManager() {
return this.eventManager;
}

Expand All @@ -149,46 +163,64 @@ public void close() throws Exception {
}

public static class Tinder extends Particle.Tinder<ServerFlame> {
private final UUID uuid;
private final Version version;
private final ServerAdapter adapter;
private final LangLibrary.Tinder<ServerLang> lang;
private final String displayName;
private final InetSocketAddress address;
private final MagicLink.Tinder magicLink;
private final EventManager eventManager;

public Tinder(
@NotNull UUID uuid,
@NotNull Version version,
@NotNull ServerAdapter adapter,
@NotNull LangLibrary.Tinder<ServerLang> lang,
@NotNull String displayName,
@NotNull InetSocketAddress address,
@NotNull MagicLink.Tinder magicLink,
@NotNull EventManager eventManager
) {
private UUID uuid = UUID.randomUUID();
private ServerAdapter adapter;
private LangLibrary.Tinder<ServerLang> lang = LangLibrary.Tinder.DEFAULT_SERVER_CONFIGURATION;
private String displayName;
private InetSocketAddress address;
private MagicLink.Tinder magicLink = null;
private EventManager.Tinder eventManager = EventManager.Tinder.DEFAULT_CONFIGURATION;

public Tinder() {
}

public Tinder uuid(@NotNull UUID uuid) {
this.uuid = uuid;
this.version = version;
return this;
}

public Tinder adapter(@NotNull ServerAdapter adapter) {
this.adapter = adapter;
return this;
}

public Tinder lang(@NotNull LangLibrary.Tinder<ServerLang> lang) {
this.lang = lang;
return this;
}

public Tinder displayName(@NotNull String displayName) {
this.displayName = displayName;
return this;
}

public Tinder address(@NotNull InetSocketAddress address) {
this.address = address;
return this;
}

public Tinder magicLink(@NotNull MagicLink.Tinder magicLink) {
this.magicLink = magicLink;
return this;
}

public Tinder eventManager(@NotNull EventManager.Tinder eventManager) {
this.eventManager = eventManager;
return this;
}

@Override
public @NotNull ServerFlame ignite() throws Exception {
if(this.magicLink == null) this.magicLink = MagicLink.Tinder.DEFAULT_CONFIGURATION(this.uuid);

return new ServerFlame(
uuid,
version,
adapter,
lang.flux(),
displayName,
address,
magicLink.flux(),
eventManager
eventManager.flux()
);
}
}
Expand Down
Loading

0 comments on commit 82a645f

Please sign in to comment.