Пример #1
0
        /// <summary>
        /// Put purchased item to mail as attachment
        /// </summary>
        /// <param name="gameRefID">Game ref id of mailbox</param>
        /// <param name="item">Item which will be put to mail</param>
        /// <returns>True if all succeded</returns>
        public bool PutAuctionItemToMailFromPurchase(string gameRefID, AuctionItem item)
        {
            log.InfoFormat("PutAuctionItemToMailFromPurchase() put item from auction to mail player = {0}, item = {1}",
                           gameRefID, item.storeItemID);

            //First create message
            MailMessage message = new MailMessage {
                //attachment empty
                attachments = new Dictionary <string, MailAttachment>(),
                //standard body for purchases
                body = "s_purchase_auction_item_body",
                //unique id of message
                id = Guid.NewGuid().ToString(),
                //game ref id of receiver
                receiverGameRefId = gameRefID,
                //sender is empty (auction)
                sendefGameRefId = string.Empty,
                //sender is empty (auction)
                senderLogin = string.Empty,
                //time of message
                time = DateTime.UtcNow.ToString(System.Globalization.CultureInfo.InvariantCulture),
                //standard title of message
                title = "s_purchase_auction_item_title"
            };

            //add attachment to message
            message.AddAttachment(item.objectInfo, item.count);
            //get mailbox of player
            var mailBox = GetMailBox(gameRefID);

            //add message to mailbox
            mailBox.AddNewMessage(message);

            application.Clients.SendGenericEventToGameref(mailBox.gameRefId,
                                                          new GenericEvent {
                subCode = (int)SelectCharacterGenericEventSubCode.NewMessageCountChanged,
                data    = new Hashtable {
                    { (int)SPC.Count, mailBox.newMessagesCount }
                }
            });

            //save mail box to DB
            SaveMails(mailBox);
            //send update event to player
            MailUpdatedEvent evt = new MailUpdatedEvent {
                mailBox = mailBox.GetInfo()
            };
            EventData data = new EventData((byte)SelectCharacterEventCode.MailUpdateEvent, evt);

            application.SendEventToClient(gameRefID, data);
            log.InfoFormat("Successfully pushed item to mail from auction");
            return(true);
        }
Пример #2
0
        public bool PutAuctionItemBack(AuctionItem item)
        {
            log.InfoFormat("Put back auction item via mail");
            MailMessage message = new MailMessage {
                attachments       = new Dictionary <string, MailAttachment>(),
                body              = "s_auction_return_body",
                id                = Guid.NewGuid().ToString(),
                receiverGameRefId = item.gameRefID,
                sendefGameRefId   = string.Empty,
                senderLogin       = string.Empty,
                time              = DateTime.UtcNow.ToString(System.Globalization.CultureInfo.InvariantCulture),
                title             = "s_auction_return_title"
            };

            message.AddAttachment(item.objectInfo, item.count);
            var mailBox = GetMailBox(item.gameRefID);

            mailBox.AddNewMessage(message);

            application.Clients.SendGenericEventToGameref(mailBox.gameRefId,
                                                          new GenericEvent {
                subCode = (int)SelectCharacterGenericEventSubCode.NewMessageCountChanged,
                data    = new Hashtable {
                    { (int)SPC.Count, mailBox.newMessagesCount }
                }
            });

            SaveMails(mailBox);

            MailUpdatedEvent evt = new MailUpdatedEvent {
                mailBox = mailBox.GetInfo()
            };
            EventData data = new EventData((byte)SelectCharacterEventCode.MailUpdateEvent, evt);

            application.SendEventToClient(item.gameRefID, data);
            return(true);
        }
Пример #3
0
        public bool HandleTransaction(PUTInventoryItemTransactionStart transactionStart, PUTInventoryItemTransactionEnd transactionEnd)
        {
            if (transactionStart.transactionSource != transactionEnd.transactionSource)
            {
                return(false);
            }
            if (transactionEnd.returnCode != (short)ReturnCode.Ok)
            {
                return(false);
            }
            if (!transactionEnd.success)
            {
                return(false);
            }

            switch ((PostTransactionAction)transactionStart.postTransactionAction)
            {
            case PostTransactionAction.RemoveMailAttachment:
            {
                Hashtable tagHash = transactionStart.tag as Hashtable;

                string attachmentID = tagHash.GetValue <string>((int)SPC.Id, string.Empty);
                string messageID    = tagHash.GetValue <string>((int)SPC.Message, string.Empty);

                if (string.IsNullOrEmpty(attachmentID))
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(messageID))
                {
                    return(false);
                }

                var mailBox = GetMailBox(transactionStart.gameRefID);
                if (mailBox == null)
                {
                    return(false);
                }
                bool result = mailBox.RemoveAttachment(messageID, attachmentID);

                if (!result)
                {
                    return(false);
                }

                SaveMails(mailBox);

                MailUpdatedEvent evt = new MailUpdatedEvent {
                    mailBox = mailBox.GetInfo()
                };
                EventData data = new EventData((byte)SelectCharacterEventCode.MailUpdateEvent, evt);
                application.SendEventToClient(transactionStart.gameRefID, data);

                return(true);
            }

            default:
                return(false);
            }
        }
