Ejemplo n.º 1
0
        private bool CheckBagCapacity(UserInfo user, TableMailInfoWrap info)
        {
            bool result = true;

            if (null == user || null == user.ItemBag ||
                null == info || null == info.m_Items)
            {
                return(result);
            }
            int ct   = info.m_Items.Count;
            int free = user.ItemBag.GetFreeCount();

            if (ct > free)
            {
                result = false;
            }
            NodeMessage        opMsg     = new NodeMessage(LobbyMessageDefine.Msg_LC_LackOfSpace, user.Guid);
            Msg_LC_LackOfSpace protoData = new Msg_LC_LackOfSpace();

            protoData.m_Succeed    = result;
            protoData.m_ReceiveNum = ct;
            protoData.m_FreeNum    = free;
            protoData.m_MailGuid   = info.Guid;
            opMsg.m_ProtoData      = protoData;
            NodeMessageDispatcher.SendNodeMessage(user.NodeName, opMsg);
            return(result);
        }
Ejemplo n.º 2
0
        private void AddDeletedUserMail(long userGuid, TableMailInfoWrap info)
        {
            List <TableMailInfoWrap> list;

            if (!m_DeletedUserMails.TryGetValue(userGuid, out list))
            {
                list = new List <TableMailInfoWrap>();
                m_DeletedUserMails.Add(userGuid, list);
            }
            info.Deleted = true;
            list.Add(info);
        }
