コード例 #1
0
        private void ProcessWrite(MailWriteInfo info)
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }

            if (info.receiver.char_idx == 0)
            {
                Log.Warning("错误的收件人id:" + info.receiver.char_idx);
                return;
            }

            //存db
            MailInfo mail_info = CommonObjectPools.Spawn <MailInfo>();

            mail_info.mail_type     = eMailType.NORMAL;
            mail_info.spid          = 0;//普通邮件,不区分渠道id
            mail_info.receiver_idx  = info.receiver.char_idx;
            mail_info.sender_idx    = m_char_idx;
            mail_info.sender_name   = player.char_name;
            mail_info.send_time     = Time.second_time;
            mail_info.expire_time   = 0;
            mail_info.delivery_time = 0;
            mail_info.flags         = (uint)eMailFlags.NONE;
            mail_info.subject       = info.subject;
            mail_info.bin_mail_content.content_type = eMailContentType.NORMAL;
            mail_info.bin_mail_content.bin_normal_content.content = info.content;
            SQLMailHandle.CreateMail(mail_info, player.db_id);
            CommonObjectPools.Despawn(mail_info);
        }
コード例 #2
0
        /// <summary>
        /// 保存所有
        /// </summary>
        public void Save()
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }

            //保存需要删除的
            if (m_del_mails.Count > 0)
            {
                SQLMailHandle.DeleteMail(m_del_mails, player.db_id);
                m_del_mails.Clear();
            }
            //保存修改的
            if (m_save_mails.Count > 0)
            {
                SQLMailHandle.ModifyMailFlags(m_all_mails, m_save_mails, player.db_id);
                m_save_mails.Clear();
            }

            m_is_dirty       = false;
            m_last_save_time = Time.timeSinceStartup;
        }
コード例 #3
0
        /// <summary>
        /// 开始读取db
        /// </summary>
        private void LoadMails()
        {
            PlayerCache player = PlayerCacheManager.Instance.GetMember(m_char_idx);

            if (player == null)
            {
                return;
            }

            SQLMailHandle.LoadCharRecvs(m_char_idx, OnLoadRecvMailEnd);
            SQLMailHandle.LoadMailList(m_char_idx, player.ss_data.spid, OnLoadMailEnd);
        }
コード例 #4
0
        private void LoadMail()
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }

            SQLMailHandle.LoadCharRecvs(m_char_idx, player.db_id, (info) =>
            {
                m_had_recv_mails = info;
                SQLMailHandle.LoadMailList(m_char_idx, player.spid, player.db_id, OnLoadMailEnd);
            });
        }
コード例 #5
0
        /// <summary>
        /// 保存所有
        /// </summary>
        public void Save()
        {
            //保存需要删除的
            if (m_del_mails.Count > 0)
            {
                SQLMailHandle.DeleteMail(m_del_mails);
            }
            m_del_mails.Clear();

            //保存修改的
            if (m_save_mails.Count > 0)
            {
                SQLMailHandle.ModifyMailFlags(m_all_mails, m_save_mails);
            }

            m_is_dirty       = false;
            m_last_save_time = Time.timeSinceStartup;
        }
コード例 #6
0
        private void ProcessWrite(MailWriteInfo info)
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }

            if (info.receiver.char_idx == 0)
            {
                Log.Debug("错误的收件人id:" + info.receiver.char_idx);
                return;
            }

            //存db
            MailInfo mail_info = CommonObjectPools.Spawn <MailInfo>();

            mail_info.mail_idx      = IdSharedManager.Instance.GetNextMailIdx();
            mail_info.mail_type     = eMailType.NORMAL;
            mail_info.spid          = 0;//普通邮件,不区分渠道id
            mail_info.receiver_idx  = info.receiver.char_idx;
            mail_info.sender_idx    = m_char_idx;
            mail_info.sender_name   = player.char_name;
            mail_info.send_time     = Time.second_time;
            mail_info.expire_time   = 0;
            mail_info.delivery_time = 0;
            mail_info.flags         = (uint)eMailFlags.NONE;
            mail_info.subject       = info.subject;
            mail_info.bin_mail_content.content_type = eMailContentType.NORMAL;
            mail_info.bin_mail_content.bin_normal_content.content = info.content;
            SQLMailHandle.CreateMail(mail_info, player.db_id);
            CommonObjectPools.Despawn(mail_info);

            //告诉客户端发送成功
            ss2c.MailCommand msg_client = PacketPools.Get(ss2c.msg.MAIL_COMMAND) as ss2c.MailCommand;
            msg_client.mail_idx     = 0;
            msg_client.command_type = eMailCommandType.WRITE_MAIL;
            msg_client.error_type   = eMailCommandError.NONE;
            ServerNetManager.Instance.SendProxy(player.client_uid, msg_client);
        }
