- Home /
Authoritative Server with Offline Single-Player
Hey guys,
So this is a design question with regards to my real-time multiplayer game using uLink (basically the same as Unity Networking).
I currently have an authoritative server instance, to which clients connect and RPC data. I separated the Server and Client scenes and scripts to prevent the Clients from having Server code and to organize them. My inheritance looks like this:
GameManager
|-NetworkedGameManager
|-ServerGameManager
|-ClientGameManager
This same setup is mirrored for other manager classes as well. This all works great! But the problem is now I can't have the client play single-player, offline. I don't want to require the clients from needing access to internet to play Single Player.
The only solution I can see, which I don't like, is to move all the necessary code to NetworkedGameManager
, and check uLink.Network.isServer
before anything that should be server only. This ruins the benefits of inheritance, makes one really large file, and feels less secure since the clients no longer depend on the server.
I also tried just adding the ServerGameManager
script to my client scene, but these things are so interdependent and that would create a lot of repetition in the code, although I prefer this option if its doable.
So what is the normal approach here? One monolithic system that has all Client and Server code? Some sort of modular setup with Client and Server in the same scene? Make a third class that extends Client and adds repetitious server code?
Thanks for any and all advice!
Answer by Komak57 · Dec 17, 2013 at 12:38 PM
I'm getting a pretty rough idea of what you're trying to achieve, but I may be missing some details, so don't hate me if I was misled.
From what I understand, you have Solo, and multiplayer content in easy access of each other, but no clear-cut separator (like buttons on the main menu). This style makes me think of Dark Souls. In such a case, you would have the game 'assume' offline mode, until an event or some such (successful connect with legit login, cued when disconnected each time the user views the local/online players) powered the online communication features.
In the case that you want online activity as soon as you started the game, with the option of jumping on without a legit login for offline mode, might I suggest creating 2 separate clients? For Steam, this means players will get to have the option of choosing online or offline mode from a single button, and you can safely store all your online-only content in your online-only client.
Not quite what I'm going for. The user will explicitly pick Single Player or $$anonymous$$ultiplayer. But the gameplay is largely the same. A singleplayer game has to be able to have 100% of the code, while a multiplayer client should only have the clientside code, for security, etc. and likewise a Server should only have its necessary code, most of which is needed for singleplayer.
I ended up with a bad system, but I'm too late int he game to refactor it. I wish I'd separated server logic from client logic, but allowed both to be added to the same game when singleplayer. Hard to explain, and harder to design and implement...
Thanks for the input though!
Answer by nastasache · Dec 17, 2013 at 07:45 PM
Since single player have nothing to do with network, server or client, I think the application design have to be a bit different, probably something like:
GameManager
|-OfflineGameManager
|-NetworkedGameManager
|-ServerGameManager
|-ClientGameManager
the only #3 levels sharing the network logic, the #2 levels sharing the shareable logic for singleμltiplayer, and #1 used as general controller. Probably it's a too high level map, I have no idea how to implement this in practice.
I prefer a monolithic non-OOP system, with simple:
if(!multiplayer) {
Network.Disconnect();
MasterServer.UnregisterHost();
}
// Whatever to continue
Yeah as I noted above, that's roughly what I ended up with... cept separated into classes that inherit in order of complexity. Definitely not ideal.
As stated above, I want a system wherein singleplayer is just client + server. But that's not easy with how complex things are, especially concerning all the network code... O well, thanks for your input!
Answer by baelthanoc · Dec 10, 2015 at 05:23 PM
@OP_toss This is a really old post, but I'm a software dev new to Unity, and thought I'd throw in a thought for others that may land here. It seems to me you could just run a server on localhost for single player. It doesn't require internet access, it's all on the client machine, and requires no design changes.
Your answer
Follow this Question
Related Questions
Authoritative server security? 2 Answers
Turn-based small scale multiplayer: server-only-logic possible? 2 Answers
ontriggerenter will not work with !islocalplayyer 0 Answers
Multiplayer on Android? 0 Answers