Page 1 of 1

send a response to all users

Posted: 14 Apr 2011, 15:01
by eventdave
I am trying to write an extension that receives some data from a client, then informs ALL users that the data was received.

Is this possible?

The sendResponse needs an array of all users, how do I that?

Many thanks

Posted: 14 Apr 2011, 15:43
by rjgtav
Hi.

If you want to inform all the users inside the room, you can get the userList by using:

_server.getCurrentRoom().getAllUsers();

If you want to inform all the users inside the zone, you can get the userList by using:

_server.getCurrentZone().getUserList();

Both this methods return an Array containing all users, so you can use it in the sendResponse method.

For more information, you can check the serverSide API:
http://www.smartfoxserver.com/docs/docP ... /index.htm

Note:
this code i posted is for an ActionScript Extension

Posted: 14 Apr 2011, 16:15
by eventdave
That's great, thanks for replying.

My extension is actually at a zone level, so this did not quite work, but it gave me a point in the right direction.

Cheers!

Posted: 15 Apr 2011, 20:31
by julifos
There is also _server.sendModeratorMessage(), which can broadcast a message to every player in the zone. You can set as moderator (temporarily) to a given user and broadcast the message --> user.setAsModerator(true/false)

Posted: 16 Apr 2011, 00:25
by Sarevok
That is security disaster waiting to happen, if you ask me :) Suppose that demoting user fail for some reason, after the message is sent :)

Posted: 16 Apr 2011, 00:34
by julifos
That depends on your implementation. In my environment, for example, moderators don't have any permission/relevance out of Smartfox's operational services. Depending on the situation, using a mod message could be a very efficient way to broadcast a message (without still giving root access to a given user), agaisnt iterating over 10k online users to send individual messages.

Posted: 16 Apr 2011, 11:21
by Sarevok
I guess you could get some efficiency that way, but I doubt it is a big one. Because iteration needs to be done, either by you, or by server API (inside moderator message function). Only performance gain you get is probably elimination of, in your example, 10 000 function call overheads :)

Posted: 16 Apr 2011, 20:23
by julifos
Agreed :wink: