mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
Fixed game crash on connection error
This commit is contained in:
parent
c89cfabb44
commit
5bda4dac7a
|
|
@ -327,49 +327,28 @@ shared_ptr<Packet> Packet::readPacket(DataInputStream *dis, bool isServer) // th
|
||||||
id = dis->read();
|
id = dis->read();
|
||||||
if (id == -1) return nullptr;
|
if (id == -1) return nullptr;
|
||||||
|
|
||||||
// Track last few good packets for diagnosing TCP desync
|
|
||||||
static thread_local int s_lastIds[8] = {};
|
|
||||||
static thread_local int s_lastIdPos = 0;
|
|
||||||
static thread_local int s_packetCount = 0;
|
|
||||||
|
|
||||||
if ((isServer && serverReceivedPackets.find(id) == serverReceivedPackets.end()) || (!isServer && clientReceivedPackets.find(id) == clientReceivedPackets.end()))
|
if ((isServer && serverReceivedPackets.find(id) == serverReceivedPackets.end()) || (!isServer && clientReceivedPackets.find(id) == clientReceivedPackets.end()))
|
||||||
{
|
{
|
||||||
app.DebugPrintf("*** BAD PACKET ID %d (0x%02X) isServer=%d totalPacketsRead=%d\n", id, id, isServer ? 1 : 0, s_packetCount);
|
// Squirrel - Fix crash on connection to server, show an in-game error instead
|
||||||
app.DebugPrintf("*** Last %d good packet IDs (oldest first): ", 8);
|
return packet;
|
||||||
for (int dbg = 0; dbg < 8; dbg++)
|
//app.DebugPrintf("Bad packet id %d\n", id);
|
||||||
{
|
//__debugbreak();
|
||||||
int idx = (s_lastIdPos + dbg) % 8;
|
//assert(false);
|
||||||
app.DebugPrintf("%d ", s_lastIds[idx]);
|
|
||||||
}
|
|
||||||
app.DebugPrintf("\n");
|
|
||||||
// Dump the next 32 bytes from the stream to see what follows
|
|
||||||
app.DebugPrintf("*** Next bytes in stream: ");
|
|
||||||
for (int dbg = 0; dbg < 32; dbg++)
|
|
||||||
{
|
|
||||||
int b = dis->read();
|
|
||||||
if (b == -1) { app.DebugPrintf("[EOS] "); break; }
|
|
||||||
app.DebugPrintf("%02X ", b);
|
|
||||||
}
|
|
||||||
app.DebugPrintf("\n");
|
|
||||||
__debugbreak();
|
|
||||||
assert(false);
|
|
||||||
// throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
|
// throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
packet = getPacket(id);
|
packet = getPacket(id);
|
||||||
if (packet == nullptr) assert(false);//throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
|
|
||||||
|
//if (packet == NULL) assert(false);//throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
|
||||||
s_lastIds[s_lastIdPos] = id;
|
if (packet == NULL) return packet;
|
||||||
s_lastIdPos = (s_lastIdPos + 1) % 8;
|
//app.DebugPrintf("%s reading packet %d\n", isServer ? "Server" : "Client", packet->getId());
|
||||||
s_packetCount++;
|
|
||||||
|
|
||||||
packet->read(dis);
|
packet->read(dis);
|
||||||
// }
|
// }
|
||||||
// catch (EOFException e)
|
// catch (EOFException e)
|
||||||
// {
|
// {
|
||||||
// // reached end of stream
|
// // reached end of stream
|
||||||
// OutputDebugString("Reached end of stream");
|
// OutputDebugString("Reached end of stream");
|
||||||
// return nullptr;
|
// return NULL;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// 4J - Don't bother tracking stats in a content package
|
// 4J - Don't bother tracking stats in a content package
|
||||||
|
|
@ -396,7 +375,7 @@ shared_ptr<Packet> Packet::readPacket(DataInputStream *dis, bool isServer) // th
|
||||||
|
|
||||||
void Packet::writePacket(shared_ptr<Packet> packet, DataOutputStream *dos) // throws IOException TODO 4J JEV, should this declare a throws?
|
void Packet::writePacket(shared_ptr<Packet> packet, DataOutputStream *dos) // throws IOException TODO 4J JEV, should this declare a throws?
|
||||||
{
|
{
|
||||||
//app.DebugPrintf("NET WRITE: packet id=%d (0x%02X) estSize=%d\n", packet->getId(), packet->getId(), packet->getEstimatedSize());
|
//app.DebugPrintf("Writing packet %d\n", packet->getId());
|
||||||
dos->write(packet->getId());
|
dos->write(packet->getId());
|
||||||
packet->write(dos);
|
packet->write(dos);
|
||||||
}
|
}
|
||||||
|
|
@ -410,7 +389,7 @@ void Packet::writeUtf(const wstring& value, DataOutputStream *dos) // throws IOE
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dos->writeShort(static_cast<short>(value.length()));
|
dos->writeShort((short)value.length());
|
||||||
dos->writeChars(value);
|
dos->writeChars(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -467,7 +446,7 @@ double Packet::PacketStatistics::getAverageSize()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return static_cast<double>(totalSize) / count;
|
return (double) totalSize / count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Packet::PacketStatistics::getTotalSize()
|
int Packet::PacketStatistics::getTotalSize()
|
||||||
|
|
@ -536,7 +515,7 @@ shared_ptr<ItemInstance> Packet::readItem(DataInputStream *dis)
|
||||||
int count = dis->readByte();
|
int count = dis->readByte();
|
||||||
int damage = dis->readShort();
|
int damage = dis->readShort();
|
||||||
|
|
||||||
item = std::make_shared<ItemInstance>(id, count, damage);
|
item = shared_ptr<ItemInstance>( new ItemInstance(id, count, damage) );
|
||||||
// 4J Stu - Always read/write the tag
|
// 4J Stu - Always read/write the tag
|
||||||
//if (Item.items[id].canBeDepleted() || Item.items[id].shouldOverrideMultiplayerNBT())
|
//if (Item.items[id].canBeDepleted() || Item.items[id].shouldOverrideMultiplayerNBT())
|
||||||
{
|
{
|
||||||
|
|
@ -549,7 +528,7 @@ shared_ptr<ItemInstance> Packet::readItem(DataInputStream *dis)
|
||||||
|
|
||||||
void Packet::writeItem(shared_ptr<ItemInstance> item, DataOutputStream *dos)
|
void Packet::writeItem(shared_ptr<ItemInstance> item, DataOutputStream *dos)
|
||||||
{
|
{
|
||||||
if (item == nullptr)
|
if (item == NULL)
|
||||||
{
|
{
|
||||||
dos->writeShort(-1);
|
dos->writeShort(-1);
|
||||||
}
|
}
|
||||||
|
|
@ -569,7 +548,7 @@ void Packet::writeItem(shared_ptr<ItemInstance> item, DataOutputStream *dos)
|
||||||
CompoundTag *Packet::readNbt(DataInputStream *dis)
|
CompoundTag *Packet::readNbt(DataInputStream *dis)
|
||||||
{
|
{
|
||||||
int size = dis->readShort();
|
int size = dis->readShort();
|
||||||
if (size < 0) return nullptr;
|
if (size < 0) return NULL;
|
||||||
byteArray buff(size);
|
byteArray buff(size);
|
||||||
dis->readFully(buff);
|
dis->readFully(buff);
|
||||||
CompoundTag *result = (CompoundTag *) NbtIo::decompress(buff);
|
CompoundTag *result = (CompoundTag *) NbtIo::decompress(buff);
|
||||||
|
|
@ -579,14 +558,14 @@ CompoundTag *Packet::readNbt(DataInputStream *dis)
|
||||||
|
|
||||||
void Packet::writeNbt(CompoundTag *tag, DataOutputStream *dos)
|
void Packet::writeNbt(CompoundTag *tag, DataOutputStream *dos)
|
||||||
{
|
{
|
||||||
if (tag == nullptr)
|
if (tag == NULL)
|
||||||
{
|
{
|
||||||
dos->writeShort(-1);
|
dos->writeShort(-1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
byteArray buff = NbtIo::compress(tag);
|
byteArray buff = NbtIo::compress(tag);
|
||||||
dos->writeShort(static_cast<short>(buff.length));
|
dos->writeShort((short) buff.length);
|
||||||
dos->write(buff);
|
dos->write(buff);
|
||||||
delete [] buff.data;
|
delete [] buff.data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue