TryReadUShort() public method

public TryReadUShort ( ushort &pValue ) : bool
pValue ushort
return bool
Exemplo n.º 1
0
        public static void SelectObjectHandler(ZoneClient client, Packet packet)
        {
            ushort id;
            if (!packet.TryReadUShort(out id))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read entity select request.");
                return;
            }

            MapObject mo;
            // Try to see if there is a map object with this ID
            if (!client.Character.Map.Objects.TryGetValue(id, out mo))
            {
                client.Character.CharacterInTarget = mo;
                return; // Nothing found. Just return lawl
            }

            mo.SelectedBy.Add(client.Character);

            if (mo is ZoneCharacter || mo is Mob)
            {
                client.Character.SelectedObject = mo;
                SendStatsUpdate(mo, client, false);
            }
        }
Exemplo n.º 2
0
 public static void VersionInfo(LoginClient pClient, Packet pPacket)
 {
     ushort year;
     ushort version;
     if (!pPacket.TryReadUShort(out year) ||
         !pPacket.TryReadUShort(out version))
     {
         Log.WriteLine(LogLevel.Warn, "Invalid client version.");
         pClient.Disconnect();
         return;
     }
     Log.WriteLine(LogLevel.Debug, "Client version {0}:{1}.", year, version);
     using (Packet response = new Packet(SH3Type.VersionAllowed))
     {
         response.WriteShort(1);
         pClient.SendPacket(response);
     }
 }
Exemplo n.º 3
0
        public static void HandleTrade(ZoneClient client, Packet packet)
        {
            ushort PlayerObjID;
            if (!packet.TryReadUShort(out PlayerObjID))
            {
                Packet ppacket = new Packet(SH19Type.TradeNotAccepted);
                ppacket.WriteUShort(client.Character.MapObjectID);
                client.SendPacket(ppacket);
                Log.WriteLine(LogLevel.Error, "TradeRequest :: Invalid Obj ID from {0}", client.Character.Name);
            }

            SendTradeRequest(client, PlayerObjID);
        }
Exemplo n.º 4
0
        public static void AttackSkillHandler(ZoneClient client, Packet packet)
        {
            ushort skill;
            if (!packet.TryReadUShort(out skill))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read skillID from attack entity skill function. {0}", client);
                return;
            }

            if (!client.Character.SkillsActive.ContainsKey(skill))
            {
                Log.WriteLine(LogLevel.Warn, "User tried to attack with a wrong skill. {0} {1} ", skill, client);
                return;
            }

            client.Character.AttackSkill(skill, null);
        }
Exemplo n.º 5
0
 public static void BuyItem(ZoneClient client, Packet packet)
 {
     ZoneCharacter character = client.Character;
     ushort buyItemID;
     int amount;
     if (packet.TryReadUShort(out buyItemID) && packet.TryReadInt(out amount))
     {
         FiestaLib.Data.ItemInfo buyItem;
         Data.DataProvider.Instance.ItemsByID.TryGetValue(buyItemID, out buyItem);
         if (amount < 255)
         {
             if (character.GiveItem(buyItemID, (byte)amount) != InventoryStatus.Full)
             {
                 character.Inventory.Money -= amount * buyItem.BuyPrice;
                 character.ChangeMoney(character.Inventory.Money);
             }
         }
         else
         {
             while (amount > 0)
             {
                 if (character.GiveItem(buyItemID, 255) != InventoryStatus.Full)
                 {
                     character.Inventory.Money -= amount * buyItem.BuyPrice;
                     character.ChangeMoney(character.Inventory.Money);
                     character.CalculateMasterCopper(buyItem.BuyPrice);
                 }
                 if (amount < 255)
                 {
                     if (character.GiveItem(buyItemID, (byte)amount) != InventoryStatus.Full)
                     {
                         character.Inventory.Money -= amount * buyItem.BuyPrice;
                         character.ChangeMoney(character.Inventory.Money);
                         character.CalculateMasterCopper(buyItem.BuyPrice);
                     }
                     break;
                 }
                 amount -= 255;
             }
         }
     }
 }
