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

Join one of the Zones in the Server. More...

#include <LoginRequest.h>

Inherits Sfs2X::Requests::BaseRequest.

Public Member Functions

 LoginRequest (string userName, string password, string zoneName, boost::shared_ptr< ISFSObject > parameters)
 Constructor More...
 
 LoginRequest (string userName, string password, string zoneName)
 LoginRequest(string, string, string, boost::shared_ptr<ISFSObject> More...
 
 LoginRequest (string userName, string password)
 LoginRequest(string, string, string, boost::shared_ptr<ISFSObject>) More...
 
 LoginRequest (string userName)
 LoginRequest(string, string, string, boost::shared_ptr<ISFSObject>) More...
 

Detailed Description

Join one of the Zones in the Server.

Each Zone represents a different application running independently
In order to join a Zone a user name and password are usually required.
If the Zone allows guest users, user name and password are not needed and a guest name will be created on the server side
If the Zone uses a server side extension to handle the login, you can also send a custom SFSObject with any extra parameters.

Constructor & Destructor Documentation

◆ LoginRequest() [1/4]

Sfs2X::Requests::LoginRequest::LoginRequest ( string  userName,
string  password,
string  zoneName,
boost::shared_ptr< ISFSObject parameters 
)

Constructor

Parameters
userNamethe user name (optional)
passwordthe password (optional)
zoneNamethe name of an existing Zone in the server (case sensitive, 'SimpleChat' != 'simplechat'). If no Zone is specified the SmartFox.Config.Zone parameter will be used.
parametersthe custom parameters (optional, if you use an Extension on server side to handle the login)
ptrSmartFox->AddEventListener(SFSEvent::LOGIN, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnLogin, (unsigned long long)this));
ptrSmartFox->AddEventListener(SFSEvent::LOGIN_ERROR, boost::shared_ptr<EventListenerDelegate> (EventListenerDelegate(CMyClass::OnLoginError, (unsigned long long)this));
// Login passing only the user name, no password and the zone name is obtained
// from the previously loaded configuration
boost::shared_ptr<IRequest> request (new LoginRequest("FozzieTheBear"));
ptrSmartFox->Send(request);
static void OnLogin(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
static void OnLoginError(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::OnLogin(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
{
CMyClass* ptrMyClass = (CMyClass*)ptrContext;
// Login success
}
void CMyClass::OnLoginError(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> ptrEventParamValueErrorMessage = (*ptrEventParams)["errorMessage"];
boost::shared_ptr<string> ptrErrorMessage = ((boost::static_pointer_cast<string>)(ptrEventParamValueErrorMessage));
string* message = new string("Login failure: " + (*ptrErrorMessage));
}
See also
Core.SFSEvent.LOGIN, Core.SFSEvent.LOGIN_ERROR, SmartFox.LoadConfig(string, bool)

◆ LoginRequest() [2/4]

Sfs2X::Requests::LoginRequest::LoginRequest ( string  userName,
string  password,
string  zoneName 
)

◆ LoginRequest() [3/4]

Sfs2X::Requests::LoginRequest::LoginRequest ( string  userName,
string  password 
)

◆ LoginRequest() [4/4]

Sfs2X::Requests::LoginRequest::LoginRequest ( string  userName)