send a response to all users

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

eventdave
Posts: 18
Joined: 02 Jul 2010, 14:12

send a response to all users

Postby eventdave » 14 Apr 2011, 15:01

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
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 14 Apr 2011, 15:43

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
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.
eventdave
Posts: 18
Joined: 02 Jul 2010, 14:12

Postby eventdave » 14 Apr 2011, 16:15

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!
User avatar
julifos
Posts: 33
Joined: 10 Oct 2009, 23:33
Contact:

Postby julifos » 15 Apr 2011, 20:31

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)
Sarevok
Posts: 75
Joined: 12 Apr 2011, 22:12

Postby Sarevok » 16 Apr 2011, 00:25

That is security disaster waiting to happen, if you ask me :) Suppose that demoting user fail for some reason, after the message is sent :)
User avatar
julifos
Posts: 33
Joined: 10 Oct 2009, 23:33
Contact:

Postby julifos » 16 Apr 2011, 00:34

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.
Sarevok
Posts: 75
Joined: 12 Apr 2011, 22:12

Postby Sarevok » 16 Apr 2011, 11:21

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 :)
User avatar
julifos
Posts: 33
Joined: 10 Oct 2009, 23:33
Contact:

Postby julifos » 16 Apr 2011, 20:23

Agreed :wink:

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 21 guests