Esempio n. 1
0
 /// <summary>
 /// Reads a 8-bit unsigned integer.
 /// </summary>
 /// <param name="name">Unused by the <see cref="BinaryValueReader"/>.</param>
 /// <returns>Value read from the reader.</returns>
 public byte ReadByte(string name)
 {
     return(_reader.ReadByte());
 }
Esempio n. 2
0
        void RecvBuyFromShop(IIPSocket conn, BitStream r)
        {
            var slot = r.ReadShopItemIndex();
            var amount = r.ReadByte();

            User user;
            if ((user = TryGetUser(conn)) == null)
                return;

            if (user.IsPeerTrading)
                return;

            user.ShoppingState.TryPurchase(slot, amount);
        }
Esempio n. 3
0
        void RecvSkillSetKnownAll(IIPSocket conn, BitStream r)
        {
            var count = r.ReadByte();
            var knownSkills = new List<SkillType>(count);

            // Read the known skills list
            for (var i = 0; i < count; i++)
            {
                var value = r.ReadEnum<SkillType>();
                knownSkills.Add(value);
            }

            Debug.Assert(knownSkills.Count == count);
            Debug.Assert(knownSkills.All(EnumHelper<SkillType>.IsDefined), "One or more known skills were unknown...");

            // Set the known skills
            UserInfo.KnownSkills.SetValues(knownSkills);
        }
Esempio n. 4
0
        void RecvStartQuestChatDialog(IIPSocket conn, BitStream r)
        {
            var npcIndex = r.ReadMapEntityIndex();

            // Available quests
            var numAvailableQuests = r.ReadByte();
            var availableQuests = new QuestID[numAvailableQuests];
            for (var i = 0; i < availableQuests.Length; i++)
            {
                availableQuests[i] = r.ReadQuestID();
            }

            // Quests that can be turned in
            var numTurnInQuests = r.ReadByte();
            var turnInQuests = new QuestID[numTurnInQuests];
            for (var i = 0; i < turnInQuests.Length; i++)
            {
                turnInQuests[i] = r.ReadQuestID();
            }

            // For the quests that are available, make sure we set their status to not being able to be turned in (just in case)
            foreach (var id in availableQuests)
            {
                UserInfo.HasFinishQuestRequirements.SetRequirementsStatus(id, false);
            }

            // For the quests that were marked as being able to turn in, set their status to being able to be finished
            foreach (var id in turnInQuests)
            {
                UserInfo.HasFinishQuestRequirements.SetRequirementsStatus(id, true);
            }

            // Grab the descriptions for both the available quests and quests we can turn in
            var qds = availableQuests.Concat(turnInQuests).Distinct().Select(x => _questDescriptions.GetOrDefault(x)).ToArray();

            // Display the form
            GameplayScreen.AvailableQuestsForm.Display(qds, npcIndex);
        }
Esempio n. 5
0
        void RecvSellInventoryToShop(IIPSocket conn, BitStream r)
        {
            var slot = r.ReadInventorySlot();
            var amount = r.ReadByte();

            User user;
            if ((user = TryGetUser(conn)) == null)
                return;

            user.ShoppingState.TrySellInventory(slot, amount);
        }
Esempio n. 6
0
        /// <summary>
        /// Handles <see cref="GroupInfoMessages.SetGroup"/>.
        /// </summary>
        /// <param name="bs">The <see cref="BitStream"/> to read from.</param>
        void ReadSetGroup(BitStream bs)
        {
            _members.Clear();
            _founder = null;

            var isInGroup = bs.ReadBool();

            if (isInGroup)
            {
                // Read the group members
                var numMembers = bs.ReadByte();
                var members = bs.ReadStrings(numMembers);
                _members.AddRange(members);

                // Read the founder's name
                _founder = bs.ReadString();
            }

            // Raise events
            OnGroupChanged();

            if (GroupChanged != null)
                GroupChanged.Raise(this, EventArgs.Empty);
        }
Esempio n. 7
0
        void RecvSetChatDialogPage(IIPSocket conn, BitStream r)
        {
            var pageID = r.ReadNPCChatDialogItemID();
            var skipCount = r.ReadByte();

            var responsesToSkip = new byte[skipCount];
            for (var i = 0; i < skipCount; i++)
            {
                responsesToSkip[i] = r.ReadByte();
            }

            GameplayScreen.ChatDialogForm.SetPageIndex(pageID, responsesToSkip);
        }
Esempio n. 8
0
        void RecvSelectAccountCharacter(IIPSocket conn, BitStream r)
        {
            ThreadAsserts.IsMainThread();

            var index = r.ReadByte();

            // Ensure the client is in a valid state to select an account character
            var userAccount = World.GetUserAccount(conn);
            if (userAccount == null)
                return;

            if (userAccount.User != null)
            {
                const string errmsg = "Account `{0}` tried to change characters while a character was already selected.";
                if (log.IsInfoEnabled)
                    log.InfoFormat(errmsg, userAccount);
                return;
            }

            // Get the CharacterID
            CharacterID characterID;
            if (!userAccount.TryGetCharacterID(index, out characterID))
            {
                const string errmsg = "Invalid account character index `{0}` given.";
                if (log.IsInfoEnabled)
                    log.InfoFormat(errmsg, characterID);
                return;
            }

            // Load the user
            userAccount.SetUser(World, characterID);


            var user = userAccount.User;
            if (user != null)
            {
                // Send the MOTD
                if (!string.IsNullOrEmpty(ServerSettings.Default.MOTD))
                {
                    using (var pw = ServerPacket.Chat(ServerSettings.Default.MOTD))
                    {
                        user.Send(pw, ServerMessageType.GUIChat);
                    }
                }

                // Send a notification to the world that the user joined
                var param = new object[] {user.Name};
                World.Send(GameMessage.UserJoinedWorld, ServerMessageType.GUIChat, param);

            }
        }
Esempio n. 9
0
        void RecvSetCharacterMPPercent(IIPSocket conn, BitStream r)
        {
            var mapEntityIndex = r.ReadMapEntityIndex();
            var percent = r.ReadByte();

            var character = _objGrabber.GetDynamicEntity<Character>(mapEntityIndex);
            if (character == null)
                return;

            character.MPPercent = percent;
        }
Esempio n. 10
0
        void RecvSetCharacterPaperDoll(IIPSocket conn, BitStream r)
        {
            var mapEntityIndex = r.ReadMapEntityIndex();
            var count = r.ReadByte();

            var layers = new string[count];
            for (var i = 0; i < layers.Length; i++)
            {
                layers[i] = r.ReadString();
            }

            var character = _objGrabber.GetDynamicEntity<Character>(mapEntityIndex);
            if (character == null)
                return;

            character.CharacterSprite.SetPaperDollLayers(layers);
        }
Esempio n. 11
0
        void RecvSendAccountCharacters(IIPSocket conn, BitStream r)
        {
            var count = r.ReadByte();
            var charInfos = new AccountCharacterInfo[count];
            for (var i = 0; i < count; i++)
            {
                var charInfo = r.ReadAccountCharacterInfo();
                charInfos[charInfo.Index] = charInfo;
            }

            _accountCharacterInfos.SetInfos(charInfos);
        }
Esempio n. 12
0
        void RecvNotifyGetItem(IIPSocket conn, BitStream r)
        {
            var name = r.ReadString();
            var amount = r.ReadByte();

            string msg;
            if (amount > 1)
                msg = string.Format("You got {0} {1}s", amount, name);
            else
                msg = string.Format("You got a {0}", name);

            GameplayScreen.InfoBox.Add(msg);
        }
Esempio n. 13
0
        void RecvStartShopping(IIPSocket conn, BitStream r)
        {
            var shopOwnerIndex = r.ReadMapEntityIndex();
            var canBuy = r.ReadBool();
            var name = r.ReadString();
            var itemCount = r.ReadByte();

            var items = new IItemTemplateTable[itemCount];
            for (var i = 0; i < itemCount; i++)
            {
                var value = new ItemTemplateTable();
                value.ReadState(r);
                items[i] = value;
            }

            var shopOwner = Map.GetDynamicEntity(shopOwnerIndex);
            var shopInfo = new ShopInfo<IItemTemplateTable>(shopOwner, name, canBuy, items);

            GameplayScreen.ShopForm.DisplayShop(shopInfo);
        }