Exemplo n.º 6
0
        public static void BeginInteractionHandler(ZoneClient client, Packet packet)
        {
            ushort entityid;
            if (!packet.TryReadUShort(out entityid))
            {
                Log.WriteLine(LogLevel.Warn, "Error reading interaction attempt.");
                return;
            }
            ZoneCharacter character = client.Character;

            MapObject obj;
            if (character.Map.Objects.TryGetValue(entityid, out obj))
            {

                Npc npc = obj as Npc;
                client.Character.CharacterInTarget = obj;
                if (npc != null)
                {
                    if (npc.Gate != null)
                    {

                        MapInfo mi = null;
                        if (DataProvider.Instance.MapsByName.TryGetValue(npc.Gate.MapServer, out mi))
                        {
                            Question q = new Question(string.Format("Do you want to move to {0} field?", mi.FullName), new QuestionCallback(AnswerOnGateQuestion), npc);
                            q.Add("Yes", "No");
                            q.Send(character, 500);
                            character.Question = q;
                        }
                        else
                        {
                            character.DropMessage("You can't travel to this place.");
                        }
                    }
                    else
                    {
                        SendNpcInteraction(client, npc);
                    }
                }
            }
            else Log.WriteLine(LogLevel.Warn, "{0} selected invalid object.", character.Name);
        }
Exemplo n.º 7
0
 public static void LootHandler(ZoneClient client, Packet packet)
 {
     ushort id;
     if (!packet.TryReadUShort(out id))
     {
         Log.WriteLine(LogLevel.Warn, "Invalid loot request.");
         return;
     }
     client.Character.LootItem(id);
 }
Exemplo n.º 8
0
        public static void UseSkillWithTargetHandler(ZoneClient client, Packet packet)
        {
            ushort skillid, victimid;
            if (!packet.TryReadUShort(out skillid) || !packet.TryReadUShort(out victimid))
            {
                Log.WriteLine(LogLevel.Warn, "Couldn't read useskill packet {0}", client);
                return;
            }
            Skill skill;
            if (!client.Character.SkillsActive.TryGetValue(skillid, out skill))
            {
                Log.WriteLine(LogLevel.Warn, "User tried to use a wrong skill. {0} {1} ", skillid, client);
                return;
            }

            MapObject victim;
            if (!client.Character.MapSector.Objects.TryGetValue(victimid, out victim))
            {
                Log.WriteLine(LogLevel.Warn, "User tried to do something with an unknown victim. {0} {1} {2}", skillid, victimid, client);
            }
            var self = client.Character;

            if (skill.Info.DemandType == 6)
            {
                if (!(victim is ZoneCharacter)) return;
                var zc = victim as ZoneCharacter;

                // Only Heal has this
                // Some heal calculation here
                uint amount = 12 * (uint)Program.Randomizer.Next(1, 300); //lulz

                if (amount > victim.MaxHP - victim.HP)
                {
                    amount = victim.MaxHP - victim.HP;
                }

                zc.HP += amount;

                ushort id = self.UpdateCounter;
                SendSkillStartSelf(self, skillid, victimid, id);
                SendSkillStartOthers(self, skillid, victimid, id);
                SendSkillOK(self);
                SendSkillAnimationForPlayer(self, skillid, id);
                // Damage as heal val :D
                SendSkill(self, id, victimid, amount, zc.HP, zc.UpdateCounter);
            }
            else
            {
                if (!(victim is Mob)) return;
                uint dmgmin = (uint)self.GetWeaponDamage(true);
                uint dmgmax = (uint)(self.GetWeaponDamage(true) + (self.GetWeaponDamage(true) % 3));
                uint amount = (uint)Program.Randomizer.Next((int)dmgmin, (int)dmgmax);
                if (amount > victim.HP)
                {
                    victim.HP = 0;
                }
                else {
                    victim.HP -= amount;
                }

                ushort id = self.UpdateCounter;
                SendSkillStartSelf(self, skillid, victimid, id);
                SendSkillStartOthers(self, skillid, victimid, id);
                SendSkillOK(self);
                SendSkillAnimationForPlayer(self, skillid, id);
                SendSkill(self, id, victimid, amount, victim.HP, victim.UpdateCounter, 0x01, 0x01);

                if (!victim.IsDead)
                {
                    victim.Attack(self);
                }
            }
        }