Пример #4
0
        public bool StartWriteMessageTransaction(string senderGameRefID, string senderDisplayName, byte inventoryType,
                                                 string receiverGameRefID, string title, string body, Hashtable attachments, string targetServer)
        {
            log.InfoFormat("Started writing message");

            var mailBox = GetMailBox(receiverGameRefID);

            if (mailBox == null)
            {
                log.ErrorFormat("mail box of receiver is null");
                return(false);
            }
            if (senderGameRefID == mailBox.gameRefId)
            {
                log.ErrorFormat("sender and receiver are same");
                return(false);
            }
            if (receiverGameRefID != mailBox.gameRefId)
            {
                log.ErrorFormat("invalid mail box");
                return(false);
            }

            MailMessage message = new MailMessage {
                attachments       = new Dictionary <string, MailAttachment>(),
                body              = body,
                id                = Guid.NewGuid().ToString(),
                receiverGameRefId = receiverGameRefID,
                sendefGameRefId   = senderGameRefID,
                senderLogin       = senderDisplayName,
                time              = DateTime.UtcNow.ToString(System.Globalization.CultureInfo.InvariantCulture),
                title             = title
            };

            var player = application.Players.GetExistingPlayer(senderGameRefID);

            if (player == null)
            {
                log.ErrorFormat("sender player not found");
                return(false);
            }

            if (string.IsNullOrEmpty(player.Data.SelectedCharacterId))
            {
                log.ErrorFormat("sender does'nt have selected character id");
                return(false);
            }


            if (attachments == null || attachments.Count == 0)
            {
                log.InfoFormat("Attachments don't exists simple write message in receiver mailbox");

                mailBox.AddNewMessage(message);
                SaveMails(mailBox);

                application.Clients.SendGenericEventToGameref(mailBox.gameRefId,
                                                              new GenericEvent {
                    subCode = (int)SelectCharacterGenericEventSubCode.NewMessageCountChanged,
                    data    = new Hashtable {
                        { (int)SPC.Count, mailBox.newMessagesCount }
                    }
                });

                MailUpdatedEvent evt = new MailUpdatedEvent {
                    mailBox = mailBox.GetInfo()
                };
                EventData data = new EventData((byte)SelectCharacterEventCode.MailUpdateEvent, evt);
                application.SendEventToClient(message.receiverGameRefId, data);
            }
            else
            {
                log.InfoFormat("Exist attachment send S2SEventCode.GETInventoryItemsStart - transaction to inventory");

                GETInventoryItemsTransactionStart start = new GETInventoryItemsTransactionStart {
                    characterID           = player.Data.SelectedCharacterId,
                    gameRefID             = senderGameRefID,
                    inventoryType         = inventoryType,
                    items                 = attachments,
                    postTransactionAction = (byte)PostTransactionAction.PutItemsToAttachment,
                    tag                    = new Hashtable(),
                    transactionID          = Guid.NewGuid().ToString(),
                    transactionSource      = (byte)TransactionSource.Mail,
                    transactionEndServer   = targetServer,
                    transactionStartServer = SelectCharacterApplication.ServerId.ToString()
                };
                start.SetNotSended(message);

                EventData evt = new EventData((byte)S2SEventCode.GETInventoryItemsStart, start);
                mGetItemsTransactionPool.StartTransaction(start);
                application.MasterPeer.SendEvent(evt, new SendParameters());
            }
            return(true);
        }
Пример #5
0
        public bool HandleTransaction(GETInventoryItemsTransactionStart transactionStart, GETInventoryItemsTransactionEnd transactionEnd)
        {
            if (transactionStart.transactionSource != transactionEnd.transactionSource)
            {
                return(false);
            }
            if (transactionEnd.returnCode != (short)ReturnCode.Ok)
            {
                return(false);
            }
            if (!transactionEnd.success)
            {
                return(false);
            }

            switch ((PostTransactionAction)transactionStart.postTransactionAction)
            {
            case PostTransactionAction.PutItemsToAttachment:
                log.InfoFormat("handle mail message with attachments when end");
                if (transactionStart.GetNotSended() == null)
                {
                    log.InfoFormat("NotSendeddata is null red");
                    return(false);
                }
                MailMessage message = transactionStart.GetNotSended() as MailMessage;
                message.ClearAttachments();
                Hashtable resultHash = transactionEnd.result as Hashtable;
                foreach (DictionaryEntry entry in resultHash)
                {
                    Hashtable itemHash = entry.Value as Hashtable;
                    Hashtable itemInfo = itemHash[(int)SPC.Info] as Hashtable;
                    int       count    = (int)itemHash[(int)SPC.Count];
                    log.InfoFormat("add some attachment to mail yellow");
                    message.AddAttachment(itemInfo, count);
                }
                MailBox mailBox = GetMailBox(message.receiverGameRefId);

                mailBox.AddNewMessage(message);

                SaveMails(mailBox);

                application.Clients.SendGenericEventToGameref(mailBox.gameRefId,
                                                              new GenericEvent {
                    subCode = (int)SelectCharacterGenericEventSubCode.NewMessageCountChanged,
                    data    = new Hashtable {
                        { (int)SPC.Count, mailBox.newMessagesCount }
                    }
                });

                log.InfoFormat("Message added to target mailbox yellow");

                MailUpdatedEvent evt = new MailUpdatedEvent {
                    mailBox = mailBox.GetInfo()
                };
                EventData data = new EventData((byte)SelectCharacterEventCode.MailUpdateEvent, evt);
                application.SendEventToClient(message.receiverGameRefId, data);
                log.InfoFormat("message sended to target yellow");
                return(true);
            }
            return(false);
        }