How to process SFSGame Invitation replies and expired

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
hecnabae
Posts: 5
Joined: 29 Jan 2013, 11:34
Location: Spain

How to process SFSGame Invitation replies and expired

Post by hecnabae »

Hi all. We are developing a card game that has many ways of confrontation (invitation, tournament,...). One way consist on invitations, for example user A sends an invitation to user B. How can I process the invitation replies (and invitation expired) on client side 'A'? Thanks in advance.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to process SFSGame Invitation replies and expired

Post by Lapo »

Hi,
I apologize for the delay.

The client side API provides the necessary events to receive the invitation responses:
SFSEvent.INVITATION
SFSEvent.INVITATION_REPLY
SFSEvent.INVITATION_REPLY_ERROR

Also you have the InvitationRequest object to send the invitation to a group of players
You can check them in the documentation here:
http://docs2x.smartfoxserver.com/api-do ... Index.html

And get an overview here:
http://docs2x.smartfoxserver.com/Advanc ... s/game-api
Lapo
--
gotoAndPlay()
...addicted to flash games
hecnabae
Posts: 5
Joined: 29 Jan 2013, 11:34
Location: Spain

Re: How to process SFSGame Invitation replies and expired

Post by hecnabae »

Hi Lapo, in first place thanks for reply.
I have defined this event handlers on side client:

Code: Select all

smartFox.AddEventListener(SFSEvent.INVITATION, OnInvitationResponse);
smartFox.AddEventListener(SFSEvent.INVITATION_REPLY, OnInvitationResponse);
smartFox.AddEventListener(SFSEvent.INVITATION_REPLY_ERROR, OnInvitationResponse);
Them all are defined with the same method in order to test if events are catched correctly.

The following diagram represents the idea:
diagram.png
(12.91 KiB) Not downloaded yet
It seems that "OnInvitationResponse" method is fired only in send invitation case. When receiver respond to invitation it seems nothing happens (both accept and decline) and sender does not know what happens. What is the correct way to manage this events?

Thanks in advance.
Héctor Navarro.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to process SFSGame Invitation replies and expired

Post by Lapo »

Can you provide a step by step description of how your test works?
Are you sure there's no server side errors?

The first two events should fire regularly. INVITATION_REPLY_ERROR is not implemented at the moment. We have decided not to send any errors back to the client.
Lapo
--
gotoAndPlay()
...addicted to flash games
hecnabae
Posts: 5
Joined: 29 Jan 2013, 11:34
Location: Spain

Re: How to process SFSGame Invitation replies and expired

Post by hecnabae »

Our system is based on the send of invitations between users. A user send an invitation to another user, if the invite accepts, immediately joins the game room and inviter learn the answer. Conversely, if the invitation to play expires or is rejected, user not know the answer because the INVITATION_REPLY event has not been fired.

STOP 0. Callback definition

Code: Select all

//...
smartFox.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom);
//...
smartFox.AddEventListener(SFSEvent.INVITATION, OnInvitationReceived);
smartFox.AddEventListener(SFSEvent.INVITATION_REPLY, OnInvitationResponse);
smartFox.AddEventListener(SFSEvent.INVITATION_REPLY_ERROR, OnInvitationResponse);
STEP 1. SENDING INVITATION (CLIENT SIDE - INVITER)

Code: Select all

// Prepare the invitation
Sfs2X.Entities.User user1 = smartFox.UserManager.GetUserByName(MySelf);
Sfs2X.Entities.User user2 = smartFox.UserManager.GetUserByName(Invitee);
		
List<object> invitedUsers = new List<object>();
invitedUsers.Add(user1);
invitedUsers.Add(user2);
		
smartFox.AddEventListener(SFSEvent.ROOM_ADD,onRoomCreated);
smartFox.AddEventListener(SFSEvent.ROOM_CREATION_ERROR,onRoomCreationError);
		
SFSGameSettings settings = new SFSGameSettings("Game name");

settings.IsGame = true;
settings.MaxUsers = 2;
settings.MaxSpectators = 0;
settings.Extension = new RoomExtension(extensionId, extensionClass);
settings.InvitedPlayers.AddRange(invitedUsers);
smartFox.Send(new CreateSFSGameRequest(settings));
STEP 2. RECEIVING INVITATION (CLIENT SIDE - INVITEE)

Code: Select all

void OnInvitationReceived(BaseEvent evt)
	{
		Room room = (Room)evt.Params["..."];
		string message = (string)evt.Params["..."];
		
		//....
		// Add invitation to invitation list of user		
	}
STEP 3. INVITATION RESPONSE (CLIENT SIDE - INVITEE)

Code: Select all

sfs2x.Send(new InvitationReplyRequest(Invitation, InvitationReply));
STEP 4. (CLIENT SIDE - INVITEE)

