SubServers-2/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketAuthorization.java

57 lines
1.8 KiB
Java
Raw Normal View History

package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
2017-01-31 04:04:37 +01:00
import net.ME1312.SubServers.Host.Network.SubDataClient;
2017-04-16 19:02:14 +02:00
import net.ME1312.SubServers.Host.ExHost;
import java.io.IOException;
2017-01-31 04:04:37 +01:00
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* Authorization Packet
*/
public final class PacketAuthorization implements PacketIn, PacketOut {
2017-04-16 19:02:14 +02:00
private ExHost host;
2017-01-31 04:04:37 +01:00
private Logger log = null;
2019-04-19 17:46:39 +02:00
private String password;
2019-04-19 17:46:39 +02:00
public PacketAuthorization(ExHost host, String password) {
if (Util.isNull(host)) throw new NullPointerException();
this.host = host;
2019-04-19 17:46:39 +02:00
this.password = password;
}
@Override
public YAMLSection generate() {
YAMLSection json = new YAMLSection();
2019-04-19 17:46:39 +02:00
json.set("password", password);
return json;
}
@Override
public void execute(YAMLSection data) {
try {
if (data.getInt("r") == 0) {
2019-01-15 00:28:18 +01:00
Util.isException(() -> Util.reflect(SubDataClient.class.getDeclaredMethod("sendPacket", NamedContainer.class), host.subdata, new NamedContainer<String, PacketOut>(null, new PacketLinkExHost(host))));
} else {
log.info.println("Could not authorize SubData connection: " + data.getRawString("m"));
host.subdata.destroy(0);
}
} catch (IOException e) {
log.error.println(e);
}
}
@Override
public Version getVersion() {
return new Version("2.11.0a");
}
}