Sign In Register

How can we help you today?

Start a new topic
Answered

Edit packet in RTScript

Hi,

This is the first project I have used GS on currently I am trying to add the server time to a packet sent from one client before broadcasting it to other clients. However the packet I receive on the client end is identical to the original sent by the other player. 

The server doesn't appear to be altering the packet in any way.


RTSession.onPacket(100, function(packet){

    

    var rtData = RTSession.newData().setNumber(1, packet.getData().getNumber(1)) //Return the time the packet was sent

                                    .setNumber(2, new Date.getTime())                                  

                                    .setNumber(3, packet.getData().getNumber(2)) //Return the message number that this was

                                    .setFloatArray(4,packet.getData().getFloatArray(3))

                                    .setFloatArray(5,packet.getData().getFloatArray(8));

    RTSession.newPacket().setData(rtData).setOpCode(100).setTargetPeers().send();

})


Does anyone know why this might be or have I understood the RTScript wrong.


Thanks,

Tyrone.


Best Answer
Hi Tyrone,

I believe there might be an error in your script above, for date objects you'll need to call them like so, new Date().getTime(); would you be able to try correcting this and do let me know how you get on.

Kind regards,
 - Steve

 


Answer
Hi Tyrone,

I believe there might be an error in your script above, for date objects you'll need to call them like so, new Date().getTime(); would you be able to try correcting this and do let me know how you get on.

Kind regards,
 - Steve

 

Hi Steve,


Thank you that was definitely part of it.

Now some packets come through having been modified. But some client packets that use the same opCode come through with out having been altered at all.

From Unity debug:

OpCode=100,Sender=0,streamExists=False,Data{[1 long] [2 long]...}

OpCode=100,Sender=2,streamExists=False,Data{[1 long] [2 int]...}

The data at position 2 for Sender 2 isn't being changed into a long representing server time. This is also only happening when the packet is sent from Sender 2. Packets from Sender 0  are all being correctly modified.


Thanks,

Tyrone.

Hi Tyrone,

 I don't believe this is an error, how are you sending these packets initially from the client? Are you sending them directly and only to the server or is every client sending each packet to every other client? If it is the later then this would make sense, a packet from client A being sent to client B directly will never have been processed by the server, hence will never have been modified, does this make sense? Packets from Sender 0 is the server, this is why these packets are getting correctly modified. I hope this helps.

Kind regards,
 - Steve

 

Hi Steve,


That seems to have been the case thanks.


Is there a way of getting the original sender of the packet from within the packet itself? I am currently adding it to the packet data on the server before sending the packet on.


Thanks,

Tyrone.

 Hi Tyrone,


Yes this is perfectly possible, from the client you can access the sender from inside the RTPacket received by OnPacketReceived like so below, and I've also provided the code you'd need to access this from the rtScript on the server below. I hope this helps.


Kind regards,

 - Steve


// Client

OnPacketReceived(RTPacket p)

{

    var senderPeerId = p.Sender;

}


// rtScript (Server)

RTSession.onPacket(100, function(packet){
    var peerId = packet.getSender();
});

Login to post a comment