2018-09-15 19:44:48 +00:00
|
|
|
package net.minecraftforge.fml.network;
|
|
|
|
|
|
|
|
import net.minecraft.nbt.INBTBase;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
import net.minecraft.nbt.NBTTagString;
|
|
|
|
import net.minecraft.network.PacketBuffer;
|
2018-09-17 00:54:03 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-09-15 19:44:48 +00:00
|
|
|
import net.minecraftforge.fml.ModList;
|
|
|
|
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
2018-09-17 00:54:03 +00:00
|
|
|
import net.minecraftforge.registries.ForgeRegistry;
|
|
|
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
2018-09-15 19:44:48 +00:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2018-09-17 00:54:03 +00:00
|
|
|
public class FMLHandshakeMessages
|
2018-09-15 19:44:48 +00:00
|
|
|
{
|
2018-09-17 00:54:03 +00:00
|
|
|
static class LoginIndexedMessage {
|
|
|
|
private int loginIndex;
|
2018-09-15 19:44:48 +00:00
|
|
|
|
2018-09-17 00:54:03 +00:00
|
|
|
void setLoginIndex(final int loginIndex) {
|
|
|
|
this.loginIndex = loginIndex;
|
|
|
|
}
|
2018-09-15 19:44:48 +00:00
|
|
|
|
2018-09-17 00:54:03 +00:00
|
|
|
int getLoginIndex() {
|
|
|
|
return loginIndex;
|
|
|
|
}
|
|
|
|
}
|
2018-09-15 19:44:48 +00:00
|
|
|
/**
|
|
|
|
* Server to client "list of mods". Always first handshake message.
|
|
|
|
*/
|
2018-09-17 00:54:03 +00:00
|
|
|
public static class S2CModList extends LoginIndexedMessage
|
2018-09-15 19:44:48 +00:00
|
|
|
{
|
|
|
|
private NBTTagList channels;
|
|
|
|
private List<String> modList;
|
|
|
|
|
2018-09-17 00:54:03 +00:00
|
|
|
public S2CModList() {
|
2018-09-15 19:44:48 +00:00
|
|
|
this.modList = ModList.get().getMods().stream().map(ModInfo::getModId).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
S2CModList(NBTTagCompound nbtTagCompound)
|
|
|
|
{
|
|
|
|
this.modList = nbtTagCompound.getTagList("modlist", 8).stream().map(INBTBase::getString).collect(Collectors.toList());
|
|
|
|
this.channels = nbtTagCompound.getTagList("channels", 10);
|
|
|
|
}
|
|
|
|
|
2018-09-17 00:54:03 +00:00
|
|
|
public static S2CModList decode(PacketBuffer packetBuffer)
|
2018-09-15 19:44:48 +00:00
|
|
|
{
|
|
|
|
final NBTTagCompound nbtTagCompound = packetBuffer.readCompoundTag();
|
|
|
|
return new S2CModList(nbtTagCompound);
|
|
|
|
}
|
|
|
|
|
2018-09-17 00:54:03 +00:00
|
|
|
public void encode(PacketBuffer packetBuffer)
|
2018-09-15 19:44:48 +00:00
|
|
|
{
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
tag.setTag("modlist",modList.stream().map(NBTTagString::new).collect(Collectors.toCollection(NBTTagList::new)));
|
|
|
|
tag.setTag("channels", NetworkRegistry.buildChannelVersions());
|
|
|
|
packetBuffer.writeCompoundTag(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getModList() {
|
|
|
|
return String.join(",", modList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NBTTagList getChannels() {
|
|
|
|
return this.channels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 00:54:03 +00:00
|
|
|
public static class C2SModListReply extends S2CModList
|
2018-09-15 19:44:48 +00:00
|
|
|
{
|
2018-09-17 00:54:03 +00:00
|
|
|
public C2SModListReply() {
|
2018-09-15 19:44:48 +00:00
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
C2SModListReply(final NBTTagCompound buffer) {
|
|
|
|
super(buffer);
|
|
|
|
}
|
|
|
|
|
2018-09-17 00:54:03 +00:00
|
|
|
public static C2SModListReply decode(PacketBuffer buffer)
|
2018-09-15 19:44:48 +00:00
|
|
|
{
|
|
|
|
return new C2SModListReply(buffer.readCompoundTag());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void encode(PacketBuffer buffer)
|
|
|
|
{
|
|
|
|
super.encode(buffer);
|
|
|
|
}
|
|
|
|
}
|
2018-09-17 00:54:03 +00:00
|
|
|
|
|
|
|
public static class C2SAcknowledge extends LoginIndexedMessage {
|
|
|
|
public void encode(PacketBuffer buf) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static C2SAcknowledge decode(PacketBuffer buf) {
|
|
|
|
return new C2SAcknowledge();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class S2CRegistry extends LoginIndexedMessage {
|
|
|
|
|
|
|
|
public S2CRegistry(final ResourceLocation key, final ForgeRegistry<? extends IForgeRegistryEntry<?>> registry) {
|
|
|
|
}
|
|
|
|
|
|
|
|
S2CRegistry() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void encode(final PacketBuffer buffer) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static S2CRegistry decode(final PacketBuffer buffer) {
|
|
|
|
return new S2CRegistry();
|
|
|
|
}
|
|
|
|
}
|
2018-09-15 19:44:48 +00:00
|
|
|
}
|