Sql filter help!

Ozden79
Ozden79
edited August 2016 in Native
Hello There,

It seems I'm not setting up the sql lobby properly as whatever I do, the player still joins to the room which shouldn't according to the sql query. Since I couldn't find any C++ code example on your website, I would like to ask your help on what am I doing wrong with the following code snippets.

Here's how I setup the room first
RoomOptions MyOptions;
    MyOptions.setIsVisible(isVisible);
    MyOptions.setIsOpen(true);
    MyOptions.setMaxPlayers(MaxPlayers);
    
    ExitGames::Common::Hashtable MyCustomProperties;
    MyCustomProperties.put("C0", playerRank);
    MyOptions.setCustomRoomProperties(MyCustomProperties);
    
    ExitGames::Common::JVector<ExitGames::Common::JString> MyLobbyProperties;
    MyLobbyProperties.addElement(JString("C0"));
    MyOptions.setLobbyType(LobbyType::SQL_LOBBY);
    MyOptions.setPropsListedInLobby(MyLobbyProperties);
    
    MyClient->opCreateRoom(roomName,MyOptions);
Than here's how I try to join a random room
std::string MySqlString = "C0 >= " + cocos2d::StringUtils::toString(minPlayerRank) + " AND C0 <= " + cocos2d::StringUtils::toString(maxPlayerRank);
    MyClient->opJoinRandomRoom(ExitGames::Common::Hashtable(), 0, MatchmakingMode::FILL_ROOM,ExitGames::Common::JString(), LobbyType::SQL_LOBBY, ExitGames::Common::JString(MySqlString.c_str()));
according to the "C0" value used to setup the room and the "C0" values in the sql query string, the player shouldn't be able to join to the room but it does. Could you please help me to identify what may be wrong?

Thanks,

Ozden

Comments

  • Well, it seems that if you pass an empty name as the roomname, sql filtering doesn't work, so my issue is fixed by changing that.

    Now, I would like to ask whether setting a fixed name like "myLobby" as the looby name would cause any trouble or not?
  • Hi @Ozden79.

    No, I don't think this causes any trouble.
    Actually you need your clients to agree on the same lobby name somehow, so that they join the same lobby and using a fixed lobby name is by far the easiest way to assure this.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited August 2016
    Hi @Ozden79,

    I couldn't reproduce the issue you have reported. (2nd one: about setting room name)
    After reading your original post it seems you encountered more than one issue with SQL lobby but managed to make it work.

    - What happens when you try w/ and w/o setting room name?
    - What happens when you try w/ and w/o setting lobby name?
    For each scenario or combination, does random join succeeds or fails? What error do you get if any?

    Can you please answer these questions related to SQL filter used:
    What's the type of "playerRank" property? string or number?
    Can you print the actual (whole string) SQL filter used?
  • yoman
    yoman
    edited February 2018
    Hello guys,

    I try to filter connections to the room, and when i filter on one parameter at type of lobby EGLobbyType_DEFAULT - everything works ok.

    i.e I created a room and pointed in it, for example: custom property "level 2" and then when connecting to the room if i give "level 3" the room will not be find and it's all right.

    BUT

    I need to find the room by filter type: C0 > 50, or C0 BETWEEN 10 AND 15
    And you wrote in docs that we need to use EGLobbyType_SQL_LOBBY and we do it.

    But whatever filters I set, I still can find a room, but in theory it should not be found

    For example:
    I create the room with custom property @{@C0 : @2}

    Then, when i try to connect to the room i set filter: @C0 > 100
    i.e to find the room where, C0 > 100

    but I still find the room created earlier, where C0 = 2

    i.e , SQL filter doesn't work, it doesn't filter the rooms.



    Upper method - i creating the room

    below method - connecting to the room by SQL filter, it connects! but should not..

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @yoman,

    Thank you for choosing Photon!

    When you create a room, can you change the type of the value of the custom room property "C0" from string ("2") to int (2) and then try again? Thanks.
  • yoman
    yoman
    edited February 2018
    Hi! @JohnTube

    We tried,
    NSDictionary *customRoomProperties = @{@"C0" : @2};
    
    But filter doesn't work

    and in NSDictionary you cant insert "int" thats why i used @2 (Objective c)
  • Kaiserludi
    Kaiserludi admin
    edited February 2018
    Hi @yoman.

    Please have a look at demo_typeSupport_objc inside the demo folder of the Client SDK.

    It demonstrates how to add various types of data to a Dictionary that is to be sent via Photon in function sendData() inside PhotonLib.mm.
    The very first example in that function is about a value of type int:
    
    	NSMutableDictionary* ev = [NSMutableDictionary new];
    
    	// nByte key and int value:
    	nByte POS_X = 101;
    	int x = 10;
    	[ev setObject:[NSValue valueWithBytes:&x objCType:@encode(int)] forKey:[NSValue value:&POS_X withObjCType:@encode(nByte)]];
    
  • yoman
    yoman
    edited February 2018
    Still not working,




    Whats wrong in this code?
  • Hi @yoman.

    What exactly do you mean by "not working"? Does it find the match when it shouldn't find it, does it not find it when it should find it, or something else?

    Could you please provide your code as text so that I can copy and paste it into Xcode?
  • yoman
    yoman
    edited February 2018
    Hi @Kaiserludi

    It means that the filter does not work, it still finds the room, while, in theory, he should not find.
    1. I create the room with option: C0 = 2
    2. Filter is C0 > 100

    So when joining the room, it should ignore the room C0 = 2, but it's not ignored and it connecting to it.
    const int maxRoomPlayers = 6;
    
    -(void) opCreateRoom {
    
        EGArray *propertiesForLobby = [[EGArray arrayWithType:NSStringFromClass([NSString class])] arrayByAddingObject:@"C0"];
        NSMutableDictionary *crp = [NSMutableDictionary dictionary];
    
        int x = 2;
        [crp setObject:[NSValue valueWithBytes:&x objCType:@encode(int)] forKey:@"C0"];
    
        EGRoomOptions *options = [[EGRoomOptions alloc] initRoomOptions:true :true :maxRoomPlayers :crp
                                                                       :propertiesForLobby :@"myLobby" :EGLobbyType_SQL_LOBBY];
    
        NSString* tmp = [NSString stringWithFormat:@"%d", GETTIMEMS()];
        [self.LoadBalancingClient opCreateRoom:tmp :options];
    
        self.mStateAccessor.State = STATE_JOINING;
        [self.mOutputListener writeLine:@"creating room \"%@\"", tmp];
    }
    
    - (void) opJoinRandomRoom
    {
        [self.LoadBalancingClient opJoinRandomRoom:nil  :maxRoomPlayers :ExitGames::LoadBalancing::MatchmakingMode::FILL_ROOM
                                                        :@"myLobby" :EGLobbyType_SQL_LOBBY :@"C0 > 100"];
    }

  • Kaiserludi
    Kaiserludi admin
    edited February 2018
    Hi @yoman.

    Your latest code is actually entirely correct.

    I have identified that the reason why this is not working is actually a bug inside the LoadBalancing ObjC Client lib.
    Fortunately this lib ships with its source code, so that you can easily apply the fix itself and don't have to wait for the next Client SDK release (which will of course also include the fix).

    Please open LoadBalancing-objc/LoadBalancing-objc.xcodeproj in Xcode and navigate to EGLoadBalancingPeer.mm.

    Inside that file in the last overload of opJoinRandomRoom() (the one with all parameters that is the actual implementation) can can find the following lines around line 151:
    
    	if(sqlLobbyFilter)
    		[op setObject:[NSValue value:&sqlLobbyFilter withObjCType:@encode(typeof(sqlLobbyFilter))] forKey:[NSValue value:&EGLB::ParameterCode::DATA withObjCType:@encode(nByte)]];
    
    Please replace them with the following:
    
    	if(sqlLobbyFilter)
    		[op setObject:sqlLobbyFilter forKey:[NSValue value:&EGLB::ParameterCode::DATA withObjCType:@encode(nByte)]];
    
    Afterwards rebuilt the lib (don't forget to rebuild both, debug and release, and also both, simulator and device, in case that we are talking about iOS and not about OS X) and do a clean and rebuilt of your application (to ensure that it does actually use the new built of the lib and not the cached old version) and try again.
    SQL filters should work now.
  • Thanks guys for your good support!)
    Everything works now