Ejemplo n.º 3
0
        internal void ReceiveMail(ulong userGuid, ulong mailGuid)
        {
            UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler;
            UserInfo             user        = dataProcess.GetUserInfo(userGuid);

            if (null != user)
            {
                List <TableMailInfoWrap> mails;
                if (m_UserMails.TryGetValue((long)userGuid, out mails))
                {
                    if (null != mails)
                    {
                        TableMailInfoWrap info = null;
                        int ct    = mails.Count;
                        int index = 0;
                        for (; index < ct; ++index)
                        {
                            if (mails[index].Guid == mailGuid)
                            {
                                info = mails[index];
                                break;
                            }
                        }
                        if (null != info && CheckBagCapacity(user, info))
                        {
                            mails.RemoveAt(index);
                            ExtractMailAttachment(info, userGuid);
                        }
                    }
                }
                MailStateInfo mailStateInfo = user.MailStateInfo;
                if (!mailStateInfo.IsAlreadyReceived(mailGuid))
                {
                    int wholeCt = m_WholeMails.Count;
                    for (int index = 0; index < wholeCt; ++index)
                    {
                        TableMailInfoWrap info = m_WholeMails[index];
                        if (info.Guid == mailGuid)
                        {
                            if (CheckBagCapacity(user, info))
                            {
                                mailStateInfo.ReceiveMail(mailGuid);
                                if (info.LevelDemand <= user.Level && info.SendDate >= user.CreateTime && info.ExpiryDate >= DateTime.Now)
                                {
                                    ExtractMailAttachment(info, userGuid);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        internal void Tick()
        {
            var ds_thread = UserServer.Instance.DataCacheThread;

            if (ds_thread.DataStoreAvailable)
            {
                if (!m_IsDataLoaded)
                {
                    return;
                }
            }
            long curTime = TimeUtility.GetLocalMilliseconds();

            if (m_LastTickTime + c_TickInterval < curTime)
            {
                m_LastTickTime = curTime;
                //清理过期邮件
                int ct = m_WholeMails.Count;
                for (int index = ct - 1; index >= 0; --index)
                {
                    TableMailInfoWrap mailInfo = m_WholeMails[index];
                    if (null != mailInfo)
                    {
                        if (mailInfo.ExpiryDate < DateTime.Now)
                        {
                            AddDeletedWholeMail(mailInfo);
                            m_WholeMails.RemoveAt(index);
                        }
                    }
                }
                foreach (KeyValuePair <long, List <TableMailInfoWrap> > pair in m_UserMails)
                {
                    var mails  = pair.Value;
                    int mailCt = mails.Count;
                    for (int index = mailCt - 1; index >= 0; --index)
                    {
                        TableMailInfoWrap mailInfo = mails[index];
                        if (null != mailInfo)
                        {
                            if (mailInfo.ExpiryDate < DateTime.Now)
                            {
                                AddDeletedUserMail(pair.Key, mailInfo);
                                mails.RemoveAt(index);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void ExtractMailAttachment(TableMailInfoWrap info, ulong userGuid)
        {
            UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler;
            UserThread           userThread  = dataProcess.GetUserThread(userGuid);

            userThread.QueueAction(userThread.AddAssets, userGuid, info.Money, info.Gold);

            int itemCt = info.m_Items.Count;

            for (int itemIx = 0; itemIx < itemCt; ++itemIx)
            {
                MailItem item = info.m_Items[itemIx];
                userThread.QueueAction(userThread.AddItem, userGuid, item.m_ItemId, item.m_ItemNum);
            }
        }
Ejemplo n.º 6
0
        internal void SendWholeMail(TableMailInfoWrap wholeMail, int validityPeriod)
        {
            wholeMail.Guid       = GenMailGuid();
            wholeMail.SendDate   = DateTime.Now;
            wholeMail.ExpiryDate = wholeMail.SendDate.AddDays(validityPeriod);
            m_WholeMails.Add(wholeMail);
            NodeMessage         newMailMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_NotifyNewMail);
            NodeMessageWithGuid headerData = new NodeMessageWithGuid();

            newMailMsg.m_NodeHeader = headerData;
            UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler;

            dataProcess.VisitUsers((UserInfo userInfo) => {
                headerData.m_Guid = userInfo.Guid;
                NodeMessageDispatcher.SendNodeMessage(userInfo.NodeName, newMailMsg);
            });
        }
Ejemplo n.º 7
0
        internal void DeleteMail(ulong userGuid, ulong mailGuid)
        {
            UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler;
            UserInfo             user        = dataProcess.GetUserInfo(userGuid);

            if (null != user)
            {
                List <TableMailInfoWrap> mails;
                if (m_UserMails.TryGetValue((long)userGuid, out mails))
                {
                    if (null != mails)
                    {
                        TableMailInfoWrap info = null;
                        int ct    = mails.Count;
                        int index = 0;
                        for (; index < ct; ++index)
                        {
                            if (mails[index].Guid == mailGuid)
                            {
                                info = mails[index];
                                break;
                            }
                        }
                        if (null != info)
                        {
                            AddDeletedUserMail((long)userGuid, info);
                            mails.RemoveAt(index);
                        }
                    }
                }
                MailStateInfo mailStateInfo = user.MailStateInfo;
                if (!mailStateInfo.IsAlreadyReceived(mailGuid))
                {
                    int wholeCt = m_WholeMails.Count;
                    for (int index = 0; index < wholeCt; ++index)
                    {
                        TableMailInfoWrap info = m_WholeMails[index];
                        if (info.Guid == mailGuid)
                        {
                            mailStateInfo.DeleteMail(mailGuid);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        internal void SendUserMail(TableMailInfoWrap userMail, int validityPeriod)
        {
            userMail.Guid       = GenMailGuid();
            userMail.SendDate   = DateTime.Now;
            userMail.ExpiryDate = userMail.SendDate.AddDays(validityPeriod);
            List <TableMailInfoWrap> mails = null;

            if (!m_UserMails.TryGetValue(userMail.Receiver, out mails))
            {
                mails = new List <TableMailInfoWrap>();
                m_UserMails.Add(userMail.Receiver, mails);
            }
            mails.Add(userMail);
            UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler;
            UserInfo             user        = dataProcess.GetUserInfo((ulong)userMail.Receiver);

            if (null != user && user.CurrentState != UserState.DropOrOffline)
            {
                NodeMessage newMailMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_NotifyNewMail, (ulong)userMail.Receiver);
                NodeMessageDispatcher.SendNodeMessage(user.NodeName, newMailMsg);
            }
        }
Ejemplo n.º 9
0
        internal void ReadMail(ulong userGuid, ulong mailGuid)
        {
            UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler;
            UserInfo             user        = dataProcess.GetUserInfo(userGuid);

            if (null != user)
            {
                List <TableMailInfoWrap> mails;
                if (m_UserMails.TryGetValue((long)userGuid, out mails))
                {
                    if (null != mails)
                    {
                        int ct    = mails.Count;
                        int index = 0;
                        for (; index < ct; ++index)
                        {
                            if (mails[index].Guid == mailGuid)
                            {
                                TableMailInfoWrap info = mails[index];
                                info.IsRead = true;
                                break;
                            }
                        }
                    }
                }
                MailStateInfo mailStateInfo = user.MailStateInfo;
                int           wholeCt       = m_WholeMails.Count;
                for (int index = 0; index < wholeCt; ++index)
                {
                    TableMailInfoWrap info = m_WholeMails[index];
                    if (info.Guid == mailGuid)
                    {
                        mailStateInfo.ReadMail(mailGuid);
                        break;
                    }
                }
            }
        }
 private void InitMailData()
 {
     if (m_MailInitStatus == DataInitStatus.Unload)
     {
         if (UserServerConfig.DataStoreAvailable == true)
         {
             m_MailInitStatus = DataInitStatus.Loading;
             Msg_LD_Load msg = new Msg_LD_Load();
             msg.MsgId = (int)DataEnum.TableMailInfo;
             GameFrameworkMessage.Msg_LD_SingleLoadRequest slr = new GameFrameworkMessage.Msg_LD_SingleLoadRequest();
             slr.MsgId    = (int)GameFrameworkData.DataEnum.TableMailInfo;
             slr.LoadType = GameFrameworkMessage.Msg_LD_SingleLoadRequest.LoadTypeEnum.LoadAll;
             slr.Keys.Clear();
             msg.LoadRequests.Add(slr);
             RequestLoad(msg, ((ret) => {
                 if (ret.ErrorNo == Msg_DL_LoadResult.ErrorNoEnum.Success)
                 {
                     List <TableMailInfoWrap> mailList = new List <TableMailInfoWrap>();
                     foreach (var singlerow in ret.Results)
                     {
                         object _msg;
                         if (DbDataSerializer.Decode(singlerow.Data, DataEnum2Type.Query(slr.MsgId), out _msg))
                         {
                             TableMailInfo dataMail = _msg as TableMailInfo;
                             if (null != dataMail)
                             {
                                 TableMailInfoWrap mailInfo = new TableMailInfoWrap();
                                 mailInfo.FromProto(dataMail);
                                 List <int> itemIds = Converter.ConvertNumericList <int>(dataMail.ItemIds);
                                 List <int> itemNums = Converter.ConvertNumericList <int>(dataMail.ItemNumbers);
                                 for (int i = 0; i < itemIds.Count && i < itemNums.Count; ++i)
                                 {
                                     var item = new MailItem();
                                     item.m_ItemId = itemIds[i];
                                     item.m_ItemNum = itemNums[i];
                                     mailInfo.m_Items.Add(item);
                                 }
                                 mailList.Add(mailInfo);
                             }
                         }
                     }
                     UserServer.Instance.GlobalProcessThread.InitMailData(mailList);
                     m_MailInitStatus = DataInitStatus.Done;
                     LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Load DataCache global data success. Table:TableMailInfo");
                 }
                 else if (ret.ErrorNo == Msg_DL_LoadResult.ErrorNoEnum.NotFound)
                 {
                     //暂时初始化为空列表
                     List <TableMailInfoWrap> mailList = new List <TableMailInfoWrap>();
                     UserServer.Instance.GlobalProcessThread.InitMailData(mailList);
                     m_MailInitStatus = DataInitStatus.Done;
                     LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Load DataCache global data success. Table:TableMailInfo (empty)");
                 }
                 else
                 {
                     m_MailInitStatus = DataInitStatus.Unload;
                     LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Load DataCache global data failed. Table: {0}", "TableMailInfo");
                 }
             }
                               ));
         }
         else
         {
             m_MailInitStatus = DataInitStatus.Done;
             LogSys.Log(LOG_TYPE.INFO, "init mail done!");
         }
     }
 }
Ejemplo n.º 11
0
 internal void SendWholeMail(TableMailInfoWrap wholeMail, int validityPeriod)
 {
     m_MailSystem.SendWholeMail(wholeMail, validityPeriod);
 }
Ejemplo n.º 12
0
 internal void SendUserMail(TableMailInfoWrap userMail, int validityPeriod)
 {
     m_MailSystem.SendUserMail(userMail, validityPeriod);
 }
Ejemplo n.º 13
0
        internal void GetMailList(ulong userGuid)
        {
            UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler;
            UserInfo             user        = dataProcess.GetUserInfo(userGuid);

            if (null != user)
            {
                List <MailInfoForMessage> mailList = new List <MailInfoForMessage>();
                List <TableMailInfoWrap>  mails;
                if (m_UserMails.TryGetValue((long)userGuid, out mails))
                {
                    int ct = mails.Count;
                    for (int ix = 0; ix < ct; ++ix)
                    {
                        TableMailInfoWrap mailInfo = mails[ix];
                        if (mailInfo.ExpiryDate >= DateTime.Now)
                        {
                            MailInfoForMessage mailInfoForMsg = new MailInfoForMessage();
                            mailInfoForMsg.m_AlreadyRead = mailInfo.IsRead;
                            mailInfoForMsg.m_MailGuid    = mailInfo.Guid;
                            mailInfoForMsg.m_Title       = mailInfo.Title;
                            mailInfoForMsg.m_Sender      = mailInfo.Sender;
                            mailInfoForMsg.m_SendTime    = mailInfo.SendDate.ToString("yyyyMMddHHmmss");
                            mailInfoForMsg.m_Text        = mailInfo.Text;
                            mailInfoForMsg.m_Money       = mailInfo.Money;
                            mailInfoForMsg.m_Gold        = mailInfo.Gold;
                            int itemCt = mailInfo.m_Items.Count;
                            if (itemCt > 0)
                            {
                                for (int index = 0; index < itemCt; ++index)
                                {
                                    MailItemForMessage mailItem = new MailItemForMessage();
                                    mailItem.m_ItemId  = mailInfo.m_Items[index].m_ItemId;
                                    mailItem.m_ItemNum = mailInfo.m_Items[index].m_ItemNum;
                                    mailInfoForMsg.m_Items.Add(mailItem);
                                }
                            }
                            mailList.Add(mailInfoForMsg);
                        }
                    }
                }
                MailStateInfo mailStateInfo = user.MailStateInfo;
                //这里不对用户数据加锁,因为用户的邮件状态的改变都在这个线程完成(除上线时的数据加载)
                int wholeMailCt = m_WholeMails.Count;
                for (int ix = 0; ix < wholeMailCt; ++ix)
                {
                    TableMailInfoWrap mailInfo = m_WholeMails[ix];
                    if (mailInfo.LevelDemand <= user.Level &&
                        mailInfo.SendDate >= user.CreateTime &&
                        mailInfo.ExpiryDate >= DateTime.Now &&
                        !mailStateInfo.IsAlreadyReceived(mailInfo.Guid))
                    {
                        if (!mailStateInfo.HaveMail(mailInfo.Guid))
                        {
                            mailStateInfo.AddMail(mailInfo.Guid, mailInfo.ExpiryDate);
                        }
                        MailInfoForMessage mailInfoForMsg = new MailInfoForMessage();
                        mailInfoForMsg.m_AlreadyRead = mailStateInfo.IsAlreadyRead(mailInfo.Guid);
                        mailInfoForMsg.m_MailGuid    = mailInfo.Guid;
                        mailInfoForMsg.m_Title       = mailInfo.Title;
                        mailInfoForMsg.m_Sender      = mailInfo.Sender;
                        mailInfoForMsg.m_SendTime    = mailInfo.SendDate.ToString("yyyyMMddHHmmss");
                        mailInfoForMsg.m_Text        = mailInfo.Text;
                        mailInfoForMsg.m_Money       = mailInfo.Money;
                        mailInfoForMsg.m_Gold        = mailInfo.Gold;
                        int itemCt = mailInfo.m_Items.Count;
                        if (itemCt > 0)
                        {
                            for (int index = 0; index < itemCt; ++index)
                            {
                                MailItemForMessage mailItem = new MailItemForMessage();
                                mailItem.m_ItemId  = mailInfo.m_Items[index].m_ItemId;
                                mailItem.m_ItemNum = mailInfo.m_Items[index].m_ItemNum;
                                mailInfoForMsg.m_Items.Add(mailItem);
                            }
                        }
                        mailList.Add(mailInfoForMsg);
                    }
                }
                NodeMessage syncMailListMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_SyncMailList, userGuid);
                GameFrameworkMessage.Msg_LC_SyncMailList protoMsg = new Msg_LC_SyncMailList();
                protoMsg.m_Mails.AddRange(mailList);
                syncMailListMsg.m_ProtoData = protoMsg;
                NodeMessageDispatcher.SendNodeMessage(user.NodeName, syncMailListMsg);
            }
        }
Ejemplo n.º 14
0
 private void AddDeletedWholeMail(TableMailInfoWrap info)
 {
     info.Deleted = true;
     m_DeletedWholeMails.Add(info);
 }