예제 #1
0
        private void RequestItemFromInventory(string login, string characterID, int count, string gameRefID,
                                              InventoryType inventoryType, string itemID, PostTransactionAction action, object tag, string targetServer)
        {
            var playerStore = GetOrCreatePlayerStore(login, gameRefID, characterID);

            if (playerStore == null)
            {
                log.InfoFormat("player store is null");
                return;
            }

            GETInventoryItemTransactionStart start = new GETInventoryItemTransactionStart {
                characterID           = characterID,
                count                 = count,
                gameRefID             = gameRefID,
                inventoryType         = (byte)inventoryType,
                itemID                = itemID,
                transactionID         = Guid.NewGuid().ToString(),
                transactionSource     = (byte)TransactionSource.Store,
                postTransactionAction = (byte)action,
                tag = tag,
                transactionEndServer   = targetServer,
                transactionStartServer = SelectCharacterApplication.ServerId.ToString()
            };
            EventData evt = new EventData((byte)S2SEventCode.GETInventoryItemStart, start);

            mTransactionPool.StartTransaction(start);
            mApplication.MasterPeer.SendEvent(evt, new SendParameters());
            log.Info("store transaction started...");
        }
예제 #2
0
 /// <summary>
 /// Start S2S transaction of moving item from player station to bank. Return true if transaction successfully started
 /// </summary>
 public bool MoveItemFromStation(string itemid, int count, string serverId)
 {
     if (isUserRegisterd)
     {
         if (bank != null)
         {
             if (bank.HasSpaceForItems(itemid))
             {
                 GETInventoryItemTransactionStart start = new GETInventoryItemTransactionStart {
                     characterID           = characterId,
                     count                 = count,
                     gameRefID             = id,
                     inventoryType         = (byte)InventoryType.station,
                     itemID                = itemid,
                     transactionID         = Guid.NewGuid().ToString(),
                     transactionSource     = (byte)TransactionSource.Bank,
                     postTransactionAction = (byte)PostTransactionAction.AddToBank,
                     tag = 0,
                     transactionEndServer   = serverId,
                     transactionStartServer = SelectCharacterApplication.ServerId.ToString()
                 };
                 EventData eventData = new EventData((byte)S2SEventCode.GETInventoryItemStart, start);
                 mGetPool.StartTransaction(start);
                 application.MasterPeer.SendEvent(eventData, new SendParameters());
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #3
0
 /// <summary>
 /// Start transaction of moving item from bank to player station
 /// itemid - id of inventory item in bank
 /// count - count of items to move
 /// server id - id of server where transaction handler placed
 /// </summary>
 public bool MoveItemToStation(string itemid, int count, string serverId)
 {
     if (isUserRegisterd)
     {
         if (bank != null)
         {
             var item = bank.GetItem(itemid);
             if (item.Count >= count)
             {
                 PUTInventoryItemTransactionStart start = new PUTInventoryItemTransactionStart {
                     characterID           = characterId,
                     count                 = count,
                     gameRefID             = id,
                     itemID                = itemid,
                     postTransactionAction = (byte)PostTransactionAction.WithdrawFromBank,
                     inventoryType         = (byte)InventoryType.station,
                     tag                    = 0,
                     targetObject           = item.GetInfo(),
                     transactionID          = Guid.NewGuid().ToString(),
                     transactionSource      = (byte)TransactionSource.Bank,
                     transactionStartServer = SelectCharacterApplication.ServerId.ToString(),
                     transactionEndServer   = serverId
                 };
                 EventData eventData = new EventData((byte)S2SEventCode.PUTInventoryItemStart, start);
                 mPutPool.StartTransaction(start);
                 application.MasterPeer.SendEvent(eventData, new SendParameters());
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #4
0
        public bool BuyStoreItem(string login, string gameRef, string character, int race, int inworkshop, int level, string productType, string server, out RPCErrorCode errorCode)
        {
            errorCode = RPCErrorCode.Ok;

            if (level < application.serverSettings.pvpStoreMinLevel)
            {
                log.InfoFormat("player level very low for pvp store {0}:{1} [red]", level, application.serverSettings.pvpStoreMinLevel);
                errorCode = RPCErrorCode.LevelNotEnough;
                return(false);
            }

            var storeItem = application.pvpStoreItems.GetItem(productType.ToLower());

            if (storeItem == null)
            {
                log.InfoFormat("pvp store item {0} not founded [red]", productType.ToLower());
                errorCode = RPCErrorCode.ObjectNotFound;
                return(false);
            }

            var store = application.Stores.GetOnlyPlayerStore(character);

            if (store == null)
            {
                log.InfoFormat("player store not founded [red]");
                errorCode = RPCErrorCode.ObjectNotFound;
                return(false);
            }

            if (store.pvpPoints < storeItem.price)
            {
                log.InfoFormat("player don't enough pvp points for purchase {0}:{1}", store.pvpPoints, storeItem.price);
                errorCode = RPCErrorCode.DontEnoughPvpPoints;
                return(false);
            }

            int workshop = inworkshop;

            if (Rand.Float01() >= 0.9f)
            {
                workshop = (byte)CommonUtils.RandomWorkshop((Race)(byte)race);
            }

            IInfo result = null;

            if (storeItem.isWeapon)
            {
                WeaponDropper dropper = new WeaponDropper(new WeaponDropper.WeaponDropParams(application.resource, level, (Workshop)(byte)workshop, WeaponDamageType.damage, Difficulty.none), 1f);
                result = (dropper.DropWeapon() as IInfo);
            }
            else
            {
                switch (productType.ToLower())
                {
                case "es":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.ES);
                }
                break;

                case "cb":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.CB);
                }
                break;

                case "cm":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.CM);
                }
                break;

                case "dm":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.DM);
                }
                break;

                case "df":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.DF);
                }
                break;
                }
            }

            if (result == null)
            {
                log.InfoFormat("creating item error [red]");
                errorCode = RPCErrorCode.UnknownError;
                return(false);
            }

            var itemHash = result.GetInfo();

            PUTInventoryItemTransactionStart start = new PUTInventoryItemTransactionStart {
                characterID           = character,
                count                 = 1,
                gameRefID             = gameRef,
                itemID                = itemHash.GetValue <string>((int)SPC.Id, string.Empty),
                postTransactionAction = (byte)PostTransactionAction.RemovePvpPoints,
                inventoryType         = (byte)InventoryType.ship,
                tag                    = storeItem.price,
                targetObject           = itemHash,
                transactionID          = Guid.NewGuid().ToString(),
                transactionSource      = (byte)TransactionSource.PvpStore,
                transactionEndServer   = server,
                transactionStartServer = SelectCharacterApplication.ServerId.ToString()
            };
            EventData eventData = new EventData((byte)S2SEventCode.PUTInventoryItemStart, start);

            mPutTransactionPool.StartTransaction(start);
            application.MasterPeer.SendEvent(eventData, new SendParameters());
            log.InfoFormat("pass put transaction started [red]...");
            return(true);
        }
