Working With Authoritative Server Option
If you have been looking through the various options on the NetworkedMonoBehavior you may have found something labeled "Server is Authority" and "Client Side Prediction" when you select this option. You quite possibly were wondering what this means.
First of all lets talk about what the "Server is Authority" option does. Basically when you select this toggle box the client doesn't do anything but send its input requests to the server. These inputs are then processed on the server rather than blindly accepting variable changes and alterations from the client. Because of this the client no longer has control over the values of the objects that it "owns" (though it still is seen as the owner of the object). This means that the server is completely responsible for simulating everything including position, rotation, physics, variables marked with NetSync or added through the AddNetworkedVariable function, etc.
Okay, so if the server is calculating everything, that would mean that the client would have to wait for the server to respond with the updated positions and variables. This makes the gamplay much more secure but now we have to deal with the idea of lag. Lets say that I press a key and it takes 100 milliseconds to go to the server and 100 milliseconds to come back. That would mean that there is a 200 millisecond delay between when the client pressed the key and when their object reacted. This obviously produces a very bad experience for the client. So how do we solve it?
Introducing client side prediction! It is actually a really simple concept. Programs you see are highly predictable, if you have all of the variables it will simulate the nearly the same everywhere (unless somewhere else the variables are different). So, knowing this, you can actually simulate the same thing that the server will simulate except on the client before the server responds. All that is left to do when you do this is to make sure that if the client gets too far out of sync with the server, it is updated. This means the server is ultimately the authority.
Great! I get the concept, now show me the code!
First, derive your class from the NetworkedMonoBehavior. Now you are able to register your input events for the server and for client side prediction. The following is a code example of how to use the events and methods for getting your authoritative server and predictive client working! :)