diff --git a/bot/gamemodes.cpp b/bot/gamemodes.cpp index d9483a4..8a0a2be 100644 --- a/bot/gamemodes.cpp +++ b/bot/gamemodes.cpp @@ -233,19 +233,19 @@ int CGameMode::OnNPCExitVehicle() //---------------------------------------------------------------------------------- // forward OnClientMessage(color, text[]); -int CGameMode::OnClientMessage(cell color, char *szText) +int CGameMode::OnClientMessage(cell color, unsigned char * szText) { int idx; cell ret = 1; - int orig_strlen = strlen(szText) + 1; + int orig_strlen = strlen((char*)szText) + 1; if (!amx_FindPublic(&m_amx, "OnClientMessage", &idx)) { cell amx_addr, *phys_addr; - amx_PushString(&m_amx, &amx_addr, &phys_addr, szText, 0, 0); + amx_PushString(&m_amx, &amx_addr, &phys_addr, (char*)szText, 0, 0); amx_Push(&m_amx, color); amx_Exec(&m_amx, &ret, idx); - amx_GetString(szText, phys_addr, 0, orig_strlen); + amx_GetString((char*)szText, phys_addr, 0, orig_strlen); amx_Release(&m_amx, amx_addr); } return (int)ret; diff --git a/bot/gamemodes.h b/bot/gamemodes.h index 9c6221b..5facae2 100644 --- a/bot/gamemodes.h +++ b/bot/gamemodes.h @@ -32,7 +32,7 @@ public: int OnNPCSpawn(); int OnNPCEnterVehicle(cell vehicleid, cell seatid); int OnNPCExitVehicle(); - int OnClientMessage(cell color, char *szText); + int OnClientMessage(cell color, unsigned char * szText); int OnPlayerDeath(cell playerid); int OnPlayerText(cell playerid, unsigned char * szText); int OnPlayerStreamIn(cell playerid); diff --git a/bot/net/netgame.h b/bot/net/netgame.h index b4e81f9..35d988d 100644 --- a/bot/net/netgame.h +++ b/bot/net/netgame.h @@ -73,6 +73,7 @@ public: CPlayerPool * GetPlayerPool() { return m_pPlayerPool; }; RakClientInterface * GetRakClient() { return m_pRakClient; }; + CGameMode * GetBotMode() { return m_pGameMode; }; void Init(PCHAR szHostOrIp,int iPort,PCHAR szPlayerName,PCHAR szPass,PCHAR szNpcMode); void Process(); diff --git a/bot/net/netrpc.cpp b/bot/net/netrpc.cpp index 517363e..2bc18a4 100644 --- a/bot/net/netrpc.cpp +++ b/bot/net/netrpc.cpp @@ -1,6 +1,7 @@ #include "../main.h" using namespace RakNet; +extern CNetGame* pNetGame; #define REJECT_REASON_BAD_VERSION 1 #define REJECT_REASON_BAD_NICKNAME 2 @@ -51,7 +52,21 @@ void ConnectionRejected(RPCParameters *rpcParams) void ClientMessage(RPCParameters *rpcParams) { - // TODO: ClientMessage + PCHAR Data = reinterpret_cast(rpcParams->input); + int iBitLength = rpcParams->numberOfBitsOfData; + RakNet::BitStream bsData(Data,(iBitLength/8)+1,false); + DWORD dwStrLen; + DWORD dwColor; + + bsData.Read(dwColor); + bsData.Read(dwStrLen); + unsigned char* szMsg = (unsigned char *)malloc(dwStrLen+1); + bsData.Read((char *)szMsg, dwStrLen); + szMsg[dwStrLen] = 0; + + if(pNetGame->GetBotMode()) pNetGame->GetBotMode()->OnClientMessage(dwColor, szMsg); + + free(szMsg); } void WorldTime(RPCParameters *rpcParams) {}