Пример #1
0
        /// <summary>
        /// 查询关系信息
        /// </summary>
        public static void QueryRelationEvent(long char_idx, Action <List <RelationEventInfo> > callback)
        {
            List <RelationEventInfo> list = new List <RelationEventInfo>();
            ByteArray by  = DBUtils.AllocDBArray();
            string    sql = "call SP_RELATION_EVENT_LOAD(" + char_idx + ")";

            DBManager.Instance.GetDB(eDBType.Center).Query(sql, (reader) =>
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        RelationEventInfo info = new RelationEventInfo();
                        info.event_idx         = reader.GetInt64(0);
                        info.target_char_idx   = reader.GetInt64(1);
                        info.source_char_idx   = reader.GetInt64(2);
                        info.event_type        = (eRelationEvent)reader.GetByte(3);
                        //内容
                        by.Clear();
                        long len = reader.GetBytes(4, 0, null, 0, int.MaxValue);
                        reader.GetBytes(4, 0, by.Buffer, 0, (int)len);
                        by.WriteEmpty((int)len);
                        info.bin_content.Read(by);

                        list.Add(info);
                    }
                }
                callback(list);
            });
        }
Пример #2
0
        /// <summary>
        /// 好友赠送
        /// </summary>
        public void FriendGiveCommand(long target_char_idx, ItemID item_id)
        {
            Unit player = UnitManager.Instance.GetUnitByIdx(m_char_idx);

            if (player == null)
            {
                return;
            }

            //先查找是否有好友
            RelationInfo relation_info;

            if (!m_relations.TryGetValue(target_char_idx, out relation_info) || relation_info.flags != eRelationFlag.Friend)
            {
                return;
            }

            //赠送是否合法
            if (!item.IsValidItem(item_id))
            {
                return;
            }

            //写入事件
            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.Give;
            e_info.bin_content.bin_give_content.char_name = player.char_name;
            e_info.bin_content.bin_give_content.item_id   = item_id;
            SQLRelationHandle.InsertRelationEvent(e_info);
            //立刻通知接受者:这里先注释,不需要及时通知
            //this.BroadcastEvent(e_info.target_char_idx, e_info.event_type);
        }
Пример #3
0
        /// <summary>
        /// 添加关系事件
        /// </summary>
        public static void InsertRelationEvent(RelationEventInfo info)
        {
            string sql = "call SP_RELATION_EVENT_CREATE(" +
                         info.target_char_idx + "," +
                         info.source_char_idx + "," +
                         (byte)info.event_type + "," +
                         "@i_bin_content);";

            ByteArray by = DBUtils.AllocDBArray();

            info.bin_content.Write(by);

            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@i_bin_content", MySqlDbType.Blob, by.GetBuffer(), by.Available);

            param.Add(p);
            DBManager.Instance.GetDB(eDBType.Center).Execute(sql, param);
        }
Пример #4
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);
                    }
                });
            }
        }
Пример #5
0
        /// <summary>
        /// 申请反馈
        /// </summary>
        public void ApplyRelationCommand(long event_idx, long target_char_idx, eRelationApplyCmd cmd)
        {
            //是否存在申请事件
            RelationEventInfo relation_evt;

            if (!m_relation_events.TryGetValue(event_idx, out relation_evt))
            {
                return;
            }

            switch (relation_evt.event_type)
            {
            case eRelationEvent.Add:
            {
                eRelationFlag flag = relation_evt.bin_content.bin_add_content.flag;
                if (cmd == eRelationApplyCmd.Agree)
                {
                    //超过上限
                    if (IsRelationFull(flag))
                    {
                        SQLRelationHandle.RemoveRelationEvent(event_idx);
                        m_relation_events.Remove(event_idx);
                        return;
                    }

                    //是否已经存在相同关系:是则返回;非相同关系先移除,再添加
                    RelationInfo relation_info;
                    if (m_relations.TryGetValue(target_char_idx, out relation_info))
                    {
                        if (relation_info.flags == flag)
                        {
                            SQLRelationHandle.RemoveRelationEvent(event_idx);
                            m_relation_events.Remove(event_idx);
                            return;
                        }
                        else
                        {
                            this.RemoveRelation(target_char_idx);
                        }
                    }

                    //如果对方在线,则取对方身上的数据;否则取数据库的数据
                    Unit target_player = UnitManager.Instance.GetUnitByIdx(target_char_idx);
                    if (target_player != null)
                    {
                        relation_info = CommonObjectPools.Spawn <RelationInfo>();
                        relation_info.Copy(target_player.player_data);
                        relation_info.flags = flag;
                        this.AddRelation(relation_info);
                        this.SyncRelation2SS(target_char_idx);
                    }
                    else
                    {
                        PlayerInfoForGL data = CommonObjectPools.Spawn <PlayerInfoForGL>();
                        SQLCharHandle.QueryCharacterInfo(target_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_char_idx);
                                }
                                CommonObjectPools.Despawn(data);
                            });
                    }
                }
                else
                {
                    //undo
                }
                //写入事件
                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.Agree;
                e_info.bin_content.bin_agree_content.flag = flag;
                e_info.bin_content.bin_agree_content.cmd  = cmd;
                SQLRelationHandle.InsertRelationEvent(e_info);
                //立刻通知接受者
                this.BroadcastEvent(e_info.target_char_idx, e_info.event_type);
            }
            break;
            }

            //清除处理过的事件
            SQLRelationHandle.RemoveRelationEvent(event_idx);

            //从事件列表移除
            m_relation_events.Remove(event_idx);
        }
Пример #6
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);
                }
            });
        }