How to Get Host Token?
Options
in Photon Bolt
I am attempting to use Protocol Tokens to send player relevant data to the server (such as player name and player selected color). To do so for joining clients (all players who are not host), I am using:
I then access the 'PlayerSettings' token on the server and other clients by looping through the connections and reading '.ConnectToken', like so:
I also want to receive a token for the player that is the host, and this is where I am having issues.
I am attempting to send the host's 'PlayerSettings' token like so:
However, I have not been able to access this token after the session has been created.
When I loop through the connections, the connection for the host does not show up.
I have also attempted to access the session token like so:
However, the token (session.HostObject) is always NULL.
How can I obtain an IProtocolToken from the player that is the host?
Any help is greatly appreciated
BoltMatchmaking.JoinSession(photonSession, PlayerSettings);Where 'PlayerSettings' is a registered IProtocolToken.
I then access the 'PlayerSettings' token on the server and other clients by looping through the connections and reading '.ConnectToken', like so:
foreach(var connection in BoltNetwork.Connections) { var playerSettings = (PlayerSettings)connection.ConnectToken; // I use 'playerSettings' here }
I also want to receive a token for the player that is the host, and this is where I am having issues.
I am attempting to send the host's 'PlayerSettings' token like so:
public override void BoltStartDone() { BoltMatchmaking.CreateSession(sessionID: "test", sceneToLoad: "Lobby", token: PlayerSettings); }
However, I have not been able to access this token after the session has been created.
When I loop through the connections, the connection for the host does not show up.
I have also attempted to access the session token like so:
var session = BoltMatchmaking.CurrentSession; var token = session.HostObject;
However, the token (session.HostObject) is always NULL.
How can I obtain an IProtocolToken from the player that is the host?
Any help is greatly appreciated
0
Comments
-
Hi,
Some points that you need to keep in mind.
1. There is not a connection to the local Server, when you start as a Server, despite what may seem, you are not running a Client AND a Server, using a fake connection. You are the local peer, and this peer accepts connections from other peers, that is what makes it the server.
2. The token you pass when creating the Session, is used either to be acceded by the Clients and/or to configure the Session, so it should not be used to send player settings. Please take a look at the API Docs: https://doc-api.photonengine.com/en/bolt/current/class_bolt_1_1_matchmaking_1_1_bolt_matchmaking.html#ae0ede5d9a889af35ca0bb07932bfbd2e
In order to get access to the Session Token, you can get it from:using Bolt.Utils; // ... // Example Code private T GetToken<T>() { var session = BoltMatchmaking.CurrentSession; return (T)session.GetProtocolToken(); // You get the Session Token here }
Links:
1. https://doc.photonengine.com/en-us/bolt/current/in-depth/photon-cloud
2. https://doc.photonengine.com/en-us/bolt/current/lobby-and-matchmaking/bolt-matchmaking
But, as you are running the player as a local player, you could just get the local settings from your Player Settings manager, no?
Unfortunately, you will need to abstract the local player using another code layer, as this is not treated by Bolt.
One suggestion, in this case, is to take a better look at the Advanced Tutorial, as it includes a Player abstraction, so you can treat all players the same way, even the local player.
Just look for the "Player.cs" file, and where it's used.
Link: https://github.com/BoltEngine/Bolt-Sample/blob/master/AdvancedTutorial/scripts/Player/Player.cs
--
Ramon Melo
Photon Bolt Team1