Пример #1
0
 private static void OnOwnerMessage(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_OwnerMessage);
     Debug.Log(
         $"ClientScene::OnOwnerMessage - connectionId={netMsg.Connection.connectionId} netId: {s_OwnerMessage.NetId}");
     if (netMsg.Connection.GetPlayerController(s_OwnerMessage.PlayerControllerId, out var playerController))
     {
         playerController.UnetView.SetNotLocalPlayer();
     }
     if (s_NetworkScene.GetNetworkIdentity(s_OwnerMessage.NetId, out var networkIdentity))
     {
         networkIdentity.SetConnectionToServer(netMsg.Connection);
         networkIdentity.SetLocalPlayer(s_OwnerMessage.PlayerControllerId);
         InternalAddPlayer(networkIdentity, s_OwnerMessage.PlayerControllerId);
     }
     else
     {
         var item = new PendingOwner
         {
             netId = s_OwnerMessage.NetId,
             playerControllerId = s_OwnerMessage.PlayerControllerId
         };
         s_PendingOwnerIds.Add(item);
     }
 }
Пример #2
0
 private static void OnObjectDestroy(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ObjectDestroyMessage);
     Debug.Log($"ClientScene::OnObjDestroy netId:{s_ObjectDestroyMessage.NetId}");
     if (s_NetworkScene.GetNetworkIdentity(s_ObjectDestroyMessage.NetId, out var networkIdentity))
     {
         networkIdentity.OnNetworkDestroy();
         if (!QNetworkScene.InvokeUnSpawnHandler(networkIdentity.AssetId, networkIdentity.gameObject))
         {
             if (networkIdentity.SceneId.IsEmpty())
             {
                 Object.Destroy(networkIdentity.gameObject);
             }
             else
             {
                 networkIdentity.gameObject.SetActive(false);
                 SpawnableObjects[networkIdentity.SceneId] = networkIdentity;
             }
         }
         s_NetworkScene.RemoveLocalObject(s_ObjectDestroyMessage.NetId);
         networkIdentity.MarkForReset();
     }
     else
     {
         Debug.LogWarning($"Did not find target for destroy message for {s_ObjectDestroyMessage.NetId}");
     }
 }
 internal void OnServerRemovePlayerMessageInternal(QNetworkMessage netMsg)
 {
     QLog.Log("NetworkManager:OnServerRemovePlayerMessageInternal");
     netMsg.ReadMessage(s_RemovePlayerMessage);
     netMsg.Connection.GetPlayerController(s_RemovePlayerMessage.PlayerControllerId, out var player);
     OnServerRemovePlayer(netMsg.Connection, player);
     netMsg.Connection.RemovePlayerController(s_RemovePlayerMessage.PlayerControllerId);
 }
Пример #4
0
 private static void OnLocalClientObjectSpawnScene(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ObjectSpawnSceneMessage);
     if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnSceneMessage.NetId, out var networkIdentity))
     {
         networkIdentity.OnSetLocalVisibility(true);
     }
 }
Пример #5
0
 private static void OnLocalClientObjectHide(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ObjectDestroyMessage);
     Debug.Log($"ClientScene::OnLocalObjectObjHide netId:{s_ObjectDestroyMessage.NetId}");
     if (s_NetworkScene.GetNetworkIdentity(s_ObjectDestroyMessage.NetId, out var networkIdentity))
     {
         networkIdentity.OnSetLocalVisibility(false);
     }
 }
Пример #6
0
 private static void OnClientAuthority(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ClientAuthorityMessage);
     Debug.Log(
         $"ClientScene::OnClientAuthority for  connectionId={netMsg.Connection.connectionId} netId: {s_ClientAuthorityMessage.netId}");
     if (s_NetworkScene.GetNetworkIdentity(s_ClientAuthorityMessage.netId, out var networkIdentity))
     {
         networkIdentity.HandleClientAuthority(s_ClientAuthorityMessage.authority);
     }
 }
