How to server check player money in SFSEvent.SPECTATOR_TO_PLAYER?

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

Moderators: Lapo, Bax

truongps
Posts: 32
Joined: 27 Sep 2015, 17:06

How to server check player money in SFSEvent.SPECTATOR_TO_PLAYER?

Postby truongps » 02 Nov 2016, 04:42

Hi,
My case is:
1. Client send SpectatorToPlayerRequest
2. Server handle SFSEvent.SPECTATOR_TO_PLAYER and check user money. If user not enough money, I throw exception: throw new SFSUserException("You don't have enough money to play game.");
3. Client don't receive SFSEvent.SPECTATOR_TO_PLAYER_ERROR. Client only receive SFSEvent.SPECTATOR_TO_PLAYER.

How can I custom this event for this case?

Thank you.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to server check player money in SFSEvent.SPECTATOR_TO_PLAYER?

Postby Lapo » 02 Nov 2016, 09:28

HI,
you need a different strategy for this operation.

The SFSEvent.SPECTATOR_TO_PLAYER is generated when the operation is already finished, so it is too late to send an error to the User. You need to run your money check before the server and send a custom error if the player is not allowed to become a player.

To do this I would suggest these steps:

1- client call custom extension command
2- Extension checks the player's money and either sends a custom error or proceeds by calling SFSApi.spectatorToPlayer(...), this in turn will send the SPECTATOR_TO_PLAYER to the user.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 52 guests