C++ iOS : facing problem with opJoinRandomRoom

edited July 2013 in Native

with all your help I have progress quite ahead in the project (cocos2d-x iOS).
Room creation is working fine with custom properties, I get them properly in createRoomReturn. but now facing problem with, 'allow player to join a room matching with his chips & no table is created. i.e. opJoinRandomRoom request.

If I have room already created then it's working fine, but if room not available then it's returning true which is unexpected behavior.

[code2=cpp]const ExitGames::Common::JString ROOM_AMOUNT = L"amt";
const int TABLE_AMOUNT_1 = 1000;

void NetworkLogic::opJoinRandomRoom(void)
ExitGames::Common::Hashtable expectedCustomRoomProperties;
int userChips = player->getChips();
if(userChips > 1500)
expectedCustomRoomProperties.put(ROOM_AMOUNT, TABLE_AMOUNT_1);
bool isRoomAvail = mLoadBalancingClient.opJoinRandomRoom(expectedCustomRoomProperties, 12);
if(!isRoomAvail) // ---- this value returning true even if there is no table present
CCLog(">>>>> room created for 1000");

void NetworkLogic::opCreateRoom(int tableValue)
ExitGames::Common::JString tmp;

ExitGames::Common::JVector<ExitGames::Common::JString> publicProperties;

ExitGames::Common::Hashtable roomCustomProperties;
roomCustomProperties.put(ROOM_AMOUNT, tableValue);

bool success = mLoadBalancingClient.opCreateRoom(tmp,true,true,12,roomCustomProperties,publicProperties);
gameState = STATE_JOINING;
CCLog(">>>>> room created as %d with properties : %s",tableValue,publicProperties.toString().UTF8Representation().cstr());

I checked it inside Client & Peer class, readings are as follows:

[code2=cpp]bool Client::opJoinRandomRoom(const Hashtable& customRoomProperties, nByte maxPlayers)
EGLOG(DebugLevel::ERRORS, L"already in a gameroom");
return false;

if(!super::opJoinRandomRoom(customRoomProperties, maxPlayers))//---- this returning true expected false
return false;

mCurrentlyJoinedRoom = MutableRoom("", stripToCustomProperties(customRoomProperties), this);

return true;
peer calss
bool Peer::opJoinRandomRoom(const Hashtable& customRoomProperties, nByte maxPlayers)
Hashtable roomProps(stripToCustomProperties(customRoomProperties));
roomProps.put(Properties::Room::MAX_PLAYERS, maxPlayers);

OperationRequest opRequest(OperationCode::JOIN_RANDOM_ROOM);

OperationRequestParameters op;
op.put(ParameterCode::ROOM_PROPERTIES, ValueObject<Hashtable>(roomProps));

return super::opCustom(opRequest, true); //---- this returning true

I am not sure its a mistake in my implementation or in photon itself, Please help me out of this.



  • Actually this is expected and correct behavior.
    opJoinRandomRoom() will only return false, if it already fails in sending the request to the server. The client doesn't know, which rooms will be available on the server, when its join request arrives (it doesn't make much sense to synchronize the room list to the clients, as the availability could change while the clients request is on the way to the server - new rooms could get opened in the meantime, others could get closed or filled up to their player max, properties for matchmaking could change and so on).
    Therefor if the server can't find a suiting match for the join random request, it will respond to the client with ErrorCode::NO_MATCH_FOUND. This response will arrive in the joinRandomRoomReturn() callback, where you can implement different behavior depending on the errorcode (errorcode 0 means success).

    The demo implementation for example in case of an error prints a message to the screen and to the log:
    [code2=cpp]void NetworkLogic::joinRandomRoomReturn(int localPlayerNr, const ExitGames::Common::Hashtable& /*gameProperties*/, const ExitGames::Common::Hashtable& /*playerProperties*/, int errorCode, const ExitGames::Common::JString& errorString)
    EGLOG(ExitGames::Common::DebugLevel::INFO, L"");
    EGLOG(ExitGames::Common::DebugLevel::ERRORS, L"%ls", errorString.cstr());
    mOutputListener->writeLine(L"opJoinRandomRoom() failed: " + errorString);
    EGLOG(ExitGames::Common::DebugLevel::INFO, L"localPlayerNr: %d", localPlayerNr);
    mOutputListener->writeLine(L"game room \"" + mLoadBalancingClient.getCurrentlyJoinedRoom().getName() + "\" has been successfully joined");
    mOutputListener->writeLine(L"regularly sending dummy events now");

    Your description reads like you are writing a poker game. Cool 8-)
  • thanks for the quick reply.

    Now after your explanation it all make sense to return true from opJoinRandomRoom, that was quite important piece of information.
    I will try it out & update you for the same.

    Thanks once again,

    this is not a poker game, it's completely new concept & fresh card game, will surely share with u once it done & up in market 8-) , but by that time I am gonna disturb you a lot :twisted:
Sign In or Register to comment.