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

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

            if (relation != null)
            {
                relation.AddRelationGL(msg.event_idx, msg.player_id, msg.flag, msg.message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 处理关系事件
        /// </summary>
        private void HandleRelationEvent(List <RelationEventInfo> list_event)
        {
            //查询过程中如果下线
            if (m_char_idx == 0)
            {
                return;
            }

            Unit player = UnitManager.Instance.GetUnitByIdx(m_char_idx);

            if (player == null)
            {
                return;
            }

            foreach (var relation_evt in list_event)
            {
                switch (relation_evt.event_type)
                {
                case eRelationEvent.Add:    //对方申请加你好友
                {
                    //超过上限
                    if (IsRelationFull(relation_evt.bin_content.bin_add_content.flag))
                    {
                        //清除处理过的事件
                        SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                        continue;
                    }

                    //是否已经存在相同关系
                    RelationInfo relation_info = null;
                    if (m_relations.TryGetValue(relation_evt.source_char_idx, out relation_info) && relation_info.flags == relation_evt.bin_content.bin_add_content.flag)
                    {
                        //清除处理过的事件
                        SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                        continue;
                    }

                    //拉黑不需要同意,所以不添加事件
                    if (relation_evt.bin_content.bin_add_content.flag == eRelationFlag.Block)
                    {
                        if (m_relations.TryGetValue(relation_evt.source_char_idx, out relation_info))
                        {        //已经存在其他关系,则用新关系覆盖旧关系
                            relation_info.flags = eRelationFlag.Block;
                            this.SyncRelation2SS(relation_evt.source_char_idx);
                        }
                        else
                        {
                            Unit target_player = UnitManager.Instance.GetUnitByIdx(relation_evt.source_char_idx);
                            if (target_player == null)
                            {
                                PlayerInfoForGL data = CommonObjectPools.Spawn <PlayerInfoForGL>();
                                SQLCharHandle.QueryCharacterInfo(relation_evt.source_char_idx, data, (ret) =>
                                    {
                                        if (ret && m_char_idx > 0)
                                        {
                                            relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                            relation_info.Copy(data);
                                            relation_info.flags = eRelationFlag.Block;
                                            this.AddRelation(relation_info);
                                            this.SyncRelation2SS(relation_evt.source_char_idx);
                                        }
                                        CommonObjectPools.Despawn(data);
                                    });
                            }
                            else
                            {
                                relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                relation_info.Copy(target_player.player_data);
                                relation_info.flags = eRelationFlag.Block;
                                this.AddRelation(relation_info);
                                this.SyncRelation2SS(relation_evt.source_char_idx);
                            }
                        }

                        //清除处理过的事件
                        SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                        m_relation_events.Remove(relation_evt.event_idx);
                    }
                    else
                    {
                        //添加关系事件
                        if (m_relation_events.ContainsKey(relation_evt.event_idx))
                        {
                            continue;
                        }
                        else
                        {
                            m_relation_events.Add(relation_evt.event_idx, relation_evt);
                        }

                        //通知逻辑服,由逻辑服转发给客户端
                        gl2ss.RelationAdd msg = PacketPools.Get(gl2ss.msg.RELATION_ADD) as gl2ss.RelationAdd;
                        msg.event_idx = relation_evt.event_idx;
                        msg.char_idx  = m_char_idx;
                        msg.player_id.Set(relation_evt.source_char_idx, relation_evt.bin_content.bin_add_content.char_name);
                        msg.message = relation_evt.bin_content.bin_add_content.message;
                        msg.flag    = relation_evt.bin_content.bin_add_content.flag;
                        ForServerNetManager.Instance.Send(player.ss_srv_uid, msg);
                    }
                    break;
                }

                case eRelationEvent.Delete:    //对方删除了你
                {
                    if (m_relations.ContainsKey(relation_evt.source_char_idx))
                    {
                        this.RemoveRelation(relation_evt.source_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 = relation_evt.source_char_idx;
                        ForServerNetManager.Instance.Send(player.ss_srv_uid, msg_remove);
                    }

                    //清除处理过的事件
                    SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                    m_relation_events.Remove(relation_evt.event_idx);
                    break;
                }

                case eRelationEvent.Agree:    //对方同意了你的申请
                {
                    if (relation_evt.bin_content.bin_agree_content.cmd == eRelationApplyCmd.Agree)
                    {
                        //如果对方在线,则取对方身上的数据;否则取数据库的数据
                        Unit target_player = UnitManager.Instance.GetUnitByIdx(relation_evt.source_char_idx);
                        if (target_player != null)
                        {
                            this.RemoveRelation(relation_evt.source_char_idx);

                            RelationInfo relation_info = CommonObjectPools.Spawn <RelationInfo>();
                            relation_info.Copy(target_player.player_data);
                            relation_info.flags = relation_evt.bin_content.bin_agree_content.flag;
                            this.AddRelation(relation_info);
                            this.SyncRelation2SS(relation_evt.source_char_idx);

                            //清除处理过的事件
                            SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                            m_relation_events.Remove(relation_evt.event_idx);
                        }
                        else
                        {
                            PlayerInfoForGL data = CommonObjectPools.Spawn <PlayerInfoForGL>();
                            SQLCharHandle.QueryCharacterInfo(relation_evt.source_char_idx, data, (ret) =>
                                {
                                    if (ret && m_char_idx > 0)
                                    {
                                        this.RemoveRelation(relation_evt.source_char_idx);

                                        RelationInfo relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                        relation_info.Copy(data);
                                        relation_info.flags = relation_evt.bin_content.bin_agree_content.flag;
                                        this.AddRelation(relation_info);
                                        this.SyncRelation2SS(relation_evt.source_char_idx);
                                    }
                                    CommonObjectPools.Despawn(data);

                                    //清除处理过的事件
                                    SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                                    m_relation_events.Remove(relation_evt.event_idx);
                                });
                        }
                    }
                    else
                    {
                        //清除处理过的事件
                        SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                        m_relation_events.Remove(relation_evt.event_idx);
                    }

                    break;
                }

                case eRelationEvent.Give:
                {
                    Log.Info("赠送 src:" + relation_evt.source_char_idx + " dst:" + relation_evt.target_char_idx);
                    RelationEventContent.GiveContent give_info = relation_evt.bin_content.bin_give_content;
                    //发给ss处理
                    if (item.IsValidItem(give_info.item_id))
                    {
                        gl2ss.RelationGive msg_give = PacketPools.Get(gl2ss.msg.RELATION_GIVE) as gl2ss.RelationGive;
                        msg_give.char_idx = m_char_idx;
                        msg_give.src_player_id.Set(relation_evt.source_char_idx, give_info.char_name);
                        msg_give.item_id = give_info.item_id;
                        ForServerNetManager.Instance.Send(player.ss_srv_uid, msg_give);
                    }

                    //清除处理过的事件
                    SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                    m_relation_events.Remove(relation_evt.event_idx);
                    break;
                }
                }
            }
        }