Exemple #1
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理选择的请求");

            int playerId = UserManager.GetPlayer(peer.Username).Identification;
            int heroId   = (int)request.Parameters.ExTryGet((byte)ParameterCode.HeroId);

            SelectRoom room = Caches.Select.Select(playerId, heroId);

            if (room == null)
            {
                // 告诉自己选择失败
                OperationResponse response = new OperationResponse(request.OperationCode);
                response.ReturnCode = (short)ReturnCode.Falied;
                peer.SendOperationResponse(response, sendParameters);
                return;
            }

            // 给房间内的所有人发一条消息:谁选择了什么英雄
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.PlayerId, playerId);
            data.Add((byte)ParameterCode.HeroId, heroId);
            room.Brocast(OperationCode.Selected, data);
        }
Exemple #2
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理技能升级的请求");

            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.GetRoomByPlayerId(playerId);

            // 获取英雄数据
            DtoHero hero = room.GetDtoHero(playerId);

            if (hero == null || hero.SP < 1)
            {
                return;
            }

            // 获取技能id
            int skillId = (int)request[(byte)ParameterCode.SkillId];

            // 技能升级
            DtoSkill skill = hero.UpgradeSkill(skillId);

            if (skill == null)
            {
                return;
            }

            // 发送升级的技能数据和英雄id
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.DtoSkill, JsonMapper.ToJson(skill));
            data.Add((byte)ParameterCode.PlayerId, playerId);
            SendResponse(peer, request.OperationCode, data);
        }
Exemple #3
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理准备完成的请求");

            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            SelectRoom room     = Caches.Select.Ready(playerId);

            if (room == null)
            {
                // 告诉自己确认失败
                SendResponse(peer, request.OperationCode, null, ReturnCode.Falied);
                return;
            }
            // 告诉房间内所有人:有人确定选择
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.PlayerId, playerId);
            room.Brocast(OperationCode.BeReadySelect, data);

            // 如果全部准备好了 则开始战斗
            if (room.IsAllReady)
            {
                // 创建战斗的房间
                Caches.Battle.CreateRoom(room.TeamOneDict.Values.ToList(), room.TeamTwoDict.Values.ToList());
                // 通知所有客户端准备战斗
                room.Brocast(OperationCode.ReadyBattle, null);
                // 销毁选择的房间
                Caches.Select.DestroyRoom(room.Id);
            }
        }
Exemple #4
0
        /// <summary>
        /// 开启定时任务 每30秒生成小兵
        /// </summary>
        public void SpawnMinion()
        {
            MobaServer.LogInfo("----------- 开始生产小兵");
            List <DtoMinion> minions = new List <DtoMinion>();

            // 生成每队的小兵
            for (int i = 0; i < 3; i++)
            {
                // 产生1队小兵
                DtoMinion minion = MinionData.GetMinionCopy(m_MinionId--, MinionData.TypeId_Warrior);
                minion.Team = 1;
                TeamOneMinions.Add(minion.Id, minion);
                minions.Add(minion);

                // 生产2队小兵
                minion      = MinionData.GetMinionCopy(m_MinionId--, MinionData.TypeId_Warrior);
                minion.Team = 2;
                TeamTwoMinions.Add(minion.Id, minion);
                minions.Add(minion);
            }

            // 告诉客户端出兵了
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.MinionArray, JsonMapper.ToJson(minions.ToArray()));
            Brocast(OperationCode.SpawnMinion, data);

            // 等待30秒再次产生小兵
            StartSchedule(DateTime.UtcNow.AddSeconds(30), SpawnMinion);
        }
