deleting a room

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

User avatar
Carl
Posts: 36
Joined: 22 Dec 2006, 20:40
Location: New York
Contact:

deleting a room

Postby Carl » 05 Jan 2007, 17:25

I guess this is an extremely dumb question, but how do you force a room to be deleted? In the manual I see these methods:


createRoom
getRoom
leaveRoom

but no DeleteRoom or removeRoom

I need the users to always be connected to the main lobby so they can chat with all other players. They can also at this time create their own rooms to invite players to play with them (this I have done), but I need them to be able to delete these rooms as well, especially if they decide to join someone else's game.

It seems that allot of the example files just allow the dynamic rooms to time out? Leaving the room doesn't immediately cause the room to be deleted as far as I can tell.....

Sorry for such a basic question; I'm sure it's in an example some place, but I can't see it in the manual....
Carl Lydon
Illustrator, animator, programmer
----------------------------------------
www.gametrust.com
www.chamberofchat.com
User avatar
Carl
Posts: 36
Joined: 22 Dec 2006, 20:40
Location: New York
Contact:

What command does the admin tool use to destroy room?

Postby Carl » 05 Jan 2007, 19:51

What command does the admin tool use to destroy room?

I guess we don't have the source for that one...

Do you need to be an admin to destroy a room?
Carl Lydon

Illustrator, animator, programmer

----------------------------------------

www.gametrust.com

www.chamberofchat.com
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 06 Jan 2007, 08:58

You can delete room by user request by using server side extensions.

SFS destroys empty rooms automaticly. If the room is dynamic and it's NOT game room it's deleted when:
The second type of rooms can be dynamically created at runtime by the client using the SmartFoxClient API. These rooms can be destroyed by the server when there're no more users inside, and its creator isn't logged anymore in the zone.
This means that if all users have logged out of the room but its creator is still present in the zone the room will not be removed.


If they are game rooms:
What's the difference between a "regular" room and a "game" one? Almost no difference, however there is a slight difference in the behaviour when the room is empty. In the "Advanced Chat" tutorial we said that "regular" rooms are removed only when the last user exits and the room creator is not connected anymore in the zone. If the creator is still around the room will not be destroyed.

A game room behaves a little differently because it will be removed as soon as the last user leaves it. This is the ony difference.


So if rooms created by uour users are game room SFS behaviour(it deletes them if they are empty) is the same as the most game sites. So you don't need to type even a line of code to delete the empty rooms. Of cource you must write if you want to delete them by user request or in some other situation.

p.s. The above quotes are from the SFS docs. It's better to look in the docs since somethings may change and the above may be will not be true in the future. The first quote is from "5.5 Tutorials: Advanced Chat (part 2)" and the second is from "5.8 Tutorials: Board game (part 1)"
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 06 Jan 2007, 09:31

Default room behavior:

1- Regular rooms: are destroyed when empty and the owner is not connected to the server anymore (if owner == server, rooms are never destroyed)

2- Game rooms: are destroyed as soon as the last user inside leaves the room. (if owner == server, room is never destroyed)

From the admin tool you can destroy any room (even those owned by the server) but they have to be empty.
Same thing can be done using the _server.destroyRoom() from a custom extension
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
jjduran
Posts: 90
Joined: 03 Jan 2007, 05:11
Contact:

roomLost is firing twice??

Postby jjduran » 03 Jun 2008, 02:04

SCENARIO:

I have lobbies (game rooms) where players can begin assembling teams of 3 players.

If the creator of one of these teams (game rooms) leaves the room, I want to boot any other players from the team back into the main lobby (regular room).

The system is configured to allow users to be in the main lobby and in the team lobby at the same time.

If the game creator leaves, I capture the event in a serverside extension and call leaveRoom to boot any remaining players. My code successfully boots the other players from the game room, and the game room is successfully deleted from the server.

THE PROBLEM:

the 'roomLost' internal event is firing twice when the creator of the room leaves. Naturally, the "onRoomDeletedHandler" then fires TWICE on the client side and thus causes problems with null values. (The 'room' param is null the second time through).

Here is a trace of the console that shows the event firing twice for the following situation.
1. User jd created the game room 'TeamLobby'
2. User md then joined the room
3. User jd (the creator) then leaves the room

Code: Select all

