How Can I Eject a Player from a Multiplayer App?
in Photon Bolt
I'm developing a multiplayer VR app for the Oculus Quest using Bolt in Unity 2019.4.4f1. I want the host to be able to eject "misbehaving" players. Can someone suggest a procedure or provide code for doing that? I tried using this code from the LobbyPlayer script from the Photon lobby demo in a script I created, but the code causes compiler errors.
public void OnRemovePlayerClick()
{
if (BoltNetwork.IsServer)
{
LobbyPlayerKick.Create(entity, EntityTargets.OnlyController).Send();
}
}
public override void OnEvent(LobbyPlayerKick evnt)
{
BoltNetwork.Shutdown();
}
public void OnRemovePlayerClick()
{
if (BoltNetwork.IsServer)
{
LobbyPlayerKick.Create(entity, EntityTargets.OnlyController).Send();
}
}
public override void OnEvent(LobbyPlayerKick evnt)
{
BoltNetwork.Shutdown();
}
0
Answers
-
how gangster would you like to eject them?0
-
Since the players would be misbehaving, it can be pretty gangster.
0 -
Hi @OjosLindos ,
This depends on how your entities are created:
1. If your server is creating all entities and assigning control to a remote client, you can get the reference for the connection using: "BoltEntity.Controller" (https://doc-api.photonengine.com/en/bolt/current/class_photon_1_1_bolt_1_1_bolt_entity.html#af0226ef10d69201dcd53495d71049b5e)
2. If each client is creating its own entity, on the server you can get the connection that has created the Entity using "BoltEntity.Source" (https://doc-api.photonengine.com/en/bolt/current/class_photon_1_1_bolt_1_1_bolt_entity.html#abe4b1a633519faad6e154cf5d463c09a)
Once you get the "BoltConnection" reference, just call "BoltConnection.Disconnect()" (https://doc-api.photonengine.com/en/bolt/current/class_photon_1_1_bolt_1_1_bolt_connection.html#a4071cd94530a97518307fe92025ef311) on the Server, this will make the client to be disconnected. If you want to send more information to the client, just invoke the second override, which includes a Protocol Token and a Disconnect Reason.
On the client-side, you can check the reason on the "GlobalEventListener.Disconnected" callback, checking either the "BoltConnection.DisconnectReason" and "BoltConnection.DisconnectToken".
--
Ramon Melo
Photon Bolt Team0