Ejemplo n.º 1
0
        public static void OnOperateRequest(MyPeer peer, OperationRequest operationRequest)
        {
            RqLeaveRoom rqEnterRoom = Deserialization(operationRequest.Parameters);

            if (null == rqEnterRoom)
            {
                LBLogger.Info(LogTag, "请求离开Room,解析失败");
                peer.SendCustomEvent(RpId.LeaveRoom, RpLeaveRoom.Serialization(false));
            }
            else
            {
                LBPlayer curPlayer = LBPlayerManager.Instance.GetPlayerByConnectionId(peer.ConnectionId);
                if (null == curPlayer)
                {
                    LBLogger.Info(LogTag, "请求离开Room,当前玩家不存在");
                    peer.SendCustomEvent(RpId.LeaveRoom, RpLeaveRoom.Serialization(false));
                }
                else
                {
                    if (!LBRoomManager.Instance.IsPlayerInRoom(curPlayer.PlayerId))
                    {
                        LBLogger.Info(LogTag, "请求离开房间,但是当前不在房间中 ");
                        peer.SendCustomEvent(RpId.LeaveRoom, RpLeaveRoom.Serialization(false));
                    }
                    else
                    {
                        bool leaveResult = LBRoomManager.Instance.PlayerLeaveRoom(curPlayer.PlayerId);
                        if (leaveResult)
                        {
                            LBLogger.Info(LogTag, "请求离开房间成功");
                            peer.SendCustomEvent(RpId.LeaveRoom, RpLeaveRoom.Serialization(true));
                        }
                        else
                        {
                            LBLogger.Info(LogTag, "请求离开失败");
                            peer.SendCustomEvent(RpId.LeaveRoom, RpLeaveRoom.Serialization(false));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
    public void LeaveRoom()
    {
        RqLeaveRoom leaveRoomRequest = new RqLeaveRoom();

        GameMain.Instance.SocketMgr.SendMessage(RqId.LeaveRoom, leaveRoomRequest);
    }