Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[Released] Master Server Kit: create your own UNET-based dedicated server

Discussion in 'Assets and Asset Store' started by gamevanilla, Oct 14, 2016.

Thread Status:
Not open for further replies.
  1. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    This is precisely what I am currently working on with the integration of Master Server Kit in CCG Kit. Consider a game using the Network Manager available in UNET's high-level API. You create new games or join existing ones by using the appropriate matchmaker functions. The way to migrate this to Master Server Kit basically boils down to:

    - On the client side, replacing UNET's matchmaking function calls with the equivalent ones in Master Server Kit.
    - On the client side, updating the network manager's IP address and port number with the values returned by the Master Server Kit's matchmaking function (which will correspond to the spawned/joined game server instance) and call networkManager.StartClient().
    - On the server side, updating the network manager's IP address and port number with the appropriate values for the spawned game server instance and call networkManager.StartServer().

    This works in CCG Kit today, with no other changes to the game's networking code (please note this code was written to be server-authoritative to begin with). I will document the entire process once I have finished with the work on this area, but hopefully this gives you a high-level overview of what it looks like.
     
  2. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Yes, the "authoritative and drive the logic of your game" is exactly what I want. From a typical UNET game where there's host client and other clients, is there a rapid way to let the server be "authoritative and drive the logic of your game"?
    I mean, it's OK if you tell me it was not your intention. I just want to make sure that I can change my former UNET games into "MSK game", and I think it could be the need of many people.:):)
     
  3. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Sorry I just saw this part. So please let me know when you finish that fantastic job! Thanks.:D:D:D
     
  4. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Either your game code is server-authoritative or it is not; the kit is not going to magically translate it from one form to another. Server-authoritative means the logic of the game is driven by the server and not the clients (which may still run some logic locally in order to reduced the perceived latency, but the server is always the one ultimately in charge). There are many ways to do this in UNET, ranging from high-level abstractions like commands to lower-level network messages, but you need to write your code in such a way from the start.

    So, just to be clear, I generally refer to server-authoritative games because they are the most common use case and what makes the most sense for a dedicated server setup like the one you can have with the kit. But, as I said earlier, there really is nothing preventing you from having something similar in concept to the player-hosted games provided by Unity Services (and I mean by using the game server as a mediator between the clients, because functionality like NAT punch-through is not provided and outside the scope of the kit). At the end of the day, the kit gives you a centralized way of spawning game server instances that clients can connect to in order to play. How the flow of information goes between the game server and its clients (server-authoritative or not) is really up to you. :)
     
    Last edited: Nov 26, 2016
  5. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Thanks for the kindly explanation. I'm eagerly looking forward to the integration tutorial ;)

    Here I'm giving you some information about the "There should be 'AuthServer_Data' folder next to the executable" issue: it still happens. It's constant on my Windows10 machine. (completely works on Mac though, just need to change the build target in the script and it's perfect)
     

    Attached Files:

  6. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Please note that this issue happens on a Win10 machine, Unity 5.4.3, which is the latest Unity version. Other information:
    1. On Mac it's fine
    2. It's not my Unity problem, cuz it's doing fine in packaging other projects
    3. It's not about win"64", since change it to BuildTarget.StandaloneWindows doesn't solve the issue
    4. It's not about the specific demo since. After I imported this package, all the scenes in this project gives me the same error.

    Hope it helps. And I'm really trying to help, please don't take me as always pointing out issues meliciously.:)
     
  7. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Please ignore above... The latest restart of my computer solved this issue.. It's the 4th restart, and I don't know what happened...
     
  8. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Happy to hear that and no worries at all! :)
     
  9. wahyuway

    wahyuway

    Joined:
    Oct 7, 2013
    Posts:
    83
    @Spelltwine-Games i have trouble to "build all" the demo scene as follow:
    I already changed DatabaseService.cs to use MongoDBProvider

    Is API Compability level have to set to .NET 2.0? As your earlier post this config is only need if i want to use SQL DB.

    Second, how to bypass authentication part? i only want to use masterserver and gameserver, i want to use random user (guest mode). I still dont find to bypass this in the doc.

    Tks
     
  10. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    You also need to remove the SQLite-related files from your project (the SQLiteDatabaseProvider.cs file and the SQLite DLLs) as explained here.

    To bypass the authentication, just set the authenticationEnabled flag in the Configuration file to false. You can see how the accompanying demo handles this in the StartScreen class. I will add an explicit note to the documentation.

    I hope this helps!
     
  11. wahyuway

    wahyuway

    Joined:
    Oct 7, 2013
    Posts:
    83
    I already followed that tutorial and already deleted sqllite-related dll, but still have that error.

    Tried to import in the fresh project, and followed the doc to remove sqlite, error still happended when using "build all" or manually build each server.

    But if i change api compatibility level to .NET 2.0 the error gone! And can run the server flawlessly.
    So, i need to change the api compatibility whether i use sql or other provider.
     
  12. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Are you removing all of these from the Plugins directory?

    Mono.Data.Sqlite.dll
    System.Data.dll
    sqlite3.dll, sqlite3.def, libsqlite3.so

    These libraries are only needed by the SQLite database implementation. I just tested this on my end and, after removing them, was able to use the ".NET 2.0 Subset" API Compatibility Level option with both the MongoDB and LiteDB implementations.
     
  13. wahyuway

    wahyuway

    Joined:
    Oct 7, 2013
    Posts:
    83
    Oh, so my bad, i removed System.Data.dll and finally could build and run flawlessly.
    I thought that file also use by other scripts, because i dunno what inside that dll file.

    Anyway thanks for your help, i ll just play around with my project now :)
     
    gamevanilla likes this.
  14. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Awesome! And no worries, always happy to help. :)

    I will add the exact names and locations of the DLLs to the official documentation so that it is perfectly clear.
     
  15. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Hi, I know you are working on more detailed documentation, and I should wait to see it. I'm just asking a question before that:
    I've read the GameServer.cs, and it's very simple&clear. In the gameServer class there isn't much logic. What's more, building the game server executive only needs the game server scene in the building settings. So , how were the "real game server logic" be referenced and compiled in this build? Or was it actually not referenced and compiled?
     
  16. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    The game server class only performs some basic management of the players connected to that game (so that it knows when to notify the master server that it can be destroyed) and is intended to be extended with the logic that is specific to your game. The accompanying demo provides a placeholder game server that only serves to illustrate the idea of how game server instances are spawned and destroyed in the context of the kit.
     
  17. Cooler88

    Cooler88

    Joined:
    May 25, 2013
    Posts:
    2
    Hi,
    I am interested in the dedicated server concept, but I have some worries around performance.
    Can you share some statistics about how much memory, cpu etc needed by a
    Unity headless game server (I will investigate as well).

    A good example would be the case of CCGKit demo running.

    Let's say that there is 1 million servers, how much it will cost to maintain it (example CCGKit).

    I really waiting for the Unity Server Library.
     
  18. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    The exact numbers will really depend on both your game and the capabilities of your server but, to give you an idea, I just run the ps aux command (which, admittedly, is not the most scientific way to measure this) on the demo server and a single game server instance has a consumption of 2.2% CPU and 7% MEM. The server is hosted on the $5/month tier of Digital Ocean VPS, with very humble specs that only make it useful for development purposes:

    512 MB Memory
    1 Core Processor
    20 GB SSD Disk

    We are talking about ~36 MB for a trivial headless game server instance that performs no real game logic (it is just a placeholder for the demo), so you should expect more with an actual game. How much more? Again, that will depend on the game.

    There is definitely an added cost in launching a Unity instance per game/match/room (even if headless) and I completely agree with you in that having an official server library for UNET will be very welcome.
     
  19. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Hi, are there updates out there?
     
  20. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    I am working on it. As always, as soon as I have finished, I will announce it here. :)
     
  21. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Hello! I have just submitted a new update to the Asset Store (version 1.04). These are the release notes:
    • Upgraded project to Unity 5.5.0.
    • Improved the default support for games using UNET's high-level Network Manager.
    • The master server now resets the 'logged in' flag of all the registered users upon launch.
    • Trying to join an expired game/match/room results in a proper error now.
    • Several improvements and refinements in the API and the organization of the kit.
    I have also extended the official documentation with more information about how the core classes of the kit work. As soon as the update is live on the store I will update the website accordingly.

    The update should be available on the Asset Store in a few days, but if you would like to have it earlier just contact me privately with your invoice number and I will send it to you.
     
    LostPanda and wahyuway like this.
  22. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Great News!
     
    gamevanilla likes this.
  23. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Hey, it just occurred to me: have you think of recording video tutorials?
    I think it's a fantastic way of showing people how to integrate CCG kit with MSK!
     
  24. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    The bad thing about videos is that they can be rendered obsolete pretty quickly. That is the reason why my focus is on written documentation for the time being. Maybe in the future!
     
  25. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Yes, it totally makes sense!
     
  26. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    The latest update of Master Server Kit (1.04) is live on the store now! :)

    These are the release notes:
    • Upgraded project to Unity 5.5.0.
    • Improved the default support for games using UNET's high-level Network Manager.
    • The master server now resets the 'logged in' flag of all the registered users upon launch.
    • Trying to join an expired game/match/room results in a proper error now.
    • Several improvements and refinements in the API and the organization of the kit.
     
  27. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Downloaded! Thank you! the new documentation let me know more about your kit!

    Question: Assume I have a FPS game using UNET(using unet to handle all the sync stuff), and I want to wrap it into Master Server Kit, am I supposed to:
    || write all the sync stuff all from scratch?
    or:
    || in build settings , put the online scene in the game server build? And the UNET logic does magic stuff automatically?
    or:
    || Make an additional game online scene copied from the original game online scene, and use script to run "server only" onStart?
     
  28. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Happy to know the new documentation is helping! :)

    In order to integrate Master Server Kit with a game that leverages UNET's high-level Network Manager, you basically need to:

    - Replace your Network Manager object with the Master Server Network Manager from the kit (it is a custom subclass that makes the manager work in conjunction with the rest of the kit). You specify your offline/online scenes, the player prefab and any other registered spawnable prefabs as usual.

    - Replace the UNET's matchmaker calls with the corresponding Master Server Kit's matchmaker calls in your lobby and use the version of the JoinGameServer method that accepts a Network Manager object (you will need to pass your Network Manager object here).

    This is what is happening when you set the usingNetworkManager configuration flag to true in the accompanying demo.

    If your game logic is server-authoritative (having a server-only object to centralize the server logic, as you mention, is a good way to do that), then everything will just work with no other changes to the game's code.
     
  29. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Thank you!
    I'm a bit confused: Why can't we just drag the whole online game scene into the game server? And, make the game server functioning just like this:

    This way it's automatically a c-s structure game, isn't it?
    I kinda feel like we are not talking 'bout the same thing...
     
  30. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    This way, the game server would calculate physics& transforms& handle SyncVars, which are actually all the important stuff in an FPS game.
     
  31. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    When using the Network Manager, both the offline and online scenes are on the game server. When the game server is launched, it starts with the offline scene, then StartServer is automatically called and the manager transitions to the online (game) scene. Clients do the same thing, except with them StartClient is called instead. So you have the game server running as the server and as many game clients as your game needs running as clients. What you are saying is exactly what is being done; you can check it in the accompanying demo.

    The fundamental difference when compared to Unity Services is that with their player-hosted games the player creating the game is the server and the client at the same time (i.e., the host), whereas with Master Server Kit the server is completely separated from the clients (i.e., a different machine). All your SyncVars, remote actions, etc. still work the same.
     
    Last edited: Dec 10, 2016
  32. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    After updating to the new version these days, I keep on failing to connect to game server, the screen shot:
    QQ截图20161212000957.png
    please note that the game server is up already, although none of the clients could be linked.
     
  33. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    I see you've added the "GameClient_Game.unity" in the game server builder configuration, which is great!
     
  34. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Does your gameServerBinaryPath point to the location of the game server binary on your system? Does this happen with the usingNetworkManager flag set to true or false (or both)? Are there any errors being thrown? Have you changed the kit's code in any way? Everything is working just fine on my end, so more detailed information would be helpful in order to know what may be happening.
     
  35. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Does your gameServerBinaryPath point to the location of the game server binary on your system?
    Yes, like I mentioned, the gameServer has been up. Since I'm using windows, I can see it up when clicked "created games" or "play now" in my bare eyes.:) By the way, I'm using windows 10. What's your terminal system?
    Does this happen with the usingNetworkManager flag set to true or false (or both)?
    Both.
    Are there any errors being thrown?
    I've built them to run, so didn't see any errors. Do you want me to start one of them in Unity Editor to check for errors?
    Have you changed the kit's code in any way?
    To locate the problem, I've kept it unchanged, except for the "configuration" class.
    Everything is working just fine on my end, so more detailed information would be helpful in order to know what may be happening.
    Hope I'll get it working, too! Cuz I'm really hurrying to get my game running on my dedicated server.:):)
     
  36. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    I am using Windows 10 too.

    Is this only happening with the new update? Did you do a clean import of the kit? Are you not building the binaries via the 'Build All' menu option (or every single binary individually with the appropriate menu option)? If you are building things manually, maybe you are just missing the game scene when building the game client? Also, can you check the game client's log (or, alternatively, run it from the editor) to see if there are any errors?

    If nothing helps, please send me your entire Unity project privately so I can take a closer look.
     
    Last edited: Dec 12, 2016
  37. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    sure, i'll check that, and hope it is due to my stupid mistake, not some os stuff that is complicated. do you suggest other execute logs other than game client?
     
  38. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Aside from the bug I'm facing, I want to say , support for UNET NetworkManager is the greatest thing, and I think it'll be even more exciting if we can support NetworkLobbyManager, for it really suits a lot of circumstances. As in War3, and in games that needs everybody to be in position as soon as the game starts, it's really useful. Also, it can make sure nobody enters the game after it's been going on.
     
  39. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Is this only happening with the new update?
    I think it is because I succeed with 5.4.3 and v1.0.3. But right now there's no way to confirm it since the old package was covered.
    Did you do a clean import of the kit?
    Yes.
    Are you not building the binaries via the 'Build All' menu option (or every single binary individually with the appropriate menu option)?
    During testing I used Build All.
    If you are building things manually, maybe you are just missing the game scene when building the game client? Also, can you check the game client's log (or, alternatively, run it from the editor) to see if there are any errors?
    I'm sure it's not the reason.
     
  40. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    FuTou, your configuration is not correct. You have this as your game server binary path:

    gameServerBinaryPath = "E:\\UnityProjects\\PureMasterServerKitTest\\Builds\\MasterServer.exe";

    The game server binary path needs to point to the location of the game server binary on your system; hence the name. This is needed so that the master server knows which binary to spawn when a new game is created. You are currently spawning master server instances instead of game server instances, and that is the reason why clients cannot connect to the game at all (i.e., there is no game). Just replace it with

    gameServerBinaryPath = "E:\\UnityProjects\\PureMasterServerKitTest\\Builds\\GameServer.exe";

    and everything works as intended.
     
  41. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    OMG, it was a stupid mistake. I mistook it for game server. Thank you for ur time!
     
  42. Red_Baron_

    Red_Baron_

    Joined:
    Jul 19, 2015
    Posts:
    8
    Hello. I want to know: with this plugin can i create master-server, which create game-instances? I develop a turn-based game and in my game users can't create rooms. I want to create some rooms on server (without player, of course) and keep it open all time, even without players. And i need master-server without authorization and database. Is this possible with plugin?
     
    Last edited: Dec 12, 2016
  43. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Having the ability to set a number of pre-created rooms is something I would like to tackle in the future. You would need to extend the kit's code yourself in order to do that today. The authentication and database systems are optional and can be bypassed if desired.
     
  44. Red_Baron_

    Red_Baron_

    Joined:
    Jul 19, 2015
    Posts:
    8
    Thanks! And second question: is plugin working on mobile devices (Android and iOS)?
     
  45. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    The servers (authentication server, master server and game server instances) are intended to run on a dedicated server machine (Windows, Mac OS, Linux) with a public IP address. I usually recommend Linux because you can build the binaries as headless, which is particularly convenient for servers. The client will run on any platform supported by UNET, including both desktop and mobile (but not WebGL).
     
  46. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Hello! I have just submitted a new update to the Asset Store (version 1.05). This is a small maintenance update that contains a few internal improvements. These are the release notes:
    • Several improvements in the matchmaking API to simplify its usage.
    • Replaced authenticationEnabled flag with authenticationRequired in the configuration.
    • Added maxPlayers property to the configuration.
    • The database does not store the “is logged in” status of a player anymore; the master server does now.
    The update should be available on the Asset Store in a few days, but if you would like to have it earlier just contact me privately with your invoice number and I will send it to you.
     
    LostPanda likes this.
  47. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Great! Is there any plan for network lobby manager?
     
  48. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    I am not sure how that would work, because there would be a lot of overlapping functionality with the lobby provided in the kit. I believe it is more useful to provide additional functionality and customization options in the kit's lobby in future updates, and I definitely plan to do so.
     
  49. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    To be more clear, let me explain the circumstance:

    Suppose it's a 5 VS 5 multiplayer game. And for each side, there are 5 different roles & start positions, each role start at a specific position.
    When I'm matched up, I want to select which team I'm in , and I want to select the role and the start position. So that when I enter the game, I'm playing with my buddies, and I'm playing in my favorite role.
    An example would be Warcraft III: Frozen Throne.
    A further example would be A RPG map of Warcraft III called "Lost Temple 3C"

    A network lobby manager would be perfect to do that.
    reference: https://docs.unity3d.com/ScriptRefe...anager.OnLobbyServerSceneLoadedForPlayer.html
     
  50. FuTou

    FuTou

    Joined:
    May 2, 2015
    Posts:
    52
    Also it ensures all the players enter the actual game at the same time. So it's fair for games in which players accumulate strength.
     
Thread Status:
Not open for further replies.