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

Sends a request to a Zone or Room Extension. More...

#include <ExtensionRequest.h>

Inherits Sfs2X::Requests::BaseRequest.

Public Member Functions

 ExtensionRequest (string extCmd, boost::shared_ptr< ISFSObject > parameters, boost::shared_ptr< Room > room, bool useUDP)
 Constructor More...
 
 ExtensionRequest (string extCmd, boost::shared_ptr< ISFSObject > parameters, boost::shared_ptr< Room > room)
 ExtensionRequest(string, boost::shared_ptr<ISFSObject>, boost::shared_ptr<Room>, bool) More...
 
 ExtensionRequest (string extCmd, boost::shared_ptr< ISFSObject > parameters)
 ExtensionRequest(string, boost::shared_ptr<ISFSObject>, boost::shared_ptr<Room>, bool) More...
 

Detailed Description

Sends a request to a Zone or Room Extension.

Each request to an extension is characterized by two parameters:

  • command name: any string that identifies an action that should be executed on the server side. We recommend to use the same command name for both the client request and the server response.
  • request data: you can send any simple or complex data structures to your extension(s) via the SFSObject class

Constructor & Destructor Documentation

◆ ExtensionRequest() [1/3]

Sfs2X::Requests::ExtensionRequest::ExtensionRequest ( string  extCmd,
boost::shared_ptr< ISFSObject parameters,
boost::shared_ptr< Room >  room,
bool  useUDP 
)

Constructor

Parameters
extCmdthe command name
parametersthe custom extension request data
roomwhen specified it will send the request to the Room Extension. The user must be joined in that Room.
useUDP(optional) uses UDP to send the request
ptrSmartFox->AddEventListener(SFSEvent::EXTENSION_RESPONSE, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnExtensionResponse, (unsigned long long)this));
// Send two integers to the Zone extension and get their sum in return
boost::shared_ptr<ISFSObject> parameters (new SFSObject());
parameers->PutInt("n1", 26);
parameters->PutInt("n2", 16);
// Send request
boost::shared_ptr<IRequest> request (new ExtensionRequest("add", parameters));
ptrSmartFox->Send(request);
static void OnExtensionResponse(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnExtensionResponse(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> ptrEventParamValueCmd = (*ptrEventParams)["cmd"];
boost::shared_ptr<string> ptrNotifiedCmd = ((boost::static_pointer_cast<string>)(ptrEventParamValueCmd));
if (*ptrNotifiedCmd == "add")
{
// Similarly the server sends us an object with custom data.
boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"];
boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams));
// We expect an int called sum
ptrNotifiedISFSObject->GetInt("sum");
}
}
See also
Core.SFSEvent.EXTENSION_RESPONSE

◆ ExtensionRequest() [2/3]

Sfs2X::Requests::ExtensionRequest::ExtensionRequest ( string  extCmd,
boost::shared_ptr< ISFSObject parameters,
boost::shared_ptr< Room >  room 
)

◆ ExtensionRequest() [3/3]

Sfs2X::Requests::ExtensionRequest::ExtensionRequest ( string  extCmd,
boost::shared_ptr< ISFSObject parameters 
)