Beispiel #1
0
 public void SaveMails(MailBox mails)
 {
     mails.ClearExpiredMails();
     application.DB.Mails.Save(mails);
 }
Beispiel #2
0
        public PUTInventoryItemTransactionEnd HandlePutMailTransactionStart(PUTInventoryItemTransactionStart transaction)
        {
            MailBox mail = GetMailBox(transaction.gameRefID);

            if (mail != null)
            {
                var inventoryObject = InventoryUtils.Create(transaction.targetObject);
                if (inventoryObject != null)
                {
                    string    title   = string.Empty;
                    string    body    = string.Empty;
                    Hashtable tagHash = transaction.tag as Hashtable;

                    if (tagHash != null)
                    {
                        title = tagHash.GetValue <string>((int)SPC.Title, string.Empty);
                        body  = tagHash.GetValue <string>((int)SPC.Body, string.Empty);
                    }

                    MailMessage message = new MailMessage {
                        id                = Guid.NewGuid().ToString(),
                        title             = title,
                        body              = body,
                        receiverGameRefId = transaction.gameRefID,
                        sendefGameRefId   = string.Empty,
                        senderLogin       = "******",
                        time              = DateTime.UtcNow.ToString(System.Globalization.CultureInfo.InvariantCulture),
                        attachments       = new Dictionary <string, MailAttachment>()
                    };
                    message.AddAttachment(inventoryObject.GetInfo(), transaction.count);
                    mail.AddNewMessage(message);
                    SaveMails(mail);
                    application.Clients.SendGenericEventToGameref(mail.gameRefId, new GenericEvent {
                        subCode = (int)SelectCharacterGenericEventSubCode.NewMessageCountChanged,
                        data    = new Hashtable {
                            { (int)SPC.Count, mail.newMessagesCount }
                        }
                    });
                    EventData updateEvent = new EventData((byte)SelectCharacterEventCode.MailUpdateEvent, new MailUpdatedEvent {
                        mailBox = mail.GetInfo()
                    });
                    application.SendEventToClient(transaction.gameRefID, updateEvent);
                    log.InfoFormat("Item successfully placed at mail [red]");
                    return(new PUTInventoryItemTransactionEnd {
                        characterID = transaction.characterID,
                        count = transaction.count,
                        gameRefID = transaction.gameRefID,
                        inventoryType = transaction.inventoryType,
                        itemID = transaction.itemID,
                        result = 0,
                        returnCode = (int)ReturnCode.Ok,
                        success = true,
                        transactionEndServer = transaction.transactionEndServer,
                        transactionStartServer = transaction.transactionStartServer,
                        transactionID = transaction.transactionID,
                        transactionSource = transaction.transactionSource
                    });
                }
            }

            return(new PUTInventoryItemTransactionEnd {
                characterID = transaction.characterID,
                count = transaction.count,
                gameRefID = transaction.gameRefID,
                inventoryType = transaction.inventoryType,
                itemID = transaction.itemID,
                result = 1,
                returnCode = (int)ReturnCode.ErrorOfAddingMail,
                success = false,
                transactionEndServer = transaction.transactionEndServer,
                transactionStartServer = transaction.transactionStartServer,
                transactionID = transaction.transactionID,
                transactionSource = transaction.transactionSource
            });
        }
Beispiel #3
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);
        }