JoinRandomroomwith property not working (Load balancing sample )

Harish_Kagale
edited May 2016 in Native
trying to create and join room with customRoomProperties , room gets created with custom property but not able to join the room with customProperty
following is the code.


static const ExitGames::Common::JString ROOM_CATEGORY = L"R";

// create room call

ExitGames::Common::Hashtable roomProperties = ExitGames::Common::Hashtable();
roomProperties.put(static_cast(ROOM_CATEGORY),ExitGames::Common::JString(L"") + 100);

mLoadBalancingClient.opCreateRoom(name, ExitGames::LoadBalancing::RoomOptions().setMaxPlayers(2).setPlayerTtl(INT_MAX/2).setEmptyRoomTtl(10000).setCustomRoomProperties(roomProperties));



//JoinRandomRoomCall


ExitGames::Common::Hashtable roomProperties = ExitGames::Common::Hashtable();
roomProperties.put(static_cast(ROOM_CATEGORY),ExitGames::Common::JString(L"") + 100);
mLoadBalancingClient.opJoinRandomRoom(roomProperties);


what i am doing wrong here please help

Comments

  • Hi @Harish_Kagale.

    Room properties are by default only available for clients that have already joined the room.
    Only those room properties get exposed in the lobby, for which this is explicitly requested on room creation by adding the keys of those properties to the "propsListedInLobby" room option.

    Regarding your follow up question per mail:
    The player properties of the players that are inside a certain room, are only available to other players that are inside the same room.
    If a client has not entered a game room, but is just inside the lobby, it can not see any player properties except its own ones.

    There is no option to expose player properties to the lobby.

    If you really need this, then you could simply add a key for it to the room properties and also to the propsListedInLobby and then later let joining players update the value behind that room property.

    For example the value could be a Dictionary > and each player could add an entry to that Dictionary with the key being it's playerNr and the value being a Dictionary that contains all the player properties that need to be shown in the lobby.

    Keep in mind however that all those properties that re made available to clients outside the room need to be transferred to every client in the lobby in which the room is listed. With a lot of open rooms this can easily cause so much traffic that new clients entering the lobby can't handle all that traffic anymore, that is incoming at once.

    So you should really be careful and think twice about every option that you want to expose to the lobby. Everything will work just fine while debugging with only a few rooms, but if out of a sudden you game takes off and you have hundreds or even thousands of opens rooms in parallel, you will be in trouble with lots of exposed properties.
    Therefor please loadtest if everything still works fine with lots of open rooms, before releasing a game that exposes many properties to clients outside the room.
  • Harish_Kagale
    edited May 2016
    hi Kaiserludi

    I dont want to expose player properites to the users outside room, i just want to share the player properties (Ex . XP level , player name etc ) within the room itself after joining , where do set these properties and how do i get those properties
    Thanks
  • Hi @Harish_Kagale.

    Thanks for the clarification.

    Client::getLocalPlayer() returns a non-const reference to the MutablePlayer instance that holds the local player.
    That instance offers the following functions and function templates for modifying the players properties:
    
    void mergeCustomProperties(const Common::Hashtable& customProperties);
    			template<typename ktype, typename vtype> void addCustomProperty(const ktype& key, const vtype& value);
    			void addCustomProperties(const Common::Hashtable& customProperties);
    			template<typename ktype> void removeCustomProperty(const ktype& key);
    			template<typename ktype> void removeCustomProperties(const ktype* keys, unsigned int count);
    Client::getCurrentlyJoinedRoom() returns the room you are in (if any). On that MutableRoom instance you can call getPlayers(), which returns a const Common::JVector of the players that are currently inside that room. On each Player instance in that JVector you can call getCustomProperties().

  • Hi @Kaiserludi
    Thanks for the explaination.

    i tried the following

    1) I set custom property for the creator of the room in CreateRoomReturn callback and tried to get it in JoinRoomEvent callback at the joiner Client,
    2) In JoinRandomRoomReturn callback of joiner client i set the custom property for Joiner client and trying to get the custom property at the room creator in JoinRoomEvent callback

    Problem :- Recieving the same Custom property for both the clients:

    Help me

  • Hi @Harish_Kagale.

    You mean you are reading out the custom property from the Player reference that gets passed to joinRoomEventAction()?

    In that case the observed behavior is intended. That Player instance alway refers to the Player that has just joined and not to a player that is already inside the room.

    Please use MutableRoom::getPlayers() to access the Player instances of all players inside the room.
  • Harish_Kagale
    edited May 2016
    Hi @Kaiserludi
    No , I am using mutable Room to access player I am using the following code to access the property of Host(Room creator ) at the client end.


    void NetworkLogic::joinRoomEventAction(int playerNr, const ExitGames::Common::JVector& /*playernrs*/, const ExitGames::LoadBalancing::Player& player)
    {
    EGLOG(ExitGames::Common::DebugLevel::INFO, L"%ls joined the game", player.getName().cstr());
    mpOutputListener->writeLine(L"");
    if(playerNr == 1)
    {

    mpOutputListener->HostJoined();
    }else
    {
    ExitGames::Common::Hashtable HostProperties = mLoadBalancingClient.getCurrentlyJoinedRoom().getPlayerForNumber(1)->getCustomProperties();
    ExitGames::Common::JString trophiesCount = ((ExitGames::Common::ValueObject)(HostProperties.getValue(static_cast(TROPHIES)))).getDataCopy();
    mpOutputListener->write(L"------------Opponent Trophies Count:"+trophiesCount);
    mpOutputListener->OpponentJoined();
    }
    //mpOutputListener->writeLine(ExitGames::Common::JString(L"player ") + playerNr + L" " + player.getName() + L" has joined the game");
    }

    and the custom property for joiner client has been set in the joinRandomRoomReturn callback as below

    ExitGames::Common::Hashtable properties =ExitGames::Common::Hashtable();
    properties.put(static_cast(TROPHIES), L"2000");
    mLoadBalancingClient.getLocalPlayer().mergeCustomProperties(properties);
  • Hi @Harish_Kagale.
    1) I set custom property for the creator of the room in CreateRoomReturn callback and tried to get it in JoinRoomEvent callback at the joiner Client,
    2) In JoinRandomRoomReturn callback of joiner client i set the custom property for Joiner client and trying to get the custom property at the room creator in JoinRoomEvent callback
    So your say that you read out the properties of both players in joinRoomEventAction(), correct?
    However in your joinRoomEventAction() implementation you only have mLoadBalancingClient.getCurrentlyJoinedRoom().getPlayerForNumber(1)->getCustomProperties();, which always gives you the custom properties of the player with player number 1, which is the game creator. So both clients read out the properties of the creator, but not the ones of the joiner.
  • Harish_Kagale
    edited May 2016
    Hi @Kaiserludi
    sorry, I explained you the wrong way , I am not reading properties for both players in joinRoomEventAction,

    I set customProperties for Room Creator In CreateRoomReturn and for joiner in JoinRandomRoomReturn callback

    1) To read RoomCreator properties at Joiner client i have written following code in "JoinRandomRoomReturn"
    mLoadBalancingClient.getCurrentlyJoinedRoom().getPlayerForNumber(0)->getCustomProperties();

    2) To read Joiner properties at RoomCreater client i have written following code in "joinRoomEventAction"
    mLoadBalancingClient.getCurrentlyJoinedRoom().getPlayerForNumber(1)->getCustomProperties();


    1) For both the "0 and 1"indexed players i am getting the same properties
    2) sometimes i am getting empty string


  • Hi @Harish_Kagale.

    You don't set the joiners properties until it already received joinRandomRoomReturn(). At that time the information that it has joined the room has already been broadcasted to the other players when the joining client sets its properties, so by no way you can expect those new properties to already be available in other clients at the moment when they receive the join info.

    You might simply already set the properties on the local client before you create/join a room, so that they immediately get send to the server together with the request for creating or joining a room and not after you have already entered it.

    If you have to wait until you are in the room because your game logic does not know to which values it should set those player properties until the player has already entered a room, then it makes sense to implement the optional Listener::onPlayerPropertiesChange() callback, so that Photon informs you whenever changes to some players properties appear (adding a property is also a change that you get informed of).
  • Harish_Kagale
    edited May 2016
    Hi @Kaiserludi
    Thanks for the support , now i am able to recieve the properties on both the side .





  • > Only those room properties get exposed in the lobby, for which this is explicitly requested on room creation by adding the keys of those properties to the "propsListedInLobby" room option.

    How to do that in "photon server plugin"?
  • I understood. I need add it to RoomOption when create the room

    var options = new RoomOptions() { MaxPlayers = ExpectedMaxPlayers };
    options.CustomRoomPropertiesForLobby = new string[] { "someProperty" };
    OpCreateRoom(roomName, options, TypedLobby.Default);