- Home /
Approval Connection allow connection with the wrong password
Hi I'm using NetCode 1.7.0-pre-2 with Unet Transform but when I'm Starting to host I get the following warning: ![enter image description here][1]
and then when I'm starting to client and pass the wrong password it allow me to connect and it shouldn't
Heres my code:
public class MainManu : MonoBehaviour
{
string Name;
string Password;
[Space] [Header("Name & Password")]
[SerializeField] TMP_InputField Name_Text;
[SerializeField] TMP_InputField Password_Text;
// run when a client conncted to approval his connection
void ApprovalCheck(byte[] connectionDate, ulong clientID, NetworkManager.ConnectionApprovedDelegate callback)
{
string Data = Encoding.ASCII.GetString(connectionDate);
bool approveConnection = Data == Password;
Debug.Log(approveConnection);
callback(true , null, false, null, null);
}
public void Host()
{
byte[] Data = Encoding.ASCII.GetBytes(Password);
NetworkManager.Singleton.NetworkConfig.ConnectionData = Data;
NetworkManager.Singleton.ConnectionApprovalCallback += ApprovalCheck;
NetworkManager.Singleton.StartHost();
}
public void Join()
{
byte[] Data = Encoding.ASCII.GetBytes(Password);
NetworkManager.Singleton.NetworkConfig.ConnectionData = Data;
NetworkManager.Singleton.StartClient();
}
}
does any body have any idea how to enable ConnectionApproval?
Answer by VanToRiaXVII · Apr 19 at 03:21 PM
I have some trouble figuring out if you're using MLAPI or UNet for this. If you are using MLAPI, there is a sample code snippet on how to do your ConnectionApproval callback here: https://docs-multiplayer.unity3d.com/netcode/0.1.0/getting-started/connection-approval/
If you are using UNet on the other hand, I had no luck finding documentation on it, but this question on Stack Overflow can give you a good starting point to figure out how to properly use ConnectionApproval: https://stackoverflow.com/questions/70206124/unity-multiplayer