As the title suggests really, I've started to notice an error when a WebGL client is sending others numbers of different sizes inside of an SFSObject.
For example Horse ID is stored as a Long, however when sent from a WebGL client it can only be read as an int otherwise will cause a classcastexception
It's the same when I send a Short, it will only allow me to read it if I read it as an int. To keep data transfer to a minimum it is very useful for me to be able to use Short variable types, and as Horse ID's are likely to exceed 2.14billion, I need to use the Long data type. What's going on here?
PutLong / PutShort Appears largely meaningless sent from WebGL
-
- Posts: 90
- Joined: 28 May 2008, 13:36
-
- Posts: 90
- Joined: 28 May 2008, 13:36
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
Just an update to this, it appears that so long as the SFSObject is not created by the WebGL user it works ok and WebGL can read Long and Short values from an SFSObject, they just can't write them without them then all having to be read as int values.
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
Hi,
are you using the latest API available (1.7.2)?
If not please update from here:
http://www.smartfoxserver.com/download/sfs2x#p=client
thanks
are you using the latest API available (1.7.2)?
If not please update from here:
http://www.smartfoxserver.com/download/sfs2x#p=client
thanks
-
- Posts: 90
- Joined: 28 May 2008, 13:36
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
This was my first thought too and went and updated straight away and am getting the same result. If this was a previously known issue and is patched I will double check it all when home and test it again
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
Yes please, check again with the latest API and let us know.
-
- Posts: 90
- Joined: 28 May 2008, 13:36
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
It's definitely running 1.7.2 at the moment (added a command to the games chat to output the current version of the SFS Client and it reports 1.7.2)
I've noticed that if it's only WebGL users running together, it runs fine. The problem comes when a WebGL client is sending information to a non-webgl user (iOS, Android, PC, Mac)
An example of code thats causing the offending behaviour. This is called when the host wants to tell all clients the AI Updates that will come into effect in 30 frames time. Again, this works fine when it's two WebGL clients talking to one another, but does not work when a WebGL client is sending this to a non-WebGL client.
Looking at the release notes on the patches on the server side, seems relevant to mention that I'm using 2.12.3
I've noticed that if it's only WebGL users running together, it runs fine. The problem comes when a WebGL client is sending information to a non-webgl user (iOS, Android, PC, Mac)
An example of code thats causing the offending behaviour. This is called when the host wants to tell all clients the AI Updates that will come into effect in 30 frames time. Again, this works fine when it's two WebGL clients talking to one another, but does not work when a WebGL client is sending this to a non-WebGL client.
Code: Select all
SFSObject obj = new SFSObject ();
obj.PutSFSArray (MiscFieldNames.HORSES, horseUpdates);
obj.PutShort ("f", Convert.ToInt16 ((short)this.framesPassed + (short)30));
base.sendHorseUpdatePackage (ServerRequests.RACE_HANDLE_MESSAGE_BOUNCE_INFO, obj);
Looking at the release notes on the patches on the server side, seems relevant to mention that I'm using 2.12.3
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
The issue you are experiencing is due to the fact that WebGL (and also our native JavaScript API) uses a text protocol based on JSON, while all other clients use a binary protocol. This will change in the future (all clients will use the binary protocol), but at the moment you have to deal with it.
The issue with the JSON protocol is that there's no way to differentiate numbers (because in JavaScript you just have Number, not Byte, Short, Int, etc), so all those up to 32 bits are transported as integers. The API makes auto-conversions when you do obj.getShort (both on the client and the server when it receives an object from a WebGL client), but at the core of the SFSObject the number is still represented as an Int.
Everything works fine until your Extension forwards an object received from the WebGL client to other clients directly. In fact, the other clients will decode the object as it is, so containing an integer and not a short.
The only workaround to this issue is to rebuild the object like this before forwarding it to the other clients (whether they are WebGL or not):
The issue with the JSON protocol is that there's no way to differentiate numbers (because in JavaScript you just have Number, not Byte, Short, Int, etc), so all those up to 32 bits are transported as integers. The API makes auto-conversions when you do obj.getShort (both on the client and the server when it receives an object from a WebGL client), but at the core of the SFSObject the number is still represented as an Int.
Everything works fine until your Extension forwards an object received from the WebGL client to other clients directly. In fact, the other clients will decode the object as it is, so containing an integer and not a short.
The only workaround to this issue is to rebuild the object like this before forwarding it to the other clients (whether they are WebGL or not):
Code: Select all
ISFSObject outParams = new SFSObject();
outParams.putShort("f", params.getShort("f"));
send(cmd, outParams, recipients);
Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
-
- Posts: 90
- Joined: 28 May 2008, 13:36
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
Have got this updated now and seems to work ok so far! Thank you for your help!
-
- Posts: 90
- Joined: 28 May 2008, 13:36
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
Is there a way to make this apply do SFSObjects that go with PrivateMessageRequest?
This is my attempt so far which doesn't seem to work:
Looking at the server logs, I can see that this code is being ran when users send PrivateMessageRequests to one another
However as soon as we hit this bit of code:
It breaks complaining about it not like the Long variable type.
This is my attempt so far which doesn't seem to work:
Code: Select all
public class HandlePrivateMessage extends BaseServerEventHandler {
@Override
public void handleServerEvent(ISFSEvent aEvent) throws SFSException {
// TODO Auto-generated method stub
SFSObject customMessage = (SFSObject) aEvent.getParameter(SFSEventParam.OBJECT);
trace("Handling private trade message");
if(customMessage.containsKey(MiscFieldNames.PRIVATE_TRADE_MY_HORSE)) {
trace("Checking to see if I have a horse");
SFSObject obj = (SFSObject) customMessage.getSFSObject(MiscFieldNames.PRIVATE_TRADE_MY_HORSE);
trace("Checking if I have ID");
if(obj.containsKey(HorseFields.FIELD_ID)) {
trace("I have ID");
obj.putLong(HorseFields.FIELD_ID, obj.getLong(HorseFields.FIELD_ID));
} else {
trace("I don't have ID");
}
if(obj.containsKey(HorseFields.FIELD_XP)) {
obj.putLong(HorseFields.FIELD_XP, obj.getLong(HorseFields.FIELD_XP));
}
if(obj.containsKey("Mother")) {
obj.putLong("Mother", obj.getLong("Mother"));
}
if(obj.containsKey("Father")) {
obj.putLong("Father", obj.getLong("Father"));
}
customMessage.putSFSObject(MiscFieldNames.PRIVATE_TRADE_MY_HORSE, obj);
}
}
}
Looking at the server logs, I can see that this code is being ran when users send PrivateMessageRequests to one another
However as soon as we hit this bit of code:
Code: Select all
SFSObject obj = (SFSObject)aPrivateTradeObject.GetSFSObject (MiscFieldNames.PRIVATE_TRADE_MY_HORSE);
try {
if (obj != null && obj.GetLong(HorseFields.FIELD_ID)>0) {
It breaks complaining about it not like the Long variable type.
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
andrew2110 wrote:However as soon as we hit this bit of code:Code: Select all
SFSObject obj = (SFSObject)aPrivateTradeObject.GetSFSObject (MiscFieldNames.PRIVATE_TRADE_MY_HORSE);
try {
if (obj != null && obj.GetLong(HorseFields.FIELD_ID)>0) {
It breaks complaining about it not like the Long variable type.
Can you please show the the dump of that object? -- obj.GetDump()
Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
-
- Posts: 90
- Joined: 28 May 2008, 13:36
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
No problem, I've included it on both the server side to show on the server side at least it thinks everything that needs to be of type "long" is of type "long", but when it gets back to the client side (this is going WebGL -> Server -> Windows Client), it's as if the packet is untouched by the server. I guess the next thing I could test is to change a variable in the SFSObject and see if changing that variable on the server side is possible at all?
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
There's a chance you can't modify the custom data object in messages like that.
We suggest to go a different way: instead of sending a private message directly, call the Extension, change data the way you need and send that private message from the Extension.
We suggest to go a different way: instead of sending a private message directly, call the Extension, change data the way you need and send that private message from the Extension.
Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
-
- Posts: 90
- Joined: 28 May 2008, 13:36
Re: PutLong / PutShort Appears largely meaningless sent from WebGL
Thank you for getting back to me, the PrivateMessageRequest stuff is just so ideal for this scenario I've just gone and made it so that the data can be converted to bytes, then a string, then converted back the other way on the other side without having to worry about it.
Who is online
Users browsing this forum: No registered users and 28 guests