Exemple #5
0
        /// <summary>
        /// 摧毁房间
        /// </summary>
        /// <param name="roomId"></param>
        public void DestroyRoom(int roomId)
        {
            SelectRoom room;

            if (!RoomDict.TryGetValue(roomId, out room))
            {
                return;
            }

            // 移除玩家id和房间id的映射
            foreach (int item in room.TeamOneDict.Keys)
            {
                PlayerRoomDict.Remove(item);
            }
            foreach (int item in room.TeamTwoDict.Keys)
            {
                PlayerRoomDict.Remove(item);
            }
            // 移除房间id和房间的映射
            RoomDict.Remove(roomId);

            // 清空房间内的数据
            room.Clear();

            // 回收
            RoomQue.Enqueue(room);

            MobaServer.LogInfo("选人房间销毁了");
        }
Exemple #6
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理获取玩家角色的请求");
            OperationResponse response = new OperationResponse(request.OperationCode);

            // 验证连接对象
            if (Caches.User.VerifyPeer(peer))
            {
                // 检测是否存在角色
                if (UserManager.HasPlayer(peer.Username))
                {
                    response.ReturnCode = (short)ReturnCode.Suceess;
                }
                else
                {
                    response.ReturnCode = (short)ReturnCode.Empty;
                }
            }
            else
            {
                response.ReturnCode   = (short)ReturnCode.Falied;
                response.DebugMessage = "非法登陆";
            }
            peer.SendOperationResponse(response, sendParameters);
        }
Exemple #7
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理开始匹配的请求");

            // 检测id是否正确
            int playerId = (int)request.Parameters[(byte)ParameterCode.PlayerId];

            if (UserManager.GetPlayer(peer.Username).Identification != playerId)
            {
                MobaServer.LogWarn("非法操作");
                return;
            }

            MatchRoom room = Caches.Match.StartMatch(peer, playerId);

            // 如果房间满了 开始选人
            if (room.IsFull)
            {
                // 创建选人的房间
                Caches.Select.CreateRoom(room.TeamOneIdList, room.TeamTwoIdList);
                // 通知所有客户端进入选人的房间
                room.Brocast(OperationCode.StartMatch, null);
                // 摧毁房间
                Caches.Match.DestroyRoom(room);
            }
        }
Exemple #8
0
        /// <summary>
        /// 摧毁指定房间
        /// </summary>
        /// <param name="room"></param>
        public void DestroyRoom(int roomId)
        {
            BattleRoom room;

            if (!RoomDict.TryGetValue(roomId, out room))
            {
                return;
            }

            // 移除玩家id和房间id的映射
            foreach (DtoHero item in room.HerosArray)
            {
                PlayerRoomDict.Remove(item.Id);
            }

            // 移除房间id和房间的映射
            RoomDict.Remove(roomId);

            // 清空房间内的数据
            room.Clear();
            // 回收
            RoomQue.Enqueue(room);

            MobaServer.LogInfo("战斗房间销毁了");
        }
        // 处理注册请求
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理注册请求");
            string username = request.Parameters.ExTryGet((byte)ParameterCode.Username) as string;
            string password = request.Parameters.ExTryGet((byte)ParameterCode.Password) as string;

            // 无效检测
            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                return;
            }

            OperationResponse response = new OperationResponse(request.OperationCode);

            if (UserManager.GetByUsername(username) == null)
            {
                // 添加新用户
                UserManager.Add(new User(username, password));
                response.ReturnCode = (byte)ReturnCode.Suceess;
            }
            else
            {
                response.ReturnCode   = (byte)ReturnCode.Falied;
                response.DebugMessage = "账号已存在";
            }
            peer.SendOperationResponse(response, sendParameters);
        }
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理进入战斗房间的请求");

            int        plyaerId = (int)UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.Enter(plyaerId, peer);

            // 判断是否全部进入
            if (!room.IsAllEnter)
            {
                return;
            }

            // 发送给所有客户端 英雄,建筑,装备的数据
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.HerosArray, JsonMapper.ToJson(room.HerosArray));
            data.Add((byte)ParameterCode.BuildsArray, JsonMapper.ToJson(room.BuildsArray));
            data.Add((byte)ParameterCode.ItemArray, JsonMapper.ToJson(ItemData.GetArray()));

            // 发送当前游戏内用到的技能数据
            data.Add((byte)ParameterCode.SkillArray, JsonMapper.ToJson(SkillData.GetSkillByHeros(room.HerosArray)));

            room.Brocast(OperationCode.EnterBattle, data);
        }
