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
Does anyone know why this might be or have I understood the RTScript wrong.
Thanks,
Tyrone.
Best Answer
C
Customer Support
said
about 3 years ago
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.
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
T
Tyrone Mills
said
about 3 years ago
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.
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.
Customer Support
said
about 3 years ago
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
T
Tyrone Mills
said
about 3 years ago
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.
Customer Support
said
about 3 years ago
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(); });
Tyrone Mills
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.
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
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
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
Tyrone Mills
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.
Customer Support
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
Tyrone Mills
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.
Customer Support
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();
});
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2486 topics