Update client auto-linking

This commit is contained in:
ME1312 2019-01-26 21:04:53 -05:00
parent 975a12f3b6
commit 024dde444c
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
13 changed files with 40 additions and 24 deletions

View File

@ -22,6 +22,12 @@ public class PacketLinkServer implements PacketIn, PacketOut {
private String message;
private String name;
private static class ServerLinkException extends IllegalStateException {
public ServerLinkException(String message) {
super(message);
}
}
/**
* New PacketLinkServer (In)
*
@ -62,12 +68,16 @@ public class PacketLinkServer implements PacketIn, PacketOut {
Server server;
if (data.contains("name") && servers.keySet().contains(data.getRawString("name").toLowerCase())) {
link(client, servers.get(data.getRawString("name").toLowerCase()));
} else if ((server = searchIP(new InetSocketAddress(client.getAddress().getAddress(), data.getInt("port")))) != null) {
} else if ((server = search(new InetSocketAddress(client.getAddress().getAddress(), data.getInt("port")))) != null) {
link(client, server);
} else if (data.contains("name")) {
} else {
throw new ServerLinkException("There is no server with address: " + client.getAddress().getAddress().getHostAddress() + ':' + data.getInt("port"));
}
} catch (ServerLinkException e) {
if (data.contains("name")) {
client.sendPacket(new PacketLinkServer(null, 2, "There is no server with name: " + data.getRawString("name")));
} else {
client.sendPacket(new PacketLinkServer(null, 2, "There is no server with address: " + client.getAddress().getAddress().getHostAddress() + ':' + data.getInt("port")));
client.sendPacket(new PacketLinkServer(null, 2, e.getMessage()));
}
} catch (Exception e) {
client.sendPacket(new PacketLinkServer(null, 1, e.getClass().getCanonicalName() + ": " + e.getMessage()));
@ -86,11 +96,11 @@ public class PacketLinkServer implements PacketIn, PacketOut {
}
}
private Server searchIP(InetSocketAddress address) {
private Server search(InetSocketAddress address) throws ServerLinkException {
Server server = null;
for (Server s : plugin.api.getServers().values()) {
if (s.getAddress().equals(address)) {
if (server != null) throw new IllegalStateException("Multiple servers match address: " + address.getAddress().getHostAddress() + ':' + address.getPort());
if (server != null) throw new ServerLinkException("Multiple servers match address: " + address.getAddress().getHostAddress() + ':' + address.getPort());
server = s;
}
}

View File

@ -58,7 +58,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
public final SubAPI api = new SubAPI(this);
public SubDataServer subdata = null;
public SubServer sudo = null;
public static final Version version = Version.fromString("2.13.2c");
public static final Version version = Version.fromString("2.13.2d");
public Proxy redis = null;
public boolean canSudo = false;

View File

@ -1,13 +1,19 @@
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
import net.ME1312.SubServers.Client.Bukkit.Library.Callback;
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.*;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.EventExecutor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@ -15,7 +21,7 @@ import java.lang.reflect.Method;
/**
* Link Server Packet
*/
public class PacketLinkServer implements PacketIn, PacketOut {
public class PacketLinkServer implements PacketIn, PacketOut, Listener {
private SubPlugin plugin;
/**
@ -46,15 +52,17 @@ public class PacketLinkServer implements PacketIn, PacketOut {
Util.reflect(SubDataClient.class.getDeclaredMethod("init"), plugin.subdata);
} catch (Exception e) {}
} else {
Bukkit.getLogger().info("SubData > Could not link name with server: " + data.getRawString("m"));
try {
if (data.getInt("r") == 2) {
if (!plugin.config.get().getSection("Settings").getSection("SubData").contains("Name")) {
plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "undefined");
plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "");
plugin.config.save();
}
if (plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Name").length() <= 0)
Bukkit.getLogger().info("SubData > Use the server \"Name\" option to override auto-linking");
}
} catch (Exception e) {}
Bukkit.getLogger().info("SubData > Could not link name with server: " + data.getRawString("m"));
plugin.onDisable();
}
}

View File

@ -55,7 +55,7 @@ public final class SubDataClient {
if (Util.isNull(plugin, address, port)) throw new NullPointerException();
socket = new NamedContainer<>(false, new Socket(address, port));
this.plugin = plugin;
this.name = name;
this.name = (name == null || name.length() > 0)?name:null;
this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream());
this.queue = new LinkedList<NamedContainer<String, PacketOut>>();
this.cipher = (cipher != null)?cipher:new Cipher() {

View File

@ -153,7 +153,6 @@ public final class SubPlugin extends JavaPlugin {
} catch (IOException e) {
e.printStackTrace();
}
setEnabled(false);
}
/**

View File

@ -1,6 +1,6 @@
name: 'SubServers-Client-Bukkit'
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
version: '2.13.2c'
version: '2.13.2d'
authors: [ME1312]
softdepend: [Vault, TitleManager]
website: 'https://github.com/ME1312/SubServers-2'
@ -25,9 +25,6 @@ permissions:
subservers.command:
description: 'Grants Access to the SubServers Command'
default: op
subservers.reload:
description: 'Grants Access to Reload SubServers.Client'
default: op
subservers.host.*:
description: 'Grants Access to SubServers Host Actions'
default: op
@ -56,7 +53,7 @@ permissions:
default: op
children:
subservers.server.teleport-others:
description: 'Grants Acces to Teleport Others to a Server'
description: 'Grants Access to Teleport Others to a Server'
default: op
subservers.server.teleport.*:
description: 'Grants Access to Teleport to a Server'

View File

@ -48,15 +48,17 @@ public class PacketLinkServer implements PacketIn, PacketOut {
Util.reflect(SubDataClient.class.getDeclaredMethod("init"), plugin.subdata);
} catch (Exception e) {}
} else {
log.info("Could not link name with server: " + data.getRawString("m"));
try {
if (data.getInt("r") == 2) {
if (!plugin.config.get().getSection("Settings").getSection("SubData").contains("Name")) {
plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "undefined");
plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "");
plugin.config.save();
}
if (plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Name").length() <= 0)
log.info("Use the server \"Name\" option to override auto-linking");
}
} catch (Exception e) {}
log.info("Could not link name with server: " + data.getRawString("m"));
plugin.disable(null);
}
}

View File

@ -58,7 +58,7 @@ public final class SubDataClient {
if (Util.isNull(plugin, address, port)) throw new NullPointerException();
socket = new NamedContainer<>(false, new Socket(address, port));
this.plugin = plugin;
this.name = name;
this.name = (name == null || name.length() > 0)?name:null;
this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream());
this.queue = new LinkedList<NamedContainer<String, PacketOut>>();
this.cipher = (cipher != null)?cipher:new Cipher() {

View File

@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
/**
* SubServers Client Plugin Class
*/
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.13.2c", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.13.2d", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
public final class SubPlugin {
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
public YAMLConfig config;

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>19w03d</version>
<version>19w04c</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -36,7 +36,7 @@ import java.util.jar.Manifest;
/**
* SubServers.Host Main Class
*/
@Plugin(name = "SubServers.Host", version = "2.13.2c", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
@Plugin(name = "SubServers.Host", version = "2.13.2d", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
public final class ExHost {
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
public HashMap<String, SubCreator.ServerTemplate> templates = new HashMap<String, SubCreator.ServerTemplate>();

View File

@ -63,7 +63,7 @@ public final class SubDataClient {
if (Util.isNull(plugin, address, port)) throw new NullPointerException();
socket = new NamedContainer<>(false, new Socket(address, port));
this.plugin = plugin;
this.name = name;
this.name = (name == null || name.length() > 0)?name:null;
this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream());
this.cipher = (cipher != null)?cipher:new Cipher() {
@Override

View File

@ -44,7 +44,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
public boolean redis = false;
public final SubAPI api = new SubAPI(this);
public SubDataClient subdata = null;
public static final Version version = Version.fromString("2.13.2c");
public static final Version version = Version.fromString("2.13.2d");
public final boolean isPatched;
public long lastReload = -1;