Sending Object to All Users in MMO Room

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

Moderators: Lapo, Bax

User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Sending Object to All Users in MMO Room

Postby meanvel » 21 Apr 2017, 13:37

Getting very on/off results using this serverside in a MMO room. Trying to broadcast a top ten leaderboard every ten seconds to all users.

Since object messages require a user, tried just setting the user to the top player. It can't be null... But, it seems to only work when the user is a SuperUser? Kinda confused why.

Code: Select all

            trace("Send LB");
            //Send leaderboard to all clients in room
            sfsApi.sendObjectMessage(mapRoom,Leaderboard.get(0),dataObj,null);


Perhaps I should use a moderator message or something else instead. Why do object messages require a user and can't be set to null for [server]?
User avatar
Lapo
Site Admin
Posts: 19202
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending Object to All Users in MMO Room

Postby Lapo » 21 Apr 2017, 14:00

hmm... the 4th param is the list of recipients, why do you pass null?
As regards the mod. message, no an object message will do just fine.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Re: Sending Object to All Users in MMO Room

Postby meanvel » 21 Apr 2017, 14:04

Lapo wrote:hmm... the 4th param is the list of recipients, why do you pass null?
As regards the mod. message, no an object message will do just fine.


I will try using my Leaderboard list, which is simply a list of all room users sorted by score. Ill update this post in a minute and tell you if that works...

Code: Select all

            trace("Send LB");
            //Send leaderboard to all clients
            sfsApi.sendObjectMessage(mapRoom,Leaderboard.get(0),dataObj,Leaderboard);


Update: Well, that seems to work, but... A null value for the user list is "supposed" to work according to the documentation. However, it only works for SuperUsers...

"recipients - use null to send the message to all clients in the Room, or specify a collection of users that should receive the message"

http://docs2x.smartfoxserver.com/api-do ... ollection-
Last edited by meanvel on 21 Apr 2017, 14:16, edited 1 time in total.
User avatar
Lapo
Site Admin
Posts: 19202
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending Object to All Users in MMO Room

Postby Lapo » 21 Apr 2017, 14:14

And what is the problem exactly when you say you get "on/off" results?
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Re: Sending Object to All Users in MMO Room

Postby meanvel » 21 Apr 2017, 14:17

Lapo wrote:And what is the problem exactly when you say you get "on/off" results?


If the user on the top of the Leaderboard isn't in the Admin/Moderator/SuperUser group, a null value for the user list results in no Object message being received by the clients. The object message User is set to the top user on the leaderboard.

According to the documentation... Null should work no matter what!
"sendObjectMessage
recipients - use null to send the message to all clients in the Room"


Ok, let me say this even more simply... Try to send a object message to all clients in a MMO room through the sfsApi with the user not being a SuperUser, and the recipients list as null. It doesn't work...
Last edited by meanvel on 21 Apr 2017, 14:23, edited 1 time in total.
User avatar
Lapo
Site Admin
Posts: 19202
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending Object to All Users in MMO Room

Postby Lapo » 21 Apr 2017, 14:22

I have no idea why this would be the case unless you have some special settings in your privilege manager config.
Maybe you should review your config.

Also if this is an error related to permissions you should find an error in the server logs.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Re: Sending Object to All Users in MMO Room

Postby meanvel » 21 Apr 2017, 14:28

Lapo wrote:I have no idea why this would be the case unless you have some special settings in your privilege manager config.
Maybe you should review your config.

Also if this is an error related to permissions you should find an error in the server logs.


I already checked that multiple times. Also, no errors in the error log.

Code: Select all

  <privilegeManager active="true">
    <profiles>
      <profile id="0">
        <name>Guest</name>
        <deniedRequests class="java.util.Arrays$ArrayList">
          <a class="string-array">
            <string>CreateRoom</string>
            <string>PrivateMessage</string>
            <string>SetRoomVariables</string>
            <string>ChangeRoomName</string>
            <string>ChangeRoomPassword</string>
            <string>ChangeRoomCapacity</string>
            <string>InitBuddyList</string>
            <string>AddBuddy</string>
            <string>BlockBuddy</string>
            <string>RemoveBuddy</string>
            <string>SetBuddyVariables</string>
            <string>GoOnline</string>
            <string>BuddyMessage</string>
            <string>ModeratorMessage</string>
            <string>AdminMessage</string>
            <string>KickUser</string>
            <string>BanUser</string>
          </a>
        </deniedRequests>
        <permissionFlags class="java.util.Arrays$ArrayList">
          <a class="string-array">
            <string>ExtensionCalls</string>
          </a>
        </permissionFlags>
      </profile>
      <profile id="1">
        <name>Standard</name>
        <deniedRequests class="java.util.Arrays$ArrayList">
          <a class="string-array">
            <string>CreateRoom</string>
            <string>PrivateMessage</string>
            <string>SetRoomVariables</string>
            <string>ChangeRoomName</string>
            <string>ChangeRoomPassword</string>
            <string>ChangeRoomCapacity</string>
            <string>InitBuddyList</string>
            <string>AddBuddy</string>
            <string>BlockBuddy</string>
            <string>RemoveBuddy</string>
            <string>SetBuddyVariables</string>
            <string>GoOnline</string>
            <string>BuddyMessage</string>
            <string>ModeratorMessage</string>
            <string>AdminMessage</string>
            <string>KickUser</string>
            <string>BanUser</string>
          </a>
        </deniedRequests>
        <permissionFlags class="java.util.Arrays$ArrayList">
          <a class="string-array">
            <string>ExtensionCalls</string>
          </a>
        </permissionFlags>
      </profile>
      <profile id="2">
        <name>Moderator</name>
        <deniedRequests class="java.util.Arrays$ArrayList">
          <a class="string-array">
            <string>AdminMessage</string>
          </a>
        </deniedRequests>
        <permissionFlags class="java.util.Arrays$ArrayList">
          <a class="string-array">
            <string>ExtensionCalls</string>
            <string>SuperUser</string>
          </a>
        </permissionFlags>
      </profile>
      <profile id="3">
        <name>Administrator</name>
        <deniedRequests/>
        <permissionFlags class="java.util.Arrays$ArrayList">
          <a class="string-array">
            <string>ExtensionCalls</string>
            <string>SuperUser</string>
          </a>
        </permissionFlags>
      </profile>
    </profiles>
  </privilegeManager>


