Best way to create a serverside room Var (owned by server)

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

Moderators: Lapo, Bax

mixart
Posts: 95
Joined: 08 Aug 2007, 20:32

Best way to create a serverside room Var (owned by server)

Postby mixart » 14 Apr 2012, 06:38

I have a server-side room extension and simply want to create a roomvariable for each room.

I have room extensions set and was trying to create the room var on init() like this...


Code: Select all

@Override
   public void init() {
      
      trace("ext running.");
      
      User u = null;
      Room room = getParentRoom();
      ArrayList<RoomVariable> roomVars = new ArrayList<RoomVariable>();
      roomVars.add(new SFSRoomVariable("canvas", ""));
      SmartFoxServer.getInstance().getAPIManager().getSFSApi().setRoomVariables(u, room, roomVars);
      
      //adding draw class
      this.addRequestHandler("draw", DrawHandler.class);


   }


What is this the best way to do this?
I'm getting errors in the console with the above code.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Best way to create a serverside room Var (owned by serve

Postby rjgtav » 14 Apr 2012, 13:20

Hello.
What errors are you getting on the console with that code? Please make sure that the room isn't null.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
mixart
Posts: 95
Joined: 08 Aug 2007, 20:32

Re: Best way to create a serverside room Var (owned by serve

Postby mixart » 14 Apr 2012, 15:22

Here is the error that I see...

Image

If I comment out the setroomvariable line, the error goes away:
//SmartFoxServer.getInstance().getAPIManager().getSFSApi().setRoomVariables(u, room, roomVars);
Last edited by mixart on 14 Apr 2012, 18:07, edited 1 time in total.
mixart
Posts: 95
Joined: 08 Aug 2007, 20:32

Re: Best way to create a serverside room Var (owned by serve

Postby mixart » 14 Apr 2012, 15:24

Also... there are no users in the room at the time of this error. Since this is all in the init() class, it is calling this when the server starts up.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Best way to create a serverside room Var (owned by serve

Postby rjgtav » 14 Apr 2012, 20:20

Hmm... I can't reproduce that error, even when using the same code... Are you using the latest SFS2X Final Release 2.0.1? Can you upload your extension as an attachment (preferably the project)?

[EDIT]
Found it. Please don't create the room when the extension inites (in the init() method). Please create the room only after the server has completely started. You can do something like:

Code: Select all

if(SmartFoxServer.getInstance().isStarted()){
    //create the room
}else{
    //listens to the SERVER_READY event
    this.addEventHandler(SFSEventType.SERVER_READY, ServerReadyHandler.class);
}


Then you need to create a ServerReadyHandler.class which extends the BaseServerEventHandler and which creates the room.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
mixart
Posts: 95
Joined: 08 Aug 2007, 20:32

Re: Best way to create a serverside room Var (owned by serve

Postby mixart » 14 Apr 2012, 21:46

The room is being created from the config file, but I will try moving it out of the init into another event handler and reply if I have some luck. Appreciate your help.
mixart
Posts: 95
Joined: 08 Aug 2007, 20:32

Re: Best way to create a serverside room Var (owned by serve

Postby mixart » 15 Apr 2012, 06:52

Thanks - this seemed to do the trick following your guidance...


Code: Select all

public class SetuproomHandler extends BaseServerEventHandler {

   @Override
   public void handleServerEvent(ISFSEvent evt) throws SFSException {
       User u = null;
       Room room = this.getParentExtension().getParentRoom();
       ArrayList<RoomVariable> roomVars = new ArrayList<RoomVariable>();
       roomVars.add(new SFSRoomVariable("canvas", ""));
       SmartFoxServer.getInstance().getAPIManager().getSFSApi().setRoomVariables(u, room, roomVars);
   }
   
}


These gotcha's kill me! :)

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 19 guests