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}"); } }
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); } }
internal void OnServerConnectInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnServerConnectInternal"); netMsg.Connection.SetMaxDelay(maxDelay); if (m_MaxBufferedPackets != 512) { for (var i = 0; i < QNetworkServer.numChannels; i++) { netMsg.Connection.SetChannelOption(i, ChannelOption.MaxPendingBuffers, m_MaxBufferedPackets); } } if (!m_AllowFragmentation) { for (var j = 0; j < QNetworkServer.numChannels; j++) { netMsg.Connection.SetChannelOption(j, ChannelOption.AllowFragmentation, 0); } } if (networkSceneName != "" && networkSceneName != offlineScene) { var msg = new QStringMessage(networkSceneName); netMsg.Connection.Send(39, msg); } OnServerConnect(netMsg.Connection); }
private static void OnLocalClientObjectSpawnScene(QNetworkMessage netMsg) { netMsg.ReadMessage(s_ObjectSpawnSceneMessage); if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnSceneMessage.NetId, out var networkIdentity)) { networkIdentity.OnSetLocalVisibility(true); } }
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); }
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); } }
internal void OnClientDisconnectInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnClientDisconnectInternal"); if (!string.IsNullOrEmpty(offlineScene)) { ClientChangeScene(offlineScene, false); } OnClientDisconnect(netMsg.Connection); }
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); } }
internal void OnClientSceneInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnClientSceneInternal"); var newSceneName = netMsg.Reader.ReadString(); if (IsClientConnected() && !QNetworkServer.active) { ClientChangeScene(newSceneName, true); } }
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}"); } } }
private static void OnUpdateVarsMessage(QNetworkMessage netMsg) { var networkInstanceId = netMsg.Reader.ReadNetworkId(); if (s_NetworkScene.GetNetworkIdentity(networkInstanceId, out var networkIdentity)) { networkIdentity.OnUpdateVars(netMsg.Reader, false); } else { Debug.LogWarning($"Did not find target for sync message for {networkInstanceId}"); } }
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); } }
private static void OnSyncListMessage(QNetworkMessage netMsg) { var networkInstanceId = netMsg.Reader.ReadNetworkId(); var cmdHash = (int)netMsg.Reader.ReadPackedUInt32(); Debug.Log($"ClientScene::OnSyncListMessage {networkInstanceId}"); if (s_NetworkScene.GetNetworkIdentity(networkInstanceId, out var networkIdentity)) { networkIdentity.HandleSyncList(cmdHash, netMsg.Reader); } else { Debug.LogWarning($"Did not find target for SyncList message for {networkInstanceId}"); } }
private static void OnRPCMessage(QNetworkMessage netMsg) { var num = (int)netMsg.Reader.ReadPackedUInt32(); var networkInstanceId = netMsg.Reader.ReadNetworkId(); Debug.Log($"ClientScene::OnRPCMessage hash:{num} netId:{networkInstanceId}"); if (s_NetworkScene.GetNetworkIdentity(networkInstanceId, out var networkIdentity)) { networkIdentity.HandleRPC(num, netMsg.Reader); } else { var cmdHashHandlerName = QNetworkBehaviour.GetCmdHashHandlerName(num); Debug.LogWarningFormat("Could not find target object with netId:{0} for RPC call {1}", networkInstanceId, cmdHashHandlerName); } }
public bool InvokeHandler(QNetworkMessage netMsg) { bool result; if (m_MessageHandlersDict.ContainsKey(netMsg.MsgType)) { var networkMessageDelegate = m_MessageHandlersDict[netMsg.MsgType]; networkMessageDelegate(netMsg); result = true; } else { result = false; } return(result); }
internal void OnClientConnectInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnClientConnectInternal"); netMsg.Connection.SetMaxDelay(maxDelay); var name = SceneManager.GetSceneAt(0).name; if (string.IsNullOrEmpty(onlineScene) || onlineScene == offlineScene || name == onlineScene) { clientLoadedScene = false; OnClientConnect(netMsg.Connection); } else { s_ClientReadyConnection = netMsg.Connection; } }
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); } } }
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; } }
public static void HandleTransform(QNetworkMessage netMsg) { var networkInstanceId = netMsg.Reader.ReadNetworkId(); var gameObject = QNetworkServer.FindLocalObject(networkInstanceId); if (gameObject == null) { QLog.Warning("Received NetworkTransform data for GameObject that doesn't exist"); } else { var component = gameObject.GetComponent <QNetworkTransform>(); if (component == null) { QLog.Warning("HandleTransform null target"); } else if (!component.LocalPlayerAuthority) { QLog.Warning("HandleTransform no localPlayerAuthority"); } else if (netMsg.Connection.ClientOwnedObjects == null) { QLog.Warning("HandleTransform object not owned by connection"); } else if (netMsg.Connection.ClientOwnedObjects.Contains(networkInstanceId)) { component.UnserializeModeTransform(netMsg.Reader, false); component.LastSyncTime = Time.time; } else { QLog.Warning( $"HandleTransform netId:{networkInstanceId} is not for a valid player"); } } }
private void OnServerReceiveMessageHandler(QNetworkMessage netMsg) { var message = netMsg.ReadMessage <T>(); OnServerReceiveMessage?.SafeInvoke(message); }
internal void OnClientErrorInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnClientErrorInternal"); netMsg.ReadMessage(s_ErrorMessage); OnClientError(netMsg.Connection, s_ErrorMessage.errorCode); }
internal void OnClientNotReadyMessageInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnClientNotReadyMessageInternal"); QClientScene.SetNotReady(); OnClientNotReady(netMsg.Connection); }
private static void OnLocalClientObjectDestroy(QNetworkMessage netMsg) { netMsg.ReadMessage(s_ObjectDestroyMessage); Debug.Log($"ClientScene::OnLocalObjectObjDestroy netId:{s_ObjectDestroyMessage.NetId}"); s_NetworkScene.RemoveLocalObject(s_ObjectDestroyMessage.NetId); }
internal void OnServerReadyMessageInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnServerReadyMessageInternal"); OnServerReady(netMsg.Connection); }
internal void OnServerDisconnectInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnServerDisconnectInternal"); OnServerDisconnect(netMsg.Connection); }
internal static void OnFragment(QNetworkMessage netMsg) => netMsg.Connection.HandleFragment(netMsg.Reader, netMsg.ChannelId);