How do I pass session details to clients in lobby?

Options
Apologies for the sort-of double-post. I asked a version of this question a few days ago on discord, but no one really had an answer, and I'm realizing I may have been asking the question wrong, and I figured that since this is so long, I should post it here. So let me describe what I'm trying to do:

I'm creating a pretty standard menu interface where a host would set up a session with details: room name, map type, number of players, etc. The client would then see all those sessions and be able to read those details before deciding which one to join. My problem is that I can't figure out how to send those details attached to the session and enable the client to read them.

The host side is pretty simple: it's just strings and integers. The client side is also simple: just use
SessionListUpdated(Map<Guid, UdpSession> sessionList)
to get the list of sessions and iterate through them, assigning those details to various text fields attached to a button for each session, which the client then clicks on to join.

But how do I get that data attached to the session by the host and then read back by the client? I see in the docs that the host would use:
BoltMatchmaking.CreateSession(sessionID: matchName, sceneToLoad: map, token: customToken);
So I assume from this line, that all I have to do is make a token with the details and it will get sent with the session, but I can't find any way for the client to actually read that token. On the same docs page there is a example that lets the client create a new token and compare it to the session, but nothing that actually shows reading the supposedly already-attached token back. There is a reference to "Bolt.Matchmaking.BoltMatchmaking.CreateSession..." and if I look up that page, it lists IProtocolToken as a parameter, but it doesn't go into any details, so it looks as if the page hasn't been fully updated and there are no examples there, either, about reading the existing session token, just creating a new one and applying it to the existing session when joining. What I'm trying to do is read the session details before actually joining. There is one oblique reference to PhotonRoomProperties(, but this seems to be the pre-token way of doing things and only defines what it can be, but not how to actually use it.

So, am I on the right track in thinking that I should be using tokens for this, or should I be looking at something else?

Comments

  • ramonmelo
    Options
    Hello @gevarre ,

    When creating a new session by using the BoltMatchmaking.CreateSession you are able to pass an optional IProtocolToken, so you can retrieve it back on when reading the sessions on the client. Also, the PhotonRoomProperties is not an old token way, it is in fact an implementation of the IProtocolToken interface with some extra functionality. It was built specifically to configure the Photon Session with custom properties and change settings like visibility or openness.

    Sorry for the lack of samples about your specific case, we are working on improving the samples that get delivered with the SDK. But we have a code sample showing how to read this information:

    It's inside the SDK in the folder samples/PhotonCloud. There, you will find the PhotonInit.cs script. As you can see, the normal workflow when using IProtocolToken occurs:

    1. You register it on BoltStartBegin with BoltNetwork.RegisterTokenClass<PhotonRoomProperties>(); (line);
    2. Create a new instance of it, and pass to the BoltMatchmaking.CreateSession (line);
    In order to pass custom data to your session, just use the method, like it's shown in line:
    token.AddRoomProperty("t", 1);
    
    3. The retrieving part is not entirely clear, but it's easy to understand.
    In this sample, you are able to use either the token RoomProtocolToken (which is just a sample Token, you can find it here) or the PhotonRoomProperties. When looking for the Protocol Token associated with the session (in this line), it's first casted to RoomProtocolToken, if you've used that type, you can get any information from it, like it's shown in the here, when looking for the ArbitraryData field. From there, you can extend to read any custom information on your custom Protocol Token. But, if you have used the PhotonRoomProperties, you can get any custom data you've included in the session by using (line):
    if (photonSession.Properties.ContainsKey("t"))
    {
    	var value_t = photonSession.Properties["t"];
    }
    

    As you can see, in the end, we are building the sessionDescription variable, that will be used to show to the clients some session information in this line.

    I hope this clarifies your question.
  • gevarre
    Options
    Thanks. That really helps. I think I've pretty much got it, but now I have to apologize because I'm stuck on the last bit, which is something any programmer should know and not really Bolt-specific:

    In my case, lets say that "t" is a string. At the top of my script I've defined a placeholder in the form of
    private String _tempString;
    

    Now in the above properties section I want to do something along the lines of
    _tempString = value_t;
    

    but of course that doesn't work. How would I go about casting that var as a string? if that's the right question...
  • ramonmelo
    Options
    Hello @gevarre ,

    I recommend that you read this page on the Microsoft documentation about Type testing and Casting, it would give you ideas of how to do any casts you want and how to properly check if the cast is valid.

    Link: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast
  • gevarre
    Options
    Thanks! That's exactly what I needed :)

    That link was a lot clearer than some of the other MS docs I'd been finding. Made a lot of sense. And with that I've finally got it all working and I learned a lot. I appreciate all the help.