Multiplayer game using PHP and mysql

  • Context: PHP 
  • Thread starter Thread starter fosh
  • Start date Start date
  • Tags Tags
    Game Mysql Php
Click For Summary

Discussion Overview

The discussion revolves around the development of a multiplayer game using PHP and MySQL, focusing on enabling real-time player interactions, including visibility of connected players and in-game chat functionality. The scope includes technical implementation strategies and coding challenges related to web development.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes the need for players to see each other and communicate while playing, highlighting the challenge of connecting players who log in at different times.
  • Another participant suggests various methods for implementing the chat feature, including using a database to store messages and making AJAX requests to check for new messages.
  • There are alternative suggestions for using application memory or session variables instead of a database for message storage.
  • Some participants propose using socket connections through Java applets or Flash for real-time messaging, while others mention the possibility of using JavaScript with IFrames.
  • A later reply emphasizes the importance of setting up a MySQL database with a specific table structure for messages and outlines a PHP script to retrieve unread messages based on user input.
  • There is a request for sample code to illustrate the implementation, but one participant declines to provide it due to time constraints, suggesting instead to start with database setup and basic PHP scripting.

Areas of Agreement / Disagreement

Participants present multiple approaches for implementing the chat feature and connecting players, but there is no consensus on the best method or a definitive solution to the challenges posed.

Contextual Notes

Participants discuss various technical options without resolving the specifics of implementation, and there are assumptions about the participants' familiarity with PHP, MySQL, and web development concepts.

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.
 

Similar threads

Replies
13
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
10
Views
22K
Replies
4
Views
3K
  • · Replies 33 ·
2
Replies
33
Views
7K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
12
Views
2K