Exemple #11
0
        /// <summary>
        /// 根据id获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DtoMinion GetDto(int id)
        {
            DtoMinion dto = null;

            // 英雄的id和玩家数据库id一致 所以正数id是英雄
            if (id >= 0)
            {
                dto = GetDtoHero(id);
            }
            // 建筑id范围
            else if (id >= ServerConfig.TeamTwoBuildId - 100 && id <= ServerConfig.TeamOneBuildId)
            {
                dto = GetDtoBuild(id);
            }
            // 小兵id范围
            else if (id <= ServerConfig.MinionId)
            {
                dto = GetDtoMinion(id);
            }
            if (dto == null)
            {
                MobaServer.LogWarn(">>>>>>>>>>>>>> id:" + id + " cant found");
            }

            return(dto);
        }
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理进入选择房间的请求");

            DataBase.Model.Player player = UserManager.GetPlayer(peer.Username);
            SelectRoom            room   = Caches.Select.EnterRoom(player.Identification, peer);

            if (room == null)
            {
                return;
            }

            OperationResponse response = new OperationResponse();

            // 先给客户端发送已经进入房间的玩家数据(房间模型)
            response.OperationCode = (byte)OperationCode.SelectGetInfo;
            response.Parameters    = new Dictionary <byte, object>();
            response[(byte)ParameterCode.TeamOneSelectData] = JsonMapper.ToJson(room.TeamOneDict.Values.ToArray());
            response[(byte)ParameterCode.TeamTwoSelectData] = JsonMapper.ToJson(room.TeamTwoDict.Values.ToArray());
            peer.SendOperationResponse(response, sendParameters);

            // 再给房间内的其他客户端发一条消息:有人进入了
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)(ParameterCode.PlayerId), player.Identification);
            room.Brocast(OperationCode.EnterSelect, data);
        }
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理玩家上线的请求");

            // 获取自身的Player数据
            DataBase.Model.Player player = UserManager.GetPlayer(peer.Username);
            if (player == null)
            {
                MobaServer.LogError(">>>>>>>>>> 数据异常 : PlayerOnlineHandler");
                return;
            }

            // 防止重复上线
            if (Caches.Player.IsOnline(player.Identification))
            {
                MobaServer.LogError(">>>>>>>>> Player:" + player.Name + " 已上线");
                return;
            }

            Caches.Player.Online(player.Identification, peer);

            OperationResponse response = new OperationResponse();

            // 上线通知好友
            if (!String.IsNullOrEmpty(player.FriendIdList))
            {
                string[] friends  = player.FriendIdList.Split(',');
                MobaPeer tempPeer = null;
                response.OperationCode = (byte)OperationCode.FriendStateChange;
                foreach (string friend in friends)
                {
                    if (string.IsNullOrEmpty(friend))
                    {
                        continue;
                    }
                    int id = int.Parse(friend);
                    if (!Caches.Player.IsOnline(id))
                    {
                        continue;
                    }
                    tempPeer = Caches.Player.GetPeer(id);

                    // 发送好友上线的消息
                    response.Parameters = new Dictionary <byte, object>();
                    DtoFriend dto = new DtoFriend(player.Identification, player.Name, true);
                    response[(byte)ParameterCode.DtoFriend] = JsonMapper.ToJson(dto);
                    tempPeer.SendOperationResponse(response, sendParameters);
                }
            }

            // 发送自身的玩家数据给客户端
            response.OperationCode = request.OperationCode;
            response.Parameters    = new Dictionary <byte, object>();
            response[(byte)ParameterCode.DtoPlayer] = JsonMapper.ToJson(player.ConvertToDot());
            peer.SendOperationResponse(response, sendParameters);
        }
