Reversing the Turn order of Users in TurnBasedRoom using appwarp s2

0 votes

I am creating a demo for the game same as UNO and in that I am in need for the "Skip and Reverse" functionality. Well, somehow skip functionality is managed by moveCompleted method, but can anyone let me know how can I reverse the turn order using s2 server?

Thank you in Advance


I am getting the S2 Server running and now I am unable to send the custom users turn.

Here is my server code 


   public void handleMoveRequest(IUser sender, String moveData, HandlingResult result){

JSONObject data = new JSONObject(moveData);
        int isSkip = data.getInt("skipTurn");
        printf("MARINE : handleMoveRequest isSkipStatus: " + data.getInt("skipTurn"));
            if (isSkip == 1){
                if (gameRoom.getJoinedUsers().size() == 2){
}catch(Exception e){
private void skipTurnFor2Users(IUser sender, String moveData, HandlingResult result){
    public boolean sendMoveUpdate(IUser nextTurn, String moveData, String sender){
        printf("Send move Update Called " + moveData );
        printf("\n Next Turn For User From Send Move Update  " + nextTurn.getName() + "\n \n ");
        return true;
I am getting the logs correctly from server but the values are not passed to client(Unity) Could you help me please
asked Mar 25, 2014 in AppWarpS2 by marine.modi (62 points)
edited Mar 31, 2014 by marine.modi

1 Answer

+1 vote
Best answer
By default the turns go in the order in which the clients joined the room. In your case since you are going to be skipping and reversing turns - its best you always override the default logic.

So in your turn room adaptor - you should always set the doDefaultTurnLogic flag of the result to false in the turn room adaptor event handlers. This will mean that the room will not update the turn according to its default logic and will expect the application to update the turn according to its requirement.

So when ever you need to update the turn - you can then use the sendMoveUpdate of ITurnBasedRoom and update the turn according to your requirement.
answered Mar 26, 2014 by dhruvc (1,099 points)
selected Apr 1, 2014 by marine.modi
@dhruvc Thank you for reply. Well, I am studying the server code for the rummy demo, can you guide me where the turn logic is maintained?
The rummy demo doesn't override default turn logic as the game play goes in the default order. In that we simply stop the game when a user leaves or pauses (instead of skipping turns) and when the user returns - we restart the game.

Let me explain my reply in more detail for your case - my suggestion is as follows -

In your TurnBasedRoomAdaptor - you will need to override all the methods that result in the turn being changed. These are the following


Then in your handlers for the above, you should set the default logic flag to false.

result.doDefaultTurnLogic = false;

This will mean that the AppWarp S2 TurnBasedRoom will not automatically update the move according to its default logic.

Now in your case since you're going to be skipping/reversing turns - I think its best that you maintain your own order and inform the client accordingly. So in your adaptor you should maintain your own list of users in the order that you want.

Now when ever you receive a move - you check which is the user that according to your logic should be next to move (from the list that you maintain). Then you call the sendMoveUpdate API (ITurnBasedRoom). This will issue the update to all the clients i.e. they will receive the onMoveCompleted event with whatever data (and next turn user from your adaptor's list) that you provide.
Ok Dhruv. So from your suggestion i need to maintain the UserTurnOrder according to what they have been entered, and from that list I would have to Reverse the order Right ?

If it is so, Where could I get the list of the player who all have joined the room in the ServerSide code by TurnBasedRoomAdapter?
You can keep the reference of the room when you set the adaptor on it. Then use IRoom's getJoinedUsers.

Also you'll need to maintain this according as users join or leave the room.
Ok @dhruv. I've tried to implement the ITurnbasedRoom Interface but I am unable to get any log statement from the server as I am trying to Override the setNextTurn() and sendMoveUpdate() methods from ITurnBasedRoom. Can you let me know how do i get call to these methods?
I've created a simple Turn Room Adaptor which reverses the order after every 6 moves.

Please see the following
Thank you Dhruv. I would have a look on it.
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