Trap server side create room event / set room variables

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

Moderators: Lapo, Bax

mrpinc
Posts: 25
Joined: 02 Nov 2009, 21:12

Trap server side create room event / set room variables

Postby mrpinc » 27 Jun 2011, 13:35

I am looking to trap these events to make the newly created room/room variables persist (as in not delete when the creator leaves the server)

How can I achieve this using the server addEventHandler() method? I would prefer to do it this way rather than writing a custom extension since I can just leverage the existing client api, and avoiding all my client devs from updating their code.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 27 Jun 2011, 16:07

You can't trap events in the way you want to.
When an event is dispatched to the listener, the action it represents already occurred.
You need a custom call to your server-side extension.
Paolo Bax
The SmartFoxServer Team
mrpinc
Posts: 25
Joined: 02 Nov 2009, 21:12

Postby mrpinc » 27 Jun 2011, 16:55

Actually if the event already occurred that is fine with me, i just want to take the newly created room or room-variables and turn them into never-delete, is this possible?
mrpinc
Posts: 25
Joined: 02 Nov 2009, 21:12

Postby mrpinc » 27 Jun 2011, 18:28

Turns out it is possible with the room variables - I am sure the exact same thing will work with the Room -

Code: Select all

public void handleServerEvent(ISFSEvent event) throws SFSException {

      List<RoomVariable> l = (List<RoomVariable>) event.getParameter(SFSEventParam.VARIABLES);
      
      for (Iterator<RoomVariable> it = l.iterator(); it.hasNext();) {
          RoomVariable r = (RoomVariable) it.next();
         
          r.setPersistent(true);
         
          User server = this.getParentExtension().getApi().getUserByName("server");
         
          r.setOwner(server);         

      }
   }

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot], Stevenor and 58 guests