Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] Multiplayer interaction

Started by menyo Jun 11, 2010 at 12:46 PM 5 replies 1.4k views
Original Post
menyo
menyo
Hi,

I was wondering how i can make interactions that other users can pick up? How do i pass information to another user? For example:

1. Player A clicks on Player B's name in a window and chooses to attack this player.

2. Player B gets a message in his screen and chooses yes.

3. Server rolls dice on who may start ans passes this to both players.

4. First players chooses what he wants to do and clicks finish.

5. Other player gets a go to make his move.

I am using PHP, AJAX, &#106avascript and MySql. But i can't find anything on how to approach this. Maybe i'm using the wrong search terms so enlighten me on what functions i should use?<br/><br/>With my knowledge i can get this to work with AJAX requests. I would make a fight toggle for the player and ajax keeps queriing the server if that toggle has been set, if so that message would appear that he got challanged. Then for the turns the same, keep doing AJAX requests to see if the finished turn toggle is set.<br/><br/>Would this be the way to go? Or are there other sollutions that are more efficient, practical and better?<br/><br/><!--EDIT--><span class="editedby"><!--/EDIT-->[Edited by - menyo on June 11, 2010 1:23:47 PM]<!--EDIT--></span><!--/EDIT-->
ID Merlin
ID Merlin
One of the Ajax tricks I've seen to reduce server load is to increase your checking interval each time there is no action/change. So, the first interval might be 5 seconds, the second 10 seconds, the third 20, etc. Or you may want to use a linear increase - whatever works best for your game.
Bahlor
Bahlor
COMET is the way to go for, can easily be achieved using node.js. There are plenty of tutorials out there. :)
Vini,Vidi,Vici (Gaius Iulius Caesar)
CodeMunkie
CodeMunkie
I agree with Bahlor. Forget Ajax, go Comet. It reduces unnecessary polling and allows the server to provide an almost instantaneous response when there is new activity.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
menyo
menyo
Hmmm comet sounds interesting but since i'm fairly new and VERY excited with ajax i want to stick to stick to ajax first and try to get some simple things going allong multiple users. I just read an article about long polling, and it seam i have been doing that already in another code i wrote to get user position x,y each 2 seconds and display them.

Still i'd like to know some more about comet, i have read some articles about it but it seems to be user unfriendly, obviously you think it's a great tool for long polling so i'd like to know from more people about comet.

Also, what exactly does comet? If i want to get data from the server i need to query it anyway. If i want to get data each second i have to do that anyway. So why not just make a &#106avascript that requests a .php file with the query in it each second?
Bahlor
Bahlor
COMET takes away a big problem on the internet, everything gets polled. With COMET the data gets pushed when new data for a user arrives. With this, you can cut traffic to a minimum. Another Ajax-problem is, if you request too many things at once, it wont work, some browsers don't allow more than 2 connections at once (per site / server) and if there are too many requests per second of each user, your server might get problems. (AJAX-Overpolling)

Longpolling is already a primitive COMET-method.

For the future, I recommend using HTML5 Websockets for real-time connection. If a browser doesn't support HTML5 you could still use a flash-bridge that will be used as alternative method for non-supporting browsers. We are currently using this method in our real-time browsergame with good success. Every browser is supported and new browsers with websockets, don't even need any plugin to get real-time gameplay. On the serverside we're just using a node.js as socket-server which is highly performant and can support many more users than normally with ajax. We can make it really complex with many data to be delivered, without any high traffic. Great way! :)
Vini,Vidi,Vici (Gaius Iulius Caesar)
unknownhero
unknownhero
I would suggest sticking with Ajax till you figure out how to do interactions. Comet can wait till later.

I think the best way to plan out interactions between two players who are looking to do battle with each other is to make it like a boxing match with the server as the referee.

Ultimately the server has control over the fight and can decide to end it or throw the fight. The players are just two boxers in the ring who can only do one action at a time.

1. Player A starts fight with player B
2. Player B accepts.
3. Server creates a row in a database or sets something in memory. This is the state of the fight.
4. Player A throws punch. Server accepts
5. Player B blocks Server accepts
6. Both actions accepted, server computes the results and puts them in the database. Both players now see the result of their move and decide on the next action. Ajax is working in the background to keep players up to date of whats happen.


Each step is lockstep to the previous step. One action cannot be done without the other action.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.