August 13th, 2009, 05:24 PM
Best way to manage multiple player data?
I'm attempting something somewhat insane right now, making a multiplayer online game with a flash client that will let you play a top-down type of game where you will be able to see other people.
I know pretty much how I would do everything, except one thing: storing and retrieving the data for where a given player is in the world.
Since I know PHP and MySQL, my initial thought is instantly, "Let's utilize what I know". The problem I see, though, is this: Multiple times a second, every player would be requesting the locations of other players near them, and updating the position of their characters in the database. I know a server can handle a, but this much? Is this feasible?
The basic query would be simply requesting data on all players within a certain range of you. The thing is, it would have to be sent multiple times (5 or so?) times a second to keep the game looking smooth. And then every time you moved, which could be multiple times a second as well (think of 'moving' as going one square in a direction... like pokemon...)
Would this be too much? Is there another, more efficient way?
I can give additional info if needed.
August 13th, 2009, 05:48 PM
It often helps to try and move as much of the work load off the server and onto the clients. For example, it might be possible to give the server higher-level commands from each client, like "Walk to (x,y)" or "Attack player z", and pass that on to the other clients, which take it and turn it into the actual step by step movements using pre-defined rules. Ultimately, as you are aware, everything that every client does must get to every other client, and the best way is through the server, so the more you can reduce the size of that information, the better.
August 13th, 2009, 06:12 PM
I have two problems here:
Originally Posted by paulscode
First off, I don't know how to go about communicating directly from client-to-client in any way, so I'd need some guidance on where to start from there. And I need to know how to do it with Flash, because the idea for this is that you don't have to download it.
Secondly, having actions analyzed by the client isn't really a good idea to an extent for me, mainly because sooner or later I'll come across some pro hacker who'll get up to something. Thus, any action needs to be validated by the server to make sure it isn't an illegal move.
August 13th, 2009, 06:28 PM
An option to reduce the impact of this when you have a large number of players would be to have only a certain number of players in a game at one time. A bit like a poker game. You don't need to worry about where 10's of player are and send their positions to every client if there are only say 5 in a particular instance of the game. Just a thought, might not work for what you have in mind but worth considering.
August 14th, 2009, 06:03 AM
I can't help youmuch with the communications part for Flash (I'm more of a Java man myself). But you are right about hackers being a concern (especially if your game becomes popular at all). There are several tactics you can employ to combat hackers:
1) Look for things with a huge potential to be exploited, and move those decisions to the server-side (for example, you don't want the client to be able to send a command to the server that says "I won!")
2) Do sanity checking of commands server-side (for example, if the client is trying to "teleport" across the map, the server could recognize the position as being too far away).
3) Add updatable encryption to your communications. This should include client verification (the server sends a random string to the client, and the client sends back a response based on some encryption algorithm).
4) Adapt to hackers and provide continuous security updates. Even the best written program has vulnerabilities, so when you notice something being exploited, write a fix and release an update to combat it.
August 19th, 2009, 12:16 AM
There are a few ways to connect players togethor. The most popular way is to have a server on a single machine that everyone reports to. The clients merely act as a remote control, and all of the action happens on the server, then is reported back to the clients for showing. The server is responsible for determining if a move is valid, or if a player was hit, etc. The client is not allowed to determine on it's own if a move is valid, if a player was hit, or how many points he got for killing the zombie, the server decides that.
This allows for the overall best performance, but can give some people an unfair advantage. (ie if a player A has a better connection to the server than player B, he may have the ability to fire a second or 2 before player B and kill him first, though player B could be dead before even seeing the shot fired).
RTS games commonly deploy a "ring" or alternatively a "mesh" topology. In this way every machine must make it's input to the game and notify all players before the next "timestep"
This can allow for a bit more of "fair" approach to the game (which is important in strategy games), the disadvantage is the game can only run as fast as the slowest link. and if you'r e using the "ring" topology the game can be lost if someone drops out (which is why you would favor mesh in this case)
How to do network games in flash? I haven't got the earthliest idea. I don't think this has ever been attempted before. Though if I were to do it, I would start out by making a server in python that can receive commands from a python client, and do the game logic. The next step would then be finding a way to make flash open a socket connection with the python server. (I haven't used flash in years, not sure how hard or easy this is).. I recomend python for no particular reason, but for some reason I like making servers in python. Feel free to use C++, Java, ..... instead.
Last edited by misterdanny; August 19th, 2009 at 12:18 AM.