gdle/Source/ChatMsgs.cpp

202 lines
4.7 KiB
C++
Raw Permalink Normal View History

2018-03-29 17:01:57 -04:00
2019-07-07 20:56:15 +00:00
#include <StdAfx.h>
2018-03-29 17:01:57 -04:00
#include "WeenieObject.h"
#include "Monster.h"
#include "Player.h"
//Network access.
#include "Client.h"
#include "BinaryWriter.h"
#include "ChatMsgs.h"
#define MESSAGE_BEGIN(x) BinaryWriter *x = new BinaryWriter
#define MESSAGE_END(x) return x
2019-07-07 20:56:15 +00:00
BinaryWriter *LocalChat(const char *text, const char *name, uint32_t sourceID, LogTextType ltt)
2018-03-29 17:01:57 -04:00
{
MESSAGE_BEGIN(LocalChat);
2019-07-07 20:56:15 +00:00
LocalChat->Write<uint32_t>(0x02BB);
2018-03-29 17:01:57 -04:00
LocalChat->WriteString(text);
LocalChat->WriteString(name);
2019-07-07 20:56:15 +00:00
LocalChat->Write<uint32_t>(sourceID);
2018-03-29 17:01:57 -04:00
LocalChat->Write<int>(ltt);
MESSAGE_END(LocalChat);
}
2019-07-07 20:56:15 +00:00
BinaryWriter *EmoteChat(const char* szText, const char* szName, uint32_t dwSourceID)
2018-03-29 17:01:57 -04:00
{
MESSAGE_BEGIN(EmoteChat);
2019-07-07 20:56:15 +00:00
EmoteChat->Write<uint32_t>(0x1E0);
EmoteChat->Write<uint32_t>(dwSourceID);
2018-03-29 17:01:57 -04:00
EmoteChat->WriteString(szName);
EmoteChat->WriteString(szText);
MESSAGE_END(EmoteChat);
}
//0x5719F5DB
2019-07-07 20:56:15 +00:00
BinaryWriter *DirectChat(const char* szText, const char* szName, uint32_t dwSourceID, uint32_t dwDestID, int32_t lColor)
2018-03-29 17:01:57 -04:00
{
//Fake-tells: bit 10 must be set.
//Envoy: bit 21 must be set.
//Example:
2019-07-07 20:56:15 +00:00
//Step 1. Take a uint32_t of any value. (entirely random if you wish, it doesn't matter.)
//Step 2. Remove bits 10 and 21 from that uint32_t.
2018-03-29 17:01:57 -04:00
//Step 3. If FAKE-tell: set bit 10 (other don't.) These tells will never be drawn to the chat.
//Step 4. If Envoy: set bit 21 (otherwise don't.) These tells will be prefixed with '+Envoy'.
2019-07-07 20:56:15 +00:00
//Step 5. Now take the uint32_t and XOR it against the source player's GUID.
2018-03-29 17:01:57 -04:00
//The final result will be the magic number.
#define RANDOM_LONG() ((rand() << 30) | (rand()<<15) | rand()) // RAND_MAX=7fff
BOOL bFakeTell = FALSE;
BOOL bEnvoy = FALSE;
2019-07-07 20:56:15 +00:00
uint32_t dwMagicValue;
2018-03-29 17:01:57 -04:00
dwMagicValue = RANDOM_LONG(); //Step 1
dwMagicValue &= ~((1 << 10) | (1 << 21)); //Step 2
if (bFakeTell) //Step 3
dwMagicValue |= 1 << 10;
if (bEnvoy) //Step 4
dwMagicValue |= 1 << 21;
dwMagicValue ^= dwSourceID; //Step 5
MESSAGE_BEGIN(DirectChat);
2019-07-07 20:56:15 +00:00
DirectChat->Write<uint32_t>(0x2BD);
2018-03-29 17:01:57 -04:00
DirectChat->WriteString(szText);
DirectChat->WriteString(szName);
2019-07-07 20:56:15 +00:00
DirectChat->Write<uint32_t>(dwSourceID);
DirectChat->Write<uint32_t>(dwDestID);
DirectChat->Write<int32_t>(lColor);
DirectChat->Write<uint32_t>(dwMagicValue);
2018-03-29 17:01:57 -04:00
MESSAGE_END(DirectChat);
}
2019-07-07 20:56:15 +00:00
BinaryWriter *ActionChat(const char* szText, const char* szName, uint32_t dwSourceID)
2018-03-29 17:01:57 -04:00
{
MESSAGE_BEGIN(EmoteChat);
2019-07-07 20:56:15 +00:00
EmoteChat->Write<uint32_t>(0x1E2);
EmoteChat->Write<uint32_t>(dwSourceID);
2018-03-29 17:01:57 -04:00
EmoteChat->WriteString(szName);
EmoteChat->WriteString(szText);
MESSAGE_END(EmoteChat);
}
2019-07-07 20:56:15 +00:00
BinaryWriter *ServerText(const char *szText, int32_t lColor)
2018-03-29 17:01:57 -04:00
{
MESSAGE_BEGIN(ServerText);
2019-07-07 20:56:15 +00:00
ServerText->Write<uint32_t>(0xF7E0);
2018-03-29 17:01:57 -04:00
ServerText->WriteString(szText);
2019-07-07 20:56:15 +00:00
ServerText->Write<int32_t>(lColor);
2018-03-29 17:01:57 -04:00
MESSAGE_END(ServerText);
}
BinaryWriter *OverlayText(const char *szText)
{
MESSAGE_BEGIN(OverlayText);
2019-07-07 20:56:15 +00:00
OverlayText->Write<uint32_t>(0x02EB);
OverlayText->WriteString(szText);
MESSAGE_END(OverlayText);
}
2019-07-07 20:56:15 +00:00
BinaryWriter *ServerBroadcast(const char *szSource, const char *szText, int32_t lColor)
2018-03-29 17:01:57 -04:00
{
// Using string class to prevent from static buffer collisions.
std::string strBroadcast;
strBroadcast = "Broadcast from ";
strBroadcast += szSource;
strBroadcast += "> ";
strBroadcast += szText;
MESSAGE_END(ServerText(strBroadcast.c_str(), lColor));
}
2019-07-07 20:56:15 +00:00
BinaryWriter *ChannelChat(uint32_t dwChannel, const char* szName, const char* szText)
2018-03-29 17:01:57 -04:00
{
MESSAGE_BEGIN(ChannelChat);
2019-07-07 20:56:15 +00:00
ChannelChat->Write<uint32_t>(0x147);
ChannelChat->Write<uint32_t>(dwChannel);
2018-03-29 17:01:57 -04:00
ChannelChat->WriteString(szName);
ChannelChat->WriteString(szText);
MESSAGE_END(ChannelChat);
}
2019-07-07 20:56:15 +00:00
BinaryWriter *TurbineInboundAck(uint32_t serial)
2018-03-29 17:01:57 -04:00
{
MESSAGE_BEGIN(msg);
2019-07-07 20:56:15 +00:00
msg->Write<uint32_t>(0xF7DE);
msg->Write<uint32_t>(0x30); // Size
msg->Write<uint32_t>(0x05); // Type 05 - ACK
msg->Write<uint32_t>(0x02); // ??
msg->Write<uint32_t>(0x01); // ??
msg->Write<uint32_t>(0xB0045); // bitfield?
msg->Write<uint32_t>(0x01);
msg->Write<uint32_t>(0xB0045); // bitfield?
msg->Write<uint32_t>(0x00);
msg->Write<uint32_t>(0x10); // Payload size
msg->Write<uint32_t>(serial); // serial
msg->Write<uint32_t>(0x02);
msg->Write<uint32_t>(0x02);
msg->Write<uint32_t>(0x00);
2018-03-29 17:01:57 -04:00
MESSAGE_END(msg);
}
std::string FilterBadChatCharacters(const char *str)
{
std::string newMessage;
const char *ptr = str;
while (*ptr)
{
char c = *ptr;
if (c < 0x20 || c > 0x7F)
{
newMessage += " ";
}
else
{
newMessage += c;
}
ptr++;
}
return newMessage;
}
2019-07-07 20:56:15 +00:00
extern std::u16string FilterBadChatCharacters(const std::u16string &str)
{
std::u16string newMessage;
std::u16string::const_iterator ptr = str.begin();
while (ptr != str.end())
{
const char16_t c = *ptr;
if (c < 0x20 || c > 0x7F)
{
newMessage += u" ";
}
else
{
newMessage += c;
}
ptr++;
}
return newMessage;
}