Atomically replaced player in the NPC

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

Moderators: Lapo, Bax

moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Atomically replaced player in the NPC

Postby moris » 16 Dec 2015, 17:00

Hello. How i can atomically replaced player in the NPC? When user disconnected and game action falls on him, he is no longer in the game, and the game crashes. It is necessary at the moment of leaving the game the player put in its place a bot, is it possible?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Atomically replaced player in the NPC

Postby Lapo » 16 Dec 2015, 18:23

Hi,
atomically no, because of the very asynchronous nature of network games.

It's also not clear why this should happen. Shouldn't players be notified that the real player has left the Room and a different, automated NPC has taken his place?

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Re: Atomically replaced player in the NPC

Postby moris » 17 Dec 2015, 09:29

The problem is that when a player leaves the game (the game closes the window), it is no longer in the zone/room in DisconnectEventHandler intercepts this event and created NPC, which takes the place of the player.
But if the course of the game is the player who has left the game, and the NPC has not had time to sit down, the game may crash.

In other words, the situation can be described as follows:
There are 2 players, they sit at the table. 1st player - 1st place, 2nd player - 2nd place.
Then the points:
1. Start the game and player's turn at the 1st place.
2. Player 1 makes a move
3. 2nd player leaves the game
4. The course goes to the player at the 2nd place (but it is no longer in the game)
5. At the 2nd place to sit NPC

How can this problem be solved?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Atomically replaced player in the NPC

Postby Lapo » 17 Dec 2015, 09:59

I think it is just a bit of programming logic that needs to be adjusted for your needs.

Wouldn't it be better if the error was caught and the turn skipped?

This is what I mean...

Player 1 is plays his move.
Now is Player 2 turn but he disconnects a few milliseconds before the turn change and the NPC is not ready yet... BOOM... error

My suggestion is to catch the error and gracefully handle it. For example you could simply send a message to the other players saying that the user has left the game and an NPC will take his place. This seems also necessary to keep the game fair for everyone. I think everyone should know that the human player has left and automated player is going to replace him.

In any case once the message has been sent you can either proceed by moving on with the next turn (Player 3) or wait for the NPC to be ready and then continue with the new Player 2 move.

Makes sense?
Lapo

--

gotoAndPlay()

...addicted to flash games
moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Re: Atomically replaced player in the NPC

Postby moris » 17 Dec 2015, 14:47

Well, I do not think so, just thought there is a way to replace the player in the NPC, something like User#switchToNPC() :)
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Atomically replaced player in the NPC

Postby Lapo » 17 Dec 2015, 15:14

No, I am sorry you can't do that because the two users are different objects.
The old User object is destroyed when he disconnects and the new NPC is a new User object with no physical socket connection.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 147 guests