If the invitee accepts joins the game room.

STEP 5. INVITER VIEW RESULTS (CLIENT SIDE - INVITER)

If the invitee accepts, game start.
If the invitee refuses the invitation or the invitation expires inviter should display a message.

The problem is that if the invitee refuses the invitation or the invitation expires, on the inviter client side doesn't fire the INVITATION_REPLY event.

This is a screencast for three cases: ACCEPT - DECLINE - EXPIRED
ACCEPT.tar.gz
(71.16 KiB) Downloaded 963 times
decline.tar.gz
(68.99 KiB) Downloaded 929 times
expired.tar.gz
(135.91 KiB) Downloaded 1018 times
SmartFoxServer version: 2.6.0
ClientAPI version: Unity/.Net/Mono C# API 1.0.7

Thanks in advance.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to process SFSGame Invitation replies and expired

Post by Lapo »

Code: Select all

// Prepare the invitation
Sfs2X.Entities.User user1 = smartFox.UserManager.GetUserByName(MySelf);
Sfs2X.Entities.User user2 = smartFox.UserManager.GetUserByName(Invitee);
      
List<object> invitedUsers = new List<object>();
invitedUsers.Add(user1);
invitedUsers.Add(user2);
You don't need to invit yourself. You are the one who is willing to start the game, the inviter, and therefore what is the point of sending an invitation to yourself?

Also you're not setting the game Room as private, which would allow someone to join it while the invitation is running.
Lapo
--
gotoAndPlay()
...addicted to flash games
hecnabae
Posts: 5
Joined: 29 Jan 2013, 11:34
Location: Spain

Re: How to process SFSGame Invitation replies and expired

Post by hecnabae »

Hi Lapo, in first place thanks for your response.
If the inviter doesn't send an invitation to himself, SmartFox throws this error:
...Invited players (size = 1) are not enough to start the game (min = 2). Additionally no searchable rooms were provided...
Now I settings the game Room as private, but I still don't receive event notifications. This is my new code:

Code: Select all

// Prepare the invitation
Sfs2X.Entities.User user1 = smartFox.UserManager.GetUserByName(Inviter);
Sfs2X.Entities.User user2 = smartFox.UserManager.GetUserByName(Invitee);
      
List<object> invitedUsers = new List<object>();
invitedUsers.Add(user1);
invitedUsers.Add(user2);
      
smartFox.AddEventListener(SFSEvent.ROOM_ADD,onRoomCreated);
smartFox.AddEventListener(SFSEvent.ROOM_CREATION_ERROR,onRoomCreationError);
      
SFSGameSettings settings = new SFSGameSettings("Game name");

settings.IsGame = true;
settings.MaxUsers = 2;
settings.IsPublic = false;
settings.MaxSpectators = 0;
settings.Extension = new RoomExtension(extensionId, extensionClass);
settings.InvitedPlayers.AddRange(invitedUsers);
smartFox.Send(new CreateSFSGameRequest(settings));
What can be the problem?

Thanks in advance.
Prajju2000
Posts: 1
Joined: 26 May 2023, 16:22

Re: How to process SFSGame Invitation replies and expired

Post by Prajju2000 »

Hii everyone, In the current flow which i'm following the "SFSEvent.INVITATION_REPLY" event is not being tiggered even after sending the new InvitationReplyRequest(invitation, InvitationReply.ACCEPT).

The flow is ,
In the client_1 ,

Code: Select all

SFSGameSettings settings = new SFSGameSettings(roomName);
            settings.GroupId = "games";
            settings.MaxUsers = 2;
            settings.MaxSpectators = 10;
            settings.MinPlayersToStartGame = 2;
            settings.IsPublic = false;
            settings.LeaveLastJoinedRoom = true;
            settings.NotifyGameStarted = true;
            settings.InvitationExpiryTime = 50;

settings.InvitedPlayers = new List<object>();
settings.InvitedPlayers.Add(sfs.BuddyManager.GetBuddyByName(buddyName));
sfs.Send(new CreateSFSGameRequest(settings));
In the client_2,

Code: Select all

sfs.AddEventListener(SFSEvent.INVITATION, OnInvitation);

private void OnInvitation(BaseEvent ev)
  {
            Debug.Log("Recieved one invitaion");
            Invitation invitation = (SFSInvitation) ev.Params["invitation"];
            sfs.Send(new InvitationReplyRequest(invitation, InvitationReply.ACCEPT));
  }
but, In Client_1, "SFSEvent.INVITATION_REPLY" event is not being triggred, even though 2 clients were joined the room successfully.

Please, Can anyone give a clarification on this.
Thank you in advance.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to process SFSGame Invitation replies and expired

Post by Lapo »

@Prajju2000
Can you clarify what version of SFS2X are you using and what client API? (also which version)

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply