Condition check for joining random rooms

nanda
edited August 2012 in Native
I have list of rooms like room1,room2,room3.. and chat1,chat2, chat3,... . How to join a player in a random room which start with roomname "chat" using opJoinRandomRoom ?. It will be help full for me to understand with sample code .

Comments

  • You don't.
    JoinRandom will not match a roomname. It can filter rooms by room properties but not by name.
    If you use JoinRandom, you don't have to use the lobby at all. It doesn't make sense to first get the room list, then ignore it.

    As Stefan is on vacation this week, I can't help with code but you should read the JoinRandom reference doc and the doc for creating rooms (where you set room properties). Those doc files are in the client SDK.
  • Hi,

    i created a room with custom property by following code:
               HashMap<Object, Object> gameprop = new HashMap<Object, Object>();
    
               gameprop.put("room", "themeroom");
       
               this.opCreateRoom(roomname, true, true, (byte)0, gameprop, null);
    

    For joining Random room,
                     HashMap<Object, Object> customProperties = new HashMap<Object, Object>();
    		           customProperties.put("room", "themeroom");
                     this.opJoinRandomRoom(customProperties, (byte)0);
    

    But I can't join into room with similar property. I joined into some other ramdom room without custom property. Please help how to fix this.
  • i am creating a room with a custom property like this
    [mLoadBalancingClient opCreateRoom:@"ChatRoom" :TRUE :TRUE :0 :[NSDictionary dictionaryWithObject:@"themeroom" forKey:[KeyObject withStringValue:@"room"]]];
    

    On another device i am joining a random room
    [mLoadBalancingClient opJoinRandomRoom:[NSDictionary dictionaryWithObject:@"themeroom" forKey:[KeyObject withStringValue:@"room"]] :nil];
    

    But it is return the error code for joining the game.

    Note:
    I tested the same code by creating a room with custom property in android and in ios ,i joined a random room with same custom property which we used for creating the room, i can abel to join the room properly.

    Can you help me in fixing the bug in ios for creating the room with custom property?
  • This week, our main C++ developer is on vacation. We will take a look next week.
    So this issue happens only when you create a room on ios? Does the room show up in the room listing? Does it have the properties you set in the listing?
  • Room is showing up in the room listing with the room properties as null. But after joining that room we can able to see the properties.

    Here are the test case we tested for the past 2 days

    1.Ios ---> Ios:
    I created a room using above code in ios and joined a room in ios with same custom properties. I coudnt able to join the room.

    2. Flex or android ---> ios

    Created a room with a custom property in flex or android and joined a room in ios with same custom properties. I can able to join the room successfully

    3. android ---> android

    In android we created 2 room , one with custom property and another with out any property set (ie .nil). We joined a room with custom property , but the android device joined a room irrespective of the custom room property.

    4. Flex -- > Flex

    Create a room with a custom property in flex and joined a room with same custom property in flex. We can able to join successfully.

    We dont know this bug arise from which photon sdk (ios or android or flex or bug in all 3 sdk).
  • Hi.
    I am back from my vacation and have just had a look at your iOS code from above.

    Please replace
    [mLoadBalancingClient opCreateRoom:@"ChatRoom" :TRUE :TRUE :0 :[NSDictionary dictionaryWithObject:@"themeroom" forKey:[KeyObject withStringValue:@"room"]]];
    

    with
    [mLoadBalancingClient opCreateRoom:@"ChatRoom" :true :true :0 :[NSDictionary dictionaryWithObject:@"themeroom" forKey:[KeyObject withStringValue:@"room"]] :nil :[EGArray arrayWithObject:@"room"]];
    
    Then your case 1 should work.

    The reason therefor is: only properties, that are explicitly specified to be listed in the lobby will be honored in joinRandom() matchmaking.
    One could say, that by listing its key in that array, one makes it a public property of the room, while by default a room property is private.
    Room properties are private (only known inside of a room) by default to save network traffic by not sending arround information which is only of interest for the players in one room to all players of your app.



    Tobias has sent you a new Android Client via mail to solve case 3.
  • Ok thanks kaiserludi:

    MaxPlayers: 0 ( by default)
    Your could work fine between ios- ios and ios -android but not with ios->flex. (ie.creating a room in ios with custom property and joining the room with same custom property in flex).

    If we set the max player property except 0 it is not working in any platform. So can you pls verify and reply me.
    [mLoadBalancingClient opCreateRoom:@"ChatRoom" :true :true :5 :[NSDictionary dictionaryWithObject:@"themeroom" forKey:[KeyObject withStringValue:@"room"]] :nil :[EGArray arrayWithObject:@"room"]];
    
  • Yes, the max players problem is a known server-side issue: the server does not match the custom properties correctly anymore, if max players are set to anything else than the default.

    Afaik Tobias has sent Krishna a new server SDK, which fixes this issue.

    About iOS->flex:
    Is android->flex working?
    Can you provide us with the equivalent flex code to the iOS/android code, which you have posted above, so that we can check, if its a misunderstanding about the usage or a bug inside the flex client?
  • I am using Photon Cloud and I have the same problem. When will you fix the problem with max players? If I put max number in JoinRandomRoom the players no matching with de room properties and if I do not put the max number mora than max players for my game can entry in the same room. I need create rooms for only two players. Any idea for fix this problem?

    Thanks you.
  • I forgot say that I use marmalade sdk. Sorry
  • If you use PhotonServer, then please update your server to the final 3.0 release, which comes with a fix for this issue.
    If you are using Photon cloud, then this issue should already been fixed for a while now.

    In case, that your experiencing this issue with the cloud or are still experiencing it after upgrading to the most recent server SDK, could you please try to reproduce it with the LoadBalancing demo from our SDK and post us the parameters, with which you have been able to reproduce it?

    Which Client SDK version are you using? I suppose, your are on 3.0.3.3?
  • Yes I am using Photon Cloud and testing with LoadBalancing demo (modificate for my to matching depending game mode). It is here where fail.
    I use 3.0.3.3 version of SDK for marmalade:

    This is my code:
    void NetworkLogic::opCreateRoom(void)
    {
    // if last digits are always nearly the same, this is because of the timer calling this function being triggered every x ms with x being a factor of 10
    ExitGames::JString tmp;

    //mLoadBalancingClient.opCreateRoom(tmp=(int)GETTIMEMS());

    //Room information
    ExitGames::Hashtable room;
    room.put(ExitGames::KeyObject<ExitGames::JString>(L"mode"), ExitGames::ValueObject<ExitGames::JString>(L"3x3"));
    //Player information
    ExitGames::Hashtable player;
    player.put(ExitGames::KeyObject<ExitGames::JString>(L"name"), ExitGames::ValueObject<ExitGames::JString>(L"unknow"));
    //public room information
    ExitGames::JVector<ExitGames::JString> lobby;
    lobby.addElement(ExitGames::JString(L"mode"));
    //Create room
    mLoadBalancingClient.opCreateRoom(tmp=(int)GETTIMEMS(),true,true,2,room,player,lobby);
    mStateAccessor.setState(STATE_JOINING);
    mOutputListener->writeLine(ExitGames::JString(L"creating game \"") + tmp + L"\"");
    }

    void NetworkLogic::opJoinRandomRoom(void)
    {
    //Room information
    ExitGames::Hashtable room;
    room.put(ExitGames::KeyObject<ExitGames::JString>(L"mode"), ExitGames::ValueObject<ExitGames::JString>(L"3x3"));
    //Player information
    ExitGames::Hashtable player;
    player.put(ExitGames::KeyObject<ExitGames::JString>(L"name"), ExitGames::ValueObject<ExitGames::JString>(L"unknow"));
    mLoadBalancingClient.opJoinRandomRoom(room,0,player);
    //mLoadBalancingClient.opJoinRandomRoom();
    }

    This run perfect, but I can't limit the num of players. The third player can entry on room.
    Y I change
    mLoadBalancingClient.opJoinRandomRoom(room,0,player);
    to
    mLoadBalancingClient.opJoinRandomRoom(room,2,player);
    Then the second player can't entry on room create by player1
  • Thanks.
    I will try to reproduce and debug that issue.
  • Sorry, but I can't reproduce this. I have copied your code from this thread into the demo source in the 3.0.3.3 Marmalade client SDK and set maxPlayers in opJoinRandomRoom to 2. my only other changes have been to supply an appID and let it connect to the cloud, like you have sure also been done. It works just fine for me with your code and maxplayers set to 2.
    We will contniue investigating here, but it looks like we won't be able to solve this issue this week already.
  • I can send to you the complete project ir you give me an email.
  • That would be great. I will pm you my mail-address.
  • We have just deployed a fix to the cloud and joining random rooms with maxplayers being set should work now. No client-side update is needed.
    Please test and confirm, that it works for you, too.
  • And if you need to apply the fix to a self-hosted serer:

    In the Photon.LoadBalancing.MasterServer.Lobby.GameState class, modify the TrySetProperties method like this:
     public bool TrySetProperties(Hashtable gameProperties, out bool changed, out string debugMessage)
            {
                changed = false;
    
                byte? maxPlayer;
                bool? isOpen;
                bool? isVisible;
                object&#91;&#93; propertyFilter;
                
                if (!GameParameterReader.TryReadDefaultParameter(gameProperties, out maxPlayer, out isOpen, out isVisible, out propertyFilter, out debugMessage))
                {
                    return false;
                }
    
                if (maxPlayer.HasValue && maxPlayer.Value != this.MaxPlayer)
                {
                    this.MaxPlayer = maxPlayer.Value;
                   this.properties&#91;(byte)GameParameter.MaxPlayer&#93; = (byte)this.MaxPlayer;
                    changed = true;
                }
    
                if (isOpen.HasValue && isOpen.Value != this.IsOpen)
                {
                    this.IsOpen = isOpen.Value;
                   *this.properties&#91;(byte)GameParameter.IsOpen&#93; = this.MaxPlayer;* 
                    changed = true;
                }
    
                if (isVisible.HasValue && isVisible.Value != this.IsVisible)
                {
                    this.IsVisible = isVisible.Value;
                    changed = true;
                }
    
                this.properties.Clear();
                foreach (DictionaryEntry entry in gameProperties)
                {
                    if (entry.Value != null)
                    {
                        this.properties&#91;entry.Key&#93; = entry.Value;
                    }
                }
    
                debugMessage = string.Empty;
                return true;
            }
    

    And in the same class, the Update method needs to be modified like this:
      public bool Update(UpdateGameEvent updateOperation)
            {
                bool changed = false;
    
                if (this.IsCreatedOnGameServer == false)
                {
                    this.IsCreatedOnGameServer = true;
                    changed = true;
                }
    
                if (this.GameServerPlayerCount != updateOperation.ActorCount)
                {
                    this.GameServerPlayerCount = updateOperation.ActorCount;
                    changed = true;
                }
    
                if (updateOperation.NewUsers != null)
                {
                    foreach (string userId in updateOperation.NewUsers)
                    {
                        this.OnPeerJoinedGameServer(userId);
                    }
                }
    
                if (updateOperation.RemovedUsers != null)
                {
                    foreach (string userId in updateOperation.RemovedUsers)
                    {
                        this.OnPeerLeftGameServer(userId);
                    }
                }
    
                if (updateOperation.MaxPlayers.HasValue && updateOperation.MaxPlayers.Value != this.MaxPlayer)
                {
                    this.MaxPlayer = updateOperation.MaxPlayers.Value;
                    this.properties&#91;(byte)GameParameter.MaxPlayer&#93; = this.MaxPlayer;
                    changed = true;
                }
    
                if (updateOperation.IsOpen.HasValue && updateOperation.IsOpen.Value != this.IsOpen)
                {
                    this.IsOpen = updateOperation.IsOpen.Value;
                    this.properties&#91;(byte)GameParameter.IsOpen&#93; = this.MaxPlayer;
                    changed = true;
                }
    
                if (updateOperation.IsVisible.HasValue && updateOperation.IsVisible.Value != this.IsVisible)
                {
                    this.IsVisible = updateOperation.IsVisible.Value;
                    changed = true;
                }
    
                if (updateOperation.PropertyFilter != null)
                {
                    var lobbyProperties = new HashSet&lt;object&gt;(updateOperation.PropertyFilter);
    
                    var keys = new object&#91;this.properties.Keys.Count&#93;;
                    this.properties.Keys.CopyTo(keys, 0);
    
                    foreach (var key in keys)
                    {
                        if (lobbyProperties.Contains(key) == false)
                        {
                            this.properties.Remove(key);
                            changed = true;
                        }
                    }
    
                    // add max players even if it's not in the property filter
                    // MaxPlayer is always reported to the client and available 
                    // for JoinRandom matchmaking
                    this.properties&#91;(byte)GameParameter.MaxPlayer&#93; = (byte)this.MaxPlayer;
    
                }
    
                if (updateOperation.GameProperties != null)
                {
                    changed |= this.UpdateProperties(updateOperation.GameProperties);
                }
    
                return changed;
            }
    

    The fix will be included in the next Photon Server SDK as well.
  • The example no work yet. The bug is not fixed on Cloud. I am using connect() without parameters. Are I connecting to the cloud fixed server?
  • Sorry for the inconvenience.
    The fix for the server side bug definitely has been deployed to the cloud and afterwards the bug went awys on all client platforms, except the C++ clients.
    There has been an additional client side bug for maxPlayers in the C++ clients. That one has also been fixed, now.

    Linked below is a new Marmalade Client SDK build, including that fix:
    https://dl.dropbox.com/u/4296291/Photon ... ud_SDK.zip