예제 #5
0
        public bool RequestPurchaseInap(string gameRef, string character, string inapId, string targetServer, out ReturnCode code)
        {
            var databaseUser = m_Application.GetUser(new GameRefId(gameRef));

            if (databaseUser == null)
            {
                code = ReturnCode.UserNotFound;
                return(false);
            }

            InapItem inapItem = m_Application.inapResource.GetInap(inapId);

            if (inapItem == null)
            {
                code = ReturnCode.ResourceNotFound;
                return(false);
            }

            if (databaseUser.nebulaCredits < inapItem.price)
            {
                code = ReturnCode.NotEnoughCredits;
                return(false);
            }

            s_Log.InfoFormat("request purchase inap = {0} with interval = {1}", inapId, inapItem.data.GetValue <int>("interval", 0));

            Hashtable objInfo = null;

            switch (inapItem.type)
            {
            case InapObjectType.exp_boost: {
                objInfo = new ExpBoostObject(
                    inapId + inapItem.tag.ToString(),
                    inapItem.data.GetValue <float>("value", 0f),
                    inapItem.data.GetValue <int>("interval", 0),
                    inapItem.tag
                    ).GetInfo();
            }
            break;

            case InapObjectType.loot_box: {
                objInfo = new LootBoxObject(
                    inapId,
                    inapItem.data.GetValue <string>("drop_list", string.Empty)
                    ).GetInfo();
            }
            break;

            case InapObjectType.pet_skin: {
                string skin = inapItem.data.GetValue <string>("model", string.Empty);
                if (string.IsNullOrEmpty(skin))
                {
                    code = ReturnCode.InvalidInapType;
                    return(false);
                }
                objInfo = new PetSkinObject(skin, skin).GetInfo();
            }
            break;

            case InapObjectType.founder_cube: {
                objInfo = new FounderCubeInventoryObject().GetInfo();
            }
            break;

            case InapObjectType.credits_bag: {
                objInfo = new CreditsBagObject("creditsbag", inapItem.data.GetValue <int>("count", 10000), false).GetInfo();
            }
            break;
            }

            if (objInfo == null)
            {
                code = ReturnCode.InvalidInapType;
                return(false);
            }

            Hashtable tagHash = new Hashtable {
                { (int)SPC.InapId, inapId },
                { (int)SPC.Price, inapItem.price },
                { (int)SPC.Title, "ginp_title" },
                { (int)SPC.Body, "ginp_body" }
            };

            string itemID = string.Empty;

            if (inapItem.type == InapObjectType.pet_skin)
            {
                itemID = objInfo.GetValue <string>((int)SPC.Id, string.Empty);
            }
            else if (inapItem.type == InapObjectType.founder_cube)
            {
                itemID = objInfo.GetValue <string>((int)SPC.Id, string.Empty);
            }
            else if (inapItem.type == InapObjectType.credits_bag)
            {
                itemID = "creditsbag";
            }
            else
            {
                itemID = inapId + inapItem.tag.ToString();
            }

            PUTInventoryItemTransactionStart startTransaction = new PUTInventoryItemTransactionStart {
                characterID           = character,
                gameRefID             = gameRef,
                count                 = 1,
                inventoryType         = (int)InventoryType.ship,
                itemID                = itemID,
                postTransactionAction = (byte)PostTransactionAction.RemoveNebulaCredits,
                tag                    = tagHash,
                targetObject           = objInfo,
                transactionEndServer   = targetServer,
                transactionStartServer = LoginApplication.ServerId.ToString(),
                transactionID          = Guid.NewGuid().ToString(),
                transactionSource      = (byte)TransactionSource.Inaps
            };

            EventData eventData = new EventData((byte)S2SEventCode.PUTMailTransactionStart, startTransaction);

            m_PutTransactionPool.StartTransaction(startTransaction);
            m_Application.MasterPeer.SendEvent(eventData, new SendParameters());
            s_Log.InfoFormat("inap transaction successfully started...");

            code = ReturnCode.Ok;
            return(true);
        }
