void ApprovalCheck(byte[] _compressedSerializedData, ulong _clientId, NetworkingManager.ConnectionApprovedDelegate _callback) { Debug.Log("Client " + _clientId + " is being approved."); bool approve = true; bool createPlayerObject = true; ConnectionApprovalData connectionData = _compressedSerializedData.GetDecompressedAndDeserialized <ConnectionApprovalData>(); // I don't actually know that this is going to do us much good, but it seems like if they hack their game this might catch it and I already coded it :p approve = true || (connectionData.playerPrefabHash == SpawnManager.GetPrefabHashFromGenerator("Player")); if (!connectionDataCache.ContainsKey(_clientId)) { connectionDataCache.Add(_clientId, connectionData); } //If approve is true, the connection gets added. If it's false. The client gets disconnected _callback(createPlayerObject, null, approve, null, null); Debug.Log("Client " + _clientId + " approved, spawning player object"); // set a reference to the NetworkedClient on the Player class for later networking CustomMessagingManager.SendNamedMessage("JoinConnectionAccepted", _clientId, Stream.Null); }
void JoinServer(string _ip, int _port = 20202, string _password = "") { if (Transport == null) { Transport = NetworkingManager.Singleton.GetComponent <UnetTransport>(); } Transport.ConnectAddress = _ip; //takes string Transport.ConnectPort = _port; Debug.Log("Connecting to " + _ip + ":" + _port); ulong?hsh = SpawnManager.GetPrefabHashFromGenerator("Player"); Debug.Log(hsh); ConnectionApprovalData connectionData = new ConnectionApprovalData((ulong)hsh, playerNameField.text, _password); NetworkingManager.Singleton.NetworkConfig.ConnectionData = connectionData.GetSerializedAndCompressed(); NetworkingManager.Singleton.StartClient(); Debug.Log("registered JoinConnectionAccepted"); CustomMessagingManager.RegisterNamedMessageHandler("JoinConnectionAccepted", OnJoinConnectionAccepted); }