Exemplo n.º 9
0
        public static void UseSkillWithPositionHandler(ZoneClient client, Packet packet)
        {
            ushort skillid;
            uint x, y;
            if (!packet.TryReadUShort(out skillid) || !packet.TryReadUInt(out x) || !packet.TryReadUInt(out y))
            {
                Log.WriteLine(LogLevel.Warn, "Couldn't read UseSkillWithPosition packet. {0} ", client);
                return;
            }

            Skill skill;
            if (!client.Character.SkillsActive.TryGetValue(skillid, out skill))
            {
                Log.WriteLine(LogLevel.Warn, "User tried to use a wrong skill. {0} {1} ", skillid, client);
                return;
            }

            var self = client.Character;
            var block = self.Map.Block;

            if (x == 0 || y == 0 || x > block.Width || y > block.Height)
            {
                Log.WriteLine(LogLevel.Warn, "User tried to use skill out of map boundaries. {0} {1} {2} {3}", x, y, skillid, client);
                return;
            }

            if (skill.Info.MaxTargets <= 1)
            {
                // No AoE skill :s
                Log.WriteLine(LogLevel.Warn, "User tried to use skill with no MaxTargets or less than 1. {0} {1}", skillid, client);
                return;
            }

            self.AttackSkillAoE(skillid, x, y);
        }
Exemplo n.º 10
0
        public static void GetRewardItemList(ZoneClient pClient, Packet pPacket)
        {
            ushort PageID;
            if (!pPacket.TryReadUShort(out PageID))
                return;

            pClient.Character.WriteRewardList(PageID);
        }
Exemplo n.º 11
0
        public static void On_GameClient_UpdateDetails(WorldClient Client, Packet Packet)
        {
            ushort lenght;
            string message;
            if (!Packet.TryReadUShort(out lenght))
                return;

            if (!Packet.TryReadString(out message, lenght))
                return;
            using (var pack = new Packet(SH38Type.SendChangeDetailsResponse))
            {
                pack.WriteUShort(6016);//code for ok
                Client.SendPacket(pack);
            }
            if(Client.Character.Guild != null)
            {
                Client.Character.Guild.Academy.Message = message;
                Client.Character.Guild.Academy.Save();
                using (var pack = new Packet(SH38Type.SendChangeDetails))
                {
                    pack.WriteUShort(lenght);
                    pack.WriteString(message,message.Length);
                    Client.Character.Guild.Broadcast(pack);
                    Client.Character.Guild.Academy.Broadcast(pack);
                }
            }
            else if (Client.Character.GuildAcademy != null)
            {
                Client.Character.GuildAcademy.Message = message;
                Client.Character.GuildAcademy.Save();
                using (var pack = new Packet(SH38Type.SendChangeDetails))
                {
                    pack.WriteUShort(lenght);
                    pack.WriteString(message, message.Length);
                    Client.Character.GuildAcademy.Broadcast(pack);
                }
            }
        }
