//only the host of a room can destroy a room
    private void DestroyRoomAckEvent(string reqData, Hashtable roomList, Hashtable roomClassList)
    {
        //reqData = roomNo+":"+validUid+":DestroyRoom"
        roomData = reqData.Split(':');

        /*roomClassList: key = room number, value = room class
         *roomList: key = host id, value = room number
         */
        try
        {
            room = (RoomHandler)roomClassList[roomData[0]];
            room.SendToClient("DestroyRoomAck");

            //remove everything related to the current room
            roomClassList.Remove(roomData[0]);
            roomList.Remove(roomData[1]);
        }
        //Handle Exception
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            return;
        }
    }
    private void StartAckEvent(string reqData, Hashtable roomList, Hashtable roomClassList)
    {
        //"StartReq"+roomNo+validUid
        roomData = reqData.Split(':');

        try
        {
            /*roomClassList: key = room title, value = room class
             *roomList: key = host id, value = room title
             */
            room = (RoomHandler)roomClassList[roomData[1]];
            if (room.isFull == false) Send("GuestNotArriveNoti");
            else if (room.isReady == true)
            {
                room.isStart = true;

                //call start game function to allocate a game class instance
                room.startGame();
                room.SendToClient(roomData[1] + ":StartAck");
                //remove a room number from a list, so that it doesn't appear on the lobby
                roomList.Remove(roomData[2]);
            }
            else Send("GuestNotReadyNoti");
        }
        //Handle Exception
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            return;
        }
    }
 private void LeaveRoomAckEvent(string reqData, Hashtable roomClassList)
 {
     //reqData =roomNo+":"+validUid+":LeaveRoom"
     roomData = reqData.Split(':');
     try
     {
         room = (RoomHandler)roomClassList[roomData[0]];
         room.ResetIsFull();
         room.SendToClient(roomData[0] + ":LeaveRoomAck");
     }
     //Handle Exception
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return;
     }
 }
    //
    private void MoveAckEvent(string reqData, Hashtable roomClassList)
    {
        /* isHost+":"+roomNo+":"+"MoveReq"+":"+myPieceName+":"+myStartPos+":"+myFinalPos
         * isHost argument is needed for define who won the game and who lost the game
         */
        roomData = reqData.Split(':');
        try
        {   /* roomClassList: key = room number, value = room class
             * find a right room for the received room number
             * and send acknowledgement
             */
            room = (RoomHandler)roomClassList[roomData[1]];
            if (room.isStart == true)
            {
                /* only startPos and finalPos are needed to proceed the movement
                 * since the server knows a board status
                 */
                bool isValidMove = room.getMovePos(int.Parse(roomData[4]), int.Parse(roomData[5]));
                if (isValidMove)
                {
                    room.setTurn(roomData[0]);
                    room.SendToClient(roomData[0] + ":" + roomData[1] + ":MoveAck:" + roomData[3] + ":" + roomData[4] + ":" + room.RealFinalPos);

                    /* any special move? like enpassant and castling?
                     * These two must be notified separately to the clients
                     */
                    //EnPassant
                    if (room.Enpassant != null)
                    {
                        room.SendToClient(room.Enpassant.ToString() + ":EnPassant");
                        room.Enpassant = null;
                    }
                    //Castling
                    if (room.StartPosCastling != null)
                    {
                        room.SendToClient(room.StartPosCastling.ToString() + ":"+ room.FinalPosCastling.ToString() + ":Castling");
                        room.StartPosCastling = null;
                        room.FinalPosCastling = null;
                    }

                    /* then send the status of the game along with the roomData[0](isHost value).
                     * if either checkmate, draw then notifies the clients to end the game
                     * if check, notifies the client to show 'check' pop-up window
                     */
                    switch (room.getStatus())
                    {
                        case "Check":
                        case "Stalemate":
                        case "Normal":
                        case "DrawByFiftyMove":
                        case "DrawByLackOfMaterial":
                        case "DrawByThreefold":
                            room.SendToClient(roomData[0] +":"+ room.getStatus());
                            break;
                        case "Checkmate":
                            room.SendToClient(roomData[0] +":"+ room.getStatus());
                            //if the move was made by the host, then do the number of the win games += 1 to host
                            if (roomData[0] == "True")
                            {
                                UpdateRankIfWin(room.hostName);
                                UpdateRankIfLose(room.guestName);
                            }
                            //if the move was made by the guset, then do the number of the win games += 1 to guest
                            else if (roomData[0] == "False")
                            {
                                UpdateRankIfWin(room.guestName);
                                UpdateRankIfLose(room.hostName);
                            }
                            break;
                        default:
                            break;
                    }
                }
                else {
                    //Send("NotMoveNoti");
                }
            }
            //room.SendToClient(reqData);
            else Send("NotStartNoti");
        }
        //Handle Exception
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            return;
        }
    }
    private void JoinRoomAckEvent(string reqData, Hashtable roomList)
    {
        //Send(s, validUid + ":" + roomName + ":JoinRoomReq", 1000);
        roomData = reqData.Split(':');

        try
        {
            /*roomClassList: key = room number, value = room class
             *roomList: key = host id, value = room number
             */
            room = (RoomHandler)roomClassList[roomData[1]];

            //only if there is no guest in a room, a player can join
            if (!room.isFull)
            {
                room.guestStartRoom(tcpClient);
                room.guestName = roomData[0];
                Console.WriteLine(room.guestName);

                //indicates the room is already full
                room.isFull = true;

                //look for host id, and send it to a client
                foreach (DictionaryEntry entry in roomList)
                {
                    if (entry.Value.ToString() == roomData[1])
                    {
                        string result = entry.Key.ToString();
                        room.SendToClient(result + ":" + roomData[0] + ":JoinRoomAck");
                        room.isReady = false;
                    }
                }
            }
            else
            {
                //if a room is full, a player cannot join a room
                Send("FullRoomNoti");
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }