SmartFoxServer 2X C++ API
Sfs2X::Requests::ObjectMessageRequest Class Reference

Send a custom data Object to all users in a Room or a sub-selection of them More...

#include <ObjectMessageRequest.h>

Inherits Sfs2X::Requests::GenericMessageRequest.

Public Member Functions

 ObjectMessageRequest (boost::shared_ptr< ISFSObject > obj, boost::shared_ptr< Room > targetRoom, boost::shared_ptr< vector< boost::shared_ptr< User > > > recipients)
 Constructor More...
 
 ObjectMessageRequest (boost::shared_ptr< ISFSObject > obj, boost::shared_ptr< Room > targetRoom)
 ObjectMessageRequest(ISFSObject obj, Room targetRoom, ICollection<User> recipients) More...
 
 ObjectMessageRequest (boost::shared_ptr< ISFSObject > obj)
 ObjectMessageRequest(ISFSObject obj, Room targetRoom, ICollection<User> recipients) More...
 

Detailed Description

Send a custom data Object to all users in a Room or a sub-selection of them

(If you are familiar with SmartFoxServer 1.x this request the equivalent of sendObject)

The request allow to send a custom data object to all users in the same Room. A typical use of this request is for sending game moves to other players

Constructor & Destructor Documentation

◆ ObjectMessageRequest() [1/3]

Sfs2X::Requests::ObjectMessageRequest::ObjectMessageRequest ( boost::shared_ptr< ISFSObject obj,
boost::shared_ptr< Room >  targetRoom,
boost::shared_ptr< vector< boost::shared_ptr< User > > >  recipients 
)

Constructor

Parameters
objthe custom object
targetRooman optional target room. This room must be joined and by default it is the last joined Room
recipientsan optional selection of Users in the target Room (by default the message is sent to all Users)
ptrSmartFox->AddEventListener(SFSEvent::OBJECT_MESSAGE, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnObjectMessage, (unsigned long long)this));
// The variables myCharacter and senderCharacter are local data objects
// Send a game move to all players
boost::shared_ptr<ISFSObject> dataObj (new SFSObject());
dataObj->PutInt("x", myCharacter.x);
dataObj->PutInt("y", myCharacter.y);
boost::shared_ptr<IRequest> request (new ObjectMessageRequest(dataObj));
ptrSmartFox->Send(request);
static void OnObjectMessage(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnObjectMessage(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> ptrEventParamValueSender = (*ptrEventParams)["sender"];
boost::shared_ptr<User> ptrNotifiedSender = ((boost::static_pointer_cast<User>)(ptrEventParamValueSender));
boost::shared_ptr<void> ptrEventParamValueObject = (*ptrEventParams)["message"];
boost::shared_ptr<ISFSObject> ptrNotifiedObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueObject));
senderCharacter.x = ptrNotifiedObject->GetInt("x");
senderCharacter.y = ptrNotifiedObject->GetInt("y");
}
See also
Core.SFSEvent.OBJECT_MESSAGE

◆ ObjectMessageRequest() [2/3]

Sfs2X::Requests::ObjectMessageRequest::ObjectMessageRequest ( boost::shared_ptr< ISFSObject obj,
boost::shared_ptr< Room >  targetRoom 
)

ObjectMessageRequest(ISFSObject obj, Room targetRoom, ICollection<User> recipients)

◆ ObjectMessageRequest() [3/3]

Sfs2X::Requests::ObjectMessageRequest::ObjectMessageRequest ( boost::shared_ptr< ISFSObject obj)

ObjectMessageRequest(ISFSObject obj, Room targetRoom, ICollection<User> recipients)