2016-12-24 05:55:17 +01:00
|
|
|
package net.ME1312.SubServers.Bungee.Network.Packet;
|
2016-12-15 22:04:39 +01:00
|
|
|
|
2019-04-18 16:02:09 +02:00
|
|
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
|
|
|
import net.ME1312.Galaxi.Library.Util;
|
|
|
|
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
|
|
|
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
2020-11-16 21:34:59 +01:00
|
|
|
import net.ME1312.SubData.Server.SubDataClient;
|
|
|
|
import net.ME1312.SubServers.Bungee.Host.Host;
|
2019-08-30 21:44:54 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.SubProxy;
|
2017-11-22 22:58:33 +01:00
|
|
|
|
2020-06-12 07:45:49 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2019-04-18 16:02:09 +02:00
|
|
|
import java.util.UUID;
|
2018-08-09 20:54:56 +02:00
|
|
|
|
2017-01-07 20:06:54 +01:00
|
|
|
/**
|
|
|
|
* Download Host Info Packet
|
|
|
|
*/
|
2019-04-18 16:02:09 +02:00
|
|
|
public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
2019-08-30 21:44:54 +02:00
|
|
|
private SubProxy plugin;
|
2020-06-12 07:45:49 +02:00
|
|
|
private String[] hosts;
|
2019-04-18 16:02:09 +02:00
|
|
|
private UUID tracker;
|
2016-12-15 22:04:39 +01:00
|
|
|
|
2017-01-07 20:06:54 +01:00
|
|
|
/**
|
|
|
|
* New PacketDownloadHostInfo (In)
|
|
|
|
*
|
|
|
|
* @param plugin SubPlugin
|
|
|
|
*/
|
2019-08-30 21:44:54 +02:00
|
|
|
public PacketDownloadHostInfo(SubProxy plugin) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(plugin);
|
2016-12-15 22:04:39 +01:00
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
2017-01-07 20:06:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* New PacketDownloadHostInfo (Out)
|
|
|
|
*
|
|
|
|
* @param plugin SubPlugin
|
2020-06-12 07:45:49 +02:00
|
|
|
* @param hosts Hosts (or null for all)
|
2019-04-18 16:02:09 +02:00
|
|
|
* @param tracker Receiver ID
|
2017-01-07 20:06:54 +01:00
|
|
|
*/
|
2020-06-12 07:45:49 +02:00
|
|
|
public PacketDownloadHostInfo(SubProxy plugin, List<String> hosts, UUID tracker) {
|
2021-10-24 06:14:07 +02:00
|
|
|
Util.nullpo(plugin);
|
2016-12-15 22:04:39 +01:00
|
|
|
this.plugin = plugin;
|
2019-04-18 16:02:09 +02:00
|
|
|
this.tracker = tracker;
|
2020-06-12 07:45:49 +02:00
|
|
|
|
|
|
|
if (hosts != null) {
|
|
|
|
this.hosts = new String[hosts.size()];
|
|
|
|
for (int i = 0; i < this.hosts.length; ++i) this.hosts[i] = hosts.get(i).toLowerCase();
|
|
|
|
Arrays.sort(this.hosts);
|
|
|
|
}
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-18 16:02:09 +02:00
|
|
|
public ObjectMap<Integer> send(SubDataClient client) {
|
|
|
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
|
|
|
if (tracker != null) data.set(0x0000, tracker);
|
2016-12-15 22:04:39 +01:00
|
|
|
|
2019-04-18 16:02:09 +02:00
|
|
|
ObjectMap<String> hosts = new ObjectMap<String>();
|
2018-08-09 20:54:56 +02:00
|
|
|
for (Host host : plugin.api.getHosts().values()) {
|
2020-06-12 07:45:49 +02:00
|
|
|
if (this.hosts == null || this.hosts.length <= 0 || Arrays.binarySearch(this.hosts, host.getName().toLowerCase()) >= 0) {
|
2019-04-18 16:02:09 +02:00
|
|
|
hosts.set(host.getName(), host.forSubData());
|
2018-08-09 20:54:56 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-18 16:02:09 +02:00
|
|
|
data.set(0x0001, hosts);
|
2018-04-15 03:53:51 +02:00
|
|
|
return data;
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-18 16:02:09 +02:00
|
|
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
2021-10-24 20:53:15 +02:00
|
|
|
client.sendPacket(new PacketDownloadHostInfo(plugin, (data.contains(0x0001))?data.getStringList(0x0001):null, (data.contains(0x0000))?data.getUUID(0x0000):null));
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
}
|