Possible bug in the objective-c code

Vasilis
Vasilis
edited November 2019 in Native
Hi,

I am trying to change the properties of a room, and I want all users to get the new properties.

I struggled a lot with the Photon code, and there is one thing that I do not understand. What is the purpose of the variable "webForward" in the next method ?

- (void) mergeCustomProperties:(NSDictionary*)customProperties :(bool)webForward


That method is in EGLoadBalancingRoom.mm file.

At the end of that method it says
if(![mCustomProperties isEqual:oldDict])
		[mLoadBalancingClient opSetPropertiesOfRoom:stripDict];
I believe that it should say
if(![mCustomProperties isEqual:oldDict])
		[mLoadBalancingClient opSetPropertiesOfRoom:mCustomProperties];		
because the properties are merged in the mCustomProperties at the line

[mCustomProperties addEntriesFromDictionary:stripDict];

When I made that change, I can update the value of a property.

Comments

  • Hi @Vasilis.

    What is the purpose of the variable "webForward" in the next method ?

    You should pass 'true' there if the properties should be forwarded to Webhooks, 'false' otherwise.
    See https://doc.photonengine.com/en-us/realtime/current/gameplay/web-extensions/webhooks for details about webhooks.


    At the end of that method it says

    if(![mCustomProperties isEqual:oldDict])
    [mLoadBalancingClient opSetPropertiesOfRoom:stripDict];

    I believe that it should say

    if(![mCustomProperties isEqual:oldDict])
    [mLoadBalancingClient opSetPropertiesOfRoom:mCustomProperties];

    because the properties are merged in the mCustomProperties at the line

    [mCustomProperties addEntriesFromDictionary:stripDict];

    This is not a bug, but intended. The client intentionally only sends the property changes to the server and not the result of those changes, because a) the server already knows hos the properties looked before those changes and can hence apply the changes itself, so we have to send less data and save bandwidth, and b) because the server might already have received a properties update from another client that has not yet arrived on this client when it sends its own update. Hence if the client would send the result of the changes to the server, then it would override the not yet known to it changes that came in from the other client.
  • Vasilis
    Vasilis
    edited November 2019
    Hi @Kaiserludi,

    I thought that the variable webForward has to do something with the Webhooks, but, that method does not use that variable. In order to use it, the last line should be modified as follows:

    if(![mCustomProperties isEqual:oldDict]) [mLoadBalancingClient opSetPropertiesOfRoom:stripDict : webForward];

    Right now, I can not correctly update the room properties. Somehow (not all times), I lose all properties.
    I am really pleased to read that the server does keep track of the changes, and hence, I only need to send the update.
  • Hi @Vasilis.

    Your are correct. The 'webForward' flag indeed gets ignored for custom properties in the objective C client.

    However this does not have anything to do with the issues that you are experiencing. They must be caused by something else.
    Vasilis said:

    Somehow (not all times), I lose all properties.

    Then you need to find out in which situation exactly this does happen. Are you testing with just one client or with multiple clients? If it is the latter, then could it be that the other client removes those properties?

  • Hi @Kaiserludi,

    I found that the iOS SDK does forward the room properties, but the Android one does not.
    I start a game between those two devices, and when the Android version is in charge of updating the room properties, the iOS version does not receive them. But, when the iOS updates them, the Android does receive them.

    I am wondering if there is a flag in the Android SDK that I have forgotten to set it to true
  • This is insane. Now, the properties are updated from the Android too
  • Hi @Vasilis.

    So everything works now?
  • yes, so far so good
  • Hi @Kaiserludi,

    No, it is not fixed. I am thinking of the following scenario:

    Two players create and join the same game room. Both players will call the

    [mLoadBalancingClient opJoinOrCreateRoom:roomName :options];

    But, the first player who calls this method has no properties to set. Then, the second player calls this method. Since that room already exists, will the properties from the second player be added to the room?
  • I think that the properties are not set.
    I changed my code so that when the 2nd player joins the room, he resets the properties.
  • Kaiserludi
    Kaiserludi admin
    edited November 2019
    Hi @Vasilis.
    the only way to pass properties to opJoinOrCreateRoom() is as part of the 'options' parameter, which is of type EGRoomOptions.
    Room options are only considered when a room is created, but not when an already existing room is joined.
    A joining client can't just override the room creation options that should be used to create the room, because at the point when it enters it, the room is already created.
    Hence there is no way for a client that enters an already existing room to set the properties which should have been used when that room is created.
    Therefor if you need whoever of the two clients enters the room last, to be in charge of setting the initial values of certain room properties, then you need to set them after you have joined the room.
  • Hi @Kaiserludi,

    thank you for clarifying this. As I wrote above, I modified my code so that I always set the properties when I createAndJoin a room