Search Unity

How exactly do I make a client-server multiplayer game?

Discussion in 'Multiplayer' started by PrecisionGaming, Apr 28, 2014.

  1. PrecisionGaming

    PrecisionGaming

    Joined:
    Nov 6, 2013
    Posts:
    6
    The title says it all. I'm embarking on an incredibly ambitious project, with practically no experience. Please don't post telling me I should do something small first, I just need to know, how do I program the client and the server to communicate, and how do I make it so that I can shoot other players? Help is needed! Thanks!
     
  2. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    There is a reason people tell you to do small things first.. Could you ever win a martial arts competition without knowing martial arts? My point, you don't know what you don't know.

    Suggestion #1 - look at the free multiplayer kit provided by unity. Dig through it and understand it.
    https://www.assetstore.unity3d.com/#/content/917

    You need to understand "I just need to know how to program the client and server" is NOT an easy question to answer. It will all depend on the game you are making, your budget, your skill, etc. There are ready made things like Photon out there, use that. Then you can avoid "How do I make a MMO" questions

    Here is an example using photon
    https://www.assetstore.unity3d.com/#/content/369

    Here is where to start on learning how to do it in Unity
    https://docs.unity3d.com/Documentation/ScriptReference/NetworkView.html

    Hopefully you aren't trolling :rolleyes:
     
    Last edited: Apr 28, 2014
    orloKun likes this.
  3. 3D Omelette Studio

    3D Omelette Studio

    Joined:
    Oct 1, 2013
    Posts:
    130
    I wonder if this fella is mocking the community.
    seems to be a massive lack of common sense with the broad general question.


    Ill give an answer with another question:
    How do I exactly perform an organ transplant surgery?
    please do not tell me that i need to go to med school first.


    You just cant.!
     
  4. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    Oh, I have another one:

    How does one fly? Please don't tell me I need to grow wings first, who has time for that crap.
     
    shahin2122 likes this.
  5. 3D Omelette Studio

    3D Omelette Studio

    Joined:
    Oct 1, 2013
    Posts:
    130
    exactly,


    Now, if one really wants to learn how to create a multiplayer game . I'll give you an exactly step by step to get you on your way, it is actually very easy, once you know the basics and experience in the industry of game developing.
    the only challenge is the undertaking time it takes to build a game, it is very time consuming, same applies for software developers, tackling the bugs is very tedious job, so you need a lot of time and patience.

    So, I assume you are new to unity due of your very first post, and your question, so first is first:

    step 1: Learn how to use a third party modeling program so you can create your own 3D assets. ie: 3dsmax, modo etc....

    step 2: Learn how to create 2d textures for your game assets and props , photoshop, gimp etc....

    step 3: Learn how to use unity engine, all inside and out features, since this will be your most important tool, master it.

    step 4: Learn a scripting language, unity provides 3 options, boo, c# and unity script, i recommend you to start with unity script. and master it.

    step 5: Learn the basics of game networking, Do a search for Gamer to game developer GTGD in this forum, awesome networking tutorial series. around 40 videos of an average of 1 hour length each one of them with pure advanced unity networking material, but you need to learn all previous stuff in order to understand this tutorials.

    step 6: then choose a networking engine to use for making your game multiplayer, there are several option and each one in different scripting language:
    photon, ulink, smartfoxserver, tnet, electroserver etc......

    step 7: once you choose a networking engine, then master it and learn the scripting language it uses to communicate with unity. master it.

    step 8: and a lot and lot of time and discipline to start building you game.



    each step will take you around 3 to 5 months to master, so if you care to learn and really dive into game developing for multiplayer games, then the first 35 to 40 months (3 to 4 years) will be all pure learning before you can actually start creating your own game

    now, unity has a lot of assets , startup kits etc.. which you can use to get you started, but without the learning of the necessary material previously mentioned, you got nothing.

    so, learn to crawl before you start walking and master walking before you start running,
    well, if you are smart enough you will get the point by now. and the reason why you will always get the "start from the beginning" responses

    Good luck with your ambitious project, you will need it.
     
    Last edited: Apr 29, 2014
  6. nastasache

    nastasache

    Joined:
    Jan 2, 2012
    Posts:
    74
  7. Hades II

    Hades II

    Joined:
    Oct 23, 2014
    Posts:
    55
    Unity also provides JavaScript...which i would recommend you start with. Don't do anything but learn JavaScript starting from the basics....check out code academy.com that's where i learned JS. While doing that play around with unity...don't try to actually start a project..but just learn where everything so that once you do learn JS you wont have a problem. Also check out blender 3d..its a modeling programs for pretty much everything in a 3d game. Once you can code an write programs on your own you should start with a small 2D game like maybe make your own version of flappy bird but with only your graphic and code. Then maybe making 2d rpg game...working your way up to a 3d game.
     
  8. ActivePrime

    ActivePrime

    Joined:
    Jan 28, 2014
    Posts:
    147
    You have a lot to learn, make sure you keep things in practice when moving to the next one. I went through same process and wasted some of my time in repeating things which I forgot.
     
  9. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    I think a lot of people here have hit the nail on the head. Game Development is not something that you can just jump into and be an expert in no time. Hell, I've been working here for 16 months in the non-technical support team and even there are some basic things I do not understand.
     
  10. R3volve

    R3volve

    Joined:
    Apr 9, 2017
    Posts:
    6
    You guys are being entirely too hard on the OP.
    I am in the same boat as him. I don't know squat about programming, I work in a factory.
    But I just followed some tutorials and thanks to how simple unity makes building games I have already released an android runner game (just to prove I could) and have moved on to a VR MMO.

    Yea, I'm banging rocks together over here, but if you bang enough rocks together you do accomplish something.
    I have a server that communicates to clients that can send whatever message I want, and I can program them to react to those messages however I want.
    My girlfriend and I just ran around in my little test arena shooting at each other and dodging, jumping, respawning....
    Its not rocket science, and you are not intellectual elites.

    OP, get started here. This is where I got started and I had ZERO knowledge of how to network anything.

     
  11. niyis

    niyis

    Joined:
    Aug 1, 2017
    Posts:
    2
    I know this thread is old, and I know I might get flack for replying, but I really wanted to say thank you! I was basically at the same point as OP. I want to make a game. I know eventually I will want it to be online. Can Unity get me there? I know so little, I know it's going to be years before I'm anywhere near actually having a finished game that can be played online, and that the online feature is ages and ages away, but I really didn't want to put at a minimum 2 years into fully mastering Unity if it could never have online capabilities. Your answer was very wonderful and thorough and answered a lot of extra bonus questions besides the original one!

    So, thank you thank you thank you, from this newb, at least. I'm going to start my first baby steps learning Unity withOUT the anxiety that it's all a waste of time, because I'm now much more certain that it's at least technically possible to go from building the game in Unity, to building the game that will eventually have online capabilities!

     
  12. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    While I haven't really watched that video. It shows some fairly bad habitts (Skipped through it a bit). Forexample: He is asking the client for their position. Why? Just make the client send their position.
    And he is also only processing one message per frame. Which is not ideal.
    And he is sending strings over the wire. Which is super naughty (for realtime games atleast. If you make a card game or something. It doesn't really matter).
     
  13. MMOInteractiveRep

    MMOInteractiveRep

    Joined:
    Apr 7, 2015
    Posts:
    88
    Sometimes even in Real time games you have to send strings over the network... Authentication for example you HAVE to send the username and password both strings over the network... With some Network Libraries like the one I use "Lidgren" the message types are all strings. You just have to be mindful of what your sending over.
     
  14. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Please, never send the username and passwords to the gameserver... Just send auth tokens.
    Unless you actually know what you are doing.
     
  15. MMOInteractiveRep

    MMOInteractiveRep

    Joined:
    Apr 7, 2015
    Posts:
    88
    And how the heck do you expect to authenticate the username and password if you don't send them to an Authentication Server to handle it? I'm guessing your answer is going to be using a PHP script... How is that any different then sending it to a server your still sending it over a network... And you sure as heck don't want the client to have access to the database to Authenticate it's self...

    Passwords are encrypted and then the username and encrypted Passwords are sent over to the authentication which then checks it against the database and if correct creates a Game Session the other servers are able to use to verify they are connected and Authenticated.
     
  16. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Well, you shouldn't really mess with Authentication yourself. You should leave it to steam. And you should NOT encrypt your passwords. Just hash and salt.
     
  17. MMOInteractiveRep

    MMOInteractiveRep

    Joined:
    Apr 7, 2015
    Posts:
    88
    Your assuming it's going on Steam which what I do isn't going on Steam or at least it's not being designed for steam. It's being designed as a traditional MMO. For the Passwords I use standard MD5 Encryption which is basically what most Websites use and what most people suggest using for passwords.
     
  18. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Oh no.
    I admit i formulated my suggestion poorly. What I ment was: Leave it to guys like steam

    But please, NEVER TOUCH ANYONES passwords.

    MD5 is a hashing algorithm that has been concidered unsecure since LOOOOONG. It's at the point where if you google common MD5 hashed passwords you will litterarly get the results due to rainbow tables.

    If you are going to do it yourself. You need to do it properly. You can't just MD5 hash the passwords in the DB and expect everything to be fine.

    You need to use some strong hashing algorithm. And you need to salt it. Otherwise you could draw conclusions about your users passwords fairly easily.

    Please, read up on proper password security before you do something like that. If someone get's access to your users passwords. You've broken data protection laws.

    Read up on the matter. And I honestly don't even believe you when you say most people recomend MD5 hashing. It's the most well known algrorithm. Cause it's broken.
    Litterarly the third line on Wikipedia:
    Like most hash functions, MD5 is neither encryption nor encoding. It can be cracked by brute-force attack and suffers from extensive vulnerabilities as detailed in the security section below.
     
    JustinMinnaar and Deleted User like this.
  19. MMOInteractiveRep

    MMOInteractiveRep

    Joined:
    Apr 7, 2015
    Posts:
    88
    This is the method I use for Hashing/Encrypting the passwords:

    public static string MD5Hash(string text)
    {
    MD5 md5 = new MD5CryptoServiceProvider();

    //compute hash from the bytes of text
    md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));

    //get hash result after compute it
    byte[] result = md5.Hash;

    StringBuilder strBuilder = new StringBuilder();
    for (int i = 0; i < result.Length; i++)
    {
    //change it into 2 hexadecimal digits
    //for each byte
    strBuilder.Append(result.ToString("x2"));
    }

    return strBuilder.ToString();
    }

    as well as a couple other tricks which I won't reveal here.

    And here is the final password saved in the database for one of my Dummy test accounts:
    90a1d5cb140ef990d568a7dedb5ae47d

    I also use the following to ensure the password is a "Strong" password...

    public static bool IsStrongPassword(string password)
    {
    // Minimum and Maximum Length of field - 6 to 12 Characters
    if (password.Length < 6 || password.Length > 25)
    return false;

    // Special Characters - Not Allowed
    // Spaces - Not Allowed
    if (!(password.All(c => char.IsLetter(c) || char.IsDigit(c))))
    return false;

    // Numeric Character - At least one character
    if (!password.Any(c => char.IsDigit(c)))
    return false;

    // At least one Capital Letter
    if (!password.Any(c => char.IsUpper(c)))
    return false;

    // Repetitive Characters - Allowed only two repetitive characters
    var repeatCount = 0;
    var lastChar = '\0';
    foreach (var c in password)
    {
    if (c == lastChar)
    repeatCount++;
    else
    repeatCount = 0;
    if (repeatCount == 2)
    return false;
    lastChar = c;
    }

    return true;
    }

     
    Last edited: Aug 2, 2017
  20. mofirouz

    mofirouz

    Joined:
    Jul 14, 2015
    Posts:
    27
    @MMOInteractiveRep @TwoTen I strongly suggest against using MD5 or any derivative of it. General purpose hash functions by themselves aren't cryptographically secure enough to use on passwords. Also avoid writing your own password hashing by combining various steps, there are plenty of extensively researched and well understood algorithms already available.

    If you must use password-based login, definitely look into BCrypt as the one-way hashing strategy. There is a C# project called BCrypt.Net that you can download from here: https://www.nuget.org/packages/BCrypt-Official/

    The more secure and useful approach is to use Steam as an authentication mechanism in your game, via the Steamwork Login API. This has the added benefit of using the Steam network as "friends". There are C# Steam libraries like this: https://www.assetstore.unity3d.com/en/#!/content/74349

    You’ll need to have your Steam Publisher Key and Steam AppID available, and use that to make calls to their API to authenticate users in and fetch their friends. This removes the need for passwords as you only deal with generated “auth tokens” which are usually one-time use only. There are various projects out there that takes care of this and more. For example code, have a look at this.

    Hopefully this helps you a little bit.
     
    Last edited: Aug 4, 2017
    wccrawford and TwoTen like this.
  21. Mr_Perlful

    Mr_Perlful

    Joined:
    Dec 21, 2016
    Posts:
    6
     
    Davon92 likes this.