mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#include "stdafx.h"
|
|
#include "InputOutputStream.h"
|
|
#include "PacketListener.h"
|
|
#include "AuthResponsePacket.h"
|
|
|
|
AuthResponsePacket::AuthResponsePacket()
|
|
{
|
|
}
|
|
|
|
AuthResponsePacket::AuthResponsePacket(const wstring& chosenScheme, const wstring& mojangUuid, const wstring& username)
|
|
{
|
|
this->chosenScheme = chosenScheme;
|
|
this->mojangUuid = mojangUuid;
|
|
this->username = username;
|
|
}
|
|
|
|
void AuthResponsePacket::read(DataInputStream *dis)
|
|
{
|
|
chosenScheme = readUtf(dis, 32);
|
|
mojangUuid = readUtf(dis, 64);
|
|
username = readUtf(dis, 16);
|
|
|
|
if (chosenScheme != L"mojang" && chosenScheme != L"offline" && chosenScheme != L"elyby")
|
|
chosenScheme = L"";
|
|
|
|
// only allow normal mc username characters
|
|
for (wchar_t c : username)
|
|
{
|
|
if (!((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z') ||
|
|
(c >= L'0' && c <= L'9') || c == L'_'))
|
|
{
|
|
username = L"";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void AuthResponsePacket::write(DataOutputStream *dos)
|
|
{
|
|
writeUtf(chosenScheme, dos);
|
|
writeUtf(mojangUuid, dos);
|
|
writeUtf(username, dos);
|
|
}
|
|
|
|
void AuthResponsePacket::handle(PacketListener *listener)
|
|
{
|
|
listener->handleAuthResponse(shared_from_this());
|
|
}
|
|
|
|
int AuthResponsePacket::getEstimatedSize()
|
|
{
|
|
return static_cast<int>(3 * sizeof(short) +
|
|
(chosenScheme.length() + mojangUuid.length() + username.length()) * sizeof(wchar_t));
|
|
}
|