Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Updated plugin source code
Browse files Browse the repository at this point in the history
  • Loading branch information
KarmaDeb committed Nov 27, 2022
1 parent 4a16036 commit aee014d
Show file tree
Hide file tree
Showing 24 changed files with 333 additions and 120 deletions.
14 changes: 1 addition & 13 deletions LockLogin-API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>eu.locklogin</groupId>
<artifactId>LockLogin</artifactId>
<version>1.13.37</version>
<version>1.13.38</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -69,18 +69,6 @@
<version>${project.karmaapi}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>eu.locklogin</groupId>
<artifactId>LockLogin-common</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>eu.locklogin</groupId>
<artifactId>LockLogin-API</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import eu.locklogin.api.common.utils.plugin.MessageQueue;
import eu.locklogin.api.module.PluginModule;
import eu.locklogin.api.module.plugin.javamodule.sender.ModulePlayer;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,6 +24,8 @@ public final class TargetServer implements Iterable<ModulePlayer> {

@SuppressWarnings("FieldMayBeFinal")
private static BiConsumer<String, Set<ModulePlayer>> onPlayers = null;
@SuppressWarnings("FieldMayBeFinal")
private static MessageQue que = null;

/**
* LockLogin module server
Expand Down Expand Up @@ -111,12 +112,13 @@ public boolean isActive() {
*/
@SuppressWarnings("UnstableApiUsage")
public void sendMessage(final PluginModule sender, final byte[] data) {
ByteArrayDataOutput modified_out = ByteStreams.newDataOutput();
modified_out.writeUTF(sender.getID().toString());
modified_out.write(data); //Not sure if this would work...
if (que != null) {
ByteArrayDataOutput modified_out = ByteStreams.newDataOutput();
modified_out.writeUTF(sender.getID().toString());
modified_out.write(data); //Not sure if this would work...

MessageQueue queue = new MessageQueue(this);
queue.add(modified_out.toByteArray());
que.add(modified_out.toByteArray());
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions LockLogin-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>eu.locklogin</groupId>
<artifactId>LockLogin</artifactId>
<version>1.13.37</version>
<version>1.13.38</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -77,10 +77,11 @@
</exclusion>
</exclusions>
</dependency>
<!-- Deprecated. Dropping support for Velocity soon -->
<dependency>
<groupId>eu.locklogin</groupId>
<artifactId>LockLogin-velocity</artifactId>
<version>${project.version}</version>
<version>1.13.37</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
16 changes: 7 additions & 9 deletions LockLogin-bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>eu.locklogin</groupId>
<artifactId>LockLogin</artifactId>
<version>1.13.37</version>
<version>1.13.38</version>
</parent>

<artifactId>LockLogin-bungee</artifactId>
Expand Down Expand Up @@ -76,19 +76,17 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.proxiodev.redisbungee</groupId>
<artifactId>RedisBungee-Bungee</artifactId>
<version>0.9.0</version>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<scope>provided</scope>
</dependency>
<!--
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.14.6</version>
<groupId>com.github.proxiodev.redisbungee</groupId>
<artifactId>RedisBungee-Bungee</artifactId>
<version>0.9.0</version>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

import eu.locklogin.api.common.utils.FileInfo;
import eu.locklogin.api.common.utils.other.ASCIIArtGenerator;
import eu.locklogin.api.common.utils.plugin.MessageQueue;
import eu.locklogin.api.common.utils.version.VersionID;
import eu.locklogin.api.file.plugin.PluginProperties;
import eu.locklogin.api.module.plugin.javamodule.ModuleLoader;
import eu.locklogin.api.module.plugin.javamodule.server.TargetServer;
import eu.locklogin.api.util.platform.CurrentPlatform;
import ml.karmaconfigs.api.common.Console;
import ml.karmaconfigs.api.common.karma.APISource;
Expand All @@ -31,32 +33,46 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.file.Files;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public interface LockLogin {
public class LockLogin {

Main plugin = (Main) ProxyServer.getInstance().getPluginManager().getPlugin("LockLogin");
private final static Map<String, MessageQueue> queues = new ConcurrentHashMap<>();

Console console = APISource.loadProvider("LockLogin").console();
public static Main plugin = (Main) ProxyServer.getInstance().getPluginManager().getPlugin("LockLogin");

String name = plugin.name();
String update = FileInfo.getUpdateName(null);
public static Console console = APISource.loadProvider("LockLogin").console();

VersionID versionID = new VersionID(plugin.version(), update).generate();
public static String name = plugin.name();
public static String update = FileInfo.getUpdateName(null);

String version = versionID.getVersionID();
public static MessageQueue fetchQueue(final TargetServer server) {
MessageQueue stored = queues.getOrDefault(server.getName(), null);
if (stored == null) {
stored = new MessageQueue(server);
queues.put(server.getName(), stored);
}

return stored;
}

public static VersionID versionID = new VersionID(plugin.version(), update).generate();

public static String version = versionID.getVersionID();

File lockloginFile = new File(Main.class.getProtectionDomain()
public static File lockloginFile = new File(Main.class.getProtectionDomain()
.getCodeSource()
.getLocation()
.getPath().replaceAll("%20", " "));

KarmaLogger logger = CurrentPlatform.getLogger();
public static KarmaLogger logger = CurrentPlatform.getLogger();

PluginProperties properties = new PluginProperties();
public static PluginProperties properties = new PluginProperties();

ASCIIArtGenerator artGen = new ASCIIArtGenerator();
public static ASCIIArtGenerator artGen = new ASCIIArtGenerator();

static ModuleLoader getLoader() {
public static ModuleLoader getLoader() {
File modulesFolder = new File(plugin.getDataFolder() + File.separator + "plugin", "modules");

if (!modulesFolder.exists())
Expand All @@ -69,7 +85,7 @@ static ModuleLoader getLoader() {
}

@Nullable
static InetAddress getIp(final SocketAddress connection) {
public static InetAddress getIp(final SocketAddress connection) {
try {
InetSocketAddress address = (InetSocketAddress) connection;
return address.getAddress();
Expand All @@ -79,7 +95,7 @@ static InetAddress getIp(final SocketAddress connection) {
}

@Nullable
static InetSocketAddress getSocketIp(final SocketAddress connection) {
public static InetSocketAddress getSocketIp(final SocketAddress connection) {
try {
return (InetSocketAddress) connection;
} catch (Throwable ex) {
Expand Down
117 changes: 115 additions & 2 deletions LockLogin-bungee/src/main/java/eu/locklogin/plugin/bungee/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,32 @@
* the version number 2.1.]
*/

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import eu.locklogin.api.common.utils.FileInfo;
import eu.locklogin.api.common.web.ChecksumTables;
import eu.locklogin.api.module.plugin.javamodule.server.TargetServer;
import eu.locklogin.api.util.platform.CurrentPlatform;
import eu.locklogin.api.util.platform.ModuleServer;
import eu.locklogin.api.util.platform.Platform;
import eu.locklogin.plugin.bungee.plugin.sender.DataSender;
import eu.locklogin.plugin.bungee.util.files.cache.TargetServerStorage;
import ml.karmaconfigs.api.bungee.KarmaPlugin;
import ml.karmaconfigs.api.common.utils.enums.Level;
import ml.karmaconfigs.api.common.utils.security.token.TokenGenerator;
import ml.karmaconfigs.api.common.utils.url.HttpUtil;
import ml.karmaconfigs.api.common.utils.url.URLUtils;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;

import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public final class Main extends KarmaPlugin {

Expand All @@ -35,8 +52,9 @@ public Main() throws Throwable {
super(false);
try {
Class.forName("com.imaginarycode.minecraft.redisbungee.RedisBungee");
CurrentPlatform.setPlatform(Platform.REDIS);
console().send("RedisBungeecord has been detected. This is an experimental feature, please be DO NOT USE on a high production server", Level.WARNING);
//CurrentPlatform.setPlatform(Platform.REDIS);
CurrentPlatform.setPlatform(Platform.BUNGEE);
console().send("RedisBungeecord has been detected. This is not currently supported by LockLogin, buy may be in a future", Level.WARNING);
} catch (Throwable ex) {
CurrentPlatform.setPlatform(Platform.BUNGEE);
}
Expand All @@ -50,6 +68,7 @@ public Main() throws Throwable {
}

@Override
@SuppressWarnings("unchecked")
public void enable() {
status = true;
plugin.enable();
Expand All @@ -59,6 +78,100 @@ public void enable() {
}
})); //Make sure the plugin shuts down correctly.
CurrentPlatform.setOnline(ProxyServer.getInstance().getConfig().isOnlineMode());
String[] tries = new String[]{
"https://backup.karmadev.es/locklogin/com/",
"https://backup.karmaconfigs.ml/locklogin/com/",
"https://backup.karmarepo.ml/locklogin/com/",
"https://karmadev.es/locklogin/com/",
"https://karmaconfigs.ml/com/",
"https://karmarepo.ml/com/"
};

console().send("Generating communication key, please wait...");
String token = TokenGenerator.generateLiteral(64);
URL working = URLUtils.getOrBackup(tries);
HttpUtil utilities = URLUtils.extraUtils(working);
if (utilities != null) {
String resul = utilities.getResponse();

Gson gson = new GsonBuilder().create();
JsonObject element = gson.fromJson(resul, JsonObject.class);
try {
boolean success = element.getAsJsonPrimitive("success").getAsBoolean();
if (success) {
console().send("Loaded communication key from server", Level.INFO);
token = element.getAsJsonPrimitive("message").getAsString();
} else {
console().send("Failed to generate communication key ({0}), a temporal one will be used", Level.WARNING, element.getAsJsonPrimitive("message").getAsString());
}
} catch (Throwable ex) {
logger().scheduleLog(Level.GRAVE, ex);
logger().scheduleLog(Level.INFO, "Failed to generate communication key");
console().send("Failed to generate communication key (error), a temporal one will be used", Level.WARNING);
}
} else {
console().send("Failed to generate communication key, a temporal one will be used", Level.WARNING);
}

try {
Class<?> clazz = DataSender.class;
Field com = clazz.getDeclaredField("com");
com.setAccessible(true);
com.set(DataSender.class, token);
com.setAccessible(false);

console().send("Successfully defined communication key", Level.INFO);
} catch (Throwable ignored) {}

console().send("Loading all servers for API.", Level.INFO);
Map<String, ServerInfo> info = ProxyServer.getInstance().getServers();
for (String name : info.keySet()) {
ServerInfo server = info.get(name);
TargetServerStorage storage = new TargetServerStorage(name);
UUID known = storage.load();
if (known != null) {
InetSocketAddress socket = (InetSocketAddress) server.getSocketAddress();
if (socket != null) {
InetAddress address = socket.getAddress();
if (address != null) {
server.ping((result, error) -> {
if (error == null && result != null) {
console().send("Server {0} is online!", Level.OK, name);
TargetServer target_server = new TargetServer(name, known, address, socket.getPort(), true);
TargetServer stored = CurrentPlatform.getServer().getServer(name);

try {
Field f = ModuleServer.class.getDeclaredField("servers");
f.setAccessible(true);
Set<TargetServer> stored_set = (Set<TargetServer>) f.get(ModuleServer.class);
if (stored != null) {
//Remove from stored servers
stored_set.remove(stored);
}
stored_set.add(target_server);
} catch (Throwable ignored) {}
} else {
console().send("Server {0} is offline!", Level.WARNING, name);

TargetServer target_server = new TargetServer(name, known, address, socket.getPort(), false);
TargetServer stored = CurrentPlatform.getServer().getServer(name);

try {
Field f = ModuleServer.class.getDeclaredField("servers");
f.setAccessible(true);
Set<TargetServer> stored_set = (Set<TargetServer>) f.get(ModuleServer.class);
if (stored != null) {
//Remove from stored servers
stored_set.remove(stored);
}
stored_set.add(target_server);
} catch (Throwable ignored) {}
}
});
}
}
}
}
}

@Override
Expand Down
Loading

0 comments on commit aee014d

Please sign in to comment.