bool cByteBuffer::WriteBEUTF16String16(const AString & a_Value) { CHECK_THREAD; CheckValid(); PUTBYTES(2); AString UTF16BE; UTF8ToRawBEUTF16(a_Value.data(), a_Value.size(), UTF16BE); WriteBEShort((short)(UTF16BE.size() / 2)); PUTBYTES(UTF16BE.size()); WriteBuf(UTF16BE.data(), UTF16BE.size()); return true; }
void cProtocolRecognizer::SendDisconnect(const AString & a_Reason) { if (m_Protocol != nullptr) { 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(reinterpret_cast<const char *>(&Packet), 1); // WriteByte() auto UTF16 = UTF8ToRawBEUTF16(a_Reason); static const u_short Size = htons(static_cast<u_short>(UTF16.size())); SendData(reinterpret_cast<const char *>(&Size), 2); // WriteShort() SendData(reinterpret_cast<const char *>(UTF16.data()), UTF16.size() * sizeof(char16_t)); // WriteString() } }
void cProtocolRecognizer::SendDisconnect(const AString & a_Reason) { if (m_Protocol != nullptr) { 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 u_short Size = htons((u_short)(UTF16.size() / 2)); SendData((const char *)&Size, 2); // WriteShort() SendData(UTF16.data(), UTF16.size()); // WriteString() } }