Solved

Multiplayer game design

Posted on 2007-03-28
11
240 Views
Last Modified: 2012-06-21
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.

0
Comment
Question by:vivaldino
  • 4
  • 4
11 Comments
 
LVL 36

Assisted Solution

by:Zyloch
Zyloch earned 250 total points
Comment Utility
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.
0
 

Author Comment

by:vivaldino
Comment Utility
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.




0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
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.
0
 

Author Comment

by:vivaldino
Comment Utility
Zyloch,
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.

Vivaldino
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
What do you have, or what have you tried, so far? It would be easier to have something of which to work off.
0
 

Author Comment

by:vivaldino
Comment Utility
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.
0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
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 = users.id';

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.
0
 

Author Comment

by:vivaldino
Comment Utility
Zyloch,
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.
<?php
<html>
<head>
<title></title>
</head>

<?php

 $user=$_POST['user'];
 $pas=$_POST['pas'];
 

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



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

 
if (!$db)
 
 {

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

      // select the appropriate database
    $mysql = mysql_select_db( 'google2' );
    if(!$mysql)
    {
      echo 'Cannot select database.';
      exit;
    }

 

  // 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 );
    if(!$result)
    {
      echo 'Cannot run query.';
      exit;
    }

    $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.';   }
    else
    {
      //

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>';


?>
</html>


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.
0
 
LVL 10

Accepted Solution

by:
Andrew Beers earned 250 total points
Comment Utility
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.

MessageInstance
-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.

Use
Login:  Test
Passwod: password123

On www.chaosbattlegrounds.com -- 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 chaosbattlegrounds.com under beta map movement.

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

~Aqua
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Network ports are the threads that hold network communication together. They are an essential part of networking that can be easily ignore or misunderstood, my goals is to show those who don't have a strong network foundation how network ports opera…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now