Page 1 of 1

Intercept object message within extension

Posted: 02 Dec 2011, 17:19
by alex_h
Hi,

I have a zone extension and a room extension written in Java.
Inside my game room (in flash), my users send object messages to each other that describe their x & y co-ordinates, movement vectors and a timestamp.
I have now found that it would be useful to also store the x & y values as user variables, so that I can retrieve that information directly from a user object client side.
I would prefer not to stop using object messages to send the x & y, but I don't want to send user variable updates in addition to the object messages.
Is it possible for my room extension to intercept the object messages, and copy the x & y information into the user variables server side?

thanks,

Alex

Posted: 02 Dec 2011, 18:46
by rjgtav
Hello. No, extensions can't intercept object messages.

But why don't you use only UserVariables instead? When you update them, the update also is broadcasted to all the players in the same room :-)

Posted: 05 Dec 2011, 09:12
by alex_h
The reason I want to use object messages rather than user variables is that I want to send a timestamp with each message (the number of millliseconds since the start of the game) in order to help keep things synchronised as far as possible. I can then compare the remote time and local time with each incoming message, and consider the players x & y vectors to work out where they are likely to be now, rather than where they were when the message was sent. I then incorporate this into their existing motion to smoothly correct for lag.

This is working great with object messages, but leaves me with the problem that I can't query a client side User instance for its x & y position. So when a new player joins an existing game, he doesn't know where to initially position the players on screen.

Thinking about it though, if I use object messages to send x & y info and also set user variables then the information is going to be begin transmitted from the server to the client twice! I think that instead I'll probably have to create an extension that allows me to handle all of this somehow. Ideally I do want use user variables, but also bundle each update of them all into one message from the server that comes through with my custom time-stamp added. Provided it is possible to update a user variable on the server without automatically sending the update message (so that I can send my own custom one) then I think this could work.

cheers,

Alex

Posted: 05 Dec 2011, 14:22
by alex_h
OK, I have this working using a request handler on my room extensions now.

Seems a bit weird that I can't add an event handler to my room extension to catch object messages though? Or at least if I can catch object messages I can't see how I could access the SFSObject that holds the message data.

Posted: 05 Dec 2011, 19:39
by rjgtav
Hi.

Yes, you can't listen to ObjectMessageRequests. In order to use the extension, you have to send an ExtensionRequest from the client and then the extension will do the job from there.

So, in this case, every time an user wants to update its position, it sends an ExtensionRequest with the timestamp and both x and y values. Then, the extension could send to all the other users an ExtensionResponse with all those parameters and could also update the user variables and not firing the client events.

Posted: 06 Dec 2011, 09:44
by alex_h
Yup, that's exactly what I have set up - it seems to be working perfectly so far!
Thanks for your reply.

cheers,

Alex