NPC leave room, disconnect or kicked

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
frcol
Posts: 96
Joined: 22 Aug 2010, 09:26
Location: Brazil
Contact:

NPC leave room, disconnect or kicked

Postby frcol » 11 Jun 2015, 15:33

Hi,
I´m creating a room dinamically when a user enters it and putting a NPC inside.

When the last user leaves the room and just the NPC is inside, I want to leave/disconnect/kick the NPC and destroy the Room.

Everything works fine without NPC inside: create and destroy room.

The leaveroom does not work for NPC.
The kick and disconnnet works and call the userLost event, but if I put the DeleteRoom inside it, the room is not deleted. As the console shows me, it apears that the user is still inside when the lostUser is called.

jvm 1 | [loginDuplicado.as]: Delete Room:49
jvm 1 | [loginDuplicado.as]: Error when trying to destroy Room #49 // i tried to delete here (userLost)
jvm 1 | 11:57:24.452 - [ FINE ] > Removed NPC connection: java.nio.channels.SocketChannel[closed]
jvm 1 | 11:57:24.453 - [ FINE ] > User [ guest_0 ] removed // NPC
jvm 1 | 11:57:24.454 - [ INFO ] > User guest_0 has been kicked.


Code: Select all

if (evt.name == "userLost") {
...
      if (usr.getVariable("_os_type").getValue() == "NPC") {
         trace("call delete because PET leave the room "+evt.roomIds);
         var param = new Object;
         param.idRoom = evt.roomIds[0];
         hDeleteRoom("",param,"","")
      }
...
else if (evt.name == "userExit") { // last real user leave the room
...
} else if (evt.room.getUserCount() == 1) {
            var usersList = evt.room.getAllUsers();
            var user = usersList[0];

            if (user.getVariable("_os_type").getValue() == "NPC") {
                                         //_server.leaveRoom(user, idRoom);
               //_server.kickUser(user, 0, "Pet kicked");
               _server.disconnectUser(user);



Any help?
Fabio Colombini
Brazil
User avatar
Lapo
Site Admin
Posts: 20113
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC leave room, disconnect or kicked

Postby Lapo » 12 Jun 2015, 10:54

HI,
let me see if I understand the sequence correctly.

When the NPC is the last user in the Room you do this:

- call disconnectUser(NPC)
- wait for "userLost" server event
- call removeRoom()

Is this correct?
Any exceptions on the server side?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
frcol
Posts: 96
Joined: 22 Aug 2010, 09:26
Location: Brazil
Contact:

Re: NPC leave room, disconnect or kicked

Postby frcol » 12 Jun 2015, 11:52

Yes, exactly the sequence.
No Exceptions on the server side (looking in the console while running).
Fabio Colombini
Brazil
User avatar
Lapo
Site Admin
Posts: 20113
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC leave room, disconnect or kicked

Postby Lapo » 15 Jun 2015, 08:17

I think it's a timing issue. When the event is fired the Room still contains the User (I think, but haven't verified) and calling destroyRoom will not succeed.

I have tested by adding a small delay (e.g. 1 second) and it works. You can use setInterval to delay the room destruction.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 4 guests