1
0
This commit is contained in:
Tiger Wang
2014-09-27 22:13:37 +01:00
parent 7b7225e50b
commit 1f8ee70d55
5 changed files with 27 additions and 32 deletions

View File

@@ -190,8 +190,21 @@ void cProtocolRecognizer::SendDestroyEntity(const cEntity & a_Entity)
void cProtocolRecognizer::SendDisconnect(const AString & a_Reason)
{
ASSERT(m_Protocol != NULL);
m_Protocol->SendDisconnect(a_Reason);
if (m_Protocol != NULL)
{
m_Protocol->SendDisconnect(a_Reason);
}
else
{
// This is used when the client sends a server-ping, respond with the default packet:
static const int Packet = 0xff; // PACKET_DISCONNECT
SendData((const char *)&Packet, 1); // WriteByte()
AString & UTF16 = UTF8ToRawBEUTF16(a_Reason.c_str(), a_Reason.length());
static const short Size = htons((short)(UTF16.size() / 2));
SendData((const char *)&Size, 2); // WriteShort()
SendData(UTF16.data(), UTF16.size()); // WriteString()
}
}