Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
    private void HandleGETInventoryItemsStart(IEventData eventData, SendParameters sendParameters)
    {
        try {
            log.InfoFormat("OutgoinfMasterServerPeer.HandleGETInventoryItemsStart()");
            GETInventoryItemsTransactionStart start = new GETInventoryItemsTransactionStart(eventData);

            MmoActor player;
            if (m_App.serverActors.TryGetValue(start.gameRefID, out player))
            {
                GETInventoryItemsTransactionEnd end = new GETInventoryItemsTransactionEnd {
                    characterID            = start.characterID,
                    gameRefID              = start.gameRefID,
                    inventoryType          = start.inventoryType,
                    transactionID          = start.transactionID,
                    transactionSource      = start.transactionSource,
                    items                  = start.items,
                    transactionStartServer = start.transactionStartServer,
                    transactionEndServer   = start.transactionEndServer
                };

                List <IDCountPair> itemPairs = new List <IDCountPair>();
                foreach (DictionaryEntry entry in start.items)
                {
                    itemPairs.Add(new IDCountPair {
                        ID = (string)entry.Key, count = (int)entry.Value
                    });
                }

                ServerInventory inventory;
                if (start.inventoryType == (byte)InventoryType.ship)
                {
                    inventory = player.Inventory;
                }
                else
                {
                    inventory = player.Station.StationInventory;
                }

                bool checkItems = true;
                foreach (var pair in itemPairs)
                {
                    if (inventory.ItemCount(pair.ID) < pair.count)
                    {
                        checkItems = false;
                        break;
                    }
                }

                if (!checkItems)
                {
                    end.result     = new Hashtable();
                    end.success    = false;
                    end.returnCode = (short)ReturnCode.InventoryItemNotFound;
                    log.InfoFormat("OutgoinfMasterServerPeer.HandleGETInventoryItemsStart(): item check invalid");
                }
                else
                {
                    Hashtable result = new Hashtable();

                    foreach (var itemPair in itemPairs)
                    {
                        ServerInventoryItem it;
                        if (inventory.TryGetItem(itemPair.ID, out it))
                        {
                            Hashtable itInfo = new Hashtable {
                                { (int)SPC.Id, it.Object.Id },
                                { (int)SPC.Count, itemPair.count },
                                { (int)SPC.Info, it.Object.GetInfo() }
                            };
                            result.Add(it.Object.Id, itInfo);
                            inventory.Remove(it.Object.Type, it.Object.Id, itemPair.count);
                        }
                    }

                    end.result     = result;
                    end.success    = true;
                    end.returnCode = (short)ReturnCode.Ok;
                    player.EventOnInventoryUpdated();
                    player.EventOnStationHoldUpdated();
                    log.InfoFormat("OutgoingMasterServerPeer.HandleGETInventoryItemsStart()-SUCCESS");
                }

                EventData evt = new EventData((byte)S2SEventCode.GETInventoryItemsEnd, end);
                SendEvent(evt, sendParameters);
            }
            else
            {
                log.InfoFormat("OutgoinfMasterServerPeer.HandleGETInventoryItemsStart(): player not found on server [dy]");
            }
        } catch (Exception exception) {
            log.ErrorFormat(exception.Message);
            log.ErrorFormat(exception.StackTrace);
        }
    }
Ejemplo n.º 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);
        }