1
0

Initial BungeeCord support.

Ref.: #1392
This commit is contained in:
madmaxoft 2014-09-17 09:38:06 +02:00
parent 96f45a48d4
commit 3406957f1b
4 changed files with 43 additions and 1 deletions

View File

@ -100,6 +100,15 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd
m_IsEncrypted(false), m_IsEncrypted(false),
m_LastSentDimension(dimNotSet) m_LastSentDimension(dimNotSet)
{ {
// BungeeCord handling:
// If BC is setup with ip_forward == true, it sends additional data in the login packet's ServerAddress field:
// hostname\00ip-address\00uuid\00profile-properties-as-json
AStringVector Params;
if (SplitZeroTerminatedStrings(a_ServerAddress, Params) && (Params.size() == 4))
{
m_ServerAddress = Params[0];
}
// Create the comm log file, if so requested: // Create the comm log file, if so requested:
if (g_ShouldLogCommIn || g_ShouldLogCommOut) if (g_ShouldLogCommIn || g_ShouldLogCommOut)
{ {

View File

@ -27,7 +27,7 @@
cProtocolRecognizer::cProtocolRecognizer(cClientHandle * a_Client) : cProtocolRecognizer::cProtocolRecognizer(cClientHandle * a_Client) :
super(a_Client), super(a_Client),
m_Protocol(NULL), m_Protocol(NULL),
m_Buffer(512) m_Buffer(8192) // We need a larger buffer to support BungeeCord - it sends one huge packet at the start
{ {
} }

View File

@ -869,3 +869,31 @@ void SetBEInt(char * a_Mem, Int32 a_Value)
bool SplitZeroTerminatedStrings(const AString & a_Strings, AStringVector & a_Output)
{
a_Output.clear();
size_t size = a_Strings.size();
size_t start = 0;
bool res = false;
for (size_t i = 0; i < size; i++)
{
if (a_Strings[i] == 0)
{
a_Output.push_back(a_Strings.substr(start, i - start));
start = i + 1;
res = true;
}
}
if (start < size)
{
a_Output.push_back(a_Strings.substr(start, size - start));
res = true;
}
return res;
}

View File

@ -99,6 +99,11 @@ extern int GetBEInt(const char * a_Mem);
/// Writes four bytes to the specified memory location so that they interpret as BigEndian int /// Writes four bytes to the specified memory location so that they interpret as BigEndian int
extern void SetBEInt(char * a_Mem, Int32 a_Value); extern void SetBEInt(char * a_Mem, Int32 a_Value);
/** Splits a string that has embedded \0 characters, on those characters.
a_Output is first cleared and then each separate string is pushed back into a_Output.
Returns true if there are at least two strings in a_Output (there was at least one \0 separator). */
extern bool SplitZeroTerminatedStrings(const AString & a_Strings, AStringVector & a_Output);
/// Parses any integer type. Checks bounds and returns errors out of band. /// Parses any integer type. Checks bounds and returns errors out of band.
template <class T> template <class T>
bool StringToInteger(const AString & a_str, T & a_Num) bool StringToInteger(const AString & a_str, T & a_Num)