예제 #6
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);
        }
예제 #7
0
        public bool StartPutAttachmentToStation(string inlogin, string messageID, string attachmentID, string targetServer)
        {
            string login = inlogin.ToLower();

            log.InfoFormat("PUT ATTCHMENT to inventory started");

            var player = application.DB.GetByLogin(login);

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

            var mailBox = GetMailBox(player.GameRefId);

            if (mailBox == null)
            {
                log.InfoFormat("mail box not found");
                return(false);
            }

            MailAttachment attachment;

            if (!mailBox.TryGetAttachment(messageID, attachmentID, out attachment))
            {
                log.ErrorFormat("desired attachment not found");
                return(false);
            }

            if (string.IsNullOrEmpty(player.SelectedCharacterId))
            {
                log.ErrorFormat("player don't have selected character");
                return(false);
            }

            string itemID = attachment.objectHash.GetValue <string>((int)SPC.Id, string.Empty);

            if (string.IsNullOrEmpty(itemID))
            {
                log.ErrorFormat("attachment item id is invalid");
                return(false);
            }

            PUTInventoryItemTransactionStart transaction = new PUTInventoryItemTransactionStart {
                characterID           = player.SelectedCharacterId,
                count                 = attachment.count,
                gameRefID             = player.GameRefId,
                inventoryType         = (byte)InventoryType.station,
                itemID                = itemID,
                postTransactionAction = (byte)PostTransactionAction.RemoveMailAttachment,
                tag = new Hashtable {
                    { (int)SPC.Id, attachmentID }, { (int)SPC.Message, messageID }
                },
                targetObject           = attachment.objectHash,
                transactionID          = Guid.NewGuid().ToString(),
                transactionSource      = (byte)TransactionSource.Mail,
                transactionEndServer   = targetServer,
                transactionStartServer = SelectCharacterApplication.ServerId.ToString()
            };
            EventData evt = new EventData((byte)S2SEventCode.PUTInventoryItemStart, transaction);

            mPutTransactionPool.StartTransaction(transaction);
            application.MasterPeer.SendEvent(evt, new SendParameters());
            return(true);
        }