mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-05-25 09:47:24 +00:00
chore: format Minecraft.World
This commit is contained in:
@@ -6,82 +6,74 @@
|
||||
#include "ChatPacket.h"
|
||||
|
||||
// longest allowed string is "<" + name + "> " + message
|
||||
const unsigned int ChatPacket::MAX_LENGTH = SharedConstants::maxChatLength + Player::MAX_NAME_LENGTH + 3;
|
||||
const unsigned int ChatPacket::MAX_LENGTH =
|
||||
SharedConstants::maxChatLength + Player::MAX_NAME_LENGTH + 3;
|
||||
|
||||
ChatPacket::ChatPacket()
|
||||
{
|
||||
m_messageType = e_ChatCustom;
|
||||
}
|
||||
ChatPacket::ChatPacket() { m_messageType = e_ChatCustom; }
|
||||
|
||||
// Old chat packet constructor, adds message, custom data and additional message to arg vectors
|
||||
ChatPacket::ChatPacket(const std::wstring& message, EChatPacketMessage type /*= e_ChatCustom*/, int customData /*= -1*/, const std::wstring& additionalMessage /*= L""*/)
|
||||
{
|
||||
m_messageType = type;
|
||||
if (customData != -1) m_intArgs.push_back(customData);
|
||||
if (message != L"" || additionalMessage != L"") m_stringArgs.push_back(message);
|
||||
if (additionalMessage != L"") m_stringArgs.push_back(additionalMessage);
|
||||
// Old chat packet constructor, adds message, custom data and additional message
|
||||
// to arg vectors
|
||||
ChatPacket::ChatPacket(const std::wstring& message,
|
||||
EChatPacketMessage type /*= e_ChatCustom*/,
|
||||
int customData /*= -1*/,
|
||||
const std::wstring& additionalMessage /*= L""*/) {
|
||||
m_messageType = type;
|
||||
if (customData != -1) m_intArgs.push_back(customData);
|
||||
if (message != L"" || additionalMessage != L"")
|
||||
m_stringArgs.push_back(message);
|
||||
if (additionalMessage != L"") m_stringArgs.push_back(additionalMessage);
|
||||
}
|
||||
|
||||
// Read chat packet (throws IOException)
|
||||
void ChatPacket::read(DataInputStream *dis)
|
||||
{
|
||||
m_messageType = (EChatPacketMessage) dis->readShort();
|
||||
void ChatPacket::read(DataInputStream* dis) {
|
||||
m_messageType = (EChatPacketMessage)dis->readShort();
|
||||
|
||||
short packedCounts = dis->readShort();
|
||||
int stringCount = (packedCounts >> 4) & 0xF;
|
||||
int intCount = (packedCounts >> 0) & 0xF;
|
||||
|
||||
for(int i = 0; i < stringCount; i++)
|
||||
{
|
||||
m_stringArgs.push_back(readUtf(dis, MAX_LENGTH));
|
||||
}
|
||||
short packedCounts = dis->readShort();
|
||||
int stringCount = (packedCounts >> 4) & 0xF;
|
||||
int intCount = (packedCounts >> 0) & 0xF;
|
||||
|
||||
for(int i = 0; i < intCount; i++)
|
||||
{
|
||||
m_intArgs.push_back(dis->readInt());
|
||||
}
|
||||
for (int i = 0; i < stringCount; i++) {
|
||||
m_stringArgs.push_back(readUtf(dis, MAX_LENGTH));
|
||||
}
|
||||
|
||||
for (int i = 0; i < intCount; i++) {
|
||||
m_intArgs.push_back(dis->readInt());
|
||||
}
|
||||
}
|
||||
|
||||
// Write chat packet (throws IOException)
|
||||
void ChatPacket::write(DataOutputStream *dos)
|
||||
{
|
||||
dos->writeShort(m_messageType);
|
||||
void ChatPacket::write(DataOutputStream* dos) {
|
||||
dos->writeShort(m_messageType);
|
||||
|
||||
short packedCounts = 0;
|
||||
packedCounts |= (m_stringArgs.size() & 0xF) << 4;
|
||||
packedCounts |= (m_intArgs.size() & 0xF) << 0;
|
||||
short packedCounts = 0;
|
||||
packedCounts |= (m_stringArgs.size() & 0xF) << 4;
|
||||
packedCounts |= (m_intArgs.size() & 0xF) << 0;
|
||||
|
||||
dos->writeShort(packedCounts);
|
||||
dos->writeShort(packedCounts);
|
||||
|
||||
for(int i = 0; i < m_stringArgs.size(); i++)
|
||||
{
|
||||
writeUtf(m_stringArgs[i], dos);
|
||||
}
|
||||
for (int i = 0; i < m_stringArgs.size(); i++) {
|
||||
writeUtf(m_stringArgs[i], dos);
|
||||
}
|
||||
|
||||
for(int i = 0; i < m_intArgs.size(); i++)
|
||||
{
|
||||
dos->writeInt(m_intArgs[i]);
|
||||
}
|
||||
for (int i = 0; i < m_intArgs.size(); i++) {
|
||||
dos->writeInt(m_intArgs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle chat packet
|
||||
void ChatPacket::handle(PacketListener *listener)
|
||||
{
|
||||
listener->handleChat(shared_from_this());
|
||||
void ChatPacket::handle(PacketListener* listener) {
|
||||
listener->handleChat(shared_from_this());
|
||||
}
|
||||
|
||||
// Get an estimated size of the packet
|
||||
int ChatPacket::getEstimatedSize()
|
||||
{
|
||||
int stringsSize = 0;
|
||||
for(int i = 0; i < m_stringArgs.size(); i++)
|
||||
{
|
||||
stringsSize += m_stringArgs[i].length();
|
||||
}
|
||||
// Get an estimated size of the packet
|
||||
int ChatPacket::getEstimatedSize() {
|
||||
int stringsSize = 0;
|
||||
for (int i = 0; i < m_stringArgs.size(); i++) {
|
||||
stringsSize += m_stringArgs[i].length();
|
||||
}
|
||||
|
||||
return
|
||||
sizeof(EChatPacketMessage) + // message type
|
||||
sizeof(short) + // packed arg counts
|
||||
stringsSize + // string args
|
||||
(m_intArgs.size() * sizeof(int)); // int args
|
||||
return sizeof(EChatPacketMessage) + // message type
|
||||
sizeof(short) + // packed arg counts
|
||||
stringsSize + // string args
|
||||
(m_intArgs.size() * sizeof(int)); // int args
|
||||
}
|
||||
Reference in New Issue
Block a user