How correctly to remove a Room?

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

Moderators: Lapo, Bax

Post Reply
vandelpal
Posts: 11
Joined: 25 Oct 2010, 17:14

How correctly to remove a Room?

Post 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?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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.
Lapo
--
gotoAndPlay()
...addicted to flash games
vandelpal
Posts: 11
Joined: 25 Oct 2010, 17:14

Post 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?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

when the object is not referenced anymore it will be garbage collected, this includes all his properties etc...
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply