Plugin: How modify the properties of a room to be created?

neoneper
neoneper
edited July 2016 in Photon Server
In my plugin, I need to change some properties of rooms in his creation.
I'm making the changes I need, but these changes are not visible on the client. Look!
      public override void OnCreateGame(ICreateGameCallInfo info)
        {
            SerializableGameState gameState = new SerializableGameState();
            gameState.IsOpen = false;
            gameState.IsVisible = false;
            if(PluginHost.SetGameState(gameState))
            {
                info.Continue();
            }
            else
            {
                info.Fail("Fail at set new state on room");
            }
        }
After the room created on the client, we perform a simple check on the Start () component, just to let me know the value of the variables (PhotonNetwork.room.isOpen). But the variables are not suffering changing from plugin! Why??

Please. Can someone help me?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2016
    Hi @neoneper,

    This is an interesting use case! I will test it and get back to you asap. From first sight, I suggest to not create and assign a GameState and use the one created by the client and change the properties that you want.

    For IsOpen and IsVisible you can set them to false as follows (253 and 254 are byte keys of reserved/well-known room properties IsOpen and IsVisible respectively, check full list here) :

    PluginHost.SetProperties(actorNr: 0, properties: new Hashtable() { { 253, false } { 254, false } }, expected: null, broadcast: true);

    so final code:
    public override void OnCreateGame(ICreateGameCallInfo info)
    {
           info.Continue();
           PluginHost.SetProperties(actorNr: 0, properties: new Hashtable() { { 253, false } { 254, false } }, expected: null, broadcast: true);
    }
    Regarding changing properties of a room from plugins in general, please check the relative question available in the Plugins FAQ.
  • Tankx Jhon (^.~). The GamePropertyKey list will be very helpful for me !
  • neoneper
    neoneper
    edited July 2016
    Regarding SetProperties, it works well for me. But it triggers the event OnCustom the room. For me this is an inconvenience in this particular case, but not enough to be a problem. So I have no problems using it.

    So to take my doubt clarify me this:
    Notes: ◦Before processing request, the room state is not initialized and contains default values. This is the only situation where the room state can be loaded from external source, parsed and assigned to the room by calling IPluginHost.SetGameState.
    ◦Before processing request, any call to PluginHost.SetProperties or PluginHost.BroadcastEvent will be ignored.
    ◦You can use ICreateGameCallInfo.IsJoin and ICreateGameCallInfo.CreateIfNotExists to know the type of the operation request.


    Is there a way for me to know what are the properties and especially the custom properties of this request, before its creation be made ?. That is, before using the Continue ()?

    I have the need to prevent the creation of rooms assessing their custom properties. But not figured out a way to capture this data, before accomplishing your creation! Before info.Continue()
  • neoneper
    neoneper
    edited July 2016
    Ohhh, Discovered :smiley: .

    public override void OnCreateGame(ICreateGameCallInfo info) { Hashtable table = (Hashtable)info.CreateOptions[HiveHostGameState.CustomProperties.ToString()]; }
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2016
    Hi again,

    I see that you got what you needed and I consider this good feedback as we may improve docs based on your question and comments.

    Yes you got the basic concept, hook call info argument provides the actual client request when the it is triggered by client operation. So you may use that.

    However, I may have read (notification in my phone) that you asked about broadcast flag (last parameter in PluginHost.SetProperties). Is it clear now?
  • Yes it's true. In my edition, just removing this doubt, I'm finding it strange the fact that when I put broadcast false, setted properties do not reach the clients.

    Could you tell me how this works?
  • JohnTube
    JohnTube ✭✭✭✭✭
    It's simple, SetProperties operation includes a "broadcast" parameter. It should be set to true if you want to propagate properties change to all actors. Sometimes, however, you may set it to false.
  • Does this broadcast include everyone or just people in the room?
    IE: Will it trigger EventCode.GameListUpdate in clients connected to the Lobby?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited March 2017
    Hi @Agustin,

    The broadcast happens only inside the room: all the actors joined to the room will receive EventCode.PropertiesChanged event.

    If you want properties changes to be available from lobby you need to set the keys of those updated properties as lobby properties when you create the room using roomOptions.CustomRoomPropertiesForLobby. The lobby properties keys are required to make them visible from the lobby.

    You can also update the lobby properties keys of a room post creation but I do not see a use case for that.
  • Ha!

    I had seen that setting around.
    Completely forgot about the good n' old CustomRoomPropertiesForLobby.

    Thanks,