startGame() failing for Turn based game for multiple users

0 votes

We are building an turn based card game application in which 

1. Users are selected randomly which are present in room.

2. Selected user have to choose one card fro 52 cards.

3. If the selected card is Ace of Spade , winner is declared.

4. If the wrong card is selected, game continues with next turn for other users in same room.


Above steps in Detail:

1. Users are selected randomly which are present in room.

i. Getting All rooms by warpClient.getAllRooms()

iii. In Success response of onGetAllRoomsDone -> All rooms are returned. Then room is created or not is achieved by looping through all rooms with getLiveRoomInfo(roomId) 

iv. In Success response of onGetLiveRoomInfoDone -> If room dose not exist we are creating it by createTurnRoomWithRoomName()

else f room exists then joining and subscribing the room by joinAndSubscribeRoom(roomId)

vi. In Success response of onJoinAndSubscribeRoomDone() -> we are calling startGame(false)

v. In Success response of onGameStarted() -> we are selecting the user and starting the game based on the nextTurn in the response.

Above flow will be same for all joined users in room. First joined users can start the game successfully. The issue is For next turn user is if next turn user tries to run startGame(false) its failing with error as BAD_REQUEST = 4 in method onStartGameDone().


I have also tried above steps with Dev Console, but no two users can startGame() at the same time.


So our query is:

1. When to call the startGame? On joining the room or On next turn completed

asked Sep 18, 2017 in iOS by vince (10 points)

1 Answer

0 votes
Hi Vince,
You are getting bad request as the game is already started in the room and you are again trying to start it. The startGame API will give you bad request unless you stop the game and then start it.
However, this is not the best approach for turn based games. I will recommend using custom turn-based management logic for your game. 
Please have a look at following steps:
1. StartGame only once and call stopGame once someone wins to finish the game
2. When you are calling startGame use following code:

    [[WarpClient getInstancestartGame:false firstTurn:@"UserName"];

Here, the userName is the user whose turn should first just after starting the game. Passing false tells the server that this game will use custom turn-based logic intead of default

3. The user will have some time(set by you) to play his turn. Here, there will be two different cases:
        a)He plays his turn then you can send his move and send the next turn alongwith it as follows:

    [[WarpClient getInstancesendMove:@"Pass" nextTurn:@"Device1"];


        b)He does not play his turn, then there will be timeout from server and in that case you will get a notification callback in which you set the next turn parameter as follows:



-(void)onNextTurnRequest:(NSString *)lastTurn


    [[WarpClient getInstancesetNextTurn:@"UserName"];


This process will goes on till someone wins the game.
I hope this will help.


answered Sep 19, 2017 by rajeev.etc (1,660 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on