Page 1 of 1

What kind of IRequest to use?

Posted: 04 Feb 2012, 08:12
by vampir2
Hello everyone

I'm sorry if this question was posted before, but I didn't find anything regarding this.
I'm creating a MMO game. I succeeded creating the connection, the zone and the room, joining the room and sending PublicMessage's in it. But. If I want to send, let's say x and y positions, direction, etc. to the server, what kind of IRequest should I use with sfs.send() for best efficiency?
A brief explanation of this IRequest's arguments will be very nice as well :)

Thanks a lot in advance,
V.

Posted: 04 Feb 2012, 10:03
by vampir2
Okay, on further research I figured out, ExtensionRequest() would be the answer but the onExtensionResponse() doesn't activate... Here is my code:

Code: Select all

SF.addEventListener(SFSEvent.EXTENSION_RESPONSE, onExtensionResponse);

var params:ISFSObject = new SFSObject();
params.putInt("x", 100);
params.putInt("y", 200);
SF.send(new ExtensionRequest("setpos", params));
trace("--------------->>> SENT");

private function onExtensionResponse (e:SFSEvent) {
	trace("--------------->>> RECEIVED");
}
The debug window is showing the "SENT" message but it doesn't show the "RECEIVED" one.
What am I doing worng, or what am I missing?

Posted: 04 Feb 2012, 21:08
by rjgtav
Hi.

I suggest you to read the whole docs here to better learn how SFS works.

The ExtensionRequest is used for communication between the client and server-side extensions. That said, if you just send that request but have no extension in your Zone/Room, then of course you won't get any response.

For sending data to the other players which are joined in the same room as you, I suggest you to use the ObjectMessageRequest.

Posted: 05 Feb 2012, 08:39
by vampir2
Thank you for your answer.
I just tried what you suggested with the ObjectMessageRequest(), like this:

Code: Select all

SF.addEventListener(SFSEvent.OBJECT_MESSAGE, onObjectMessage);
var params:ISFSObject = new SFSObject(); 
params.putInt("x", 100); 
params.putInt("y", 200);
SF.send(new ObjectMessageRequest(params));

private function onObjectMessage (e:SFSEvent) {
	trace("------------------------------------------Object Message Received!");
}
Still doesn't work for me. Actually after posting my previous post, I've tried this out out as well... no luck.
But I've found a way around it. Since PublicMessageRequest() also accepts a SFSObject, I'm using that one. In the event handler function I check if there is a SFSObject, then I handle it as a command (the message text acting as a command identifyer), if not, it is handled as a simple message.
I'm just wondering if this will have a hit on the performance instead of using an ObjectMessageRequest()?

Posted: 05 Feb 2012, 22:37
by rjgtav
Well, when you send an ObjectMessageRequest, only the other users will get the OBJECT_MESSAGE event.

The problem of using public messages is that they can be hacked easily, for example, if a player sends that command in a simple chat, the game will think that it was a command, but then it wasn't.

Posted: 06 Feb 2012, 08:29
by vampir2
I see now the problem with ObjectMessageRequest() :) thanks for clearing it out for me. And thanks for the prompt support as well.
I think I'll use the PublicMessageRequest(), because when a player -let's say- moves, it also happens sending the new coordinates to the server and then i get it back and then move. I guess this way I'll always be in synch with the other players.
Well, I solved the problem of user-entering-command, because the game checks if there is an object attached to the message, only then it takes the message as a command. And players will not be able to attach objects.
The other way could be to append a character to the message that players cannot enter in the chat.

If I'm doing something too complicated, please let me know :) This forum has a wonderful support!

PS: I succeeded making a application that gives every user a ball that he/she can move. Until now it works well. I also made my own sfs class that makes everything for me and eases the use.

Posted: 06 Feb 2012, 23:00
by rjgtav
Well, my only suggestion is really to use the ObjectMessageRequest() method instead, and leave the PublicMessageRequest for public chat ;-). In the SFSObject that you send on the ObjectMessageRequest, one of its parameters could be called "cmd", which represents the command to be sent.

Posted: 07 Feb 2012, 05:44
by vampir2
I would love to use ObjectMessageRequest(), after all it was created for that specific task... but I also want to keep this system: I click, the coordinates go to the server, the server tells everyone online where I clicked, including myself. And my character goes there.
Is there a way to do that with ObjectMessageRequest()? Or the only way is that I tell the server where my character goes, and the server tells everyone online but me. And my character acts directly on the command from me. And after that I sync them on-the-fly.

Posted: 07 Feb 2012, 20:06
by rjgtav
What do you mean with "tell the server"? You handle it with an Extension? If so, I suggest you to use an ExtensionRequest instead. If you send an ObjectMessageRequest it also sends that info to every user in that room.

Re: What kind of IRequest to use?

Posted: 21 Feb 2012, 11:05
by itsmylifesoham
hi vampir2,

is it that you want to use publicmessage request becoz it is notified to the sender also?
an objectmessage request will not fire a object_message event to the sender himself.

the thing is the kind of sync you are looking for is never gonna be there.
even though you use publicmessagerequest you cant be perfectly sure that all received the coordinates exactly at the same time including you.

so i do not see any harm in moving your character yourself on click and dispatching event as objectmessagerequest to others. i knw there will be delay from character moving on your screen,and the same character moving on others' screens but there are other ways to get the kind of sync that you want, its not really using the publicmessage request that will give you exact sync between all clients.

just my 2 cents. :)