[Suggestion] Multiplayer RelayToPeer

Discussion and feedback on Construct 2

Post » Sat Aug 30, 2014 2:16 pm

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?
B
31
S
7
G
8
Posts: 232
Reputation: 6,274

Post » Sun Aug 31, 2014 5:39 am

cacotigon wrote: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.
Capture.JPG


cacotigon wrote: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.
You do not have the required permissions to view the files attached to this post.
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Sun Aug 31, 2014 10:07 am

@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.
B
31
S
7
G
8
Posts: 232
Reputation: 6,274

Post » Sun Aug 31, 2014 12:01 pm

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 :D.
B
28
S
8
G
4
Posts: 553
Reputation: 4,924


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 13 guests