Search Unity

Question 2 Clone project, 1 server and 1 client ?

Discussion in 'Netcode for GameObjects' started by CoryMelth, Oct 20, 2022.

  1. CoryMelth

    CoryMelth

    Joined:
    Oct 2, 2022
    Posts:
    4
    Hello,

    I'm playing with Netcode and I have a thing I didn't understand.

    I have a project A, server_build.
    This project contain only the network manager and a script to startup the networkmanager.
    The name scene is "main_scene".
    This project is build under "Dedicated server" build option. No flaws, no graphics, just a command line console.

    I have a project B, client_build
    This project contain the network manager, a script to start as client and pretty much that's it.
    The name scene is "main_menu" and I have another scene called "world" to eventually add things there.

    When I connect my client to server, I got an error in debug log.

    I understand that I'm supposed to have two exact same project, clone #1 will be the server and clone #2 will be the client.

    In a way that the server will run on dedicated server, only with build option for dedicated server, what's the purpose to this build to have all the scenes, scripts, prefab, ... and never see it ?

    Maybe I do something not correctly ? I would like to learn that !
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    I think that you are doing something wrong with the scene change. Are you changing it using the network manager?
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    Do you really have two separate projects? If so, make it one. It won‘t work with two projects because everything, scenes prefabs etc. will be considered as incompatible objects by Netcode. Both builds need to have the same scenes, specifically launch the NetworkManager from the same startup scene.
     
  4. CoryMelth

    CoryMelth

    Joined:
    Oct 2, 2022
    Posts:
    4
    Hello,

    I’m not changing scene, just connect to network.


    That mean, everyone will also have the dedicated server code inside normal build ?

    How avoid/prevent someone getting this code and start illegal dedicated server ?
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    Use SERVER_BUILD preprocessor macro.
    See: https://forum.unity.com/threads/is-...rver-code-good-practice.1128578/#post-7255937

    Alternatively, Fish-Networking has automated code stripping.

    Regardless of that, this isn't an issue unless your game sports thousands of daily active users for a longer period of time, at which point you can easily add a couple defines here and there where it's most important to remove the most crucial server code to make that slightly more difficult. You certainly needn't strip every server code from client builds, especially any trivial code.

    However, once you get to a certain level of success, you will find have dedicated servers no matter what. MMOs are mainly getting hacked this way because it's a matter of not having to pay a monthly fee. Second most hacked are games that require some account/registration (EA, Epic, Steam, etc) because not everyone can or wants to get one.

    But none of this really matters if you're solo or a small team because statistically speaking, you have maybe a 0.1% chance of that happening to you, and when it does, you're already making way more money than you'd ever hoped for. ;)
     
  6. unity_9C644C973A27A492A08C

    unity_9C644C973A27A492A08C

    Joined:
    Today
    Posts:
    1
    I found it out, If your scene name in the server build is different than the client build or the client build does not contain the scene the server is running then you will see this error.