Fix connection to forge 1.7.10 servers.

This includes making sure plugin channels have their packet.
Also, it fixes a mistake in #92, where brand info doesn't send
length in 1.7.10 (same channel issue).  Finally, there's only 1
registry sent to the client in 1.7.10.
This commit is contained in:
Pokechu22 2015-10-24 21:17:28 -07:00
parent ad38154f8f
commit 7c8e856392

View file

@ -212,6 +212,12 @@ namespace MinecraftClient.Protocol.Handlers
break; break;
case 0x3F: //Plugin message. case 0x3F: //Plugin message.
String channel = readNextString(ref packetData); String channel = readNextString(ref packetData);
if (protocolversion < MC18Version)
{
// 1.7 and lower prefix plugin channel packets with the length.
// We can skip it, though.
readNextShort(ref packetData);
}
if (forgeInfo != null) if (forgeInfo != null)
{ {
if (channel == "FML|HS") if (channel == "FML|HS")
@ -277,6 +283,21 @@ namespace MinecraftClient.Protocol.Handlers
if (discriminator != FMLHandshakeDiscriminator.RegistryData) if (discriminator != FMLHandshakeDiscriminator.RegistryData)
return false; return false;
if (protocolversion < MC18Version)
{
// 1.7.10 and below have one registry
// with blocks and items.
int registrySize = readNextVarInt(ref packetData);
ConsoleIO.WriteLineFormatted("§8Received registry " +
"with " + registrySize + " entries");
fmlHandshakeState = FMLHandshakeClientState.PENDINGCOMPLETE;
}
else
{
// 1.8+ has more than one registry.
bool hasNextRegistry = readNextBool(ref packetData); bool hasNextRegistry = readNextBool(ref packetData);
string registryName = readNextString(ref packetData); string registryName = readNextString(ref packetData);
int registrySize = readNextVarInt(ref packetData); int registrySize = readNextVarInt(ref packetData);
@ -288,6 +309,7 @@ namespace MinecraftClient.Protocol.Handlers
{ {
fmlHandshakeState = FMLHandshakeClientState.PENDINGCOMPLETE; fmlHandshakeState = FMLHandshakeClientState.PENDINGCOMPLETE;
} }
}
return false; return false;
case FMLHandshakeClientState.PENDINGCOMPLETE: case FMLHandshakeClientState.PENDINGCOMPLETE:
@ -627,9 +649,21 @@ namespace MinecraftClient.Protocol.Handlers
/// <param name="data">packet Data</param> /// <param name="data">packet Data</param>
private void SendPluginChannelPacket(string channel, byte[] data) private void SendPluginChannelPacket(string channel, byte[] data)
{
// In 1.7, length needs to be included.
// In 1.8, it must not be.
if (protocolversion < MC18Version)
{
byte[] length = BitConverter.GetBytes((short)data.Length);
Array.Reverse(length);
SendPacket(0x17, concatBytes(getString(channel), length, data));
}
else
{ {
SendPacket(0x17, concatBytes(getString(channel), data)); SendPacket(0x17, concatBytes(getString(channel), data));
} }
}
/// <summary> /// <summary>
/// Send a packet to the server, compression and encryption will be handled automatically /// Send a packet to the server, compression and encryption will be handled automatically
@ -829,11 +863,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; return false;
try try
{ {
byte[] channel = Encoding.UTF8.GetBytes("MC|Brand"); SendPluginChannelPacket("MC|Brand", getString(brandInfo));
byte[] channelLen = getVarInt(channel.Length);
byte[] brand = Encoding.UTF8.GetBytes(brandInfo);
byte[] brandLen = getVarInt(brand.Length);
SendPacket(0x17, concatBytes(channelLen, channel, brandLen, brand));
return true; return true;
} }
catch (SocketException) { return false; } catch (SocketException) { return false; }