Server sending *public messages* into a 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

Luke64
Posts: 21
Joined: 08 Nov 2020, 23:15

Server sending *public messages* into a room?

Postby Luke64 » 20 Oct 2021, 20:54

Hi Lapo,

during my successful development journey with SFS2X, I came across a problem I couldn't solve. And at this near-finished stage, I somehow need to solve it without breaking all the code there is. :oops:

The situation
Players can form clubs. Each club has an own room. Players are automatically joined into that room on login and cannot leave it. They can chat publicly in that room.
The server keeps a little chat history in each club room: it registers for "public message" SFSEvents and keeps the last 20 messages of the room in one room variable. Updates to this variable are not sent to the clients so that only new joining players can fill their initial chat window from that variable.
Sometimes special events should happen involving certain clubs. Like a club vs. club challenge triggered by the server. The server should then notify both club rooms about this challenge.

The problem
I can't for the love of all foxes get the server to send a normal public message into a room without needing user to send it with! But there is no user triggering this event in this case - it's only the server. And I need it to be a public message so it can be picked up by the chat history event handler, so new joining players also can see that special event.
Sending individual messages to all players of one room won't help with the chat history.

How can I do this?

Thanks a ton,
Niklas

(Disclaimer: I simplified the problem and all the side effects a little for this explanation - I'm actually desperately needing a "server public message", that would be the easiest fix here...)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Server sending *public messages* into a room?

Postby Lapo » 21 Oct 2021, 08:22

Hi,
I can't for the love of all foxes get the server to send a normal public message into a room without needing user to send it with!

A public message is supposed to be sent by someone in the Room. If not the receivers won't know who actually sent the message. Makes sense?
What you're looking for is either a Moderator or Admin Message. Both of which are available from the server side, as:

    SFSApi.sendModeratorMessage()
    SFSApi.sendAdminMessage()

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Luke64
Posts: 21
Joined: 08 Nov 2020, 23:15

Re: Server sending *public messages* into a room?

Postby Luke64 » 21 Oct 2021, 15:10

Hi Lapo,
A public message is supposed to be sent by someone in the Room. If not the receivers won't know who actually sent the message. Makes sense?

Sort of, but why can't the public message originate from "the server" instead of a person in the room? The server is omnipresent, it doesn't need to be in a room, it IS the room! :wink:
It's like a public room message for all the participants of a room. But without a real person sending it.

I saw moderator and admin messages but they both can only be sent to users, not to a room... So I guess it really isn't possible to send a public server message to one distinct room?

Cheers
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Server sending *public messages* into a room?

Postby Lapo » 27 Oct 2021, 10:13

A public message must be sent by a User joined in the Room. There's no way to override this. The client side API need the User Id of the sender to be able to reference the necessary objects passed in the SFSEvent.PUBLIC_MESSAGE.

To accomplish what you're asking you would need to create an NPC on the server side, join it in the Room and then send a public message.
Using and Admin or Moderator message seems more convenient, plus it provides a separate event which is useful to handle the message in a customized way, if necessary.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Luke64
Posts: 21
Joined: 08 Nov 2020, 23:15

Re: Server sending *public messages* into a room?

Postby Luke64 » 02 Nov 2021, 09:29

Hi Lapo,

thank you for the explanation! I'll go with the admin/mod messages then, good hint with the separate event! This way I should be able to add it to the message history as it is.

Best,
Niklas

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot], Justinzeaidew and 43 guests