Exemplo n.º 12
0
        public static void TransferKeyHandler(ZoneClient client, Packet packet)
        {
            ushort randomID;
            string characterName, checksums; //TODO: check in securityclient
            if (!packet.TryReadUShort(out randomID) || !packet.TryReadString(out characterName, 16) ||
                !packet.TryReadString(out checksums, 832))
            {
                Log.WriteLine(LogLevel.Warn, "Invalid game transfer.");
                return;
            }
            ClientTransfer transfer = ClientManager.Instance.GetTransfer(characterName);
            if (transfer == null || transfer.HostIP != client.Host || transfer.RandID != randomID)
            {
                Log.WriteLine(LogLevel.Warn, "{0} tried to login without a valid client transfer.", client.Host);
                //Handler3.SendError(client, ServerError.INVALID_CREDENTIALS);
                Handler4.SendConnectError(client, ConnectErrors.RequestedCharacterIDNotMatching);
                return;
            }

            try
            {
               ClientManager.Instance.RemoveTransfer(characterName);

                 ZoneCharacter zonecharacter = new ZoneCharacter(transfer.CharID);
                if (zonecharacter.Character.AccountID != transfer.AccountID)
                {
                    Log.WriteLine(LogLevel.Warn, "Character is logging in with wrong account ID.");
                    Handler4.SendConnectError(client, ConnectErrors.RequestedCharacterIDNotMatching);
                    //Handler3.SendError(client, ServerError.INVALID_CREDENTIALS);
                    return;
                }

                client.Authenticated = true;
                client.Admin = transfer.Admin;
                client.AccountID = transfer.AccountID;
                client.Username = transfer.Username;
                client.Character = zonecharacter;
                zonecharacter.Client = client;
                //Zonecharacter.Client. = ;

                if (ClientManager.Instance.AddClient(client))
                {
                    zonecharacter.SendGetIngameChunk(); //TODO: interserver packet?
                    Log.WriteLine(LogLevel.Debug, "{0} logged in successfully!", zonecharacter.Name);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogLevel.Exception, "Error loading character {0}: {1} - {2}", characterName, ex.ToString(), ex.StackTrace);
                Handler4.SendConnectError(client, ConnectErrors.ErrorInCharacterInfo);
            }
        }
Exemplo n.º 13
0
        public static void On_GameClient_UpdateGuildMessage(WorldClient Client, Packet Packet)
        {
            ushort length;
            string message;
            if (Client.Character.Guild == null
                || !Packet.TryReadUShort(out length)
                || !Packet.TryReadString(out message, length))
            {
                return;
            }

            //response packets
            using (var packet = new Packet(SH29Type.UnkMessageChange))
            {
                packet.WriteHexAsBytes("68 1B 00 92 AD F8 4F 2E 00 00 00 2B 00 00 00 17 00 00 00 07 00 00 00 06 00 00 00 70 00 00 00 06 00 00 00 BC 00 00 00 01 00 00 00 00 00");

                Client.SendPacket(packet);
            }
            using (var packet = new Packet(SH29Type.ClearGuildDetailsMessage))
            {
                packet.WriteUShort(3137);
                packet.WriteLong(0);

                Client.SendPacket(packet);
            }
            using (var packet = new Packet(SH29Type.UpdateGuildMessageResponse))
            {
                packet.WriteUShort(3137);
                Client.SendPacket(packet);
            }

            //update guild
            lock (Client.Character.Guild.ThreadLocker)
            {
                Client.Character.Guild.Message = message;
                Client.Character.Guild.MessageCreater = Client.Character;
                Client.Character.Guild.MessageCreateTime = Program.CurrentTime;

                Client.Character.Guild.Save();

                //broadcast packet to all guild members
                using (var packet = new Packet(SH29Type.SendUpdateGuildDetails))
                {
                    packet.Fill(4, 0x00);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Second);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Minute);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Hour);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Day);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Month - 1);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Year - 1900);
                    packet.WriteInt(0);
                    packet.WriteLong(0);
                    packet.WriteString(Client.Character.Character.Name, 16);
                    packet.WriteUShort(length);
                    packet.WriteString(message, length);

                    Client.Character.Guild.Broadcast(packet);
                }

                //send packet to zone that guild message changed
                using (var packet = new InterPacket(InterHeader.ZONE_GuildMessageUpdate))
                {
                    packet.WriteInt(Client.Character.Guild.ID);
                    packet.WriteInt(Client.Character.ID);
                    packet.WriteDateTime(Client.Character.Guild.MessageCreateTime);

                    packet.WriteUShort(length);
                    packet.WriteString(message, length);
                    ZoneManager.Instance.Broadcast(packet);
                }
            }
        }
Exemplo n.º 14
0
 public static void TradeReqest(ZoneClient pClient, Packet pPacket)
 {
     ushort MapObjectID;
     if (!pPacket.TryReadUShort(out MapObjectID))
         return;
     TradeManager.Instance.AddTradeRequest(pClient, MapObjectID);
 }