Search Unity

Multiplayer/Online game how it should be made, correct my theory[i wanna know if this is the right]

Discussion in 'Multiplayer' started by YoyoMario, Jun 10, 2015.

  1. YoyoMario

    YoyoMario

    Joined:
    Apr 8, 2013
    Posts:
    16
    Hello,

    First of all I am wondering how are multiplayer/online games made?
    And is my theory correct?

    So my theory is:

    1. I need to make a SQL server, create a Table in it which contains (xPos,yPos,zPos)
    2. Send my players info every, lets say, 20ms to the server
    3. Recieve JSON with the info of the other palyers
    4. Create other palyers based on info from the databse updated every 20ms
    Im actually wondering if this is how online/multipalyer games are made?
     
    Last edited: Jun 10, 2015
  2. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    Depending upon your type of game, you really need to look at a dedicated authoritative server. For more than a handful of players, WWW requests every 20ms is not a good solution.

    25 players x 50 requests per second = 1250 requests per second & 1250 sql queries per second and it scales up badly from there. Possibly your SQL database won't even manage 1250 queries per second. This also does not take bandwidth into account either, something else to consider with a multiplayer game.
     
    YoyoMario likes this.
  3. YoyoMario

    YoyoMario

    Joined:
    Apr 8, 2013
    Posts:
    16
    But how are they made then?
     
  4. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
  5. AlexConnolly

    AlexConnolly

    Joined:
    Dec 23, 2012
    Posts:
    32
    One thing to think about with online games is who (what) has authority. This is usually overlooked by people when they first dive in to networking, but it's actually very important and could leave you with issues later on when people realise this.

    You always have to make sure the server has the last word. Always. What you have stated is that the user will send their location. No, no, no... Please don't do this! Rather than sending their location, let them change states eg. Have an enum that has MovementState.Forward, MovementState.Backward, MovementState.Stational. Then, what you can do, is let both sides calculate it. The client sits there and goes "Ok, am I moving? Yes, Ok, lets move!". When the user presses the forward button, you switch the state and tell the server that the state has changed (eg. MovementState.Forward). The server then realises this, and begins to calculate the movement. When they stop, the MovementState is changed to MovementState.Stational. You then get the server to send back the location that the user should be at. Since this user HAS to agree with the server, any incorrect values should be adjusted so that the player is in the right location.

    Just my two cents.
     
    Whippets likes this.