Ejemplo n.º 1
0
        /// <summary>
        /// 关系操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCellClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = e.RowIndex;
            int col = e.ColumnIndex; //获取当前列的索引

            if (col == 5)
            {
                PropID item_id = new PropID();
                item_id.type      = ePropType.CURRENCY;
                item_id.obj_type  = (uint)eCurrencyType.Gold;
                item_id.obj_value = 1000;

                string idx      = m_list_relation.Rows[row].Cells["Idx"].Value.ToString();
                long   char_idx = long.Parse(idx);
                ServerMsgSend.SendRelationGive(char_idx, item_id);
            }
            else if (col == 6)
            {
                string            idx       = m_list_relation.Rows[row].Cells["Idx"].Value.ToString();
                long              char_idx  = long.Parse(idx);
                RelationAddTarget target_id = new RelationAddTarget();
                target_id.type     = eRelationAddType.Idx;
                target_id.char_idx = char_idx;
                ServerMsgSend.SendRelationAdd(target_id, eRelationFlag.Block, "");
            }
            else if (col == 7)
            {
                string idx      = m_list_relation.Rows[row].Cells["Idx"].Value.ToString();
                long   char_idx = long.Parse(idx);
                m_list_relation.Rows.RemoveAt(row);
                RelationDataManager.Instance.RemoveRelation(char_idx);
                ServerMsgSend.SendRelationRemove(char_idx);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 请求添加好友
 /// </summary>
 public static void SendRelationAdd(RelationAddTarget target, eRelationFlag flag, string message)
 {
     c2ss.RelationAdd msg = PacketPools.Get(c2ss.msg.RELATION_ADD) as c2ss.RelationAdd;
     msg.target_id = target;
     msg.message   = message;
     msg.flag      = flag;
     ClientNetManager.Instance.Send(msg);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加关系
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBtnOK(object sender, EventArgs e)
        {
            string str_value = m_txt_value.Text.Trim();

            if (m_add_type.SelectedIndex < 0 || m_add_flag.SelectedIndex < 0 || str_value.Length == 0)
            {
                return;
            }

            RelationAddTarget target = new RelationAddTarget();

            if (m_add_type.SelectedIndex == 0)
            {
                target.type = eRelationAddType.Idx;
                if (!StringUtils.IsInteger(str_value))
                {
                    return;
                }
                target.char_idx = long.Parse(str_value);
            }
            else
            {
                target.type      = eRelationAddType.Name;
                target.char_name = str_value;
            }

            eRelationFlag flag = eRelationFlag.Invalid;

            if (m_add_flag.SelectedIndex == 0)
            {
                flag = eRelationFlag.Friend;
            }
            else
            {
                flag = eRelationFlag.Block;
            }

            ServerMsgSend.SendRelationAdd(target, flag, m_txt_message.Text.Trim());

            this.Close();
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
                }
            });
        }