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); } }
protected override void OnEvent(IEventData eventData, SendParameters sendParameters) { try { switch ((S2SEventCode)eventData.Code) { default: { if (log.IsDebugEnabled) { log.DebugFormat("Received unknown event code {0}", eventData.Code); } break; } case S2SEventCode.UpdateShipModel: { HandleUpdateShipModelEvent(eventData); break; } case S2SEventCode.UpdateCharacter: { HandleUpdateCharacterEvent(eventData); break; } case S2SEventCode.GETInventoryItemEnd: { GETInventoryItemTransactionEnd end = new GETInventoryItemTransactionEnd(eventData); switch ((TransactionSource)end.transactionSource) { case TransactionSource.Store: { application.Stores.inventoryGETPool.HandleTransaction(end); log.Info("GET transaction handled"); break; } case TransactionSource.Bank: { application.Clients.HandleTransaction(end); log.Info("bank add transaction returned...."); break; } } break; } case S2SEventCode.GETInventoryItemsEnd: { GETInventoryItemsTransactionEnd end = new GETInventoryItemsTransactionEnd(eventData); switch ((TransactionSource)end.transactionSource) { case TransactionSource.Mail: { application.Mail.inventoryItemsGETPool.HandleTransaction(end); log.Info("get transaction handled"); break; } } break; } case S2SEventCode.PUTInventoryItemEnd: { HandlePUTInventoryTransactionEnd(eventData, sendParameters); break; } //called when from login inap store we put item to character mail case S2SEventCode.PUTMailTransactionStart: { HandlePutMailTransactionStart(eventData, sendParameters); } break; case S2SEventCode.InvokeMethodStart: { string method = (string)eventData.Parameters[(byte)ServerToServerParameterCode.Method]; object[] arguments = eventData.Parameters[(byte)ServerToServerParameterCode.Arguments] as object[]; string sourceServerID = eventData.Parameters[(byte)ServerToServerParameterCode.SourceServer] as string; byte targetServetType = (byte)eventData.Parameters[(byte)ServerToServerParameterCode.TargetServer]; var mtd = mInvoker.GetType().GetMethod(method); S2SInvokeMethodEnd end = new S2SInvokeMethodEnd { method = method, sourceServerID = sourceServerID, targetServerType = targetServetType, }; if (mtd != null) { object result = mtd.Invoke(mInvoker, arguments); end.callSuccess = true; end.result = result; } else { end.callSuccess = false; end.result = null; } EventData retEvent = new EventData((byte)S2SEventCode.InvokeMethodEnd, end); SendEvent(retEvent, new SendParameters()); break; } case S2SEventCode.InvokeMethodEnd: { bool success = (bool)eventData.Parameters[(byte)ServerToServerParameterCode.Success]; object result = eventData.Parameters[(byte)ServerToServerParameterCode.Result] as object; string method = eventData.Parameters[(byte)ServerToServerParameterCode.Method] as string; NebulaCommon.ServerType serverType = (NebulaCommon.ServerType)(byte) eventData.Parameters[(byte)ServerToServerParameterCode.TargetServer]; if (success) { log.InfoFormat("method {0} successfully called on server {1}", method, serverType); } else { log.InfoFormat("fail call method {0} on server {1}", method, serverType); } } break; } }catch (Exception ex) { log.Error(ex); } }
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); }