Click or drag to resize

InviteUsersRequest Class

Sends a generic invitation to a list of users.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.Requests.GameInviteUsersRequest

Namespace:  Sfs2X.Requests.Game
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class InviteUsersRequest : BaseRequest

The InviteUsersRequest type exposes the following members.

Constructors
  NameDescription
Public methodInviteUsersRequest
Creates a new InviteUsersRequest instance.
Top
Remarks
Invitations can be used for different purposes, such as requesting users to join a game or visit a specific Room, asking the permission to add them as buddies, etc. Invited users receive the invitation as an 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.
Examples
The following example sends an invitation to join the current user in his private Room; the invitation contains a custom message and the Room name and password, so that the recipient clients can join the Room if the users accept the invitation:
void SomeMethod() {
    // Add a listener to the invitation reply
    sfs.AddEventListener(SFSEvent.INVITATION_REPLY, OnInvitationReply);

    // Choose the invitation recipients
    User friend1 = sfs.UserManager.GetUserByName("Piggy");
    User friend2 = sfs.UserManager.GetUserByName("Gonzo");

    List<object> invitedUsers = new List<object>();
    invitedUsers.Add(friend1);
    invitedUsers.Add(friend2);

    // Set the custom invitation details
    ISFSObject parameters = new SFSObject();
    parameters.PutUtfString("msg", "Would you like to join me in my private room?");
    parameters.PutUtfString("roomName", "Kermit's room");
    parameters.PutUtfString("roomPwd", "drowssap");

    // Send the invitation; recipients have 20 seconds to reply before the invitation expires
    sfs.Send( new InviteUsersRequest(invitedUsers, 20, parameters) );
}

void OnInvitationReply(BaseEvent evt) {    
    // If at least one recipient accepted the invitation, make me join my private Room to meet him there
    if ((InvitationReply)evt.Params["reply"] == InvitationReply.ACCEPT) {
        Room currentRoom = sfs.LastJoinedRoom;
        if (currentRoom.name != "Kermit's room")
            sfs.Send(new JoinRoomRequest("Kermit's room"));
    }
    else ((InvitationReply)evt.Params["reply"] == InvitationReply.REFUSE) {
        Console.WriteLine((User)evt.Params["invitee"] + " refused the invitation");                         // .Net / Unity
        System.Diagnostics.Debug.WriteLine((User)evt.Params["invitee"] + " refused the invitation");        // UWP
    }
}
See Also