Beispiel #1
0
        public void SendMessage(int peerConnectionId, RpId rpId, Dictionary <byte, object> dicParameters)
        {
            MyPeer peer = GetPeer(peerConnectionId);

            if (null != peer)
            {
                peer.SendCustomEvent(rpId, dicParameters);
            }
        }
        public void CreateAccountResult(bool success, int accountId, string accountName, string password, int peerConnectionId)
        {
            MyPeer peer = LBPeerManager.Instance.GetPeer(peerConnectionId);

            if (null != peer)
            {
                peer.SendCustomEvent(RpId.CreateAccountResult, RpCreateAccountResult.Serialization(success, RpCreateAccountResult.CreateAccountErrorCode.AccountExist));
            }
        }
Beispiel #3
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));
                        }
                    }
                }
            }
        }
        public static void OnOperateRequest(MyPeer peer, OperationRequest operationRequest)
        {
            RqCreateRoom rqCreateRoom = Deserialization(operationRequest.Parameters);

            if (null == rqCreateRoom)
            {
                LBLogger.Info(LogTag, "请求创建房间,消息解析失败");
                peer.SendCustomEvent(RpId.CreateRoom, RpCreateRoom.Serialization(false, CommonDefine.InvalidRoomId, string.Empty));
            }
            else
            {
                LBPlayer curPlayer = LBPlayerManager.Instance.GetPlayerByConnectionId(peer.ConnectionId);
                if (null == curPlayer)
                {
                    LBLogger.Info(LogTag, "请求创建房间,账号未登陆,连接ID:" + peer.ConnectionId);
                    peer.SendCustomEvent(RpId.CreateRoom, RpCreateRoom.Serialization(false, CommonDefine.InvalidRoomId, string.Empty));
                }
                else
                {
                    if (LBRoomManager.Instance.IsPlayerInRoom(curPlayer.PlayerId))
                    {
                        LBLogger.Info(LogTag, "无法创建,因为当前已经处于房间");
                        peer.SendCustomEvent(RpId.CreateRoom, RpCreateRoom.Serialization(false, CommonDefine.InvalidRoomId, string.Empty));
                    }
                    else
                    {
                        int roomId = LBRoomManager.Instance.CreateRoom(rqCreateRoom.RoomName);
                        if (CommonDefine.InvalidRoomId == roomId)
                        {
                            LBLogger.Info(LogTag, "创建房间失败");
                            peer.SendCustomEvent(RpId.CreateRoom, RpCreateRoom.Serialization(false, CommonDefine.InvalidRoomId, string.Empty));
                        }
                        else
                        {
                            LBLogger.Info(LogTag, "创建房间成功 " + roomId);
                            peer.SendCustomEvent(RpId.CreateRoom, RpCreateRoom.Serialization(true, roomId, rqCreateRoom.RoomName));
                        }
                    }
                }
            }
        }
        public void AccountCreate(string accountName, string password, int peerConnectionId)
        {
            LBLogger.Info(LogTag, "请求创建账号");
            LBAccount curAccount = GetAccountByName(accountName);

            if (null != curAccount)
            {
                MyPeer peer = LBPeerManager.Instance.GetPeer(peerConnectionId);
                if (null != peer)
                {
                    peer.SendCustomEvent(RpId.CreateAccountResult, RpCreateAccountResult.Serialization(false, RpCreateAccountResult.CreateAccountErrorCode.AccountExist));
                }
            }
            else
            {
                LBSqlManager.Instance.CreateAccount(accountName, password, peerConnectionId);
            }
        }
        public static void OnOperateRequest(MyPeer peer, OperationRequest operationRequest)
        {
            LBLogger.Info(LogTag, "请求创建账号");
            RqCreateAccount rqCreateAccount = Deserialization(operationRequest.Parameters);

            if (null != rqCreateAccount)
            {
                LBAccountManager.Instance.AccountCreate(rqCreateAccount.AccountName, rqCreateAccount.Password, peer.ConnectionId);
            }
            else
            {
                if (ParseErrorCode == RqLoginErrorCode.Null)
                {
                    LBLogger.Error(LogTag, "登录游戏解析失败,但是没有错误码");
                    return;
                }
                peer.SendCustomEvent(RpId.CreateAccountResult, RpCreateAccountResult.Serialization(false, RpCreateAccountResult.CreateAccountErrorCode.ParseError));
            }
        }
        public void AccountLogin(string accountName, string password, int peerConnectionId)
        {
            LBAccount curAccount = GetAccountByName(accountName);

            if (null != curAccount)
            {
                if (curAccount.IsCorrectPassword(password))
                {
                    if (peerConnectionId == curAccount.PeerConnectionId)
                    {
                        LBLogger.Error(LogTag, "当前连接重复发送登录 " + peerConnectionId);
                        return;
                    }
                    //TODO 这里的逻辑感觉有点不合理,应该抽出方法
                    mPeerIdDic.Remove(curAccount.PeerConnectionId);
                    curAccount.KickAccount();
                    curAccount.Login(peerConnectionId);
                    mPeerIdDic[curAccount.PeerConnectionId] = curAccount;
                    MyPeer peer = LBPeerManager.Instance.GetPeer(peerConnectionId);
                    if (null != peer)
                    {
                        peer.SendCustomEvent(RpId.LoginResult, RpLoginResult.Serialization(true, RpLoginResult.LoginErrorCode.ParseError));
                        LBSqlManager.Instance.PlayerLogin(curAccount.AccountName, curAccount.AccountId, peerConnectionId);
                    }
                }
                else
                {
                    //提示客户端密码错误
                    MyPeer peer = LBPeerManager.Instance.GetPeer(peerConnectionId);
                    if (null != peer)
                    {
                        peer.SendCustomEvent(RpId.LoginResult, RpLoginResult.Serialization(false, RpLoginResult.LoginErrorCode.PasswordError));
                    }
                }
            }
            else
            {
                LBSqlManager.Instance.CheckAccount(accountName, password, peerConnectionId);
            }
        }
        public void AccountLoginResult(bool success, int accountId, string accountName, string password, int peerConnectionId)
        {
            LBLogger.Info(LogTag, "数据服务器返回结果 " + success + " " + accountId + " " + peerConnectionId);
            LBAccount curAccount = GetAccountByName(accountName);

            if (null != curAccount)
            {
                //客户端发送了多条登录消息?
                LBLogger.Error(LogTag, "收到账号登录结果时,当前账号已经存,账号名 " + accountName);
                return;
            }
            curAccount = GetAccountById(accountId);
            if (null != curAccount)
            {
                //客户端发送了多条登录消息?
                LBLogger.Error(LogTag, "收到账号登录结果时,当前账号已经存。账号ID " + accountName + "  为什么mAccountNameDic中没有账号?");
                return;
            }
            MyPeer peer = LBPeerManager.Instance.GetPeer(peerConnectionId);

            if (null == peer)
            {
                //客户端主动断开连接了?
                LBLogger.Info(LogTag, "没有找到网络连接 " + peerConnectionId);
                return;
            }
            if (success)
            {
                LBAccount account = mAccountCacheMgr.GetObject();
                account.SetAccountInfo(accountName, password, accountId, peerConnectionId);
                mAccountIdDic[accountId]     = account;
                mAccountNameDic[accountName] = account;
                mPeerIdDic[peerConnectionId] = account;
            }
            peer.SendCustomEvent(RpId.LoginResult, RpLoginResult.Serialization(success, RpLoginResult.LoginErrorCode.PasswordError));
        }