Ejemplo n.º 1
0
        public void HandleServerData(ushort protocol, byte[] data)
        {
            switch (protocol)
            {
            case NetMsg.MSG_RELATION_INFO:
            {
                var        pack       = S2CPackBase.DeserializePack <S2CRelationInfo>(data);
                FriendType friendType = (FriendType)pack.type;
                if (friendType != FriendType.Closer)
                {
                    FriendsManager.Instance.GetListByType(friendType).Clear();
                }
                for (int i = 0; i < pack.infos.Count; i++)
                {
                    var         netInfo = pack.infos[i];
                    FriendsInfo info    = new FriendsInfo(netInfo);
                    FriendsManager.Instance.AddFriend(friendType, info, true);
                }
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_CHANGE, new CEventBaseArgs(friendType));
                break;
            }

            case NetMsg.MSG_RELATION_ONLINE_INFO:
            {
                var        pack       = S2CPackBase.DeserializePack <S2CRelationOnlineInfo>(data);
                FriendType friendType = (FriendType)pack.type;
                var        list       = FriendsManager.Instance.GetListByType(friendType);
                for (int i = 0; i < list.Count; i++)
                {
                    var friends = list[i];
                    friends.TeamId = 0;
                    friends.UpdateOnlineState(0);
                }

                for (int j = 0; j < pack.infos.Count; j++)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        var friends    = list[i];
                        var srvFriends = pack.infos[j];
                        if (friends.Uid == srvFriends.uuid)
                        {
                            if (srvFriends.name != null)
                            {
                                friends.Name = Encoding.UTF8.GetString(srvFriends.name);
                            }

                            friends.Level        = srvFriends.level;
                            friends.TeamId       = srvFriends.team_id;
                            friends.TransferLv   = srvFriends.transfer;
                            friends.VipLv        = srvFriends.vip;
                            friends.BubbleId     = ActorHelper.GetPartInList(srvFriends.shows, DBAvatarPart.BODY_PART.BUBBLE);
                            friends.PhotoFrameId = ActorHelper.GetPartInList(srvFriends.shows, DBAvatarPart.BODY_PART.PHOTO_FRAME);
                            if (srvFriends.mate != null)
                            {
                                friends.MateName = Encoding.UTF8.GetString(srvFriends.mate.name);
                                friends.MateUUID = srvFriends.mate.uuid;
                            }
                            else
                            {
                                friends.MateUUID = 0;
                                friends.MateName = "";
                            }

                            friends.UpdateOnlineState(1);
                        }
                    }
                }

                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_ONLINE_CHANGE, new CEventBaseArgs(friendType));
                break;
            }

            case NetMsg.MSG_RELATION_ADD:
            {
                var         pack       = S2CPackBase.DeserializePack <S2CRelationAdd>(data);
                FriendsInfo info       = new FriendsInfo(pack.info);
                FriendType  friendType = (FriendType)pack.type;
                string      playerName = System.Text.Encoding.UTF8.GetString(pack.info.name);
                switch (friendType)
                {
                case FriendType.Friend:
                {
                    UINotice.Instance.ShowMessage(string.Format(DBConstText.GetText("FRIENDS_ADD_POSITIVE"), playerName));
                    ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_ADD_BOTH_SIDES, new CEventBaseArgs(info.Uid));
                    break;
                }

                case FriendType.Black:
                {
                    UINotice.Instance.ShowMessage(DBConstText.GetText("FRIENDS_ADD_3"));
                    break;
                }

                case FriendType.Enemy:
                {
                    break;
                }
                }
                FriendsManager.Instance.AddFriend(friendType, info, false);
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_CHANGE, new CEventBaseArgs(friendType));
                break;
            }

            case NetMsg.MSG_RELATION_BE_ADDED:
            {
                var         pack       = S2CPackBase.DeserializePack <S2CRelationBeAdded>(data);
                FriendsInfo friendInfo = new FriendsInfo(pack.info);
                string      playerName = System.Text.Encoding.UTF8.GetString(pack.info.name);
                FriendsManager.Instance.AddFriend(FriendType.Friend, friendInfo, false);
                UINotice.Instance.ShowMessage(string.Format(DBConstText.GetText("FRIENDS_ADD_PASSIVE"), playerName));
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_ADD_BOTH_SIDES, new CEventBaseArgs(friendInfo.Uid));
                break;
            }

            case NetMsg.MSG_RELATION_ALREADY_BEEN:
            {
                var pack = S2CPackBase.DeserializePack <S2CRelationAlreadyBeen>(data);
                if ((FriendType)pack.type == FriendType.Friend)
                {
                    ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_ADD_BOTH_SIDES, new CEventBaseArgs(pack.uuid));
                }
                break;
            }

            case NetMsg.MSG_RELATION_DEL:
            {
                var        pack       = S2CPackBase.DeserializePack <S2CRelationDel>(data);
                FriendType friendType = (FriendType)pack.type;
                FriendsManager.Instance.Remove(friendType, pack.target_id);
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_CHANGE, new CEventBaseArgs(friendType));
                break;
            }

            case NetMsg.MSG_RELATION_SEARCH:
            {
                var pack = S2CPackBase.DeserializePack <S2CRelationSearch>(data);
                if (pack.info == null)
                {
                    UINotice.Instance.ShowMessage(string.Format(DBConstText.GetText("FRIENDS_SEARCH")));
                }
                else
                {
                    FriendsInfo info = new FriendsInfo(pack.info);
                    ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_SEARCH_RESULT, new CEventBaseArgs(info));
                }
                break;
            }

            case NetMsg.MSG_RELATION_RECOMMEND:
            {
                var pack = S2CPackBase.DeserializePack <S2CRelationRecommend>(data);
                FriendsManager.Instance.Recommends.Clear();
                for (int i = 0; i < pack.infos.Count; i++)
                {
                    FriendsInfo info = new FriendsInfo(pack.infos[i]);
                    FriendsManager.Instance.Recommends.Add(info);
                }
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_RECOMMEND, null);
                break;
            }

            // 好友申请列表
            case NetMsg.MSG_RELATION_FRIEND_APPLY_L:
            {
                var pack = S2CPackBase.DeserializePack <S2CRelationFriendApplyL>(data);
                FriendsManager.Instance.Applicants.Clear();
                for (int i = 0; i < pack.apply_l.Count; i++)
                {
                    FriendsInfo info = new FriendsInfo(pack.apply_l[i]);
                    FriendsManager.Instance.AddApplicant(info);
                }
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_APPLICANTS_CHANGE, null);
                break;
            }

            // 新增好友申请
            case NetMsg.MSG_RELATION_FRIEND_APPLY_ADD:
            {
                var pack = S2CPackBase.DeserializePack <S2CRelationFriendApplyAdd>(data);
                for (int i = 0; i < pack.apply_l.Count; i++)
                {
                    FriendsInfo info = new FriendsInfo(pack.apply_l[i]);
                    FriendsManager.Instance.AddApplicant(info);
                }
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_APPLICANTS_CHANGE, null);
                break;
            }

            // 好友申请删除
            case NetMsg.MSG_RELATION_FRIEND_APPLY_DEL:
            {
                var pack = S2CPackBase.DeserializePack <S2CRelationFriendApplyDel>(data);
                FriendsManager.Instance.RemoveApplicant(pack.uuid);
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_APPLICANTS_CHANGE, null);
                break;
            }

            // 好友亲密度
            case NetMsg.MSG_RELATION_FRIENDSHIP:
            {
                var pack = S2CPackBase.DeserializePack <S2CRelationFriendship>(data);
                for (int i = 0; i < pack.infos.Count; i++)
                {
                    var  info     = pack.infos[i];
                    uint uuid     = info.k;
                    uint intimacy = info.v;
                    List <FriendsInfo> FriendList;
                    if (FriendsManager.Instance.mCommon.TryGetValue(FriendType.Friend, out FriendList))
                    {
                        var FriendInfo = FriendList.Find(_FriendInfo => _FriendInfo.Uid == uuid);
                        if (FriendInfo != null)
                        {
                            FriendInfo.Intimacy = intimacy;
                        }
                    }
                }
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_FRIENDS_INTIMACY_CHANGE, null);
                break;
            }

            case NetMsg.MSG_RELATION_RECEIVE_FLOWER:
            {
                var  pack      = S2CPackBase.DeserializePack <S2CRelationReceiveFlower>(data);
                var  brief     = pack.info;
                uint GID       = pack.gid;
                uint FlowerNum = pack.num;
                uint Anonymous = pack.secret;

                uint warSubType = InstanceManager.Instance.InstanceInfo.mWarSubType;
                if (warSubType == GameConst.WAR_SUBTYPE_ARENA || warSubType == GameConst.WAR_SUBTYPE_BATTLE_FIELD)
                {
                    ClientEventMgr.GetInstance().PostEvent((int)ClientEvent.CE_RECEIVE_FLOWER, new CEventEventParamArgs(brief, GID, FlowerNum, Anonymous));
                }
                else
                {
                    ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_RECEIVE_FLOWER, new CEventEventParamArgs(brief, GID, FlowerNum, Anonymous));
                }

                break;
            }

            case NetMsg.MSG_RELATION_SEND_FLOWER_KISS:
            {
                var pack  = S2CPackBase.DeserializePack <S2CRelationSendFlowerKiss>(data);
                var brief = pack.info;
                ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_SEND_FLOWER_KISS, new CEventBaseArgs(brief));
                break;
            }
            }
        }