Exemple #14
0
 /// <summary>
 /// 输出用户的所有玩家信息
 /// </summary>
 /// <param name="list"></param>
 public void PrintPlayerList(IList <Player> list)
 {
     for (int i = 0; i < list.Count; i++)
     {
         int    id       = list[i].Identification;
         string Name     = list[i].Name;
         int    Power    = list[i].Power;
         int    RunCount = list[i].RunCount;
         string info     = ">>>>>>>> id : " + id + " name : " + Name + " Power : " + Power + " RunCount : " + RunCount;
         MobaServer.LogInfo(info);
     }
 }
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo(peer.Username + ":初始化完成");

            BattleRoom room = Caches.Battle.GetRoomByPlayerId(UserManager.GetPlayer(peer.Username).Identification);

            room.InitCount++;
            // 所有客户端初始化完成
            if (room.IsAllInit)
            {
                // 开始生产小兵
                room.SpawnMinion();
            }
        }
Exemple #16
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理停止匹配的请求");

            int playerId = (int)request.Parameters[(byte)ParameterCode.PlayerId];

            OperationResponse response = new OperationResponse(request.OperationCode);

            if (Caches.Match.StopMatch(peer, playerId))
            {
                // 告诉客户端离开成功
                response.ReturnCode = (short)ReturnCode.Suceess;
                peer.SendOperationResponse(response, sendParameters);
            }
        }
Exemple #17
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理是否添加好友的反馈");

            // 是否同意
            bool isAccept = (bool)request.Parameters.ExTryGet((byte)ParameterCode.AcceptAddFriend);
            // 请求添加的玩家数据
            int    fromId   = (int)request.Parameters.ExTryGet((byte)ParameterCode.PlayerId);
            string fromName = (string)request.Parameters.ExTryGet((byte)ParameterCode.PlayerName);

            // 请求的客户端
            MobaPeer fromPeer = Caches.Player.GetPeer(fromId);

            OperationResponse response = new OperationResponse((byte)OperationCode.PlayerAddResult);

            if (isAccept)
            {
                response.ReturnCode = (short)ReturnCode.Suceess;

                // 自身的数据
                DataBase.Model.Player player = UserManager.GetPlayer(peer.Username);
                // 好友的数据
                DataBase.Model.Player friend = PlayerManager.GetById(fromId);

                // 添加好友
                PlayerManager.AddFriend(player.Identification, fromId);

                // 发送更新后的数据
                DtoPlayer dtoPlayer = player.ConvertToDot();
                response.Parameters = new Dictionary <byte, object>();
                response[(byte)ParameterCode.DtoFriend] = JsonMapper.ToJson(dtoPlayer.Friends.Last());
                peer.SendOperationResponse(response, sendParameters);

                dtoPlayer           = friend.ConvertToDot();
                response.Parameters = new Dictionary <byte, object>();
                response[(byte)ParameterCode.DtoFriend] = JsonMapper.ToJson(dtoPlayer.Friends.Last());
                fromPeer.SendOperationResponse(response, sendParameters);

                return;
            }
            else
            {
                response.ReturnCode   = (short)ReturnCode.Falied;
                response.DebugMessage = fromName + " 拒绝添加你为好友";
            }

            fromPeer.SendOperationResponse(response, sendParameters);
        }
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理选人界面的聊天请求");

            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            SelectRoom room     = Caches.Select.GetRoomByPlayerId(playerId);

            if (room == null)
            {
                MobaServer.LogError(">>>>> 异常:玩家找不到房间 TalkInSelectHandler");
                return;
            }

            // 将聊天内容发给所有客户端 测试方便
            room.Brocast(OperationCode.TalkInSelect, request.Parameters);
        }