Well, I am not going to worry about it. As long as the object message request receives a user list it works.
User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Re: Sending Object to All Users in MMO Room

Postby meanvel » 21 Apr 2017, 14:42

As an experiment, I denied all object message permissions. No errors. Leaderboard update object messages are still being received properly clientside... As long as the user list is not "null."
Image

I don't think this is permission related. I am 99% sure that setting recipients "null" to send to all users in a room is not working properly... But, don't worry about it. It's not exactly a bug. You could just update your documentation to say "You must pass a user list!", and nobody would ever have an issue.
Attachments
noPerms.png
(5.38 KiB) Not downloaded yet
User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Re: Sending Object to All Users in MMO Room

Postby meanvel » 21 Apr 2017, 15:20

I may have solved it...

A null value is supposed to do this.
"recipients - use null to send the message to all clients in the Room"

However, it seems like it's actually doing this...
"recipients - use null to send the message to all clients in the Room except the sender"

Which caused a problem when trying to broadcast a Leaderboard to all users with a serverside interval.

Code: Select all

//Java Serverside API Doc
    sendObjectMessage
    Parameters:
        targetRoom - the room where the message will be sent to
        sender - the sender of the message
        message - a custom SFSObject
        recipients - use null to send the message to all clients in the Room, or specify a collection of users that should receive the message

http://docs2x.smartfoxserver.com/api-do ... ollection-
User avatar
Lapo
Site Admin
Posts: 19202
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending Object to All Users in MMO Room

Postby Lapo » 21 Apr 2017, 15:35

Yes, sender is not included, there's no reason to.
We'll make it more clear in the docs.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Re: Sending Object to All Users in MMO Room

Postby meanvel » 21 Apr 2017, 15:38

Lapo wrote:Yes, sender is not included, there's no reason to.
We'll make it more clear in the docs.


You could also just make it so that "sender" can be null... For object messages from [server].
User avatar
Lapo
Site Admin
Posts: 19202
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending Object to All Users in MMO Room

Postby Lapo » 21 Apr 2017, 15:53

SendObject is mainly a client-side way of broadcasting data to other people. From server side it isn't particularly useful, you easily replace it with your own extension call that does exactly what you want.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Re: Sending Object to All Users in MMO Room

Postby meanvel » 21 Apr 2017, 22:57

Lapo wrote:SendObject is mainly a client-side way of broadcasting data to other people. From server side it isn't particularly useful, you easily replace it with your own extension call that does exactly what you want.

cheers


Are you suggesting that the most efficient way to broadcast a leaderboard update intermittently is to put a call to sfsApi.sendExtensionResponse in a for loop for all room users?

Psedocode...
for (each user)
sfsApi.sendExtensionResponse("lb", leaderboardObj, user, currentRoom, false);

I disagree, send object message is perfectly useful from serverside... I use it everywhere in my extensions. Each object message is assigned a ID "t" for Type which the client uses to recognize what the purpose of each object is.

Code: Select all

            //Object message type
            newParams.putByte("t",(byte) 9);
            mmoApi.sendObjectMessage(mapRoom,Reporter,newParams,mapAoi);

As security against cheating... I even make it so that object messages that go from one client to other clients are initially sent from the client as a extension request, then assigned their purpose, then sent to other clients as an object message from serverside.

That way, I can build out my cheat detection and prevention system easily as needed. Verifying that players are near where their projectile is supposed to come from, and that players that are getting attacked are reporting they are getting attacked enough, etc...
User avatar
Lapo
Site Admin
Posts: 19202
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending Object to All Users in MMO Room

Postby Lapo » 22 Apr 2017, 10:20

meanvel wrote:Are you suggesting that the most efficient way to broadcast a leaderboard update intermittently is to put a call to sfsApi.sendExtensionResponse in a for loop for all room users?

Yes, but not in a for loop. The method takes a list of users, use that instead of the loop.

As security against cheating... I even make it so that object messages that go from one client to other clients are initially sent from the client as a extension request, then assigned their purpose, then sent to other clients as an object message from serverside.

If it works for you no problem.
We usually recommend that if you send an Extension request you also get an Extension response, but it's not a "law".

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
meanvel
Posts: 128
Joined: 19 Jan 2017, 14:06

Re: Sending Object to All Users in MMO Room

Postby meanvel » 22 Apr 2017, 16:56

Lapo wrote:
As security against cheating... I even make it so that object messages that go from one client to other clients are initially sent from the client as a extension request, then assigned their purpose, then sent to other clients as an object message from serverside.

If it works for you no problem.
We usually recommend that if you send an Extension request you also get an Extension response, but it's not a "law".

Cheers

Yep, works great. :)

I just checked my code. The main reason I have not been using many extension responses is because the majority of game communication is local and goes back through the MMO Api. The only model for secure communication is Client > extensionRequest > Extension (Logging,proximity check/cheat detection, etc) > objectMessage > Clients.

Thanks for the tip that extension responses can go back to multiple users. Not used to using method overloading... Have a good weekend!

Image
Attachments
mmoApiUsed.png
(8.45 KiB) Not downloaded yet

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 14 guests