コード例 #1
0
        /// <summary>
        /// 移除关系
        /// </summary>
        public void RemoveRelationCommand(long target_char_idx)
        {
            //不在线了
            Unit player = UnitManager.Instance.GetUnitByIdx(m_char_idx);

            if (player == null)
            {
                return;
            }

            //是否已经存在关系
            RelationInfo relation_info = null;

            if (m_relations.TryGetValue(target_char_idx, out relation_info))
            {
                this.RemoveRelation(target_char_idx);

                //通知逻辑服,由逻辑服转发给客户端
                gl2ss.RelationRemove msg_remove = PacketPools.Get(gl2ss.msg.RELATION_REMOVE) as gl2ss.RelationRemove;
                msg_remove.char_idx   = m_char_idx;
                msg_remove.target_idx = target_char_idx;
                ForServerNetManager.Instance.Send(player.ss_srv_uid, msg_remove);

                //添加到db,需要先判断数据库是否已经有写入过,防止重复写入
                SQLRelationHandle.QueryExistsRelationEvent(m_char_idx, target_char_idx, relation_info.flags, (event_idx) =>
                {
                    if (event_idx == 0 && m_char_idx > 0)
                    {//保存事件
                        RelationEventInfo e_info = new RelationEventInfo();
                        e_info.target_char_idx   = target_char_idx;
                        e_info.source_char_idx   = m_char_idx;
                        e_info.event_type        = eRelationEvent.Delete;
                        SQLRelationHandle.InsertRelationEvent(e_info);
                        //立刻通知接受者
                        this.BroadcastEvent(e_info.target_char_idx, e_info.event_type);
                    }
                });
            }
        }
コード例 #2
0
        /// <summary>
        /// 添加关系
        /// </summary>
        public void AddRelationCommand(RelationAddTarget target_id, eRelationFlag flag, string message)
        {
            //超过上限
            if (IsRelationFull(flag))
            {
                return;
            }

            //不在线了
            Unit player = UnitManager.Instance.GetUnitByIdx(m_char_idx);

            if (player == null)
            {
                return;
            }

            //判断是否已经存在关系,另外防止添加自己为好友
            if (target_id.type == eRelationAddType.Idx)
            {
                if (target_id.char_idx == m_char_idx)
                {
                    return;
                }
                RelationInfo relation_info;
                if (m_relations.TryGetValue(target_id.char_idx, out relation_info) && relation_info.flags == flag)
                {
                    return;
                }
            }
            else
            {
                if (target_id.char_name == player.char_name)
                {
                    return;
                }
                foreach (var relation_info in m_relations)
                {
                    if (relation_info.Value.char_name == target_id.char_name && relation_info.Value.flags == flag)
                    {
                        return;
                    }
                }
            }

            //如果是根据名称加好友,必须在缓存里面能查找到玩家数据
            Unit target_player = null;

            if (target_id.type == eRelationAddType.Idx)
            {
                target_player = UnitManager.Instance.GetUnitByIdx(target_id.char_idx);
            }
            else if (target_id.type == eRelationAddType.Name)
            {
                target_player = UnitManager.Instance.GetUnitByName(target_id.char_name);
                if (target_player == null)
                {
                    return;//TODO:后期如果有需求,可以查表
                }
                else
                {
                    target_id.char_idx = target_player.char_idx;
                }
            }

            //拉黑直接处理,如果有好友关系,需要先去掉好友
            if (flag == eRelationFlag.Block)
            {
                RelationInfo relation_info;
                if (m_relations.TryGetValue(target_id.char_idx, out relation_info))
                {
                    relation_info.flags = eRelationFlag.Block;
                    this.SyncRelation2SS(target_id.char_idx);
                }
                else
                {
                    if (target_player == null)
                    {
                        PlayerInfoForGL data = CommonObjectPools.Spawn <PlayerInfoForGL>();
                        SQLCharHandle.QueryCharacterInfo(target_id.char_idx, data, (ret) =>
                        {
                            if (ret && m_char_idx > 0)
                            {
                                relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                relation_info.Copy(data);
                                relation_info.flags = flag;
                                this.AddRelation(relation_info);
                                this.SyncRelation2SS(target_id.char_idx);
                            }
                            CommonObjectPools.Despawn(data);
                        });
                    }
                    else
                    {
                        relation_info = CommonObjectPools.Spawn <RelationInfo>();
                        relation_info.Copy(target_player.player_data);
                        relation_info.flags = flag;
                        this.AddRelation(relation_info);
                        this.SyncRelation2SS(target_id.char_idx);
                    }
                }
            }

            //添加到db,需要先判断数据库是否已经有写入过,防止重复写入
            //注:如果赠送可以同时存在的话,这里需要屏蔽赠送类型
            SQLRelationHandle.QueryExistsRelationEvent(m_char_idx, target_id.char_idx, flag, (event_idx) =>
            {
                if (event_idx == 0 && m_char_idx > 0)
                {//保存事件
                    RelationEventInfo e_info = new RelationEventInfo();
                    e_info.target_char_idx   = target_id.char_idx;
                    e_info.source_char_idx   = m_char_idx;
                    e_info.event_type        = eRelationEvent.Add;
                    e_info.bin_content.bin_add_content.char_name = player.char_name;
                    e_info.bin_content.bin_add_content.message   = message;
                    e_info.bin_content.bin_add_content.flag      = flag;
                    SQLRelationHandle.InsertRelationEvent(e_info);

                    //立刻通知接受者
                    this.BroadcastEvent(e_info.target_char_idx, e_info.event_type);
                }
            });
        }