add logs to GetPlayerId

This commit is contained in:
Mister_Nebula 2021-06-11 21:19:08 +01:00
parent 2ed5e43db3
commit d3f0af5d3c

View File

@ -40,8 +40,33 @@ namespace QSB.Utility
// QNET
public static uint GetPlayerId(this QNetworkConnection connection)
{
var go = connection.PlayerControllers[0].Gameobject;
if (connection == null)
{
DebugLog.DebugWrite($"Error - Trying to get player id of null QNetworkConnection.", MessageType.Error);
return uint.MaxValue;
}
var playerController = connection.PlayerControllers[0];
if (playerController == null)
{
DebugLog.DebugWrite($"Error - Player Controller of {connection.address} is null.", MessageType.Error);
return uint.MaxValue;
}
var go = playerController.Gameobject;
if (go == null)
{
DebugLog.DebugWrite($"Error - GameObject of {playerController.UnetView.NetId.Value} is null.", MessageType.Error);
return uint.MaxValue;
}
var controller = go.GetComponent<PlayerTransformSync>();
if (controller == null)
{
DebugLog.DebugWrite($"Error - No PlayerTransformSync found on {go.name}", MessageType.Error);
return uint.MaxValue;
}
return controller.NetId.Value;
}