Search Unity

Looking for a guide on how to make ones own network

Discussion in 'Multiplayer' started by Thimble2600, Jan 28, 2019.

  1. Thimble2600

    Thimble2600

    Joined:
    Nov 27, 2015
    Posts:
    165
    Hi, I'm looking to make my own network for an MMO style game.

    I've experience using PUN and Unity's network system and while these are both fine I'd like to make something that I can proudly say I made myself. I've had a few tries in the past following guides but have ended up giving up as I've struggled to figure out a way to efficiently send data back and forth between the client and server.

    Now I've a pretty solid game in the works and I think it deserves my better effort, but instead of picking a random guide on Youtube I thought I'd ask for suggestions or advice here.

    I've quickly put together a bogus winForm program which I'm planning on using as a server.


    tl;dr If you know any PHP networking guides focused on Unity or game development in general, please share them with me here.

    My plan is for it to work like this (you don't have to read this, it's not relevant, just me babbling)
    • In the main menu the player is automatically put into a lobby
    • They enter their username and password and hit login
    • The server checks whether or not the username is recognised, checks the password
    • If its successful the client is instructed to load the gameplay scene
    • After the scene loads, the server is instructed to send the client the player data and world seed
    • The server sends this information including any player made changes to the seed, including terrain changes, vegetation missing, erected structures, etc...
    • The client builds the world using the seed then makes changes to account for player made changes
    • The player can now move around, and as they approach the edge of their chunk, another server transaction is made and after a while chunks that haven't been walked in get object pooled.
     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I recommend taking a look at UNET and/or Mirror. You can have the server and the client in one project, which will save you huge amounts of code to write.

    If you definitely want to go from scratch then I recommend to go bottom-up. Start with a decent low level transport first. E.g. TCP, reliable UDP, etc. - for MMOs you definitely need reliability. Then make your Unity client connect with your server that you made there. If you really want to make an MMO, then your transport will have to deal with hundreds/thousands of connections. See how far you can scale it up.

    Once the client is connected to the server, you'll need to handle the login handshake (client sends account/password, server checks it and says yes/no, sends client to character selection, client selects one, server sends client to world).

    Once in the game world, you'll need to broadcast every client's actions to every other client in proximity. Read up on areas of interest.

    Let the client request actions at the server, e.g. 'please move me to xyz' or 'please use health potion', let the server validate and then do it.

    Hook everything up to a database so a player's state isn't lost after reconnecting. Sqlite is a easy to use first choice. Mysql works too.