[SDK] Is there any way to intercept chat?

Déja

Beyond the Mod
Joined
Dec 19, 2005
Messages
353
I'm trying to make a mod that will automatically pass in-game chat messages along to a central database, but I'm curious if anyone knows if it's possible, and where one might find the means, to intercept the chat messages being sent to the host within the SDK.
 
I'm trying to make a mod that will automatically pass in-game chat messages along to a central database, but I'm curious if anyone knows if it's possible, and where one might find the means, to intercept the chat messages being sent to the host within the SDK.

Check out CvPlayer::addMessage. It handles a multitude of messages, but you can pick out the ones you want. here's something I've used:

Code:
void CvPlayer::addMessage(const CvTalkingHeadMessage& message)
{
	m_listGameMessages.push_back(message);
	
	/* Added by Gerikes for Civcraft: SC */
	[b]if (GC.getGameINLINE().getActivePlayer() == getID())
	{
		if (message.getMessageType() == MESSAGE_TYPE_CHAT && message.getTarget() == CHATTARGET_ALL)
		{[/b]
...

I think you'll need the first emboldened line, but I'm not sure. You might have what is in the resulting code block happen multiple times otherwise.
 
Ah, excellent! Thanks
 
Okay, I'm a little rusty on my C++ (I've gotten so used to C# :D), so the answer may be extremely obvious, but where in the CvTalkingHeadMessage class is the actual message? I would assume getDescription(), but I don't like to assume things :)

Do you know wherein the message lies?
 
Déja said:
Okay, I'm a little rusty on my C++ (I've gotten so used to C# :D), so the answer may be extremely obvious, but where in the CvTalkingHeadMessage class is the actual message? I would assume getDescription(), but I don't like to assume things :)

Do you know wherein the message lies?

You are right, it is getDescription. It's a wchar*, but that can be easily cast to a CvString to do most of what you'd want to do with it.
 
Ah, casting to a CvString was the tidbit I was missing... my C++ is so rusty, I'd been struggling with converting unicode to ascii, but that cast is so much easier than using wcstombs().

Thanks!
 
Back
Top Bottom