Sign In Register

How can we help you today?

Start a new topic

Packet created on server, is sent to sender.

Not sure if this by design, but it is quite odd that it works this way. Consider the following:

 

RTSession.onPacket(99, function(packet)
{
    var peerId = packet.getSender().getPeerId();
    var responseData = RTSession.newData().setNumber(1, 9999);
    
    RTSession.newPacket().setOpCode(99).setData(responseData).setSender(peerId).send();
});

 

The above code will send the packet to ALL connected players, including the sender that was set before sending. It is simple enough to loop through like so:

  

var players = RTSession.getPlayers();
var targets = [];
        
for (var i = 0; i < players.length; i++)
{
    if (players[i].getPeerId() !== peerId)
        targets.push(players[i].getPeerId());
}

if (targets.length > 0)
    // send the packet

 
However, logically, it is quite odd that the packet is sent to the sender, if the packet is sent via Cloud Code, by default. 


Basically, I have the client send a peer packet first to the server, the server validates it and then, if valid, forwards it on.

I considered pulling the original packet's targetPeers and setting those peers on the new packet, but if only one player is connected - the targetPeers will be empty (as the server was the only original target) and the backend sees that as "no targets, send to all" and again the sender receives the packet.

Login to post a comment