A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Multiplayer interactivity - theory questions

  1. #1
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90

    Lightbulb Multiplayer interactivity - theory questions

    Hi guys,

    I am thinking on creating simple multiplayer game with custom backend for the fun of the learning and afterwards when i gain some experience and knowledge i have an idea for online multiplayer game which i'd like to create.

    I believe i have enough coding experience (although i am aware this is not going to be an easy thing to do) but i lack some multiplayer design theory so i came here to ask you more experience guys couple of questions related to connecting client front end and server backend.

    Let's say backend is going to be developed in Java and will be using sockets to connect with flash and vice versa. Also, mysql database will be used to save any game related informations.


    My first question is regarding character movement in such a multiplayer online game.

    If you have a character in client swf file which you instruct to move (either by clicking mouse on a distanced position or by keyboard arrows) how do you exactly propagate such an instruction to all other connected clients. I came to a two options so was wondering which one of them would be best practice and why:

    1) after such a move instruction you move you character in swf client file by updating it's movieclip positio in display list and then propagate "move" instruction to server through socket with additional parameters like character id and position where it should go. Then server dispatches such a instruction to all connected clients other than this one which initiated movement.

    2) after such a move instruction, client swf file sends a "move" instruction to sockets but don't move a character until server receives "move" instruction and dispatch it to all connected clients including this one who initiated movement. When clients receive this notice, they update position of that character inlcuding client who initiated movement.

    From what i see, the second option looks better to me but i am not sure wheather this will cause delay/latency since there will pass some time from the moment client swf file decides to move a character to time needed to send that move command to server through socket and recieve that same notice dispatched from server again and act on it. What do you think, what is considered to be best practice and how to deal with this kind of things?


    My second question is similar but regarding to saving game status. If you have a game where you'll be collecting money for example and buying certain items you have to store current status somehow. My logical guess would be to store it to a databas such as mysql or similar. But now i get to the question.

    If you move your character around and collect the money do you send right a way command like "updateMoneyCount" or similar through socket and then save new value to a database? Do you at the same time update visually number of coins TextField on client side swf or all of this is done somehow differently? I guess there is no point to dispatch such an action through server to other connected clients since it has nothing to do with them?

    If that's how it's done, then why a lot of online multiplayer games store some kind of information in SharedObject files? What do they store and why when those files can be easily manipulated and basically cheat?


    I know this is a lot of questions, i would appreciate any input i can get since those are question moving through my head and i would like to know that stuff before even starting to work on such a game.

    Thanks in advance,
    Cheers

  2. #2
    Senior Member
    Join Date
    Feb 2004
    Posts
    312
    Your first question:
    It doesn't matter whether you move the movieclip object on the client and than broadcast the event to other clients or broadcast the event than move the object. Is just a matter of preference, where you'd rather have the logic. Personally i like the second option because the broadcast is done generically i don't have to exclude the sender from the broadcast list.

    As far as saving goes or game design in general when talking multi-player mode. The client never tells the server to update an attribute or property. The server should be able to handle this and notify the client(s) accordingly. Example: The client detects a mouse click, and sends the server a message saying, 'mouse was clicked on x and y coordinates by player id 100 '. Assuming this was a shooting game, the server knows the position of all players. It knows how to calculate the trajectory of a bullet, based on the current location of the player and the mouse position. The server checks for hits against other players positions, and awards money to the player with id 100, if a kill happens. It than notifies the client how much money he/she currently has. The client displays this information on a textfield.
    [Edit] Just for the record, coding the above is not as simple as I described it, you have to take into the account lag time between packets etc. Just trying to convey the idea.[/edit]

    Storing any vital attributes or properties of the game locally(shared object) is cheatting prone(if you are conserned.) Not to mention that the information is only available from the computer which is saved on. Some developers store static data so that the client doesn't have to download it everytime. For example, say your maps data is stored as an xml/json/txt file, and you know the map data is relatively static and will not change. Why not ask the user for permission to store all this date on the shared object. The next time they try to load the game, the map will be instantly available. You can use the shared objects to store login infomation so that the user is automatically logged in the game the next time around.
    Last edited by AluminX; 08-18-2010 at 04:10 PM.

  3. #3
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90
    Quote Originally Posted by AluminX View Post
    Your first question:
    It doesn't matter whether you move the movieclip object on the client and than broadcast the event to other clients or broadcast the event than move the object. Is just a matter of preference, where you'd rather have the logic. Personally i like the second option because the broadcast is done generically i don't have to exclude the sender from the broadcast list.
    I see, that's what i thought also. It should be better to have as much as possible of logic on the server side. So in the case of movement, client just sends the "move" instruction to server to move character to "x,y" position and server upon receival calculates route from current character position to new "x,y". So if the movement is based on A* pathfinding algorithm, then A* logic and calculation should be done on server side?

    As far as saving goes or game design in general when talking multi-player mode. The client never tells the server to update an attribute or property. The server should be able to handle this and notify the client(s) accordingly. Example: The client detects a mouse click, and sends the server a message saying, 'mouse was clicked on x and y coordinates by player id 100 '. Assuming this was a shooting game, the server knows the position of all players. It knows how to calculate the trajectory of a bullet, based on the current location of the player and the mouse position. The server checks for hits against other players positions, and awards money to the player with id 100, if a kill happens. It than notifies the client how much money he/she currently has.
    When you are talking on server knowing character position, i was wondering what's the best option for server to store such an information, i guess server has to know some other info too (like character's money amount etc.). Does server store it internally in an array like structure that keeps updated internally or every time it has to do something (calculation of movement, updating current money amount etc.) with such an info server queries the database and get the info from there all the time? And vice versa, when server recieves the "update" command then it updates internal structure or database (or even both)? What's the best practice when it comes to storing such informations?

    Storing any vital attributes or properties of the game locally(shared object) is cheatting prone(if you are conserned.) Not to mention that the information is only available from the computer which is saved on. Some developers store static data so that the client doesn't have to download it everytime. For example, say your maps data is stored as an xml/json/txt file, and you know the map data is relatively static and will not change. Why not ask the user for permission to store all this date on the shared object. The next time they try to load the game, the map will be instantly available. You can use the shared objects to store login infomation so that the user is automatically logged in the game the next time around.
    I see, that makes sense.

    I would really like to thank you AluminX for taking time and putting effort in helping me, it's really helpful and i appreciate it. Things are getting much more clear to me with your every post.

    Cheers

  4. #4
    Senior Member
    Join Date
    Feb 2004
    Posts
    312
    Umm i don't know about implementing A * algorithm on a server. You might run into performance issues. The algorithm can get really CPU expensive. Trying doing some research on that matter.
    I would not recommend you implementing any complicated multiplayer interaction in the beginning. However if you must, take a look at this article, might give you some ideas. http://developer.valvesoftware.com/w...yer_Networking

    When i say the server knows the players location, i mean that you have coded on the server the functionality that creates a player instance from a class, the socket listener for incoming requests and the parsing logic which does something with the request to the player class(or other classes.) And all of this code is running in one machine, the server.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center