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

Sends an invitation to other users/players to join a specific Room. More...

#include <JoinRoomInvitationRequest.h>

Inherits Sfs2X::Requests::BaseRequest.

Public Member Functions

 JoinRoomInvitationRequest (boost::shared_ptr< Room > targetRoom, boost::shared_ptr< list< string > > invitedUserNames, boost::shared_ptr< ISFSObject > parameters, long int expirySeconds, bool asSpectator)
 Creates a new JoinRoomInvitationRequest instance. More...
 
 JoinRoomInvitationRequest (boost::shared_ptr< Room > targetRoom, boost::shared_ptr< list< string > > invitedUserNames, boost::shared_ptr< ISFSObject > parameters, long int expirySeconds)
 See JoinRoomInvitationRequest(boost::shared_ptr<Room>, boost::shared_ptr<list<string> >, boost::shared_ptr<ISFSObject>, long int, bool) constructor. More...
 
 JoinRoomInvitationRequest (boost::shared_ptr< Room > targetRoom, boost::shared_ptr< list< string > > invitedUserNames, boost::shared_ptr< ISFSObject > parameters)
 See JoinRoomInvitationRequest(boost::shared_ptr<Room>, boost::shared_ptr<list<string> >, boost::shared_ptr<ISFSObject>, long int, bool) constructor. More...
 
 JoinRoomInvitationRequest (boost::shared_ptr< Room > targetRoom, boost::shared_ptr< list< string > > invitedUserNames)
 See JoinRoomInvitationRequest(boost::shared_ptr<Room>, boost::shared_ptr<list<string> >, boost::shared_ptr<ISFSObject>, long int, bool) constructor. More...
 

Static Public Attributes

static boost::shared_ptr< string > KEY_ROOM_ID
 <exclude>
 
static boost::shared_ptr< string > KEY_EXPIRY_SECONDS
 <exclude>
 
static boost::shared_ptr< string > KEY_INVITED_NAMES
 <exclude>
 
static boost::shared_ptr< string > KEY_AS_SPECT
 <exclude>
 
static boost::shared_ptr< string > KEY_OPTIONAL_PARAMS
 <exclude>
 

Detailed Description

Sends an invitation to other users/players to join a specific Room.

Invited users receive the invitation as an Sfs2X.Core.SFSEvent.INVITATION event dispatched to their clients: they can accept or refuse it by means of the InvitationReplyRequest request, which must be sent within the specified amount of time.

Depending on the Room's settings this invitation can be sent by the Room's owner only or by any other user. This behavior can be set via the RoomSettings.AllowOwnerOnlyInvitation parameter.

NOTE: spectators in a Game Room are not allowed to invite other users; only players are.

An invitation can also specify the amount of time given to each invitee to reply. Default is 30 seconds. A positive answer will attempt to join the user in the designated Room. For Game Rooms the asSpectator flag can be toggled to join the invitee as player or spectator (default = player).

There aren't any specific notifications sent back to the inviter after the invitee's response. Users that have accepted the invitation will join the Room while those who didn't reply or turned down the invitation won't generate any event. In order to send specific messages (e.g. chat), just send a private message back to the inviter.

The following example invites two more users in the current game:

void SomeMethod()
{
ptrSmartFox->AddEventListener(SFSEvent::USER_ENTER_ROOM, boost::shared_ptr<EventListenerDelegate> (new EventListenerDelegate(CMyClass::onUserJoin, (unsigned long long)this)));
boost::shared_ptr<list<string> > invitedUsers(new list<string>());
invitedUsers->push_back("Fozzie");
invitedUsers->push_back("Piggy");
boost::shared_ptr<Room> room = ptrSmartFox->GetRoomByName("The Garden");
// Add message to be shown to the invited users
boost::shared_ptr<ISFSObject> params= SFSObject.NewInstance();
params.PutUtfString("msg", "You are invited in this Room: " + room->Name());
// Send the request
boost::shared_ptr<IRequest> request (new JoinRoomInvitationRequest(room, invitedUsers, params));
ptrSmartFox->Send(request);
}
static void onUserJoin(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent);
void CMyClass::onUserJoin(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent)
{
// Get the pointer to my class
CMyClass* instance = (CMyClass*)ptrContext;
boost::shared_ptr<void> ptrEventParamValueUser = (*ptrEventParams)["user"];
boost::shared_ptr<User> ptrUser = ((boost::static_pointer_cast<User>))(ptrEventParamValueUser);
System.Diagnostics.Debug.WriteLine("Room joined by: " + user->Name()); // for win8 and win phone
}
See also
Sfs2X.Requests.RoomSettings

Constructor & Destructor Documentation

◆ JoinRoomInvitationRequest() [1/4]

Sfs2X::Requests::Game::JoinRoomInvitationRequest::JoinRoomInvitationRequest ( boost::shared_ptr< Room >  targetRoom,
boost::shared_ptr< list< string > >  invitedUserNames,
boost::shared_ptr< ISFSObject parameters,
long int  expirySeconds,
bool  asSpectator 
)

Creates a new JoinRoomInvitationRequest instance.

The instance must be passed to the SmartFox.Send method for the request to be performed.

Parameters
targetRoomThe Room to join (must have free user/player slots).
invitedUserNamesA list of user names to invite.
parametersAn instance of Sfs2X.Entities.Data.SFSObject containing any relevant parameter or message to be sent to the invited users (for example an invitation message). Default is null.
expirySecondsThe time given to the invitee to reply to the invitation. Default is 30.
asSpectatorIn Game Rooms only, indicates if the invited user(s) should join as spectator(s) instead of player(s). Default is false.

◆ JoinRoomInvitationRequest() [2/4]

Sfs2X::Requests::Game::JoinRoomInvitationRequest::JoinRoomInvitationRequest ( boost::shared_ptr< Room >  targetRoom,
boost::shared_ptr< list< string > >  invitedUserNames,
boost::shared_ptr< ISFSObject parameters,
long int  expirySeconds 
)

See JoinRoomInvitationRequest(boost::shared_ptr<Room>, boost::shared_ptr<list<string> >, boost::shared_ptr<ISFSObject>, long int, bool) constructor.

◆ JoinRoomInvitationRequest() [3/4]

Sfs2X::Requests::Game::JoinRoomInvitationRequest::JoinRoomInvitationRequest ( boost::shared_ptr< Room >  targetRoom,
boost::shared_ptr< list< string > >  invitedUserNames,
boost::shared_ptr< ISFSObject parameters 
)

See JoinRoomInvitationRequest(boost::shared_ptr<Room>, boost::shared_ptr<list<string> >, boost::shared_ptr<ISFSObject>, long int, bool) constructor.

◆ JoinRoomInvitationRequest() [4/4]

Sfs2X::Requests::Game::JoinRoomInvitationRequest::JoinRoomInvitationRequest ( boost::shared_ptr< Room >  targetRoom,
boost::shared_ptr< list< string > >  invitedUserNames 
)

See JoinRoomInvitationRequest(boost::shared_ptr<Room>, boost::shared_ptr<list<string> >, boost::shared_ptr<ISFSObject>, long int, bool) constructor.