예제 #1
0
 public override void Read(ByteArray by)
 {
     base.Read(by);
     event_idx       = by.ReadLong();
     target_char_idx = by.ReadLong();
     cmd             = (eRelationApplyCmd)(by.ReadByte());
 }
        /// <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; //获取当前列的索引

            long event_idx        = 0;
            long char_idx         = 0;
            eRelationApplyCmd cmd = eRelationApplyCmd.Agree;

            if (col == 4)
            {
                string idx = m_list_relation.Rows[row].Cells["Idx"].Value.ToString();
                event_idx = long.Parse(idx);
                string str_char_idx = m_list_relation.Rows[row].Cells["CharIdx"].Value.ToString();
                char_idx = long.Parse(str_char_idx);
                cmd      = eRelationApplyCmd.Agree;
            }
            else if (col == 5)
            {
                string idx = m_list_relation.Rows[row].Cells["Idx"].Value.ToString();
                event_idx = long.Parse(idx);
                string str_char_idx = m_list_relation.Rows[row].Cells["CharIdx"].Value.ToString();
                char_idx = long.Parse(str_char_idx);
                cmd      = eRelationApplyCmd.Reject;
            }
            m_list_relation.Rows.RemoveAt(row);
            RelationDataManager.Instance.RemoveNewApplys(event_idx);

            ServerMsgSend.SendRelationApplyCommand(event_idx, char_idx, cmd);
        }
예제 #3
0
 /// <summary>
 /// 请求好友操作
 /// </summary>
 public static void SendRelationApplyCommand(long event_idx, long char_idx, eRelationApplyCmd cmd)
 {
     c2ss.RelationApplyCmd msg = PacketPools.Get(c2ss.msg.RELATION_APPLY_CMD) as c2ss.RelationApplyCmd;
     msg.event_idx       = event_idx;
     msg.target_char_idx = char_idx;
     msg.cmd             = cmd;
     ClientNetManager.Instance.Send(msg);
 }
예제 #4
0
 /// <summary>
 /// 申请反馈
 /// </summary>
 public void ApplyCommandClient(long event_idx, long target_char_idx, eRelationApplyCmd cmd)
 {
     //发送到gl
     ss2gl.RelationApplyCmd msg = PacketPools.Get(ss2gl.msg.RELATION_APPLY_CMD) as ss2gl.RelationApplyCmd;
     msg.event_idx       = event_idx;
     msg.char_idx        = m_char_idx;
     msg.target_char_idx = target_char_idx;
     msg.cmd             = cmd;
     ServerNetManager.Instance.Send2GL(msg);
 }
예제 #5
0
 public void Read(ByteArray by)
 {
     flag = (eRelationFlag)(by.ReadByte());
     cmd  = (eRelationApplyCmd)(by.ReadByte());
 }
예제 #6
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);
        }