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

Set custom User Variables for the current User More...

#include <SetUserVariablesRequest.h>

Inherits Sfs2X::Requests::BaseRequest.

Public Member Functions

 SetUserVariablesRequest (boost::shared_ptr< vector< boost::shared_ptr< UserVariable > > > userVariables)
 Constructor More...
 

Detailed Description

Set custom User Variables for the current User

See also
SFSUserVariable

Constructor & Destructor Documentation

◆ SetUserVariablesRequest()

Sfs2X::Requests::SetUserVariablesRequest::SetUserVariablesRequest ( boost::shared_ptr< vector< boost::shared_ptr< UserVariable > > >  userVariables)

Constructor

Parameters
userVariablesan Array of UserVariables

Example #1 Shows how set a number of User variables

boost::shared_ptr<vector<boost::shared_ptr<UserVariable>>> collectionUserVariable (new vector<boost::shared_ptr<UserVariable>>());
boost::shared_ptr<std::string> value(new string("SwedishCook"));
boost::shared_ptr<UserVariable> variable(new SFSUserVariable ("avatarType", value, VARIABLETYPE_STRING));
collectionUserVariable->push_back(variable);
boost::shared_ptr<std::string> value1(new string("Sweden"));
boost::shared_ptr<UserVariable> variable1(new SFSUserVariable ("country", value1, VARIABLETYPE_STRING));
collectionUserVariable->push_back(variable1);
boost::shared_ptr<int> value2(new int());
*value2 = 10;
boost::shared_ptr<UserVariable> variable2(new SFSUserVariable ("x", value2, VARIABLETYPE_INT));
collectionUserVariable->push_back(variable2);
boost::shared_ptr<int> value3(new int());
*value3 = 10;
boost::shared_ptr<UserVariable> variable3(new SFSUserVariable ("y", value3, VARIABLETYPE_INT));
collectionUserVariable->push_back(variable3);
boost::shared_ptr<IRequest> request (new SetUserVariablesRequest(collectionUserVariable));
ptrSmartFox->Send(request);

Example #2 Shows how to listen and react to some other User's updates

ptrSmartFox->AddEventListener(SFSEvent::USER_VARIABLES_UPDATE, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnUserVarsUpdate, (unsigned long long)this));
static void OnUserVarsUpdate(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnUserVarsUpdate(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> ptrEventParamValueUser = (*ptrEventParams)["user"];
boost::shared_ptr<User> user = ((boost::static_pointer_cast<User>)(ptrEventParamValueUser));
boost::shared_ptr<UserVariable> variable = user->GetVariable("x");
boost::shared_ptr<UserVariable> variable1 = user->GetVariable("y");
if ((variable != NULL) && (variable1 != NULL))
{
// Move the character to a new position...
}
}
See also
SFSUserVariable