// *************************************************************** // Function: ChatProcessing.cpp // *************************************************************** #include "Instance.h" #include "Main.h" void CommandProcessing(char* pCommandString, bool adminConsole, void* pLir, Player* pPlayer); #define CHAT_MESSAGE_ERROR "Message rejected." //************************************ // Name: WriteGeneralChat // // This function outputs chat text described by the arguments. // // Parameters: // pBuffer - The UNICODE text buffer // numUniChars - How many UNICODE characters are in the buffer. // color - What color the text should be. See packet documentation for colors. // localId - The local ID of the player who is sending the chat. Only required if the speaking entity has a name. // networkId - The networkId of the client this packet needs to go to. // // Return: // - none //************************************ void Instance::WriteGeneralChat(unsigned char* pBuffer, long numUniChars, char color, unsigned long localId, short networkId) { if (pBuffer==NULL) { return; } CompiledPacket pck(true); //Add the message packet pck.AddShort(ServerOpcode(40)); //Calculate the number of packets we must append float tpf=numUniChars / 119.0; float tr=fmod(tpf, (float)1.0); if (tr>0.0) { tpf += 1.0; } int numPackets=(int)tpf; unsigned char* pBufPointer=pBuffer; unsigned short length=0; //Loop for each packet for (int i=0; i1){addLength--;} //Calculate the length of the data we are adding length=numUniChars; if (numUniChars>119){length=119;} //Add our data and the extra bytes pck.AddShort(length+addLength); pck.AddLong(0x01070108); pck.Add(pBufPointer, length*2, false); //Update our pointers so we don't under/over read the buffer pBufPointer+=length*2; numUniChars-=length; } else { //Calculate how much length we must add. 01070108 is 4 bytes and 0100 is 2 0100 is always at the end of the text so it may not be here int addLength=0; if (i==numPackets-1){addLength++;} //Calculate the length of our data length=numUniChars; if (numUniChars>119){length=119;} //Add the chat packet header and our data pck.AddShort(ServerOpcode(40)); pck.AddShort(length+addLength); pck.Add(pBufPointer, length*2, false); //Update pointers pBufPointer+=length*2; numUniChars-=length; } } //This must always be after the last UNICODE character pck.AddShort(0x0001); //Add the message owner packet if (localId>0) { pck.AddShort(ServerOpcode(41)); pck.AddShort((unsigned short)localId); pck.AddByte(color); } //If the message has no owner else { pck.AddShort(ServerOpcode(50)); pck.AddShort(0); pck.AddByte(color); } NetMessage s; s.networkId=networkId; s.pData=pck.GetString(&s.dataSize); gpGameServer->SendData(&s); } //************************************ // Name: ChatMessageOk // // Checks that the chat message does not contain any invalid characters. // // Parameters: // pMess - UNICODE text message // length - Length of UNICODE string // // Return: // true - Chat message is ok // false - Chat message is invalid //************************************ bool ChatMessageOk(char* pMess, short length) { //Check for non-ASCII characters for (int i=1; iControllerIs(AGENT_PLAYER)) { Player* pPlayer=(Player*)pAgent->ControllerIs(AGENT_PLAYER); pAg_instance->Broadcast((char*)message, channel, pPlayer->GetLocalId()); } return GM_OK; } int Instance::ProcessGuildChat(int id, unsigned char* pData) { return 0; } //************************************ // Name: ProcessCommand // // Prepares a command chat packet for server command processing. // // Parameters: // pPckData - Packet data // pData - Network message // pLir - Player's data // // Return: // - Size of packet //************************************ int Instance::ProcessCommand(unsigned char* pPckData, NetMessage* pData, void* pLir) { Player* pPlayer=AccessPlayer(((PLAYER_DATA*)pLir)->networkId); //Copy the command string into a buffer and convert to ASCII char buffer[250]; memset(buffer, 0, 250); memcpy(buffer, pPckData+6, ((*(pPckData+2))-1)*2); if (!ChatMessageOk(buffer, ((*(pPckData+2))-1))) { ConsoleWrite(CHAT_MESSAGE_ERROR, false, pData->networkId, COMMAND_COLOR); } else { Util::StripUnicode(buffer); CommandProcessing(buffer, false, pLir, pPlayer); return 4+(pPckData[2]*2)+4; } return 0; } //************************************ // Name: ProcessTeamChat // // Processes the team chat packet. // // Parameters: // pPckData - Packet data // pData- Network message // pLir - Player's local data // // Return: // - size of packet //************************************ int Instance::ProcessTeamChat(unsigned char* pPckData, NetMessage* pData, void* pLir) { return 0; } //************************************ // Name: ProcessLocalChat // // Processes the local chat packet. // // Parameters: // pPckData - Packet data // pData - Network message // pLir - Player's data // // Return: // - size of packet //************************************ int Instance::ProcessLocalChat(unsigned char* pPckData, NetMessage* pData, void* pLir) { Player* pPlayer=AccessPlayer(((PLAYER_DATA*)pLir)->networkId); char message_u[250]; memset(message_u, 0, 250); memcpy( message_u, &pPckData[0x06], ((*((unsigned short*)&pPckData[0x02])) - 1) * 2 ); if (!ChatMessageOk(message_u, ((*((unsigned short*)&pPckData[0x02])) - 1))) { ConsoleWrite(CHAT_MESSAGE_ERROR, false, pData->networkId, COMMAND_COLOR); } else { //PLAYER_CYCLE_START() if (true) { hash_map::iterator cycleItr; for (cycleItr=mAgents.begin(); cycleItr!=mAgents.end(); cycleItr++) { Player *cont=(Player*)cycleItr->second.mpController; if (cont!=NULL && cycleItr->second.mAgentType==AGENT_PLAYER && cont->GetFlag(PLAYER_IS_CONNECTED) && !cont->GetFlag(PLAYER_IS_GHOST)) { Player *curPlayer=cont; WriteGeneralChat((unsigned char*)message_u, ((*((unsigned short*)&pPckData[0x02])) - 1), 3, pPlayer->GetLocalId(), curPlayer->GetnetworkId()); PLAYER_CYCLE_END(); return 4+(pPckData[2]*2)+4; } return 0; } //************************************ // Name: ProcessTradeChat // // Processes the trade chat packet. // // Parameters: // pPckData - Packet data // pData - Network message // pLir - Player's data // // Return: // - size of packet //************************************ int Instance::ProcessTradeChat(unsigned char* pPckData, NetMessage* pData, void* pLir) { Player* pPlayer=AccessPlayer(((PLAYER_DATA*)pLir)->networkId); char message_u[250]; memset(message_u, 0, 250); memcpy( message_u, &pPckData[0x06], ((*((unsigned short*)&pPckData[0x02])) - 1) * 2 ); if (!ChatMessageOk(message_u, ((*((unsigned short*)&pPckData[0x02])) - 1))) { ConsoleWrite(CHAT_MESSAGE_ERROR, false, pData->networkId, COMMAND_COLOR); } else { PLAYER_CYCLE_START() WriteGeneralChat((unsigned char*)message_u, ((*((unsigned short*)&pPckData[0x02])) - 1), 12, pPlayer->GetLocalId(), curPlayer->GetnetworkId()); PLAYER_CYCLE_END(); return 4+(pPckData[2]*2)+4; } return 0; } //************************************ // Name: ProcessWhisperChat // // Processes the whisper chat packet. // // Parameters: // pPckData - Packet data // pData - Network message // pLir - Player's data // // Return: // - size of packet //************************************ int Instance::ProcessWhisperChat(unsigned char* pPckData, NetMessage* pData, void* pLir) { return 0; }