[login.as]: Event received: userExit
[teamLobby.as]: userExit    User: jd left the TeamLobby
[login.as]: Event received: userExit
[teamLobby.as]: userExit    User: md left the TeamLobby
02:08:17.476 - [ FINE ] > Shutting down extension: teamLobby
[teamLobby.as]: Extension Destroyed
[login.as]: Event received: roomLost - ROOM ID: 26
02:08:17.477 - [ INFO ] > Game Room Deleted: TeamLobby
[login.as]: Event received: roomLost - ROOM ID: 26
 02:08:17.479 - [ INFO ] > Game Room Deleted: TeamLobby


I don't understand why 'roomLost' would fire twice here. Any ideas?? Here is my server side code:

Code: Select all

else if (eventName == "userExit" || eventName == "userLost"){

    // Get the user from the local list
    pi = evt.oldPlayerIndex
      
    // If the team leader exits, boot the other players
    if(pi == 1){
   
          var user2 = playerList[2];
          var user3 = playerList[3];
         
          if(user2 != undefined){
                _server.leaveRoom(user2, r.getId())
          }
           
          if(user3 != undefined){
                _server.leaveRoom(user3, r.getId())
           }
         
     }
            
}         





Thanks!
Jonathan
User avatar
jjduran
Posts: 90
Joined: 03 Jan 2007, 05:11
Contact:

Postby jjduran » 03 Jun 2008, 14:18

Code: Select all

[ RECEIVED ]: <msg t='sys'><body action='userGone' r='26'><user id='0' /></body></msg>, (len: 72)
[ RECEIVED ]: <msg t='sys'><body action='roomDel'><rm id='26'/></body></msg>, (len: 62)
[ RECEIVED ]: <msg t='sys'><body action='leaveRoom' r='-1'><rm id='26' /></body></msg>, (len: 72)
[ RECEIVED ]: <msg t='sys'><body action='roomDel'><rm id='26'/></body></msg>, (len: 62)
TypeError: Error #1009: Cannot access a property or method of a null object reference.


This is a trace with the SmartFoxClient debug enabled. You can see the null problem, it occurs in my handling of onRoomDeleted since the room param is null. Any thoughts?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 03 Jun 2008, 19:28

This line of code is not clear:

Code: Select all

