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

Sends a chat Public Message to other users in the Room More...

#include <PublicMessageRequest.h>

Inherits Sfs2X::Requests::GenericMessageRequest.

Public Member Functions

 PublicMessageRequest (string message, boost::shared_ptr< ISFSObject > parameters, boost::shared_ptr< Room > targetRoom)
 Constructor More...
 
 PublicMessageRequest (string, boost::shared_ptr< ISFSObject > parameters)
 PublicMessageRequest(string, boost::shared_ptr<ISFSObject>, boost::shared_ptr<Room>) More...
 
 PublicMessageRequest (string message)
 PublicMessageRequest(string*, boost::shared_ptr<Room>) More...
 

Detailed Description

Sends a chat Public Message to other users in the Room

Public Messages are broadcast to all users in the specified Room

An optional custom SFSObject can be sent together with the message. The extra parameters can be used to transmit information about the font and color of the message or any other properties that are relevant to the message.

Constructor & Destructor Documentation

◆ PublicMessageRequest() [1/3]

Sfs2X::Requests::PublicMessageRequest::PublicMessageRequest ( string  message,
boost::shared_ptr< ISFSObject parameters,
boost::shared_ptr< Room >  targetRoom 
)

Constructor

Parameters
messagethe chat message
parameterscustom extra parameters (optional)
targetRoomhe target room (optional). By default it is used the last joined Room
ptrSmartFox->AddEventListener(SFSEvent::PUBLIC_MESSAGE, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnPublicMessage, (unsigned long long)this));
boost::shared_ptr<User> messageRecipient = ptrSmartFox->UserManager()->GetUserByName("Piggy");
// Say 'Hello' to every one
boost::shared_ptr<IRequest> request (new PublicMessageRequest("Hello everyone!"));
ptrSmartFox->Send(request);
static void OnPublicMessage(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnPublicMessage(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> ptrEventParamValueMessage = (*ptrEventParams)["message"];
boost::shared_ptr<string> ptrNotifiedMessage = ((boost::static_pointer_cast<string>)(ptrEventParamValueMessage));
string* message = new string("Message: " + (*ptrNotifiedMessage) + ", Sender: " + *user->Name());
}
See also
Core.SFSEvent.PUBLIC_MESSAGE, PrivateMessageRequest

◆ PublicMessageRequest() [2/3]

Sfs2X::Requests::PublicMessageRequest::PublicMessageRequest ( string  message,
boost::shared_ptr< ISFSObject parameters 
)

◆ PublicMessageRequest() [3/3]

Sfs2X::Requests::PublicMessageRequest::PublicMessageRequest ( string  message)

PublicMessageRequest(string*, boost::shared_ptr<Room>)