Esempio n. 14
0
        void RecvDeleteAccountCharacter(IIPSocket conn, BitStream r)
        {
            var slot = r.ReadByte();

            // Check for a valid account
            var account = TryGetAccount(conn);
            if (account == null)
            {
                const string errmsg =
                    "Connection `{0}` tried to delete account character but no account is associated with this connection.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, conn);
                return;
            }

            // Ensure the connection isn't logged in
            if (account.User != null)
            {
                const string errmsg = "User `{0}` tried to delete account character while already logged in.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, account.User);
                return;
            }

            // Get the character ID
            CharacterID charID;
            if (!account.TryGetCharacterID(slot, out charID))
            {
                const string errmsg = "Could not delete character in slot `{0}` - no character exists.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, slot);
                return;
            }

            // Delete
            var q = DbController.GetQuery<DeleteUserCharacterQuery>();
            q.Execute(charID);

            // Update
            account.LoadCharacterIDs();
            account.SendAccountCharacterInfos();
        }
Esempio n. 15
0
        void RecvSetInventorySlot(IIPSocket conn, BitStream r)
        {
            var slot = r.ReadInventorySlot();
            var hasGraphic = r.ReadBool();
            var graphic = hasGraphic ? r.ReadGrhIndex() : GrhIndex.Invalid;
            var amount = r.ReadByte();

            UserInfo.Inventory.Update(slot, graphic, amount, GetTime());
        }
Esempio n. 16
0
        void RecvDropInventoryItem(IIPSocket conn, BitStream r)
        {
            var slot = r.ReadInventorySlot();
            var amount = r.ReadByte();

            User user;
            if ((user = TryGetUser(conn)) == null)
                return;

            if (user.IsPeerTrading)
                return;

            if (amount < 1)
                return;

            user.Inventory.Drop(slot, amount);
        }
Esempio n. 17
0
        void RecvSetProvidedQuests(IIPSocket conn, BitStream r)
        {
            var mapEntityIndex = r.ReadMapEntityIndex();
            var count = r.ReadByte();
            var questIDs = new QuestID[count];
            for (var i = 0; i < count; i++)
            {
                questIDs[i] = r.ReadQuestID();
            }

            var character = _objGrabber.GetDynamicEntity<Character>(mapEntityIndex);
            if (character != null)
                character.ProvidedQuests = questIDs;
        }
Esempio n. 18
0
        void RecvSelectNPCChatDialogResponse(IIPSocket conn, BitStream r)
        {
            var responseIndex = r.ReadByte();

            User user;
            if ((user = TryGetUser(conn)) == null)
                return;

            user.ChatState.EnterResponse(responseIndex);
        }
Esempio n. 19
0
        void RecvSkillSetGroupCooldown(IIPSocket conn, BitStream r)
        {
            var skillGroup = r.ReadByte();
            var cooldownTime = r.ReadUShort();

            GameplayScreen.SkillCooldownManager.SetCooldown(skillGroup, cooldownTime, GetTime());
        }
Esempio n. 20
0
        /// <summary>
        /// Handles <see cref="QuestInfoMessages.LoadInitialValues"/>.
        /// </summary>
        /// <param name="bs">The <see cref="BitStream"/> to read from.</param>
        void ReadLoadInitialValues(BitStream bs)
        {
            _completedQuests.Clear();
            _activeQuests.Clear();

            // Read completed quests
            var count = bs.ReadByte();
            for (var i = 0; i < count; i++)
            {
                _completedQuests.Add(bs.ReadQuestID());
            }

            // Read Active quests
            count = bs.ReadByte();
            for (var i = 0; i < count; i++)
            {
                _activeQuests.Add(bs.ReadQuestID());
            }

            // Raise events
            OnLoaded();

            if (Loaded != null)
                Loaded.Raise(this, EventArgs.Empty);
        }
Esempio n. 21
0
 void RecvSetLevel(IIPSocket conn, BitStream r)
 {
     var level = r.ReadByte();
     UserInfo.Level = level;
 }