Esempio n. 1
0
        public FriendsInfo GetFriend(FriendType type, uint uid)
        {
            FriendsInfo        info = null;
            List <FriendsInfo> list = null;

            if (mCommon.TryGetValue(type, out list) == false)
            {
                return(info);
            }
            else
            {
                info = list.Find(delegate(FriendsInfo _info)
                {
                    return(_info.Uid == uid);
                });

                if (info != null)
                {
                    return(info);
                }
            }
            return(info);
        }
Esempio n. 2
0
        public void CreateStrangeData(uint uuid, string name, uint level, uint roleId, uint teamId, uint honor, uint transferLv, uint vipLv)
        {
            uint localPlayerId = Game.GetInstance().LocalPlayerID.obj_idx;

            if (uuid == localPlayerId)
            {
                return;
            }

            bool        online     = false;
            FriendsInfo friendInfo = GetFriend(FriendType.Friend, uuid);

            if (friendInfo != null)
            {
                online = friendInfo.Online;
            }
            else
            {
                friendInfo = GetFriend(FriendType.Enemy, uuid);
                if (friendInfo != null)
                {
                    online = friendInfo.Online;
                }
                else
                {
                    friendInfo = GetFriend(FriendType.Black, uuid);
                    if (friendInfo != null)
                    {
                        online = friendInfo.Online;
                    }
                }
            }

            FriendsInfo stranger = new FriendsInfo(uuid, name, level, roleId, online, teamId, honor, transferLv, vipLv);

            AddStrange(stranger, false);
        }
Esempio n. 3
0
        public void Remove(uint uid)
        {
            FriendsInfo info = null;
            uint        uuid = 0;
            FriendType  type = FriendType.Closer;

            foreach (var kv in mCommon)
            {
                info = kv.Value.Find(delegate(FriendsInfo _info){
                    return(_info.Uid == uid);
                });

                if (info != null)
                {
                    uuid = info.Uid;
                    type = kv.Key;
                    break;
                }
            }
            if (uuid != 0)
            {
                Remove(type, uuid);
            }
        }
Esempio n. 4
0
        public void LoadCloser()
        {
            if (m_isReconnect) // 断线重连不重新load
            {
                return;
            }

            if (mCommon.ContainsKey(FriendType.Closer))
            {
                mCommon[FriendType.Closer].Clear();
            }
            string uid  = Game.GetInstance().LocalPlayerID.obj_idx.ToString();
            string path = Const.persistentDataPath + "/" + uid + "FriendsCloser.xml";

            if (File.Exists(path) == false)
            {
                return;
            }

            try
            {
                // 解决Unity读取utf8编码xml文件的BOM问题
                string      xmlString = System.IO.File.ReadAllText(path);
                XmlDocument xmlDoc    = new XmlDocument();
                xmlDoc.LoadXml(xmlString);
                XmlNode root = xmlDoc.SelectSingleNode("FriendsCloserList");

                if (root != null)
                {
                    foreach (XmlNode kChild in root.ChildNodes)
                    {
                        if (kChild.Name == "FriendsCloser")
                        {
                            XmlElement _elem   = kChild as XmlElement;
                            uint       _uid    = uint.Parse(_elem.GetAttribute("UID"));
                            string     _name   = _elem.GetAttribute("Name");
                            uint       _level  = uint.Parse(_elem.GetAttribute("Level"));
                            uint       _roleid = uint.Parse(_elem.GetAttribute("RoleId"));

                            uint _teamid = 0;
                            uint.TryParse(_elem.GetAttribute("TeamId"), out _teamid);

                            uint _power      = uint.Parse(_elem.GetAttribute("BattlePower"));
                            uint _societypos = uint.Parse(_elem.GetAttribute("SocietyPos"));
                            uint _lasttime   = uint.Parse(_elem.GetAttribute("LastChatTime"));

                            uint _honor = 0;
                            uint.TryParse(_elem.GetAttribute("Honor"), out _honor);

                            uint _transferLv = 0;
                            uint.TryParse(_elem.GetAttribute("TransferLv"), out _transferLv);

                            uint _vipLv = 0;
                            uint.TryParse(_elem.GetAttribute("VipLv"), out _vipLv);

                            uint _mateUUID = 0;
                            uint.TryParse(_elem.GetAttribute("MateUUID"), out _mateUUID);

                            string _mateName = _elem.GetAttribute("MateName");

                            uint _bubbleId = 0;
                            uint.TryParse(_elem.GetAttribute("BubbleId"), out _bubbleId);

                            uint _photoFrameId = 0;
                            uint.TryParse(_elem.GetAttribute("PhotoFrameId"), out _photoFrameId);

                            FriendsInfo info = new FriendsInfo(_uid, _name, _level, _roleid, false, _teamid, _honor, _transferLv, _vipLv, _mateUUID, _mateName, _bubbleId, _photoFrameId);
                            info.LastChatTime = _lasttime;
                            AddFriend(FriendType.Closer, info, true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // 文件为空时,xmlDoc.LoadXml会异常
            }
        }
Esempio n. 5
0
        public void AddFriend(FriendType type, FriendsInfo friend, bool isInit)
        {
            List <FriendsInfo> friendList = null;

            if (mCommon.TryGetValue(type, out friendList))
            {
                var info = friendList.Find(delegate(FriendsInfo _info)
                {
                    return(_info.Uid == friend.Uid);
                });
                if (info != null)
                {
                    if (type != FriendType.Enemy)
                    {
                        info.IsFirst = false;
                    }
                    else
                    {
                        foreach (var v in friendList)
                        {
                            if (v.Uid == info.Uid)
                            {
                                v.IsFirst = true;
                            }
                            else
                            {
                                v.IsFirst = false;
                            }
                        }
                    }
                    info.Copy(friend);
                }
                else
                {
                    if (type != FriendType.Enemy)
                    {
                        friendList.Add(friend);
                    }
                    else
                    {
                        int enemyInt = GameConstHelper.GetInt("GAME_ENEMY_NUM_LIMIT");
                        if (friendList.Count == enemyInt)
                        {
                            friendList.RemoveAt(friendList.Count - 1);
                        }
                        if (!isInit)
                        {
                            foreach (var v in friendList)
                            {
                                v.IsFirst = false;
                            }
                            friend.IsFirst = true;
                        }
                        friendList.Insert(0, friend);
                    }
                }
            }
            else
            {
                friendList = new List <FriendsInfo>();
                friendList.Add(friend);
                mCommon.Add(type, friendList);
            }
        }
Esempio n. 6
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;
            }
            }
        }