Dispatching Events

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

Moderators: Lapo, Bax

padde
Posts: 7
Joined: 25 Nov 2010, 12:54

Dispatching Events

Postby padde » 18 Feb 2011, 10:23

Hi,

I'd like to know how I can dispatch an event to every client with the help of an extension.
What I try to do in particular is kicking a user out of a room and then sending an USER_EXIT_ROOM event to every user in the zone.

This is my code so far:

Code: Select all

@Override
   public void handleClientRequest(User sender, ISFSObject params)
   {
      // Get the client parameters
        String user = params.getUtfString("user");
        String room = params.getUtfString("room");
       
        trace(ExtensionLogLevel.INFO, "Kick Strings: User = " + user + " | Room = " + room + ".");
       
        User u = SmartFoxServer.getInstance().getUserManager().getUserByName(user);
        Room r = SmartFoxServer.getInstance().getZoneManager().getZoneByName("SimpleChat").getRoomByName(room);
       
        trace(ExtensionLogLevel.INFO, "Kick Objects: User = " + u + " | Room = " + r + ".");
        trace(ExtensionLogLevel.INFO, "Try to kick user '" + u.getName() + "' out of room '" + r.getName() + "' by '" + sender.getName() + "'.");
       
        HashMap<ISFSEventParam, java.lang.Object> map = new HashMap<ISFSEventParam, java.lang.Object>();
       map.put(SFSEventParam.ZONE, SmartFoxServer.getInstance().getZoneManager().getZoneByName("SimpleChat"));
       map.put(SFSEventParam.ROOM, r);
       map.put(SFSEventParam.USER, u);
       SmartFoxServer.getInstance().getEventManager().dispatchEvent(new SFSEvent(SFSEventType.USER_LEAVE_ROOM, map));
       
        if(r.containsUser(u))
        {
           r.removeUser(u);
        }
       
        // Create a response object
        ISFSObject resObj = SFSObject.newInstance();
        resObj.putUtfString("user", u.getName());
         
        // Send it back
        send("kick", resObj, sender);
       
        trace(ExtensionLogLevel.INFO, "Kicked user '" + u.getName() + "' out of room '" + r.getName() + "' by '" + sender.getName() + "'.");
   }


The user get's removed from the room, but I will not get the event.
Maybe there's another solution on client-side? However, I'd really apreciate any solution for sending events to every chat-user. Thanks!

Bye,
Patrick
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 18 Feb 2011, 11:46

I dont know if you can trigger internal events.

But you could always simply make a extension command yourself which does what you want

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund

Return to “SFS2X Questions”

Who is online

Users browsing this forum: DavinVicy, DerikFent, JerodSa and 17 guests