internal static void HandleAddObject(uint clientId, byte[] incommingData, int channelId) { BitReader reader = new BitReader(incommingData); if (netManager.NetworkConfig.HandleObjectSpawning) { bool isPlayerObject = reader.ReadBool(); uint networkId = reader.ReadUInt(); uint ownerId = reader.ReadUInt(); int prefabId = reader.ReadInt(); bool sceneObject = reader.ReadBool(); bool visible = reader.ReadBool(); float xPos = reader.ReadFloat(); float yPos = reader.ReadFloat(); float zPos = reader.ReadFloat(); float xRot = reader.ReadFloat(); float yRot = reader.ReadFloat(); float zRot = reader.ReadFloat(); if (isPlayerObject) { netManager.connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId }); GameObject go = SpawnManager.SpawnPlayerObject(ownerId, networkId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot)); go.GetComponent <NetworkedObject>().SetLocalVisibility(visible); } else { GameObject go = SpawnManager.SpawnPrefabIndexClient(prefabId, networkId, ownerId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot)); go.GetComponent <NetworkedObject>().SetLocalVisibility(visible); go.GetComponent <NetworkedObject>().sceneObject = sceneObject; } } else { uint ownerId = reader.ReadUInt(); netManager.connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId }); } }
internal static void HandleAddObjects(uint clientId, BitReader reader, int channelId) { if (netManager.NetworkConfig.HandleObjectSpawning) { ushort objectCount = reader.ReadUShort(); for (int i = 0; i < objectCount; i++) { bool isPlayerObject = reader.ReadBool(); uint networkId = reader.ReadUInt(); uint ownerId = reader.ReadUInt(); int prefabId = reader.ReadInt(); bool sceneObject = reader.ReadBool(); bool visible = reader.ReadBool(); float xPos = reader.ReadFloat(); float yPos = reader.ReadFloat(); float zPos = reader.ReadFloat(); float xRot = reader.ReadFloat(); float yRot = reader.ReadFloat(); float zRot = reader.ReadFloat(); if (isPlayerObject) { netManager.connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId }); netManager.connectedClientsList.Add(netManager.connectedClients[ownerId]); GameObject go = SpawnManager.SpawnPlayerObject(ownerId, networkId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot), visible ? reader : null); go.GetComponent <NetworkedObject>().SetLocalVisibility(visible); } else { GameObject go = SpawnManager.SpawnPrefabIndexClient(prefabId, networkId, ownerId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot), visible ? reader : null); go.GetComponent <NetworkedObject>().SetLocalVisibility(visible); go.GetComponent <NetworkedObject>().sceneObject = sceneObject; } } } }
internal static void HandleConnectionApproved(uint clientId, BitReader reader, int channelId) { netManager.myClientId = reader.ReadUInt(); uint sceneIndex = 0; if (netManager.NetworkConfig.EnableSceneSwitching) { sceneIndex = reader.ReadUInt(); } #if !DISABLE_CRYPTOGRAPHY if (netManager.NetworkConfig.EnableEncryption) { byte[] serverPublicKey = reader.ReadByteArray(); netManager.clientAesKey = netManager.clientDiffieHellman.GetSharedSecret(serverPublicKey); if (netManager.NetworkConfig.SignKeyExchange) { byte[] publicKeySignature = reader.ReadByteArray(); using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa.PersistKeyInCsp = false; rsa.FromXmlString(netManager.NetworkConfig.RSAPublicKey); if (!rsa.VerifyData(serverPublicKey, new SHA512CryptoServiceProvider(), publicKeySignature)) { //Man in the middle. if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { LogHelper.LogWarning("Signature doesnt match for the key exchange public part. Disconnecting"); } } netManager.StopClient(); return; } } } } #endif float netTime = reader.ReadFloat(); int remoteStamp = reader.ReadInt(); byte error; int msDelay = NetworkingManager.singleton.NetworkConfig.NetworkTransport.GetRemoteDelayTimeMS(clientId, remoteStamp, out error); netManager.networkTime = netTime + (msDelay / 1000f); netManager.connectedClients.Add(netManager.MyClientId, new NetworkedClient() { ClientId = netManager.MyClientId }); int clientCount = reader.ReadInt(); for (int i = 0; i < clientCount; i++) { uint _clientId = reader.ReadUInt(); netManager.connectedClients.Add(_clientId, new NetworkedClient() { ClientId = _clientId }); netManager.connectedClientsList.Add(netManager.connectedClients[_clientId]); } if (netManager.NetworkConfig.HandleObjectSpawning) { SpawnManager.DestroySceneObjects(); int objectCount = reader.ReadInt(); for (int i = 0; i < objectCount; i++) { bool isPlayerObject = reader.ReadBool(); uint networkId = reader.ReadUInt(); uint ownerId = reader.ReadUInt(); int prefabId = reader.ReadInt(); bool isActive = reader.ReadBool(); bool sceneObject = reader.ReadBool(); bool visible = reader.ReadBool(); float xPos = reader.ReadFloat(); float yPos = reader.ReadFloat(); float zPos = reader.ReadFloat(); float xRot = reader.ReadFloat(); float yRot = reader.ReadFloat(); float zRot = reader.ReadFloat(); if (isPlayerObject) { GameObject go = SpawnManager.SpawnPlayerObject(ownerId, networkId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot), visible ? reader : null); go.GetComponent <NetworkedObject>().SetLocalVisibility(visible); } else { GameObject go = SpawnManager.SpawnPrefabIndexClient(prefabId, networkId, ownerId, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot), visible ? reader : null); go.GetComponent <NetworkedObject>().SetLocalVisibility(visible); go.GetComponent <NetworkedObject>().sceneObject = sceneObject; go.SetActive(isActive); } } } if (netManager.NetworkConfig.EnableSceneSwitching) { NetworkSceneManager.OnSceneSwitch(sceneIndex); } netManager._isClientConnected = true; if (netManager.OnClientConnectedCallback != null) { netManager.OnClientConnectedCallback.Invoke(netManager.MyClientId); } }