Finish forge hand shaking before enabling the chat prompt.

This commit is contained in:
Pokechu22 2015-10-25 12:20:38 -07:00
parent fb87de1ff5
commit 3a19de82ae

View file

@ -772,6 +772,15 @@ namespace MinecraftClient.Protocol.Handlers
{ {
ConsoleIO.WriteLineFormatted("§8Server is in offline mode."); ConsoleIO.WriteLineFormatted("§8Server is in offline mode.");
login_phase = false; login_phase = false;
if (forgeInfo != null) {
// Do the forge handshake.
if (!CompleteForgeHandshake())
{
return false;
}
}
StartUpdating(); StartUpdating();
return true; //No need to check session or start encryption return true; //No need to check session or start encryption
} }
@ -779,6 +788,33 @@ namespace MinecraftClient.Protocol.Handlers
} }
} }
/// <summary>
/// Completes the Minecraft Forge handshake.
/// </summary>
/// <returns>Whether the handshake was successful.</returns>
private bool CompleteForgeHandshake()
{
int packetID = -1;
byte[] packetData = new byte[0];
while (fmlHandshakeState != FMLHandshakeClientState.DONE)
{
readNextPacket(ref packetID, ref packetData);
if (packetID == 0x40) // Disconect
{
handler.OnConnectionLost(ChatBot.DisconnectReason.LoginRejected, ChatParser.ParseText(readNextString(ref packetData)));
return false;
}
else
{
handlePacket(packetID, packetData);
}
}
return true;
}
/// <summary> /// <summary>
/// Start network encryption. Automatically called by Login() if the server requests encryption. /// Start network encryption. Automatically called by Login() if the server requests encryption.
/// </summary> /// </summary>
@ -826,6 +862,16 @@ namespace MinecraftClient.Protocol.Handlers
else if (packetID == 0x02) //Login successful else if (packetID == 0x02) //Login successful
{ {
login_phase = false; login_phase = false;
if (forgeInfo != null)
{
// Do the forge handshake.
if (!CompleteForgeHandshake())
{
return false;
}
}
StartUpdating(); StartUpdating();
return true; return true;
} }