Web Browser MMO QUESTION

Joined
Aug 4, 2010
Messages
573
Reaction score
178
Hello

I need a serious answer from the pros or whatever for this question. I'm curious when making a MMORPG like the 2D ones you see in the web browser with characters that are able to walk around and interact with each other.

This game is made in Javascript,Jquery and PHP. I already got the character moving and etc able to do interactions with a different person that I provided but offline so its a bot.

Anyhow how can I get more then 1 player ( online player ) to be shown at once along with how should I manage where the players spawn each time they login etc. Databases of course are used but how do I actually get two players or more on the screen from different people I'm not sure on how to approach this.

Feedback feedback Fback.
 
You're better off using something more persistent than PHP+MySQL for a server. NodeJS would do this very well, though you would find correctly using a NoSQL database on top of PHP+MySQL would also be an improvement from your current setup.

That being said, if we're just using PHP+MySQL, every action should be sent to the server which, in most cases, will update the database. When sending back the response to the player, i.e. what they see, you should also check for any nearby players data, found in the database, and show it as well.
 
Thanks I got that clear but like how does the game work, I.E how will the database know to output another character image per say. Each time a new person logs in it prints out a new character in game. I understand how to do it offline of course but I still don't understand and I really want to understand because learning new things is the way to go in life.

If you or others could explain more in depth I would definitely appreciate it not that I didn't appreciate your previous reply.
Thank you
 
Thanks I got that clear but like how does the game work, I.E how will the database know to output another character image per say. Each time a new person logs in it prints out a new character in game. I understand how to do it offline of course but I still don't understand and I really want to understand because learning new things is the way to go in life.

If you or others could explain more in depth I would definitely appreciate it not that I didn't appreciate your previous reply.
Thank you

Do note that my aforementioned explanation and the following explanation are what I'm coming up with off the top of my head for a solution that uses only PHP and MySQL. I very much so recommend getting something more persistent in the mix as well, or things could get very messy quite quickly.

Consider the following:
The game world, i.e. the places a character can be, has a grid. This grid has an X and Y coordinate.
The game logs many actions the character takes, including moving. Many variables, including the character's current X and Y coordinate, are saved to the database on every action.
After a player does an action, the server gets ready to show a response to the user. This usually will update the user's browser display in some fashion.
Part of this response will entail looking for other character's that are within 5 coordinate points away from the player. It will find all the characters, look at the actions they performed, and relay this back to the player via showing multiple characters on the map (rather than just the current player's character).

Does that help?
 
You should use WebSockets- Be it with PHP or Node.JS, or any server, really. As much as I hate arguing with Timebomb, his answer only clouds the correct solution with a lesser.. solution. I believe he tried to explain that around the top section of his second answer.

Node.JS seems to be the best equipped technology (at the moment) to create this sort of web app. However, I keep wanting to try this thing called Ratchet for PHP web sockets.. Never get around to coding PHP though. And tbh, I can't see yet how a PHP program would handle running for long periods of time and handling the job of the server with PHP's current garbage collection system. Even if you are using PHP for some things, it doesn't hurt to use Node.JS for the real-time aspects of the game.
 
Last edited:
You should use WebSockets- Be it with PHP or Node.JS, or any server, really. As much as I hate arguing with Timebomb, his answer only clouds the correct solution with a lesser.. solution. I believe he tried to explain that around the top section of his second answer.

Node.JS seems to be the best equipped technology (at the moment) to create this sort of web app. However, I keep wanting to try this thing called Ratchet for PHP web sockets.. Never get around to coding PHP though. And tbh, I can't see yet how a PHP program would handle running for long periods of time and handling the job of the server with PHP's current garbage collection system. Even if you are using PHP for some things, it doesn't hurt to use Node.JS for the real-time aspects of the game.

My lack of an elaboration as to better solutions is linked to the perceived probability of WizCoder actually being willing to learn and able to use Node.JS (or alternatives). In other words, I felt that it wasn't worth my time.

I haven't heard of Ratchet before. It's based off of React apparently. React is an "event-driven, non-blocking I/O." I wouldn't touch it in a serious project. I'd be scared to see what happens when you try to run PHP like that, hah. If I need that functionality, I'll stick to Node.JS.
 
You're better off using something more persistent than PHP+MySQL for a server. NodeJS would do this very well, though you would find correctly using a NoSQL database on top of PHP+MySQL would also be an improvement from your current setup.

That being said, if we're just using PHP+MySQL, every action should be sent to the server which, in most cases, will update the database. When sending back the response to the player, i.e. what they see, you should also check for any nearby players data, found in the database, and show it as well.
Do note that my aforementioned explanation and the following explanation are what I'm coming up with off the top of my head for a solution that uses only PHP and MySQL. I very much so recommend getting something more persistent in the mix as well, or things could get very messy quite quickly.

Consider the following:
The game world, i.e. the places a character can be, has a grid. This grid has an X and Y coordinate.
The game logs many actions the character takes, including moving. Many variables, including the character's current X and Y coordinate, are saved to the database on every action.
After a player does an action, the server gets ready to show a response to the user. This usually will update the user's browser display in some fashion.
Part of this response will entail looking for other character's that are within 5 coordinate points away from the player. It will find all the characters, look at the actions they performed, and relay this back to the player via showing multiple characters on the map (rather than just the current player's character).
Well, I would not talk to the database on each players step. It is better to hold the map data with the player coordinates in memory and store them maybe every x minutes to database. Imagine a few hundred or thousand players moving all at once... your database will be overloaded.
What are you trying to solve by NoSQL anyway? If data consistency/integrity (imagine he want introduce a dupe-free item system) gets a concern, it will be easier to solve with SQL.
 
Last edited:
Well, I would not talk to the database on each players step. It is better to hold the map data with the player coordinates in memory and store them maybe every x minutes to database. Imagine a few hundred or thousand players moving all at once... your database will be overloaded.
What are you trying to solve by NoSQL anyway? If data consistency/integrity (imagine he want introduce a dupe-free item system) gets a concern, it will be easier to solve with SQL.

I'm quite aware of all this. A client-server relation as WizCoder is trying to create shouldn't be done in PHP+MySQL, but it isn't impossible. I gave him very basic instructions as to how to implement this with nothing other than PHP+MySQL, while also relaying that it was not a good idea.

Ideally some sort of quick, highly-scalable storage solution should be paired with a relational database, not one or the other. For the data that doesn't need to be assured ACID-compliant, you don't have to and often shouldn't put it in the relational database, though it's all situational.
For example, if necessary, data retention can be improved by syncing portions of whatever non-relational database solution you use with the relational database at certain time intervals.

I'm glad to see that WizCoder is looking into a more suitable solution rather than sticking with PHP+MySQL.
 
Back