mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
77 lines
2 KiB
C++
77 lines
2 KiB
C++
#include "stdafx.h"
|
|
#include "InputOutputStream.h"
|
|
#include "PacketListener.h"
|
|
#include "AuthResultPacket.h"
|
|
|
|
AuthResultPacket::AuthResultPacket()
|
|
{
|
|
success = false;
|
|
}
|
|
|
|
AuthResultPacket::AuthResultPacket(bool success, const wstring& assignedUuid, const wstring& assignedUsername,
|
|
const wstring& errorMessage, const wstring& skinKey,
|
|
std::vector<uint8_t> skinData)
|
|
{
|
|
this->success = success;
|
|
this->assignedUuid = assignedUuid;
|
|
this->assignedUsername = assignedUsername;
|
|
this->errorMessage = errorMessage;
|
|
this->skinKey = skinKey;
|
|
this->skinData = std::move(skinData);
|
|
}
|
|
|
|
void AuthResultPacket::read(DataInputStream *dis)
|
|
{
|
|
success = dis->readBoolean();
|
|
assignedUuid = readUtf(dis, 64);
|
|
assignedUsername = readUtf(dis, 64);
|
|
errorMessage = readUtf(dis, 256);
|
|
skinKey = readUtf(dis, 256);
|
|
|
|
// read the skin blob (length + bytes)
|
|
// cap at 32kb, a real skin png is like 4kb tops
|
|
int skinSize = dis->readInt();
|
|
if (skinSize > 0 && skinSize <= 32768)
|
|
{
|
|
skinData.resize(static_cast<size_t>(skinSize));
|
|
for (int i = 0; i < skinSize; i++)
|
|
skinData[i] = dis->readByte();
|
|
}
|
|
else
|
|
{
|
|
skinData.clear();
|
|
// eat the bytes anyway so the stream doesnt get fucked up
|
|
if (skinSize > 0)
|
|
{
|
|
for (int i = 0; i < skinSize; i++)
|
|
dis->readByte();
|
|
}
|
|
}
|
|
}
|
|
|
|
void AuthResultPacket::write(DataOutputStream *dos)
|
|
{
|
|
dos->writeBoolean(success);
|
|
writeUtf(assignedUuid, dos);
|
|
writeUtf(assignedUsername, dos);
|
|
writeUtf(errorMessage, dos);
|
|
writeUtf(skinKey, dos);
|
|
|
|
int skinSize = static_cast<int>(skinData.size());
|
|
dos->writeInt(skinSize);
|
|
for (int i = 0; i < skinSize; i++)
|
|
dos->writeByte(skinData[i]);
|
|
}
|
|
|
|
void AuthResultPacket::handle(PacketListener *listener)
|
|
{
|
|
listener->handleAuthResult(shared_from_this());
|
|
}
|
|
|
|
int AuthResultPacket::getEstimatedSize()
|
|
{
|
|
return static_cast<int>(sizeof(bool) + 4 * sizeof(short) +
|
|
(assignedUuid.length() + assignedUsername.length() + errorMessage.length() + skinKey.length()) * sizeof(wchar_t)
|
|
+ sizeof(int) + skinData.size());
|
|
}
|