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

Set custom Room Variables in a Room More...

#include <SetRoomVariablesRequest.h>

Inherits Sfs2X::Requests::BaseRequest.

Public Member Functions

 SetRoomVariablesRequest (boost::shared_ptr< vector< boost::shared_ptr< RoomVariable > > > roomVariables, boost::shared_ptr< Room > room)
 Constructor More...
 
 SetRoomVariablesRequest (boost::shared_ptr< vector< boost::shared_ptr< RoomVariable > > > roomVariables)
 SetRoomVariablesRequest(vector<RoomVariable*>*, Room*) More...
 

Detailed Description

Set custom Room Variables in a Room

See also
SFSRoomVariable

Constructor & Destructor Documentation

◆ SetRoomVariablesRequest() [1/2]

Sfs2X::Requests::SetRoomVariablesRequest::SetRoomVariablesRequest ( boost::shared_ptr< vector< boost::shared_ptr< RoomVariable > > >  roomVariables,
boost::shared_ptr< Room >  room 
)

Constructor

Parameters
roomVariablesa vector of RoomVariables
roomthe target Room

Example #1

boost::shared_ptr<vector<boost::shared_ptr<RoomVariable>>> collectionRoomVariables (new vector<boost::shared_ptr<RoomVariable>>());
boost::shared_ptr<bool> value(new bool());
*value = false;
boost::shared_ptr<RoomVariable> variable(new SFSRoomVariable("gameStarted", value, VARIABLETYPE_BOOL));
collectionRoomVariables->push_back(variable);
boost::shared_ptr<std::string> value1(new string("Snooker"));
boost::shared_ptr<RoomVariable> variable1(new SFSRoomVariable("gameType", value1, VARIABLETYPE_STRING));
collectionRoomVariables->push_back(variable1);
boost::shared_ptr<int> value2(new int());
*value2 = 10;
boost::shared_ptr<RoomVariable> variable2(new SFSRoomVariable("minRank", value2, VARIABLETYPE_INT));
collectionRoomVariables->push_back(variable2);
boost::shared_ptr<IRequest> request (new SetRoomVariablesRequest(collectionRoomVariables, ptrSmartFox->LastJoinedRoom()));
ptrSmartFox->Send(request);

Example #2

ptrSmartFox->AddEventListener(SFSEvent::ROOM_VARIABLES_UPDATE, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnRoomVarsUpdate, (unsigned long long)this));
static void OnRoomVarsUpdate(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnRoomVarsUpdate(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> ptrEventParamValueVars = (*ptrEventParams)["changedVars"];
boost::shared_ptr<vector<string>> changedVars = ((boost::static_pointer_cast<vector<string>>)(ptrEventParamValueVars));
boost::shared_ptr<void> ptrEventParamValueRoom = (*ptrEventParams)["room"];
boost::shared_ptr<Room> room = ((boost::static_pointer_cast<Room>)(ptrEventParamValueRoom));
boost::shared_ptr<RoomVariable> variable = room->GetVariable("gameStarted");
if (variable != NULL)
{
if (variable->GetBoolValue() == true)
{
// Game Starts!
}
else
{
// Game was Stopped!
}
}
}

◆ SetRoomVariablesRequest() [2/2]

Sfs2X::Requests::SetRoomVariablesRequest::SetRoomVariablesRequest ( boost::shared_ptr< vector< boost::shared_ptr< RoomVariable > > >  roomVariables)

SetRoomVariablesRequest(vector<RoomVariable*>*, Room*)