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

69 lines
2.2 KiB
Java
Raw Normal View History

package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
2019-05-13 05:28:27 +02:00
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
2019-05-14 04:02:38 +02:00
import net.ME1312.SubData.Client.Library.DebugUtil;
2019-05-13 05:28:27 +02:00
import net.ME1312.SubData.Client.Protocol.Initial.InitialPacket;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
import net.ME1312.SubData.Client.SubDataClient;
2019-10-19 00:24:58 +02:00
import net.ME1312.SubData.Client.SubDataSender;
2017-04-16 19:02:14 +02:00
import net.ME1312.SubServers.Host.ExHost;
2019-05-13 05:28:27 +02:00
import java.util.logging.Logger;
/**
* Link Host Packet
*/
2019-05-13 05:28:27 +02:00
public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
2017-04-16 19:02:14 +02:00
private ExHost host;
2019-05-13 05:28:27 +02:00
private int channel;
/**
2019-05-13 05:28:27 +02:00
* New PacketLinkHost (In)
*
* @param host SubServers.Host
*/
2017-04-16 19:02:14 +02:00
public PacketLinkExHost(ExHost host) {
if (Util.isNull(host)) throw new NullPointerException();
this.host = host;
2019-05-13 05:28:27 +02:00
}
/**
* New PacketLinkHost (Out)
*
* @param host SubServers.Host
*/
public PacketLinkExHost(ExHost host, int channel) {
if (Util.isNull(host)) throw new NullPointerException();
this.host = host;
this.channel = channel;
}
@Override
2019-10-19 00:24:58 +02:00
public ObjectMap<Integer> send(SubDataSender client) {
2019-05-13 05:28:27 +02:00
ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, host.api.getName());
data.set(0x0001, channel);
return data;
}
@Override
2019-10-19 00:24:58 +02:00
public void receive(SubDataSender client, ObjectMap<Integer> data) throws Throwable {
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.getConnection()), null);
2019-05-13 05:28:27 +02:00
if (data.getInt(0x0001) == 0) {
2019-10-19 00:24:58 +02:00
setReady(client.getConnection(), true);
2017-04-01 22:31:57 +02:00
} else {
2019-05-14 04:02:38 +02:00
log.severe("Could not link name with host" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
DebugUtil.logException(new IllegalStateException(), log);
GalaxiEngine.getInstance().stop();
}
}
@Override
2019-05-13 05:28:27 +02:00
public int version() {
return 0x0001;
}
}