else if (eventName == "userExit" || eventName == "userLost"){

every use leaving a room will fire a userExit event, so if two users are leaving room A you'll get that event twice.

Also in your code I don't see where this log:
[login.as]: Event received: roomLost - ROOM ID: 26

is outputted.

Maybe could you submit a working example that produces the issue?
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
jjduran
Posts: 90
Joined: 03 Jan 2007, 05:11
Contact:

Postby jjduran » 03 Jun 2008, 19:44

Thanks for the reply,

The code segment you mentioned that was unclear is from a room extension called teamLobby.as.

every user leaving a room will fire a userExit event, so if two users are leaving room A you'll get that event twice.


This actually doesn't fire twice because I check that the playerId (pi) equals 1 (ensuring the player was the creator of the team).

Also in your code I don't see where this log:
[login.as]: Event received: roomLost - ROOM ID: 26
is outputted.


login.as is a zone extension used for my custom login logic. Below is code from login.as that produces the output you mentioned:

Code: Select all

function handleInternalEvent(evt)
{
    trace("Event received: " + evt.name + " - ROOM ID: " + evt.roomId);
}



Some of my trace statements have been changed for my own testing purposes so the output I've shown may not perfectly match up with the trace statement shown above.
User avatar
jjduran
Posts: 90
Joined: 03 Jan 2007, 05:11
Contact:

Postby jjduran » 03 Jun 2008, 20:11

To provide more detail, the user joins a regular room called the Lobby. From here, the user can create a new game room (team lobby). Because it is a game room, the user is automatically joined and receives playerId = 1.

NOTE: I use exitCurrent = false when creating the game rooms to keep the user in the main lobby as well so that they can still chat etc. So users are thus in both the Lobby and the Team Lobby simultaneously.

Here is where I create the game room and attach the extension:

Code: Select all

// define team lobby server extension
   var teamLobby:Object = {}
   teamLobby.name = "teamLobby"
   teamLobby.script = "teamLobby.as"
            
   // create the new room
   var roomObject:Object = new Object();
   roomObject.name = duel_lobby_module.team_name_txt.text;
   roomObject.maxUsers = 6;
   roomObject.exitCurrent = false;
   roomObject.isGame = true;
   roomObject.extension = teamLobby;


After other players join the game room, if the team creator leaves the room, the handleInternalEvent userLost / userExit event fires in teamLobby.as. This is where I call leaveRoom to boot any remaining players.

Code: Select all

else if (eventName == "userExit" || eventName == "userLost"){

    // Get the user from the local list
    pi = evt.oldPlayerIndex
     
    // If the team leader exits, boot the other players
    if(pi == 1){
   
          var user2 = playerList[2];
          var user3 = playerList[3];
         
          if(user2 != undefined){
                _server.leaveRoom(user2, r.getId())
          }
           
          if(user3 != undefined){
                _server.leaveRoom(user3, r.getId())
           }
         
     }
           
}   


Even with three players in the room, the code successfully boots them all, the clients react appropriately, but because the 'roomLost' event fires twice, and thus the 'onRoomDeleted' event gets launched twice on the client causing problems.

UPDATE: I'VE ISOLATED THE EXACT PROBLEM BELOW

Thanks in advance for your time,
Jonathan
Last edited by jjduran on 04 Jun 2008, 01:33, edited 2 times in total.
User avatar
jjduran
Posts: 90
Joined: 03 Jan 2007, 05:11
Contact:

Postby jjduran » 04 Jun 2008, 00:55

So I spent the rest of the night working to isolate the problem and I finally found exactly where it is happening. Here is a scenario:

1. User jd creates the game room
2. User pac joins the room
3. User md joins the room
4. User jd (the creator) then leaves the room

When the userExit event triggers for the departure of user jd, the event is interrupted by the _server.leaveRoom calls. As you can see in the simplified trace below, the userExit event for jd does not finish until after the userExit events finish for users pac and md.

Code: Select all

[teamLobby.as]: userExit BEGIN - Player: 1  User: jd

[teamLobby.as]: BOOT PLAYER 2
[teamLobby.as]: userExit BEGIN - Player: 2  User: pac
[teamLobby.as]: userExit FINISH - Player: 2 User: pac

[teamLobby.as]: BOOT PLAYER 3
[teamLobby.as]: userExit BEGIN - Player: 3  User: md
[teamLobby.as]: userExit FINISH - Player: 3 User: md

[teamLobby.as]: TeamLobby Extension Destroyed
[login.as]: ROOM LOST: 41
01:20:17.974 - [ INFO ] > Game Room Deleted: Team Lobby

[teamLobby.as]: userExit FINISH   - Player: 1 User: jd
[login.as]: ROOM LOST: 41
01:20:17.981 - [ INFO ] > Game Room Deleted: Team Lobby


It seems that the extension finds no remaining users after booting player 3. Thus the extension is destroyed, but the code then seems to finish executing the first userExit event that was triggered when jd (the room creator) exited the room.

Below is the most recent teamLobby.as room extension that produced the above output:

Code: Select all

} else if (eventName == "userExit" || eventName == "userLost"){
      
   // Get the user from the local list
   pi = evt.oldPlayerIndex
   u = playerList[pi]
      
   trace("userExit BEGIN - Player: " + pi + "  User: " + u.getName());
      
   // If the team leader exits, boot the other players
   if(pi == 1){         
         
       var user2 = playerList[2];
       var user3 = playerList[3];
         
       if(user2 != undefined){
             trace("BOOT PLAYER 2);
             _server.leaveRoom(user2, r.getId())
             delete playerList[2]
       }
       if(user3 != undefined){
              trace("BOOT PLAYER 3);
              _server.leaveRoom(user3, r.getId())
              delete playerList[3]
        }
   }
      
  delete playerList[pi];
  trace("userExit FINISH - Player: " + pi + " User: " + u.getName());
}


I need some sort of workaround to stop the userExit event from continuing after the extension is destroyed. I hope this helps explain the issue.

THANKS!
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 04 Jun 2008, 11:43

I'm not sure if this can help you but can't you set a boolean flag inside destroy() function so you can check if the destroy() is already called?
User avatar
jjduran
Posts: 90
Joined: 03 Jan 2007, 05:11
Contact:

Postby jjduran » 04 Jun 2008, 12:41

Thanks patso, but the destroy() function actually isn't the part that is being called twice... it is the 'roomLost' event that is being triggered twice.

Copied from my output above, you can see that the trace:

Code: Select all

[teamLobby.as]: TeamLobby Extension Destroyed
only fires once.

But the line:

Code: Select all

01:20:17.974 - [ INFO ] > Game Room Deleted: Team Lobby
fires twice

Any other ideas?
J
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 04 Jun 2008, 15:19

Oh excuse me :oops: .
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 12 Jun 2008, 09:28

sorry for the delay, we have filed the reported issue in our bug db and we are going to take a closer look at it in the next days.

stay tuned
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 38 guests