private void OnServerReceiveClientInfo(NetworkMessage Msg)
    {
        if (Msg.conn.playerControllers.Count > 0)
        {
            PlayerController player = Msg.conn.playerControllers[0];
            if (player != null && player.gameObject != null)
            {
                JigsawPlayerController jigsawController = player.gameObject.GetComponent <JigsawPlayerController>();
                if (jigsawController != null)
                {
                    if (NetWorldState == null)
                    {
                        GenerateWorldState();
                    }
                    ClientInfoMsg     clientMsg   = Msg.ReadMessage <ClientInfoMsg>();
                    JigsawPlayerState playerState = NetWorldState.RegisterPlayer(clientMsg.Username);
                    jigsawController.PlayerState = playerState;
                    return;
                }
            }
        }
        ClientInfoMsg tmp = Msg.ReadMessage <ClientInfoMsg>();

        DeferredClientInfo.Add(Msg.conn.connectionId, tmp);
    }
    public override void OnServerRemovePlayer(NetworkConnection conn, PlayerController player)
    {
        // TODO: figure out why deregister isn't getting called
        Debug.Log("OnServerRemovePlayer executed");
        if (player.gameObject != null)
        {
            JigsawPlayerController jigsawController = player.gameObject.GetComponent <JigsawPlayerController>();
            if (jigsawController)
            {
                NetWorldState.DeregisterPlayer(jigsawController.PlayerState);
            }

            NetworkServer.Destroy(player.gameObject);
        }
    }
    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    {
        if (NetWorldState == null)
        {
            GenerateWorldState();
        }

        var player = (GameObject)GameObject.Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);

        NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
        Debug.Log("Client has requested to get his player added to the game");

        ClientInfoMsg clientMsg;

        if (DeferredClientInfo.TryGetValue(conn.connectionId, out clientMsg))
        {
            JigsawPlayerState      playerState      = NetWorldState.RegisterPlayer(clientMsg.Username);
            JigsawPlayerController jigsawController = player.GetComponent <JigsawPlayerController>();
            jigsawController.PlayerState = playerState;
            DeferredClientInfo.Remove(conn.connectionId);
        }
    }
    public override void OnServerDisconnect(NetworkConnection conn)
    {
        for (int i = 0; i < conn.playerControllers.Count; ++i)
        {
            PlayerController player = conn.playerControllers[i];
            if (player.gameObject != null)
            {
                JigsawPlayerController jigsawController = player.gameObject.GetComponent <JigsawPlayerController>();
                if (jigsawController)
                {
                    jigsawController.CleanupPlayer();
                    NetWorldState.DeregisterPlayer(jigsawController.PlayerState);
                }
            }
        }

        NetworkServer.DestroyPlayersForConnection(conn);
        if (conn.lastError != NetworkError.Ok && LogFilter.logError)
        {
            Debug.LogError("ServerDisconnected due to error: " + conn.lastError);
        }
        Debug.Log("A client disconnected from the server: " + conn);
    }
 private void ReceiveLocalJigsawPlayer(GameObject PlayerObject)
 {
     LocalPlayer = PlayerObject.GetComponent <JigsawPlayerController>();
 }