Пример #7
0
 private static void OnObjectSpawn(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ObjectSpawnMessage);
     if (!s_ObjectSpawnMessage.assetId.IsValid())
     {
         Debug.LogError($"OnObjSpawn netId: {s_ObjectSpawnMessage.NetId} has invalid asset Id. {s_ObjectSpawnMessage.assetId}");
     }
     else
     {
         if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnMessage.NetId, out var component))
         {
             ApplySpawnPayload(component, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Payload, s_ObjectSpawnMessage.NetId, null);
         }
         else if (QNetworkScene.GetPrefab(s_ObjectSpawnMessage.assetId, out var original))
         {
             var gameObject = Object.Instantiate(original, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Rotation);
             component = gameObject.GetComponent <QNetworkIdentity>();
             if (component == null)
             {
                 Debug.LogError($"Client object spawned for {s_ObjectSpawnMessage.assetId} does not have a NetworkIdentity");
             }
             else
             {
                 component.Reset();
                 ApplySpawnPayload(component, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Payload, s_ObjectSpawnMessage.NetId, gameObject);
             }
         }
         else if (QNetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out var spawnDelegate))
         {
             var gameObject2 = spawnDelegate(s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.assetId);
             if (gameObject2 == null)
             {
                 Debug.LogWarning($"Client spawn handler for {s_ObjectSpawnMessage.assetId} returned null");
             }
             else
             {
                 component = gameObject2.GetComponent <QNetworkIdentity>();
                 if (component == null)
                 {
                     Debug.LogError($"Client object spawned for {s_ObjectSpawnMessage.assetId} does not have a network identity");
                 }
                 else
                 {
                     component.Reset();
                     component.SetDynamicAssetId(s_ObjectSpawnMessage.assetId);
                     ApplySpawnPayload(component, s_ObjectSpawnMessage.Position, s_ObjectSpawnMessage.Payload, s_ObjectSpawnMessage.NetId, gameObject2);
                 }
             }
         }
         else
         {
             Debug.LogError($"Failed to spawn server object, did you forget to add it to the QSBNetworkManager? assetId={s_ObjectSpawnMessage.assetId} netId={s_ObjectSpawnMessage.NetId}");
         }
     }
 }
 internal void OnServerAddPlayerMessageInternal(QNetworkMessage netMsg)
 {
     QLog.Log("NetworkManager:OnServerAddPlayerMessageInternal");
     netMsg.ReadMessage(s_AddPlayerMessage);
     if (s_AddPlayerMessage.msgSize != 0)
     {
         var extraMessageReader = new NetworkReader(s_AddPlayerMessage.msgData);
         OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId, extraMessageReader);
     }
     else
     {
         OnServerAddPlayer(netMsg.Connection, s_AddPlayerMessage.playerControllerId);
     }
 }
Пример #9
0
 private static void OnObjectSpawnFinished(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ObjectSpawnFinishedMessage);
     Debug.Log($"SpawnFinished:{s_ObjectSpawnFinishedMessage.State}");
     if (s_ObjectSpawnFinishedMessage.State == 0U)
     {
         PrepareToSpawnSceneObjects();
         s_IsSpawnFinished = false;
     }
     else
     {
         foreach (var networkIdentity in Objects.Values)
         {
             if (!networkIdentity.IsClient)
             {
                 networkIdentity.OnStartClient();
                 CheckForOwner(networkIdentity);
             }
         }
         s_IsSpawnFinished = true;
     }
 }
Пример #10
0
 private static void OnObjectSpawnScene(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ObjectSpawnSceneMessage);
     if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnSceneMessage.NetId, out var networkIdentity))
     {
         ApplySpawnPayload(networkIdentity, s_ObjectSpawnSceneMessage.Position, s_ObjectSpawnSceneMessage.Payload, s_ObjectSpawnSceneMessage.NetId, networkIdentity.gameObject);
     }
     else
     {
         var networkIdentity2 = SpawnSceneObject(s_ObjectSpawnSceneMessage.SceneId);
         if (networkIdentity2 == null)
         {
             Debug.LogError($"Spawn scene object not found for {s_ObjectSpawnSceneMessage.SceneId}");
         }
         else
         {
             Debug.Log(
                 $"Client spawn for [netId:{s_ObjectSpawnSceneMessage.NetId}] [sceneId:{s_ObjectSpawnSceneMessage.SceneId}] obj:{networkIdentity2.gameObject.name}");
             ApplySpawnPayload(networkIdentity2, s_ObjectSpawnSceneMessage.Position, s_ObjectSpawnSceneMessage.Payload, s_ObjectSpawnSceneMessage.NetId, networkIdentity2.gameObject);
         }
     }
 }
Пример #11
0
 internal void OnClientErrorInternal(QNetworkMessage netMsg)
 {
     QLog.Log("NetworkManager:OnClientErrorInternal");
     netMsg.ReadMessage(s_ErrorMessage);
     OnClientError(netMsg.Connection, s_ErrorMessage.errorCode);
 }
Пример #12
0
 private static void OnLocalClientObjectDestroy(QNetworkMessage netMsg)
 {
     netMsg.ReadMessage(s_ObjectDestroyMessage);
     Debug.Log($"ClientScene::OnLocalObjectObjDestroy netId:{s_ObjectDestroyMessage.NetId}");
     s_NetworkScene.RemoveLocalObject(s_ObjectDestroyMessage.NetId);
 }
Пример #13
0
        private void OnServerReceiveMessageHandler(QNetworkMessage netMsg)
        {
            var message = netMsg.ReadMessage <T>();

            OnServerReceiveMessage?.SafeInvoke(message);
        }