Exemple #19
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理购买道具的请求");

            // 获取道具
            int       itemId = (int)request[(byte)ParameterCode.ItemId];
            ItemModel item   = ItemData.GetItem(itemId);

            if (item == null)
            {
                return;
            }

            // 获取房间
            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.GetRoomByPlayerId(playerId);

            if (room == null)
            {
                return;
            }

            // 获取英雄
            DtoHero hero = room.GetDtoHero(playerId);

            // 金币不足
            if (hero.Money < item.Price)
            {
                SendResponse(peer, request.OperationCode, null, ReturnCode.Falied, "金币不足");
                return;
            }

            // 开始购买
            if (hero.BuyItem(item))
            {
                // 给所有客户端发送消息 谁买了什么装备
                Dictionary <byte, object> data = new Dictionary <byte, object>();
                data.Add((byte)ParameterCode.DtoHero, JsonMapper.ToJson(hero));
                room.Brocast(OpCode, data);
            }
            else
            {
                SendResponse(peer, request.OperationCode, null, ReturnCode.Falied, "装备已满");
            }
        }
Exemple #20
0
        /// <summary>
        /// 根据SkillData中的静态常量 创建对应委托
        /// </summary>
        public static void Init()
        {
            EffectDict = new Dictionary <string, EffectHandler>();
            DamageDict = new Dictionary <string, DamageHandler>();
            TimerDict  = new Dictionary <string, TimerAction>();

            Type       typeHandler = typeof(SkillHandlerData);
            Type       typeData    = typeof(SkillData);
            MethodInfo method      = null;

            // 获取SkillData中的所有静态常量
            foreach (FieldInfo filed in typeData.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                string value = filed.GetValue(null) as string;
                if (value == null)
                {
                    continue;
                }

                // 保存效果类委托
                if (value.StartsWith(SkillData.EffectType))
                {
                    method = typeHandler.GetMethod(filed.Name);
                    if (method == null)
                    {
                        MobaServer.LogWarn(">>>> effect method is not found : " + filed.Name);
                        continue;
                    }
                    EffectDict.Add(value, (EffectHandler)Delegate.CreateDelegate(typeof(EffectHandler), method));
                }
                // 保存伤害类委托
                else if (value.StartsWith(SkillData.DamageType))
                {
                    method = typeHandler.GetMethod(filed.Name);
                    if (method == null)
                    {
                        MobaServer.LogWarn(">>>> damage method is not found : " + filed.Name);
                        continue;
                    }
                    DamageDict.Add(value, (DamageHandler)Delegate.CreateDelegate(typeof(DamageHandler), method));
                }
            }
        }
Exemple #21
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理创建角色的请求");

            string playerName = request.Parameters.ExTryGet((byte)ParameterCode.PlayerName) as string;

            // 无效检测
            if (String.IsNullOrEmpty(playerName))
            {
                return;
            }

            User user = UserManager.GetByUsername(peer.Username);

            DataBase.Model.Player player = new DataBase.Model.Player(playerName, user);
            PlayerManager.Add(peer.Username, player);

            OperationResponse response = new OperationResponse(request.OperationCode);

            peer.SendOperationResponse(response, sendParameters);
        }
Exemple #22
0
        // 处理登陆请求
        public override void OnOperationRequest(OperationRequest request,
                                                SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理登陆请求");
            string username = request.Parameters.ExTryGet((byte)ParameterCode.Username) as string;
            string password = request.Parameters.ExTryGet((byte)ParameterCode.Password) as string;

            // 无效检测
            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                return;
            }

            OperationResponse response = new OperationResponse(request.OperationCode);

            // 验证在线
            if (Caches.User.IsOnline(username))
            {
                response.ReturnCode   = (short)ReturnCode.Falied;
                response.DebugMessage = "账号已登陆";
            }
            else
            {
                // 验证用户名,密码是否正确
                if (UserManager.VerifyUser(username, password))
                {
                    Caches.User.Online(username, peer);

                    response.ReturnCode = (short)ReturnCode.Suceess;
                }
                else
                {
                    response.ReturnCode   = (short)ReturnCode.Falied;
                    response.DebugMessage = "用户名或密码不正确";
                }
            }

            peer.SendOperationResponse(response, sendParameters);
        }
