So, I was wondering how I can check if a player controller is a host or client, who is doing this function is the server, for security reasons. So in this case I can’t use the “switch has authority”, because I want to know specifically from that player controller
I know this is late, but Get Remote Role
can be used here.
Do your check on the server and check if IsLocalController
, (true → host), (false → client).
How do you do in this case? When…
-AIControllers has authority too
-None AControllers have been spawned yet (there is no pawns)
Thank you!!
Ok, i got it…
//-------------------------------------------------
bool FStaticNet::IsHost(const AController* Controller)
{
if (!IsValid(Controller))
{
message::Error("FStaticNet::IsHost -> Controller is NULL");
return false;
}
return (Controller->HasAuthority() && Controller->IsLocalController() && !IsBot(Controller));
}
//---------------------------------------------------------
bool FStaticNet::IsBot(const AController* Controller)
{
if (!IsValid(Controller))
{
message::Error("FStaticNet::IsBot -> Controller is NULL");
return false;
}
const UClass* Class = Controller->GetClass();
if (!IsValid(Class))
{
message::Error("FStaticNet::IsBot -> Class is NULL");
return false;
}
//Is a BOT
if(!Class->IsChildOf(AAIController::StaticClass())) return false;
return true;
}
it seem to work… but i’m no sure if it is the rigth way…
¿What do you think?
thx u so much!!
It works, but IsLocalController && !IsBot
can be replaced with IsLocalPlayerController
.
If still needed, the second function IsBot
can also be replaced with simply Controller->IsA<AAIController>()
, or !Controller->IsPlayerController()
I like your way better. The simpler the better. Thank you very much for the help Chatouille!!
Guys, the most proper way imo is just use function/node “Has autority”. It simply mean does this player controller has network autority.
That won’t work though because the host also has authority over the other controllers.
IsLocalPlayerController is the solution which has already been mentioned.
Hmm, strange, in my case, to separate execution flow for host and clients only Has Autority helped. IsLocalPlayerController was not working as needed.
I think this function “IsLocalPlayerController” helps to understand, does we work with server player controllers or with local controllers, which mean first controller for each client side.
And “Has Authority” gives info about network access level for specific Player Controller. So it is important to have clear understanding which to use in which case.