SmartFoxServer 2X C++ API
Sfs2X::Requests::Game::InviteUsersRequest Class Reference

Send one or more generic invitations to a list of Users. More...

#include <InviteUsersRequest.h>

Inherits Sfs2X::Requests::BaseRequest.

Public Member Functions

 InviteUsersRequest (boost::shared_ptr< list< boost::shared_ptr< User > > > invitedUsers, long int secondsForReply, boost::shared_ptr< ISFSObject > parameters)
 Constructor More...
 

Detailed Description

Send one or more generic invitations to a list of Users.

Invitations can be used for different purposes such as playing games, visiting a specific Room, Buddy requests etc...

See also
SFSInvitation

Constructor & Destructor Documentation

◆ InviteUsersRequest()

Sfs2X::Requests::Game::InviteUsersRequest::InviteUsersRequest ( boost::shared_ptr< list< boost::shared_ptr< User > > >  invitedUsers,
long int  secondsForReply,
boost::shared_ptr< ISFSObject parameters 
)

Constructor

Parameters
invitedUsersa list of invited Users
secondsForReplythe amount of seconds allowed to the invited User to reply (recommended range 15-40 seconds)
parametersoptional custom invitation parameters
// Add event listener for the Invitation reply event
ptrSmartFox->AddEventListener(SFSEvent::INVITATION_REPLY, boost::shared_ptr<EventListenerDelegate> (new EventListenerDelegate(CMyClass::OnInvitationReply, (unsigned long long)this)));
// Prepare the invitation
boost::shared_ptr<User> user1 = = ptrSmartFox->UserManager()->GetUserByName("Piggy");
boost::shared_ptr<User> user2 = = ptrSmartFox->UserManager()->GetUserByName("Gonzo");
boost::shared_ptr<list<boost::shared_ptr<User>>> invitedUsers (new list<boost::shared_ptr<User>());
invitedUsers->push_back(user1);
invitedUsers->push_back(user2);
// Send invitation
boost::shared_ptr<IRequest> request (new InviteUsersRequest(invitedUsers, 20, boost::shared_ptr<ISFSObject>()));
ptrSmartFox->Send(request);
static void OnInvitationReply(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
// Handle responses from invited users
void CMyClass::OnInvitationReply(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent)
{
// Get the pointer to my class
CMyClass* instance = (CMyClass*)ptrContext;
// If User accepts the invitation, send the Room id to join (as promised)
boost::shared_ptr<void> ptrEventParamValueReply = (*ptrEventParams)["reply"];
boost::shared_ptr<unsigned char> ptrNotifiedReply = ((boost::static_pointer_cast<unsigned char>))(ptrEventParamValueReply);
if (*ptrNotifiedReply) == INVITATIONREPLY_ACCEPT)
{
// Send a game move to all players
boost::shared_ptr<ISFSObject> dataObj (new SFSObject());
dataObj->PutInt("roomId", aRoomReference->Id());
boost::shared_ptr<IRequest> request (new ObjectMessageRequest(dataObj));
ptrSmartFox->Send(request);
}
else
{
// User has refused the invitation
boost::shared_ptr<void> ptrEventParamValueUser = (*ptrEventParams)["invitee"];
boost::shared_ptr<User> ptrNotifiedReply = ((boost::static_pointer_cast<User>))(ptrEventParamValueUser);
}
}
See also
Core.SFSEvent.INVITATION_REPLY, SFSInvitation, InvitationReply