SmartFoxServer 2X C++ API
Sfs2X::Requests::Buddylist::BuddyMessageRequest Class Reference

BuddyMessage(s) are similar to private chat messages but are specifically designed for the Buddy List system. More...

#include <BuddyMessageRequest.h>

Inherits Sfs2X::Requests::GenericMessageRequest.

Public Member Functions

 BuddyMessageRequest (string message, boost::shared_ptr< Buddy > targetBuddy, boost::shared_ptr< ISFSObject > parameters)
 Constructor More...
 

Detailed Description

BuddyMessage(s) are similar to private chat messages but are specifically designed for the Buddy List system.

They don't require any Room parameter, nor they require that Users are joined into any particular Room. Additionally the Buddy Message performs specific validation such as making sure that the recipient is in the User's BuddyList and verifies the Buddy block status.

Constructor & Destructor Documentation

◆ BuddyMessageRequest()

Sfs2X::Requests::Buddylist::BuddyMessageRequest::BuddyMessageRequest ( string  message,
boost::shared_ptr< Buddy targetBuddy,
boost::shared_ptr< ISFSObject parameters 
)

Constructor

Parameters
messagethe message
targetBuddythe recipient of the message
parameterscustom parameters (e.g. the textfield font and color, a sender avatar id, or any other data...)
ptrSmartFox->AddEventListener(SFSEvent::BUDDY_MESSAGE, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnBuddyMessage, (unsigned long long)this));
// Obtain the recipient of the message
boost::shared_ptr<Buddy> kermitTheFrog = ptrSmartFox->BuddyListManager()->GetBuddyByName("KermitTheFrog");
boost::shared_ptr<IRequest> request (new BuddyMessageRequest("Hello Kermit!", kermitTheFrog));
ptrSmartFox->Send(request);
static void OnBuddyMessage(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnBuddyMessage(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
{
CMyClass* ptrMyClass = (CMyClass*)ptrContext;
boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params();
boost::shared_ptr<void> ptrEventParamValueBuddy = (*ptrEventParams)["buddy"];
boost::shared_ptr<Buddy> ptrNotifiedBuddy = ((boost::static_pointer_cast<Buddy>)(ptrEventParamValueBuddy));
boost::shared_ptr<void> ptrEventParamValueMessage = (*ptrEventParams)["message"];
boost::shared_ptr<string> ptrNotifiedMessage = ((boost::static_pointer_cast<string>)(ptrEventParamValueMessage));
boost::shared_ptr<void> ptrEventParamValueIsItMe = (*ptrEventParams)["isItMe"];
boost::shared_ptr<bool> ptrNotifiedIsItMe = ((boost::static_pointer_cast<bool>)(ptrEventParamValueIsItMe));
if ((*ptrNotifiedIsItMe) == true)
{
string* message = new string("I said: " + (*ptrNotifiedMessage));
}
else
{
string* message = new string("Buddy said: " + (*ptrNotifiedMessage));
}
}
See also
Core.SFSBuddyEvent.BUDDY_MESSAGE, AddBuddyRequest, RemoveBuddyRequest, BlockBuddyRequest