Esempio n. 1
0
        /// <summary>
        /// 添加关系
        /// </summary>
        private void OnRelationAdd(PacketBase packet)
        {
            ss2gl.RelationAdd msg = packet as ss2gl.RelationAdd;

            MemberRelation relation = RelationManager.Instance.GetMember(msg.char_idx);

            if (relation == null)
            {
                return;
            }

            relation.AddRelationCommand(msg.target_id, msg.flag, msg.message);
        }
Esempio n. 2
0
        /// <summary>
        /// 添加关系
        /// </summary>
        /// <param name="target">目标</param>
        /// <param name="flag">关系标记</param>
        public void AddRelationClient(RelationAddTarget target, eRelationFlag flag, string message)
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }

            //超过上限
            if (IsRelationFull(flag))
            {
                return;
            }

            //判断是否已经存在关系
            if (target.type == eRelationAddType.Idx)
            {
                RelationInfo relation_info;
                if (m_relations.TryGetValue(target.char_idx, out relation_info))
                {
                    //已经存在相同关系,或黑名单状态加好友
                    if (relation_info.flags == flag || (relation_info.flags == eRelationFlag.Block && flag == eRelationFlag.Friend))
                    {
                        return;
                    }
                }
            }
            else
            {
                foreach (var relation_info in m_relations)
                {
                    if (relation_info.Value.char_name == target.char_name)
                    {
                        //已经存在相同关系,或黑名单状态加好友
                        if (relation_info.Value.flags == flag || (relation_info.Value.flags == eRelationFlag.Block && flag == eRelationFlag.Friend))
                        {
                            return;
                        }
                    }
                }
            }

            //是否已经请求过
            long last_add_time = 0;

            if (m_add_relations.TryGetValue(target, out last_add_time))
            {
                if (Time.timeSinceStartup - last_add_time < relation.ADD_RELATION_TIME_OFFSET * 1000)
                {
                    return;
                }
                m_add_relations.Remove(target);
            }

            //发送到gl
            ss2gl.RelationAdd msg = PacketPools.Get(ss2gl.msg.RELATION_ADD) as ss2gl.RelationAdd;
            msg.char_idx  = m_char_idx;
            msg.target_id = target;
            msg.flag      = flag;
            msg.message   = message;
            ServerNetManager.Instance.Send2GL(msg);

            //添加到请求队列
            m_add_relations.Add(target, Time.timeSinceStartup);
        }