SFSInvitation behaviour doesn't match documentation

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Void*
Posts: 75
Joined: 15 Feb 2021, 13:49

SFSInvitation behaviour doesn't match documentation

Postby Void* » 15 Aug 2022, 21:57

http://docs2x.smartfoxserver.com/api-do ... ation.html

The SFS2X Invitation Manager is very simple to use. All you need to provide is:

inviter: the User starting the invitation (null == Server)
invitee: the User to invite
expiryTime: the amount of time (in seconds) that the invitee has to accept/refuse the invitation. (default is 15 sec)
params: any custom params to send with the invitation (e.g. a message, game name etc...)

The Invitation system will then fire events back to a CallBack handler that you will provide in the form of a Class extending InvitationCallback.


If you pass null as the inviter, either to the SFSInvitation object, or to the API's sendInvitation method, you are given the following exception:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: │
│Exception: java.lang.IllegalArgumentException │
│Message: Both Inviter and Invitee must be non-null User objects. │
│Description: Error while handling client request in extension: { Ext: __lib__, Type: JAVA, Lev: ROOM, { Zone: REDACTED }, [ MMORoom: REDACTED, Id: 0, Group: default, AOI: (100.0, 100.0, 1.0) ] } │
│Extension Cmd: REDACTED │
│+--- --- ---+ │
│Stack Trace: │
│+--- --- ---+ │
│com.smartfoxserver.v2.entities.invitation.SFSInvitationManager.prepareStartInvitation(SFSInvitationManager.java:178) │
│com.smartfoxserver.v2.entities.invitation.SFSInvitationManager.startInvitation(SFSInvitationManager.java:138) │
│com.smartfoxserver.v2.api.SFSGameApi.sendInvitation(SFSGameApi.java:213)


Just wanted to report.

SFS2X Version 2.18.3

Thanks.

Edit: I wanted to add that you can ignore the fact that this error occurs during a client request. I am building the SFSInvitation object manually on the server in response to a player command action that picks two users at random and then allocates them to a game room. I had also tried using the API command directly e.g.:

Code: Select all

User sender = null; // Server
List<User> userList = new CustomList<User>(userA, userB); // class CustomList<T> extends ArrayList<T> and has CustomList(T... things) { super(Arrays.asList(things)); } etc.
int expiry = 60;
Room gameRoom = exampleGeneratedRoom();
int invitedPlayers = userList.size();
boolean leaveLastRoom = false;

SFSGameInvitationCallback callbackHandler = new CustomCallbackHandler(gameRoom, invitedPlayers, leaveLastRoom);
getExtension().getGameApi().sendInvitation​(sender, userList, expiry, callbackHandler, SFSObject.newInstance());


The reason I wasn't setting one of them as the "inviter" is
A) That doesn't make logical sense, if the option to have no inviter exists I'd have rather used it
B) The inviter doesn't seem to reliably trigger the server's OnRoomJoin event, which causes problems because I need to perform certain actions when a user joins the room
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFSInvitation behaviour doesn't match documentation

Postby Lapo » 16 Aug 2022, 14:00

Hi,
thanks for reporting.
It seems like the documentation might be out of synch, because the invitation API has not been changed in a long time.
But we need to investigate this more in depth.

I'll report back as soon as possible.

There is a workaround that can be used to obtain what you're looking for. Instead of passing null as the "inviter" you can use:

Code: Select all

UsersUtil.getServerAdmin();

which returns a "virtual" server-side User.

To align the documentation with the API we could also do the same behind the scenes when the developer passes a null as the inviter. We need to check this a bit more in depth.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 48 guests