Multiplayer game design

I need help! I am designing a Map Game using google map as a platform, Php server, Mysql, javascript and HTML.
I dont know how to get players signing-in to the website to see one another (screen names) and be able to chat (problem 1)
I want the system to randomly choose and connect players to play one another (problem 2)
I dont know how to make players connected to share the same screen image and be able to communicate and play the game together. I will really appreciate your responses.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A very simplistic model would do the following:

1) Chat -- When a user sends a chat, it gets added to the database. Have each user's screen refresh every few seconds, possibly with AJAX. Each time, they check the database to see if there is a new message for them to display. If so, display the message and delete it from the database.

2) Random Connect -- Just make sure to keep a database table or field with all the active users and choose from among them.

3) Same Screen Image -- Make sure you have the master data on the server. Then, just check the current data the user has with the master data and update when they refresh. I do not know how to do this with Google Maps, since I have not used it. The concept is clear, but it is difficult to do.

All of these might take up more bandwidth than you want, and it may not be as fast as you'd like. If you can, you should try making network games with more amenable languages, such as Flash or Java.
vivaldinoAuthor Commented:
Thank you Zyloch,  for responding to the questions, though the problem is not yet solved.
1. I  designed a map Game, users need to register to access the page. When a player sign-in, I want the list of players that have signed-in to be listed on the following page. so the players can see the list of players on site and they can chat with one another. I am using Mysql database, PHP on window. thanks.

I would suggest a separate sessions table to hold the current active sessions. Periodically, you can delete sessions that have remained inactive for too long, thus automatically logging out those players. The pseudocode is follows:

When users are logging in
   Connect to database
   Add user and time of login to the sessions table
   Grab the entire sessions table and display

When users perform an action (e.g. automatically retrieve update through AJAX)
   Connect to database
   Update the time for the session to the new time

When users log out
   Connect to database
   Delete the user from the database

In any of these three sections, you can also intersperse the action of deleting inactive sessions from the database. You only need to check the time of the session; if it is too long in the past, then it has been inactive for too long and may be deleted.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

vivaldinoAuthor Commented:
I really appreciate you. I tried to figure it out the way you explained but it did not work. Please can you help me out with sample code. So I can have something to build on.

What do you have, or what have you tried, so far? It would be easier to have something of which to work off.
vivaldinoAuthor Commented:
I have been able to design the website database using PHP, mysql, From the website players need to register, after registration they can now login, all these had been done.  I have a database that holds the name of all players that have registered

not yet done!

after signing-in I want the players to be directed to a page  where can view the list of other players who want to play the game who are online or who had been engaged already playing the game. on this page they can chat fom this page, then they will be engaged to players they will play with from this page.

also connecting the players to play themselves.
Let's take care of the first part. You should create a sessions table, and it should have (at least) the following fields:

id (auto_increment)    userid          login [int(11)]        active [int(11)]

This setup may require that you use a join with your main user table to find the username, for instance.

Since you have knowledge of mysql, it'll be easier to tell you the queries you need instead of all the code. When they first login, you should have a query such as

$time = time();
$qry = 'INSERT INTO sessions (userid, login, active) VALUES (' . $userid . ', ' . $time . ', ' . $time . ')';

Then, at your list of other pages, you can always do

$qry = 'SELECT * FROM sessions, users WHERE sessions.userid =';

where you have to fill in the necessary fields. You can then grab all the results and do a print_r() on them to see what they are.
vivaldinoAuthor Commented:
really appreciate you for the help. I created the table sessions the way you explained, not working yet.  I think it is not working due to the fact that I am misinterpreting your explanation. I posted my code here, may be you can figure out the problem.



if(!$user|| !$pas)
echo'!!! you have not entered all the required details.<br/>'
       .'Please go back and try again.';

@ $db = mysql_pconnect('localhost', 'root', 'vivaldino);

if (!$db)

 echo 'Error: Could not connect to database.  Please try again later.';

      // select the appropriate database
    $mysql = mysql_select_db( 'google2' );
      echo 'Cannot select database.';


  // query the database to see if there is a record which matches
    $query = "select count(*) from cluegame where
              user = '$user' and

  pas = '$pas'";

    $result = mysql_query( $query );
      echo 'Cannot run query.';

    $count = mysql_result( $result,

0, 0 );

    if ( $count > 0 )

// visitor's name and password combination are correct
      echo '<h1>Here it is!</h1>';
      echo 'Welcome to GeoSmart Game.';   }

visitor's name and password combination are not correct
      echo '<h1>GO AND REGISTER!</h1>';
      echo 'You are not authorized to play the game.';

$time = time();
$query = 'INSERT INTO sessions (user, login, active) VALUES (' . $user . ', ' . $time . ', ' . $time . ')';

$query = "SELECT * FROM sessions, users WHERE user = user'";

echo '$user <br>';
echo '$time <br>';


Please I don't know if you have time, I wish to contact you beside this medium to help me out with the code, thank you, really appreciate you.
Andrew BeersTechnology LeadCommented:
I have experienced the best approach to Chat is to use an AJAX control to pass a XML argument back to a PhP control.  It has been ages since I've toyed around with PhP but here goes.

I'll help Zyloch out a bit with the chat explination:

PhP has a cache control, at the time I was using PhP it was not built into the PhP version and had to be installed.  ((Thus I ended up switching to C#))

Your chat object needs to have a few objects.

-From User
-Time Stamp
-Message Content

PublicChat -- Array Implementation
!!This is an array of MessageInstnaces

When a new chat is recieved through the AJAX control you insert it at the 0 index of the array and return the entire array collection parsed into HTML to return it back through the AJAX control, this can then be inserted into a DIV tag that renders the chat.  

This is the simplest way to do it, and I have example code (although it plugs to a C# control) will work the same for a PhP control.

Login:  Test
Passwod: password123

On -- Once logged in using a IE brower, click on Chaos Chat and check it out.  The source can be viewed from the window that it opens.

As far as user validation goes, I've always used session to store this information, you query the database of registered users and validate their login credentials, you then populate a User object and store it in the Session Array.

I have always stayed away from logging chat into a database as it requires too much over head and is unbearably slow with a larger user base.

As for your map questions, if you want users to real-time be able to see eachother there too, you can use another cached control for User locations.  Once again you can see my ajax code on under beta map movement.

Let me know if you are interested in persuing this method, I can explain further if you have more questions.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.