How do I get the NetworkPlayer of the host?

How can I get the NetworkPlayer of the player hosting a online match in the default Unity Networking system? I would like to make sure that when important RPCs are called that need to come from the server, that they actually come from the server, not just a hacking client.

Simply use:

Network.connections[0]

As a client is only connected to the server, on all clients this will return the NetworkPlayer of the server. Only on the server itself that doesn’t work, but there you know that you are the server.

You can use a helper method like this:

public static NetworkPlayer GetServerPlayer()
{
    if(Network.isClient)
        return Network.connections[0];
    if(Network.isServer)
        return Network.player;
    // not connected or not running as server
    return NetworkPlayer.unassigned;
}

That should give you the server player in all cases.