コード例 #7
0
        /// <summary>
        /// 读邮件
        /// </summary>
        public void HandleReadMail(long mail_idx)
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }
            MailInfo mail_info;

            if (m_all_mails.TryGetValue(mail_idx, out mail_info))
            {
                if (m_del_mails.Contains(mail_idx))
                {
                    return;
                }

                //是否全服邮件
                if (mail_info.receiver_idx == 0)
                {
                    if (!m_had_recv_mails.Contains(mail_idx))
                    {//同步到db,已经领取过全局邮件
                        m_had_recv_mails.Add(mail_idx);
                        SQLMailHandle.UpdateCharRecvs(m_char_idx, m_had_recv_mails, player.db_id);
                    }
                }
                else if (!Utils.HasFlag(mail_info.flags, (uint)eMailFlags.READED))
                {//修改标记
                    mail_info.flags = Utils.InsertFlag(mail_info.flags, (uint)eMailFlags.READED);
                    m_save_mails.Add(mail_idx);
                    m_is_dirty = true;
                }

                //通知客户端
                ss2c.MailRead msg_client = PacketPools.Get(ss2c.msg.MAIL_READ) as ss2c.MailRead;
                msg_client.mail_info.Copy(mail_info);
                ServerNetManager.Instance.SendProxy(player.client_uid, msg_client);
            }
        }
コード例 #8
0
        private void ProcessWrite(MailWriteInfo info)
        {
            PlayerCache player = PlayerCacheManager.Instance.GetMember(m_char_idx);

            if (player == null)
            {
                return;
            }

            if (info.receiver_idx <= 0)
            {
                Log.Warning("错误的收件人id:" + info.receiver_idx);
                return;
            }
            //存db
            MailInfo mail_info = CommonObjectPools.Spawn <MailInfo>();

            mail_info.mail_type     = eMailType.NORMAL;
            mail_info.spid          = 0;//普通邮件,不区分渠道id
            mail_info.receiver_idx  = info.receiver_idx;
            mail_info.sender_idx    = m_char_idx;
            mail_info.sender_name   = player.ss_data.char_name;
            mail_info.send_time     = Time.second_time;
            mail_info.expire_time   = 0;
            mail_info.delivery_time = 0;
            mail_info.flags         = (uint)eMailFlags.NONE;
            mail_info.subject       = info.subject;
            mail_info.bin_mail_content.content_type = eMailContentType.NORMAL;
            mail_info.bin_mail_content.bin_normal_content.content = info.content;
            SQLMailHandle.CreateMail(mail_info);
            CommonObjectPools.Despawn(mail_info);

            //返回结果给ss
            db2ss.MailCommand rep_msg = PacketPools.Get(db2ss.msg.MAIL_COMMAND) as db2ss.MailCommand;
            rep_msg.mail_idx     = 0;
            rep_msg.command_type = eMailCommandType.WRITE_MAIL;
            rep_msg.error_type   = eMailCommandError.NONE;
            ForServerNetManager.Instance.Send(player.ss_uid, rep_msg);
        }
コード例 #9
0
        /// <summary>
        /// 邮件操作:优先级依次是 读->领取附件->删除
        /// </summary>
        public void HandleCommandMail(long mail_idx, eMailCommandType type)
        {
            PlayerCache player = PlayerCacheManager.Instance.GetMember(m_char_idx);

            if (player == null)
            {
                return;
            }

            switch (type)
            {
            case eMailCommandType.READ_MAIL:
            {
                MailInfo mail_info;
                if (m_all_mails.TryGetValue(mail_idx, out mail_info))
                {
                    if (m_del_mails.Contains(mail_idx))
                    {
                        break;
                    }
                    if (m_save_mails.Contains(mail_idx))
                    {
                        break;
                    }
                    if (mail_info.receiver_idx == 0)
                    {
                        if (!m_had_recv_mails.Contains(mail_idx))
                        {        //同步到db,已经领取过全局邮件
                            m_had_recv_mails.Add(mail_idx);
                            SQLMailHandle.UpdateCharRecvs(m_char_idx, m_had_recv_mails);
                        }
                        break;
                    }

                    //判断是否已经读取
                    if (!Utils.HasFlag(mail_info.flags, (uint)eMailFlags.READED))
                    {
                        m_save_mails.Add(mail_idx);
                        mail_info.flags = Utils.InsertFlag(mail_info.flags, (uint)eMailFlags.READED);
                        m_is_dirty      = true;
                    }
                }
            }
            break;

            case eMailCommandType.DELETE_MAIL:
            {
                MailInfo mail_info;
                if (m_all_mails.TryGetValue(mail_idx, out mail_info))
                {
                    if (m_del_mails.Contains(mail_idx))
                    {
                        break;
                    }
                    if (mail_info.receiver_idx == 0)
                    {
                        break;
                    }

                    m_del_mails.Add(mail_idx);
                    m_save_mails.Remove(mail_idx);
                    m_all_mails.Remove(mail_idx);
                    CommonObjectPools.Despawn(mail_info);
                    m_is_dirty = true;
                }
            }
            break;

            case eMailCommandType.TAKE_MAIL:
            case eMailCommandType.TAKE_MAIL_BUT_RETAIN:
            {
                MailInfo mail_info;
                if (m_all_mails.TryGetValue(mail_idx, out mail_info))
                {
                    if (m_del_mails.Contains(mail_idx))
                    {
                        break;
                    }
                    if (mail_info.receiver_idx == 0)
                    {
                        break;
                    }

                    //修改状态,前提是带附件
                    if (Utils.HasFlag(mail_info.flags, (uint)eMailFlags.CARRY_ITEM))
                    {
                        m_save_mails.Remove(mail_idx);
                        mail_info.flags = Utils.InsertFlag(mail_info.flags, (uint)eMailFlags.READED);
                        mail_info.flags = Utils.RemoveFlag(mail_info.flags, (uint)eMailFlags.CARRY_ITEM);
                        m_is_dirty      = true;
                    }
                }
            }
            break;
            }
        }