Page 1 of 1

Can't delete a room created by the server

Posted: 22 Oct 2007, 13:51
by Francois
hey!

On my Zone Extension, I create a new room when needed...

Code: Select all

var newRoom_obj = {};
newRoom_obj.name = getNewGamingRoomName(roomPrefix_str);
newRoom_obj.pwd = NEW_ROOM_PWD;
newRoom_obj.maxU = MAX_USERS_PER_GAME;
newRoom_obj.isGame = true;
newRoom_obj.isTemp = true;
newRoom_obj.uCount = false;
var sendUpdate = true;
var broadcastEvt = true;
var roomVars = [{name:"roomClosed", val:false, priv:true, persistent:false}];
var varsOwner = null;
var setOwnership = false;
var room = _server.createRoom(newRoom_obj, null, sendUpdate, broadcastEvt, roomVars, varsOwner, setOwnership);
and when someone disconnect I got...

Code: Select all

var room_obj = (event_str == "userExit") ? evt.room : CURRENT_ZONE.getRoom(evt.roomIds[0]);
trace("UC: "+room_obj.getUserCount());
trace("isGame: "+room_obj.isGame());
if(room_obj.getUserCount() <= 1 && room_obj.isGame())
{
trace("DESTROY ROOM #"+room_obj.getId());
var destroyed = _server.destroyRoom(CURRENT_ZONE, room_obj.getId());
trace((destroyed)?"OK":"KO");
}
room_obj.getUserCount() <= 1
is not
room_obj.getUserCount() == 0

Because it returns me 1 but no one is in the room !

I always get a "KO" in my trace()...


Any ideas? thank you guys


-François-

Posted: 22 Oct 2007, 14:40
by Lapo
So the problem is that you expect an empty room but it seems that someone is inside?
Try tracing the users inside the room ( with getAllUsers() ) and see who's inside. Additionally double check with the admin tool to see who's inside.

Let me know

Posted: 23 Oct 2007, 06:23
by Francois
The strange thing is that according to the admin tool no one is inside!
I'm gonna check with some trace statements now...

I got this:

it.gotoandplay.smartfoxserver.data.User@1c6866d

But no one is in here according to the admin tool!

If I check its name it is the last (and he was alone) user that was connected...

Seems like the admin tool sees he's gone but the extension thinks he is still out there...

Posted: 23 Oct 2007, 07:00
by Francois
I found a workaround when creating the room, I set the room owner to the first user... this way it'll automatically disappear when empty.

Do you know if I must take special care of something using this "trick" ?
Like side effects that I would expect ?

Thank you for your help.

-François-

Posted: 23 Oct 2007, 07:24
by Lapo
The trick is okay, and there're no side effects. However we're not able to reproduce the problem.

We created a simple extension that handles the userExit event and prints out the number of users in the room. It always work as expected.

Could you please tell us the steps to reproduce the issue?
Additionally, what version of the server is being used?

Thanks

Posted: 23 Oct 2007, 08:02
by Francois
My version 1.5.5.

[CS] Client Side
[SS] Server Side

1. [CS] User login
2. [CS] User receives the RoomListUpdate event...
3. [CS] Join a waiting room (one per lang) so waitingRoomFR or waitingRoomNL
4. [SS] handleInternalEvent check if he just joined a waiting room
5. [SS] if yes, call th smartJoin function.
6. [SS] smartJoin check if a gameplay is still open and if not it will automatically create one for the user and throw him in.
7. [SS] When userExit or userLost if this is in a gameroom, i try to erase the room if empty...

does that help you?

Posted: 24 Oct 2007, 14:02
by Lapo
Thanks.
It can be reproduced in the "userLost" event but not the "userExit" and we expected it as there's a slight difference in how these 2 events are fired.

To make a long story short when you receive the userLost event the user object has is not yet removed from the room. I've already discussed this somewhere else with the pros and cons of using this approach instead of firing the event after the user is lost.
Maybe we'll change this in the future but, since it may impact existing applications, we'll have to add a parameter that allows both the old way and the new one.

My reccommendation is to use one of these 2 solutions:

1. Assign the room ownership to one of the users, so that it's cleared immediately when it's empty
2. Create a thread / setInterval that looks for empty rooms every 1-2 minutes and destroys them.

Probably #1 is the best in this case

Posted: 25 Oct 2007, 14:56
by Francois
I just saw your reply, thank you!
One brilliant thing about SFS is its support, thanks again mate!

Here is how I workaround this issue:

Code: Select all

...
case "userExist":
case "userLost":
	var room = (event_str=="userExist") ? evt.room : CURRENT_ZONE.getRoom(evt.roomIds[0]);
	var lostUserId = evt.userId;
	
	if(room.isGame())
	{	//If this is in a Game
		var allUsers_arr = room.getAllUsers();
		var recipients = [];
		for(var i=0; i<allUsers_arr.length; i++)
		{	// Creating the real user list
			var recipient = allUsers_arr[i];
			if(recipient.getUserId()!=lostUserId)
			{
				recipients.push(recipient);
			}
		}
		if(recipients.length<MIN_USERS_PER_GAME)
		{	// Not enough players anymore!
			trace("GAMESTOPPED!!!");
			var response = {_cmd:"gameStopped"};
			_server.sendResponse(response, -1, null, recipients);
		}
	}
	break;
...
Good evening!

:)