Skip to content

Understanding server owner other

pointcache edited this page Aug 17, 2017 · 1 revision

If you like me lacked the experience this doc can help you wrap your head around basics.

What is a Server? Server is a machine that launched the game first basically. Meaning everything in the game that exists on that machine will be considered IsServer, every bullet that exists on that machine, every player representation. In contrast other players that connect also will mostly have all of those objects cloned on their local machine, but they will never have IsServer flag.

Every client that connects has a "copy" of the whole game that is running. They all are connecting to the server machine, and on start download the current state of the servers game. So each client has duplicate objects, his "local" objects. But since there is only one server instance where each of those has IsServer flag, it's very easy to force each local object to simply do exactly what it's server clone does, thus correcting local players state.

When instantiating objects the correct way is to always specify where you want it to be spawned. This has to deal with who "owns" the object, meaning who has the authority over that object.

 public override void SpawnProjectile(RpcArgs args) {

        if (networkObject.IsServer) {

            var obj = NetworkManager.Instance.InstantiateProjectile(args.GetNext<int>(), args.GetNext<Vector3>(), args.GetNext<Quaternion>(), true);

        }

    }

Here when projectile is spawned with an RPC that was set to ALL, everyone will receive the instantiation request. If it wasn't for the server check the projectile would be spawned both on the client and on the server, meaning the player that is the server would see 2 projectiles!

By limiting the spawning to only server machine, we ensure that we have only one instance of the object, and that it belongs to the server and no client can tamper with it.

The server / owner thing boils down to whos machine is dictating the changes to objects. If we do the movement in IsOwner, this means that the calculations will happen on the machine of the client, and then sent to server, that will send it to everybody.

Home

Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
NetWorker
Master Server
Web Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
Clone this wiki locally
You can’t perform that action at this time.