Skip to content

Commit 81bb2a7

Browse files
LpsdStrixGpatrikjuvonen
authored
Implement messageType parameter to onClientChatMessage (#1020)
Co-authored-by: Nikita Obrekht <obrekht@gmail.com> Co-authored-by: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com>
1 parent f422891 commit 81bb2a7

File tree

8 files changed

+54
-19
lines changed

8 files changed

+54
-19
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,7 @@ void CClientGame::AddBuiltInEvents()
25512551
m_Events.AddEvent("onClientConsole", "text", NULL, false);
25522552

25532553
// Chat events
2554-
m_Events.AddEvent("onClientChatMessage", "test, r, g, b", NULL, false);
2554+
m_Events.AddEvent("onClientChatMessage", "text, r, g, b, messageType", NULL, false);
25552555

25562556
// Debug events
25572557
m_Events.AddEvent("onClientDebugMessage", "message, level, file, line", NULL, false);

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,14 +1336,15 @@ void CPacketHandler::Packet_ChatEcho(NetBitStreamInterface& bitStream)
13361336
unsigned char ucRed;
13371337
unsigned char ucGreen;
13381338
unsigned char ucBlue;
1339-
bool ucColorCoded;
1339+
bool bColorCoded;
13401340

13411341
CClientEntity* pClient = nullptr;
13421342

1343-
if (bitStream.Read(ucRed) && bitStream.Read(ucGreen) && bitStream.Read(ucBlue) && bitStream.ReadBit(ucColorCoded))
1343+
if (bitStream.Read(ucRed) && bitStream.Read(ucGreen) && bitStream.Read(ucBlue) && bitStream.ReadBit(bColorCoded))
13441344
{
13451345
// Read the client's ID
1346-
int iNumberOfBytesUsed;
1346+
int iNumberOfBytesUsed;
1347+
unsigned char ucMessageType;
13471348

13481349
if (bitStream.Can(eBitStreamVersion::OnClientChatMessage_PlayerSource))
13491350
{
@@ -1357,6 +1358,13 @@ void CPacketHandler::Packet_ChatEcho(NetBitStreamInterface& bitStream)
13571358
iNumberOfBytesUsed = bitStream.GetNumberOfBytesUsed() - 4;
13581359
}
13591360

1361+
if (bitStream.Can(eBitStreamVersion::OnClientChatMessage_MessageType))
1362+
{
1363+
// Get the message type and push the argument
1364+
bitStream.Read(ucMessageType);
1365+
iNumberOfBytesUsed -= 1;
1366+
}
1367+
13601368
// Valid length?
13611369
if (iNumberOfBytesUsed >= MIN_CHATECHO_LENGTH)
13621370
{
@@ -1381,11 +1389,16 @@ void CPacketHandler::Packet_ChatEcho(NetBitStreamInterface& bitStream)
13811389
Arguments.PushNumber(ucRed);
13821390
Arguments.PushNumber(ucGreen);
13831391
Arguments.PushNumber(ucBlue);
1384-
bool bCancelled = !pEntity->CallEvent("onClientChatMessage", Arguments, pEntity != pRootEntity);
1385-
if (!bCancelled)
1392+
1393+
if (bitStream.Can(eBitStreamVersion::OnClientChatMessage_MessageType))
1394+
{
1395+
Arguments.PushNumber(ucMessageType);
1396+
}
1397+
1398+
if (pEntity->CallEvent("onClientChatMessage", Arguments, pEntity != pRootEntity))
13861399
{
13871400
// Echo it
1388-
g_pCore->ChatEchoColor(szMessage, ucRed, ucGreen, ucBlue, ucColorCoded);
1401+
g_pCore->ChatEchoColor(szMessage, ucRed, ucGreen, ucBlue, bColorCoded);
13891402
}
13901403
}
13911404
delete[] szMessage;

Server/mods/deathmatch/logic/CConsoleCommands.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ bool CConsoleCommands::Say(CConsole* pConsole, const char* szInArguments, CClien
340340
// Send the chat message and player pointer to the script
341341
CLuaArguments Arguments;
342342
Arguments.PushString(szArguments);
343-
Arguments.PushNumber(0); // Normal chat
343+
Arguments.PushNumber(MESSAGE_TYPE_PLAYER); // Normal chat
344344
bool bContinue = static_cast<CPlayer*>(pClient)->CallEvent("onPlayerChat", Arguments);
345345
if (bContinue)
346346
{
@@ -475,7 +475,7 @@ bool CConsoleCommands::TeamSay(CConsole* pConsole, const char* szInArguments, CC
475475
// Send the chat message and player pointer to the script
476476
CLuaArguments Arguments;
477477
Arguments.PushString(szArguments);
478-
Arguments.PushNumber(2); // Team chat
478+
Arguments.PushNumber(MESSAGE_TYPE_TEAM); // Team chat
479479
bool bContinue = static_cast<CPlayer*>(pClient)->CallEvent("onPlayerChat", Arguments);
480480
if (bContinue)
481481
{
@@ -488,7 +488,7 @@ bool CConsoleCommands::TeamSay(CConsole* pConsole, const char* szInArguments, CC
488488
list<CPlayer*>::const_iterator iter = pTeam->PlayersBegin();
489489
for (; iter != pTeam->PlayersEnd(); iter++)
490490
{
491-
(*iter)->Send(CChatEchoPacket(strEcho, ucRed, ucGreen, ucBlue, true));
491+
(*iter)->Send(CChatEchoPacket(strEcho, ucRed, ucGreen, ucBlue, true, MESSAGE_TYPE_TEAM));
492492
}
493493
// Call onChatMessage if players chat message was delivered
494494
CLuaArguments Arguments2;
@@ -588,7 +588,7 @@ bool CConsoleCommands::Msg(CConsole* pConsole, const char* szInArguments, CClien
588588
if (bContinue)
589589
{
590590
// Send it to the player
591-
pPlayer->Send(CChatEchoPacket(strMessage, CHATCOLOR_INFO));
591+
pPlayer->Send(CChatEchoPacket(strMessage, CHATCOLOR_INFO, false, MESSAGE_TYPE_PRIVATE));
592592

593593
// Send a reponse to the player who sent it
594594
pEchoClient->SendEcho(SString("-> %s: %s", pPlayer->GetNick(), szMessage));
@@ -601,7 +601,7 @@ bool CConsoleCommands::Msg(CConsole* pConsole, const char* szInArguments, CClien
601601
CLogger::LogPrintf("CONSOLEMSG: %s to %s: %s\n", szNick, pPlayer->GetNick(), szMessage);
602602

603603
// Send it to the player
604-
pPlayer->Send(CChatEchoPacket(strMessage, CHATCOLOR_INFO));
604+
pPlayer->Send(CChatEchoPacket(strMessage, CHATCOLOR_INFO, false, MESSAGE_TYPE_PRIVATE));
605605
break;
606606
}
607607
case CClient::CLIENT_SCRIPT:
@@ -610,7 +610,7 @@ bool CConsoleCommands::Msg(CConsole* pConsole, const char* szInArguments, CClien
610610
CLogger::LogPrintf("SCRIPTMSG: %s to %s: %s\n", szNick, pPlayer->GetNick(), szMessage);
611611

612612
// Send it to the player
613-
pPlayer->Send(CChatEchoPacket(strMessage, CHATCOLOR_INFO));
613+
pPlayer->Send(CChatEchoPacket(strMessage, CHATCOLOR_INFO, false, MESSAGE_TYPE_PRIVATE));
614614
break;
615615
}
616616
default:
@@ -680,16 +680,16 @@ bool CConsoleCommands::Me(CConsole* pConsole, const char* szArguments, CClient*
680680
if (pClient->GetClientType() == CClient::CLIENT_PLAYER)
681681
{
682682
CLuaArguments Arguments;
683-
Arguments.PushString(szArguments); // text
684-
Arguments.PushNumber(1); // Me chat
683+
Arguments.PushString(szArguments); // text
684+
Arguments.PushNumber(MESSAGE_TYPE_ACTION); // Me chat
685685
bool bContinue = static_cast<CPlayer*>(pClient)->CallEvent("onPlayerChat", Arguments);
686686
if (bContinue)
687687
{
688688
// Log it in the console
689689
CLogger::LogPrintf("CHAT: %s\n", strEcho.c_str());
690690

691691
// Broadcast the message to all clients
692-
pConsole->GetPlayerManager()->BroadcastOnlyJoined(CChatEchoPacket(strEcho, CHATCOLOR_ME));
692+
pConsole->GetPlayerManager()->BroadcastOnlyJoined(CChatEchoPacket(strEcho, CHATCOLOR_ME, false, MESSAGE_TYPE_ACTION));
693693

694694
// Call onChatMessage if players chat message was delivered
695695
CPlayer* pPlayer = static_cast<CPlayer*>(pClient);

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ void CGame::AddBuiltInEvents()
14931493

14941494
// Player events
14951495
m_Events.AddEvent("onPlayerConnect", "player", NULL, false);
1496-
m_Events.AddEvent("onPlayerChat", "text", NULL, false);
1496+
m_Events.AddEvent("onPlayerChat", "text, messageType", NULL, false);
14971497
m_Events.AddEvent("onPlayerDamage", "attacker, weapon, bodypart, loss", NULL, false);
14981498
m_Events.AddEvent("onPlayerVehicleEnter", "vehicle, seat, jacked", NULL, false);
14991499
m_Events.AddEvent("onPlayerVehicleExit", "vehicle, reason, jacker", NULL, false);

Server/mods/deathmatch/logic/CPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ uint CPlayer::Send(const CPacket& Packet)
307307

308308
void CPlayer::SendEcho(const char* szEcho)
309309
{
310-
Send(CChatEchoPacket(szEcho, CHATCOLOR_MESSAGE));
310+
Send(CChatEchoPacket(szEcho, CHATCOLOR_MESSAGE, false, MESSAGE_TYPE_INTERNAL));
311311
}
312312

313313
void CPlayer::SendConsole(const char* szEcho)

Server/mods/deathmatch/logic/packets/CChatEchoPacket.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ bool CChatEchoPacket::Write(NetBitStreamInterface& BitStream) const
2929
size_t sizeMessage = m_strMessage.length();
3030
if (sizeMessage >= MIN_CHATECHO_LENGTH)
3131
{
32+
if (BitStream.Can(eBitStreamVersion::OnClientChatMessage_MessageType))
33+
{
34+
// Write the message type
35+
BitStream.Write(m_ucMessageType);
36+
}
37+
3238
// Write the string
3339
BitStream.Write(m_strMessage.c_str(), sizeMessage);
40+
3441
return true;
3542
}
3643

Server/mods/deathmatch/logic/packets/CChatEchoPacket.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,26 @@
2222
#define CHATCOLOR_ADMINSAY 131, 205, 241
2323
#define CHATCOLOR_CONSOLESAY 223, 149, 232
2424

25+
enum eMessageType
26+
{
27+
MESSAGE_TYPE_PLAYER,
28+
MESSAGE_TYPE_ACTION,
29+
MESSAGE_TYPE_TEAM,
30+
MESSAGE_TYPE_PRIVATE,
31+
MESSAGE_TYPE_INTERNAL
32+
};
33+
2534
class CChatEchoPacket final : public CPacket
2635
{
2736
public:
28-
CChatEchoPacket(SString strMessage, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, bool bColorCoded = false)
37+
CChatEchoPacket(SString strMessage, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, bool bColorCoded = false, unsigned char ucMessageType = MESSAGE_TYPE_PLAYER)
2938
{
3039
m_strMessage = strMessage;
3140
m_ucRed = ucRed;
3241
m_ucGreen = ucGreen;
3342
m_ucBlue = ucBlue;
3443
m_bColorCoded = bColorCoded;
44+
m_ucMessageType = ucMessageType;
3545
};
3646

3747
// Chat uses low priority channel to avoid getting queued behind large map downloads #6877
@@ -47,4 +57,5 @@ class CChatEchoPacket final : public CPacket
4757
unsigned char m_ucBlue;
4858
SString m_strMessage;
4959
bool m_bColorCoded;
60+
unsigned char m_ucMessageType;
5061
};

Shared/sdk/net/bitstream.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ enum class eBitStreamVersion : unsigned short
465465
// 2021-02-26 0x73
466466
VehicleBlowStateSupport,
467467

468+
// Implement messageType parameter to onClientChatMessage (#1020)
469+
// 2021-05-15 0x74
470+
OnClientChatMessage_MessageType,
471+
468472
// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
469473
// Make sure you only add things above this comment.
470474
Next,

0 commit comments

Comments
 (0)