1
0

Packets now parse themselves from a cByteBuffer object (1st part of packeting rewrite, http://forum.mc-server.org/showthread.php?tid=524 )

git-svn-id: http://mc-server.googlecode.com/svn/trunk@744 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2012-08-17 10:18:07 +00:00
parent 33ca4d5003
commit 70a4ca5bc1
57 changed files with 684 additions and 352 deletions

View File

@@ -233,3 +233,49 @@ AStringList GetDirectoryContents(const char * a_Directory)
// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8)
{
a_UTF8.clear();
a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size
for (int i = 0; i < a_NumShorts; i++)
{
int c = ntohs(*(a_RawData + i));
if (c < 0x80)
{
a_UTF8.push_back((char)c);
}
else if (c < 0x800)
{
a_UTF8.push_back((char)(192 + c / 64));
a_UTF8.push_back((char)(128 + c % 64));
}
else if (c - 0xd800u < 0x800)
{
// Error, silently drop
}
else if (c < 0x10000)
{
a_UTF8.push_back((char)(224 + c / 4096));
a_UTF8.push_back((char)(128 + c / 64 % 64));
a_UTF8.push_back((char)(128 + c % 64));
}
else if (c < 0x110000)
{
a_UTF8.push_back((char)(240 + c / 262144));
a_UTF8.push_back((char)(128 + c / 4096 % 64));
a_UTF8.push_back((char)(128 + c / 64 % 64));
a_UTF8.push_back((char)(128 + c % 64));
}
else
{
// Error, silently drop
}
}
return a_UTF8;
}