Page 1 of 1

How correctly to remove a Room?

Posted: 30 Jan 2011, 18:04
by vandelpal
I write Zone extensoin to which players are connected. Then, between them, I create a room and joint them to it also adds NPC.
When the game is over I need to free up room and clean up after itself. Now I call

Code: Select all

for (User user : room.getUserList())
        {
            if(user.isNpc())            SmartFoxServer.getInstance().getAPIManager().getSFSApi().disconnectUser(user);
            else                SmartFoxServer.getInstance().getAPIManager().getSFSApi().leaveRoom(user, room);
        }
Room remove mode is WHEN_EMPTY.
Destroy function in Room Extension is override when I free resources.
Everything is correct?
NPC variables and properties will be cleared and dispose?

Posted: 31 Jan 2011, 08:50
by Lapo
Just a note: you don't need this:

Code: Select all

SmartFoxServer.getInstance().getAPIManager().getSFSApi()
you can obtain a reference to the API by using

Code: Select all

getApi()
from within any Extension or Event/Request handler

In your code you don't need to call disconnect first and leaveRoom after. The disconnect will already remove the NPC from all the Rooms and the Zone itself.

Posted: 01 Feb 2011, 06:21
by vandelpal
LeaveRoom I call the only real players, because I want them to remain on the server in the zone.
What about NPC variables and properties attached to NPCUser?

Posted: 01 Feb 2011, 15:10
by Lapo
when the object is not referenced anymore it will be garbage collected, this includes all his properties etc...