Exemple #23
0
        /// <summary>
        /// 攻击buff/debuff
        /// </summary>
        /// <param name="room"></param>
        /// <param name="skillId"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="effect"></param>
        /// <returns></returns>
        public static void AttackDouble(RoomBase <MobaPeer> room, int skillId, DtoMinion from, DtoMinion[] to,
                                        EffectModel effect)
        {
            // 增加攻击
            double value = from.Attack * (effect.EffectValue - 1);

            from.Attack += (int)value;
            string timerKey = ServerConfig.GetEffectKey(from.Id, skillId, effect.Type);

            MobaServer.LogInfo(">>>>>>>>>>> value:" + value);
            MobaServer.LogInfo(">>>>>>>>>> attack : " + from.Attack);
            // 恢复攻击
            Action action = () =>
            {
                from.Attack -= (int)value;
                MobaServer.LogInfo(">>>>>>>>>> attack : " + from.Attack);
                // 移除延时处理
                TimerDict.Remove(timerKey);
            };
            Guid guid = room.Timer.AddAction(DateTime.UtcNow.AddSeconds(effect.Duration), action);

            // 添加到延时处理
            TimerDict.Add(timerKey, new TimerAction(guid, action));
        }
Exemple #24
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理添加好友的请求");

            // 请求添加的玩家名字
            string name = request.Parameters.ExTryGet((byte)ParameterCode.PlayerName) as string;

            // 无效判断
            if (String.IsNullOrEmpty(name))
            {
                return;
            }

            // 获取添加好友的数据
            OperationResponse response = new OperationResponse(request.OperationCode);

            DataBase.Model.Player player = PlayerManager.GetByName(name);
            if (player == null)
            {
                response.ReturnCode   = (short)ReturnCode.Falied;
                response.DebugMessage = "没有此玩家";
                peer.SendOperationResponse(response, sendParameters);
                return;
            }
            // 如果添加的玩家为自身
            DataBase.Model.Player selfPlayer = UserManager.GetPlayer(peer.Username);
            if (selfPlayer.Identification == player.Identification)
            {
                response.ReturnCode   = (short)ReturnCode.Falied;
                response.DebugMessage = "不能添加自身";
                peer.SendOperationResponse(response, sendParameters);
                return;
            }
            // 如果已经是好友
            string[] friends = UserManager.GetPlayer(peer.Username).FriendIdList.Split(',');
            foreach (string friend in friends)
            {
                if (String.IsNullOrEmpty(friend))
                {
                    continue;
                }
                if (int.Parse(friend) == player.Identification)
                {
                    response.ReturnCode   = (short)ReturnCode.Falied;
                    response.DebugMessage = "玩家已经是你的好友";
                    peer.SendOperationResponse(response, sendParameters);
                    return;
                }
            }
            // 判断是否在线 这里不提供离线处理 直接返回失败
            // TODO 不能给离线的玩家发送信息
            bool isOnline = Caches.Player.IsOnline(player.Identification);

            if (!isOnline)
            {
                response.ReturnCode   = (short)ReturnCode.Falied;
                response.DebugMessage = "玩家离线";
                peer.SendOperationResponse(response, sendParameters);
                return;
            }

            // 玩家在线 向玩家发送是否同意的响应
            MobaPeer toPeer = Caches.Player.GetPeer(player.Identification);

            response.OperationCode = (byte)OperationCode.PlayerAddToClient;
            response.Parameters    = new Dictionary <byte, object>();
            // 传输玩家名和id
            response[(byte)(ParameterCode.PlayerName)] = selfPlayer.Name;
            response[(byte)(ParameterCode.PlayerId)]   = selfPlayer.Identification;
            toPeer.SendOperationResponse(response, sendParameters);
        }