PHP Multiplayer game using PHP and mysql

  • Thread starter Thread starter fosh
  • Start date Start date
  • Tags Tags
    Game Mysql Php
AI Thread Summary
The discussion focuses on developing a map game using PHP and MySQL, specifically addressing the challenge of enabling players to see and chat with each other while playing. Key points include the need for a chat feature that allows real-time messaging between players. Suggestions for implementation include storing messages in a database and using AJAX to periodically check for new messages. An alternative approach involves using application memory or session variables to manage messages. Additionally, options such as Java applets or Flash for socket connections are mentioned, although AJAX is recommended for its efficiency. The conversation also emphasizes the importance of setting up a MySQL database to store messages with relevant fields and creating a PHP script to handle message retrieval based on user queries. The use of JavaScript's setTimeout for regular AJAX requests to fetch unread messages is highlighted as a crucial part of the implementation.
fosh
Messages
2
Reaction score
0
I am designing a map game, using PHP and MYSQL. I don't know how to make the players who sign-in to the website to see other players who are also connected to the site and be able to chat with one another.

I want to design the game in such a way that 2 players can play with each other and be able to send messages during the game while others groups are playing at the same time.

I have designed the map game successfully, but the problem is making the player 1 who log-in to site to see the player 2 who will also log-in and both can get connected to play each other.

I will appreciate your responses.
 
Technology news on Phys.org
You have many options. For example, for the chat feature you can store all messages in a database. On the client side you would then make AJAX requests every X seconds to a PHP script which checks the database for new, unread messages and returns them, if any.
You might be able to just store the messages in the application's memory space, rather than in a Database, using Application Scope variables or Session variables.
If you go with the AJAX option i recommend a "Reverse Ajax" approach to avoid lots of unnecessary traffic.

Besides a PHP/Ajax implementation you also have the option of using a Java applet or a flash movie. With either of these two you are able to use socket connections. You would make a socket connection to your PHP script (or possibly your own custom server) to obtain the unread messages

You are also able to use Javascript with IFrames instead of AJAX as well.
 
Job thanks for the response,
please can you help with a sample code just for illustration.
 
Sorry but i really don't have the time to write sample code for a 3 layer app.
Why don't you start by creating a MySQL database with a table for storing messages (i.e. the table will need fields for Message Body, Sender, Receiver, DateSent, HasBeenRead, etc).

Then create a PHP script which captures variables (from the QUERYSTRING or FORM collection). You'll use these variables to tell the PHP script what to do.
i.e. myscript.php?action=getUnreadMessages&user=fosh
Which would retrieve the unread messages for user fosh. The PHP script would connect to the database and do a select of all rows in the Messages table which have been sent to user Fosh and which have not yet been read.

Once you have that set up i can help you more closely with the (forward) AJAX portion. You'll use javascript's setTimeout to perform Ajax requests every x seconds to myscript.php with the necessary querystring variables.

The php script will return the messages, which are returned from the Ajax request and finally displayed to the user with Javascript.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top