[Suggestion] Multiplayer RelayToPeer

0 favourites
  • 4 posts
From the Asset Store
The official Scirra Multiplayer Signalling Server for helping peers find and connect to each other
  • It would be great if we had an action that could send a message from a peer to a non-host peer and the host would automatically handle relaying it. I can get around this with some fancy footwork and awkward packing/unpacking functions, but this would save some time:

    Multiplayer.RelayToPeer(Destination Id, Tag, Message, Reliability)

    • If this action is used from host, it functions like a normal Send Message.
    • If this action is used from a non-host peer, it sends the message to the host which would relay the message to the appropriate peer id and also preserve the true from id.

    *** If this is considered too in-depth ***

    Maybe could we just add a simple action BroadcastToSinglePeer which adds a DestPeer Id field?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Maybe could we just add a simple action BroadcastToSinglePeer which adds a DestPeer Id field?

    This is already achievable with action:room:send message. You can store a peerID in variables or array, then just use it.

    [attachment=0:31k0i1s8][/attachment:31k0i1s8]

    If this action is used from a non-host peer, it sends the message to the host which would relay the message to the appropriate peer id and also preserve the true from id.

    It will not take too much event to produce this actually. It's doable with single event from peer and single event from host.

  • DuckfaceNinja

    That's what I refer to as "unpacking/packing" in my original post. It's inelegant for a number of reasons especially if you want to preserve a "is host/peer agnostic" type of architecture in the code.

    In order to address the problem, I had to create a top-level function called "CustomSendMessage" which takes three parameters:

    • DestinationId
    • Tag
    • Message

    There is a special global tag I created called "RELAY_MESSAGE" which I will reference later.

    Let me outline the function's logic branches for you:

    • Function is being called by the host: no wrapping is necessary, use Multiplayer Send Message normally.
    • Function is being called by a client but the destination is the host: Again no wrapping is necessary, use Multiplayer Send Message normally.
    • Function is being called by a client and destination is a client: Send a message to the host with Tag (RELAY_MESSAGE), message is modified to be: DestId & "|" & OriginalTag & "|" & OriginalMessage

    Now we need a Host-only Multiplayer On Message RELAY_MESSAGE received logical trigger:

    • Unpacks the modified message, prepares to send a normal message to the true peer DestId with OriginalTag
    • The modified message becomes: Multiplayer.FromID & "|" & OriginalMessage

    Whenever a client receives any message, they have to determine if the true sender was the HOST or a relayed client which is done through a custom function called:

    GetTrueSender (string Message) - Returns Multiplayer.FromID or a token if the true source peer id was packed into the message.

    It works and solves the problem since the messages in my app are fairly infrequent, otherwise this solution might possibly introduce some latency in a different type of app.

    Either way, I'm still having to write a bit of kludge in that I'm adding a potentially unnecessary man-in-the-middle if it is actually possible to send direct messages peer-to-peer. However, this may be a limitation of WebRTC (all messages have to be sent to the peer-to-host-to-peer), I haven't done enough research.

  • As a non-coder, I would rather approach it in inelegant way because it helps me to read my event and know what is happening. I'm not against the idea to add the feature, but it may raise confusion among non-coder like me asking "which one should I use" because not everyone are well educated with terminology used by people with substantial coding knowledge.

    I'm glad I have started using MP plugin, because the action/condition it has right now are straight forward to understand and to be used.

    In this case, personally I would rather have modularity features, make a module myself in place of having similar looking function. Just an opinion .

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)