Leaving room works sometimes and fails other times.

0 votes
My Client sometimes fails to leave a room. ie I'll tell it to leave the room, and it'll act like it left, but on the server it will still say it's in the room. Anyone have a solution to handle when the client fails to leave a room? Or a way to check if a client is in a room? Thanks.
asked Dec 31, 2020 in Operations and Maintenance by ferritna (11 points)

1 Answer

0 votes

I found out a good way to do this. There is probably a more efficient way, but here's the code I used. 

This method is called. RoomLis is then a Room listener I defined earlier. 

internal bool LeaveGame()
        {
            MyClient.LeaveRoom(roomID); //Call leave room
            for (int i = 0; i < 20; i++) //Loop a couple times. This is done to check if leave room was succesful. It can take a second.
            {
                if (RoomLis.GetInRoom() == true) //If still in room, sleep the thread and wait
                    Thread.Sleep(100);
 
                else // else successful
                    return true;
            }
 
            return false; //If 2 seconds past and still haven't left, assume failure.
        }
 
Below is the code for my room listener
 
internal class MyRoomListener : RoomRequestListener
        {
            private bool inRoom;
 
            public bool GetInRoom()
            {
                return inRoom;
            }
 
            public void onJoinRoomDone(RoomEvent eventObj)
            {
                if (eventObj.getResult() == WarpResponseResultCode.SUCCESS)
                {
                    Console.WriteLine("Room join success");
                    inRoom = true;
                }
                else
                {
                    Console.WriteLine("Room join fail");
                    inRoom = false;
                }
            }
 
            public void onLeaveRoomDone(RoomEvent eventObj)
            {
                if (eventObj.getResult() == WarpResponseResultCode.SUCCESS)
                    inRoom = false;
 
                else
                    inRoom = true;
            }
 
          //... other handler code
}

 

answered Dec 31, 2020 by ferritna (11 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 support@shephertz.com
...