Skip to content

Commit 8c70955

Browse files
author
Marek Kulik
authored
Add player element for onClientChatMessage (#138)
1 parent 87b67d1 commit 8c70955

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,21 +1268,36 @@ void CPacketHandler::Packet_ChatEcho ( NetBitStreamInterface& bitStream )
12681268
// unsigned char (1) - green
12691269
// unsigned char (1) - blue
12701270
// unsigned char (1) - color-coded
1271+
// ElementID (2) - client (if typed by a player)
12711272
// unsigned char (x) - message
12721273

12731274
// Read out the color
12741275
unsigned char ucRed;
12751276
unsigned char ucGreen;
12761277
unsigned char ucBlue;
12771278
bool ucColorCoded;
1279+
1280+
CClientEntity * pClient = nullptr;
1281+
12781282
if ( bitStream.Read ( ucRed ) &&
12791283
bitStream.Read ( ucGreen ) &&
12801284
bitStream.Read ( ucBlue ) &&
12811285
bitStream.ReadBit ( ucColorCoded ) )
12821286
{
1283-
// Valid length?
1287+
// Read the client's ID
1288+
int iNumberOfBytesUsed;
1289+
1290+
if ( bitStream.Version() >= 0x06B ) {
1291+
ElementID ClientID;
1292+
bitStream.Read( ClientID );
1293+
pClient = ( ClientID != INVALID_ELEMENT_ID ) ? CElementIDs::GetElement( ClientID ) : nullptr;
1294+
iNumberOfBytesUsed = bitStream.GetNumberOfBytesUsed() - 6;
1295+
}
1296+
else {
1297+
iNumberOfBytesUsed = bitStream.GetNumberOfBytesUsed() - 4;
1298+
}
12841299

1285-
int iNumberOfBytesUsed = bitStream.GetNumberOfBytesUsed () - 4;
1300+
// Valid length?
12861301
if ( iNumberOfBytesUsed >= MIN_CHATECHO_LENGTH )
12871302
{
12881303
// Read the message into a buffer
@@ -1295,13 +1310,17 @@ void CPacketHandler::Packet_ChatEcho ( NetBitStreamInterface& bitStream )
12951310
// Strip it for bad characters
12961311
StripControlCodes ( szMessage, ' ' );
12971312

1313+
// Determine the event source entity
1314+
CClientEntity * pRootEntity = g_pClientGame->GetRootEntity();
1315+
CClientEntity * pEntity = pClient ? pClient : pRootEntity;
1316+
12981317
// Call an event
12991318
CLuaArguments Arguments;
13001319
Arguments.PushString ( szMessage );
13011320
Arguments.PushNumber ( ucRed );
13021321
Arguments.PushNumber ( ucGreen );
13031322
Arguments.PushNumber ( ucBlue );
1304-
bool bCancelled = !g_pClientGame->GetRootEntity()->CallEvent ( "onClientChatMessage", Arguments, false );
1323+
bool bCancelled = !pEntity->CallEvent ( "onClientChatMessage", Arguments, pEntity != pRootEntity );
13051324
if ( !bCancelled )
13061325
{
13071326
// Echo it

Client/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
7878
#define _CLIENT_NET_MODULE_VERSION 0x0A7 // (0x000 - 0xfff) Lvl9 wizards only
7979
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
80-
#define MTA_DM_BITSTREAM_VERSION 0x06A // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).
80+
#define MTA_DM_BITSTREAM_VERSION 0x06B // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).
8181

8282
// To avoid user confusion, make sure the ASE version matches only if communication is possible
8383
#if defined(MTA_DM_CONNECT_TO_PUBLIC)

Server/mods/deathmatch/logic/CConsoleCommands.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ bool CConsoleCommands::Say ( CConsole* pConsole, const char* szInArguments, CCli
361361
}
362362

363363
// Broadcast the message to all clients
364-
pConsole->GetPlayerManager ()->BroadcastOnlyJoined ( CChatEchoPacket ( strEcho, ucR, ucG, ucB, true ) );
364+
auto ChatEchoPacket = CChatEchoPacket ( strEcho, ucR, ucG, ucB, true );
365+
ChatEchoPacket.SetSourceElement( pPlayer );
366+
pConsole->GetPlayerManager ()->BroadcastOnlyJoined ( ChatEchoPacket );
365367

366368
// Call onChatMessage if players chat message was delivered
367369
CLuaArguments Arguments2;
368370
Arguments2.PushString ( szArguments );
369371
Arguments2.PushElement ( pPlayer );
370-
static_cast < CPlayer* > ( pClient )->CallEvent ( "onChatMessage", Arguments2 );
372+
pPlayer->CallEvent ( "onChatMessage", Arguments2 );
371373
}
372374

373375
break;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ bool CChatEchoPacket::Write ( NetBitStreamInterface& BitStream ) const
2020
BitStream.Write ( m_ucBlue );
2121
BitStream.WriteBit ( m_bColorCoded );
2222

23+
// Write the client's ID
24+
if ( BitStream.Version() >= 0x06B ) {
25+
BitStream.Write ( GetSourceElement() ? GetSourceElement()->GetID() : INVALID_ELEMENT_ID );
26+
}
27+
2328
// Too short?
2429
size_t sizeMessage = m_strMessage.length();
2530
if ( sizeMessage >= MIN_CHATECHO_LENGTH )

Server/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
8282
#define _SERVER_NET_MODULE_VERSION 0x0A7 // (0x000 - 0xfff) Lvl9 wizards only
8383
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
84-
#define MTA_DM_BITSTREAM_VERSION 0x06A // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).
84+
#define MTA_DM_BITSTREAM_VERSION 0x06B // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).
8585

8686
// To avoid user confusion, make sure the ASE version matches only if communication is possible
8787
#if defined(MTA_DM_CONNECT_FROM_PUBLIC)

0 commit comments

Comments
 (0)