TryReadByte() публичный Метод

public TryReadByte ( byte &pValue ) : bool
pValue byte
Результат bool
Пример #1
0
        public static void CreateCharHandler(WorldClient client, Packet packet)
        {
            string name;
            byte slot, jobGender, hair, color, style;
            if (!packet.TryReadByte(out slot) || !packet.TryReadString(out name, 16) ||
                !packet.TryReadByte(out jobGender) || !packet.TryReadByte(out hair) ||
                !packet.TryReadByte(out color) || !packet.TryReadByte(out style))
            {
                Log.WriteLine(LogLevel.Warn, "Error reading create char for {0}", client.Username);
                return;
            }

            if (DatabaseChecks.IsCharNameUsed(name))
            {
                SendCharCreationError(client, CreateCharError.NameTaken);
                return;
            }
            else if (DataProvider.Instance.IsBadName(name))
            {
                SendCharCreationError(client, CreateCharError.NameInUse);
                return;
            }

            byte isMaleByte = (byte)((jobGender >> 7) & 0x01);
            byte classIDByte = (byte)((jobGender >> 2) & 0x1F);
            Job job = (Job)classIDByte;
            switch (job)
            {
                case Job.Archer:
                case Job.Cleric:
                case Job.Fighter:
                case Job.Mage:
                case Job.Trickster:
                case Job.Crusader:
                   //create character here
                    try
                    {
                        WorldCharacter wchar = client.CreateCharacter(name, slot, hair, color, style, job, Convert.ToBoolean(isMaleByte));
                        SendCharOKResponse(client, wchar);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine(LogLevel.Exception, "Error creating character for {0}: {1}", client.Username, ex.InnerException.ToString());
                        SendCharCreationError(client, CreateCharError.FailedToCreate);
                        return;
                    }
                    break;
                default:
                    SendCharCreationError(client, CreateCharError.WrongClass);
                    Log.WriteLine(LogLevel.Warn, "Invalid job ID at char creation from {0}", client.Username);
                    break;
            }
        }
Пример #2
0
        public static void CharacterSelectHandler(WorldClient client, Packet packet)
        {
            byte slot;
            if (!packet.TryReadByte(out slot) || slot > 10 || !client.Characters.ContainsKey(slot))
            {
                Log.WriteLine(LogLevel.Warn, "{0} selected an invalid character.", client.Username);
                return;
            }

            WorldCharacter character;
            if (client.Characters.TryGetValue(slot, out character))
            {
                //generate transfer

                ZoneConnection zone = Program.GetZoneByMap(character.Character.PositionInfo.Map);
                if (zone != null)
                {
                    client.Characters.Clear(); //we clear the other ones from memory
                    client.Character = character; //only keep the one selecte
                    //Database.Storage.Characters.AddChars(character.Character);
                    zone.SendTransferClientFromZone(client.AccountID, client.Username, client.Character.Character.Name,client.Character.ID, client.RandomID, client.Admin, client.Host);
                    ClientManager.Instance.AddClientByName(client); //so we can look them up fast using charname later.
                    SendZoneServerIP(client, zone);
                }
                else
                {
                    Log.WriteLine(LogLevel.Warn, "Character tried to join unloaded map: {0}", character.Character.PositionInfo.Map);
                    SendConnectError(client, ConnectErrors.MapUnderMaintenance);
                }
            }
        }
Пример #3
0
        public static void HandleSetStatPoint(ZoneClient client, Packet packet)
        {
            byte stat;
            if (!packet.TryReadByte(out stat))
            {
                Log.WriteLine(LogLevel.Warn, "Couldn't read HandleSetStatPoint packet. {0}", client);
                return;
            }

            if (client.Character.Character.UsablePoints == 0)
            {
                Log.WriteLine(LogLevel.Warn, "User tried to set stat point while not having any left. {0}", client);
            }
            else
            {
                // LETS DO ET
                switch (stat)
                {
                    case 0: client.Character.Str++; break;
                    case 1: client.Character.Dex++; break;
                    case 2: client.Character.End++; break;
                    case 3: client.Character.Int++; break;
                    case 4: client.Character.Spr++; break;
                    default:
                        {
                            Log.WriteLine(LogLevel.Warn, "User tried to set stat point on unknown stat {0} {1}", stat, client);
                            return;
                        }
                }
                client.Character.Character.UsablePoints--;
                //Program.Entity.SaveChanges();
                SendSetUsablePoint(client, stat);
            }
        }
Пример #4
0
 public static void ChangeDropMode(WorldClient client, Packet packet)
 {
     byte dropState;
     if (packet.TryReadByte(out dropState)) {
         client.Character.Group.ChangeDropType(client.Character, dropState);
     }
 }
Пример #5
0
        public static void sendPartyMessage(WorldClient client, Packet packet)
        {
            string mess;
            byte len;
            if (!packet.TryReadByte(out len) || !packet.TryReadString(out mess, len))
            {
                Log.WriteLine(LogLevel.Error, "PartyChat :: Can not parse party chat from {0}", client.Character.Character.Name);
                return;
            }

            if(Program.Entity.Parties.Where(c => c.CharNo == client.Character.Character.ID).Count() == 1)
            {
                Party getPartyInfo = Program.Entity.Parties.First(c => c.CharNo == client.Character.Character.ID);
                foreach (Party party in Program.Entity.Parties.Where(c => c.PartyNo == getPartyInfo.PartyNo))
                {
                    Character character = Program.Entity.Characters.First(c => c.ID == party.CharNo);
                    WorldClient wclient = ClientManager.Instance.GetClientByCharname(character.Name);
                    using (var ppacket = new Packet(SH8Type.PartyChat))
                    {
                        ppacket.WriteString(client.Character.Character.Name, 16);
                        ppacket.WriteByte(len);
                        ppacket.WriteString(mess, len);
                        wclient.SendPacket(ppacket);
                    }
                }
            }
            else
            {
                using (var ppacket = new Packet(SH8Type.PartyChatErr))
                {
                    ppacket.WriteUShort(1985);
                    client.SendPacket(ppacket);
                }
            }
        }
Пример #6
0
 public static void TradeRemovitem(ZoneClient pClient, Packet pPacket)
 {
     byte pSlot;
     if (!pPacket.TryReadByte(out pSlot))
         return;
     if (pClient.Character.Trade == null)
         return;
     pClient.Character.Trade.RemoveItemToHandel(pClient.Character, pSlot);
 }
Пример #7
0
 public static void MasterRequestCoper(ZoneClient client, Packet pPacket)
 {
     byte unk;
     if (!pPacket.TryReadByte(out unk))
         return;
     using (var packet = new Packet(SH37Type.SendRecivveCopper))
     {
         packet.WriteUShort(7264);//unk
         packet.WriteLong(client.Character.Character.ReviveCoper);
         client.SendPacket(packet);
     }
 }
Пример #8
0
        public static void PartyChat(WorldClient client, Packet packet)
        {
            if (client.Character.Group == null)
                return;

            byte msgLen;
            string msg = string.Empty;

            if (!packet.TryReadByte(out msgLen) || !packet.TryReadString(out msg, msgLen))
                return;

            client.Character.Group.Chat(client, msg);
        }
Пример #9
0
 public static void ChangeCharNameHandler(WorldClient client, Packet packet)
 {
     byte Character_slot;
     string charname;
     if (!packet.TryReadByte(out Character_slot) || !packet.TryReadString(out charname, 16))
         return;
     using (var pack = new Packet(SH5Type.SendCharacterChangeNewName))
     {
         pack.WriteByte(Character_slot);
         pack.WriteString(charname,16);
         pack.WriteUShort(208);//Responsecode?
     }
     //Todo ChangeinDatabase
 }
Пример #10
0
 public static void Wisper(WorldClient client, Packet packet)
 {
     string toname;
     byte messagelenght;
     if (packet.TryReadString(out toname, 16) && packet.TryReadByte(out messagelenght))
     {
         string message;
         if (!packet.TryReadString(out message, messagelenght))
         {
             return;
         }
         WorldClient toChar = ClientManager.Instance.GetClientByCharname(toname);
         if (toChar != null)
         {
             using (var frompacket = new Packet(SH8Type.WisperFrom))
             {
                 frompacket.WriteString(client.Character.Character.Name, 16);
                 if (!toChar.Character.BlocketUser.Contains(client.Character.Character.Name))
                 {
                     frompacket.WriteByte(0);
                 }
                 else
                 {
                     frompacket.WriteByte(12);//blocket notdisplay message
                 }
                 frompacket.WriteByte(messagelenght);
                 frompacket.WriteString(message, messagelenght);
                 toChar.SendPacket(frompacket);
             }
             using (var pack = new Packet(SH8Type.WisperTo))
             {
                 pack.WriteString(toname, 16);
                 pack.WriteByte(messagelenght);
                 pack.WriteString(message, messagelenght);
                 client.SendPacket(pack);
             }
         }
         else
         {
             //target not found
             using (var pp = new Packet(SH8Type.WisperTargetNotfound))
             {
                 pp.WriteUShort(3945);//unk
                 pp.WriteString(toname, 16);
                 client.SendPacket(pp);
             }
         }
     }
 }
Пример #11
0
        public static void questionHandler(ZoneClient client, Packet packet)
        {
            byte answer;
            if (!packet.TryReadByte(out answer))
            {
                Log.WriteLine(LogLevel.Warn, "Received invalid question response.");
                return;
            }

            ZoneCharacter character = client.Character;
            if (character.Question == null)
                return;
            else if (character.Question.Answers.Count <= answer)
                return;

            character.Question.Function(character, answer);
            character.Question = null;
        }
Пример #12
0
        public static void ClientEquippedItem(ZoneClient pClient, Packet pPacket)
        {
            byte fromSlot;
            if (!pPacket.TryReadByte(out fromSlot))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read equip slot.");
                return;
            }

            Item fromItem;
            if (!pClient.Character.Inventory.InventoryItems.TryGetValue(fromSlot, out fromItem))
            {
                Log.WriteLine(LogLevel.Warn, "Equipping empty inventory slot.");
                return;
            }

            if (fromItem == null)
            {
                Log.WriteLine(LogLevel.Warn, "Client tries to equip an ITEM, not EQUIP!");
                return;
            }
            byte toSlot = (byte)fromItem.Slot;
            Item toEquip = pClient.Character.Inventory.EquippedItems.Find(e => e.ItemInfo.Slot == fromItem.ItemInfo.Slot);

            // TODO: Check, does user equip item to correct slot. Right now client only does it.

            ZoneClient client = pClient;
            if (fromItem.ItemInfo.Level > pClient.Character.Level)
            {
                FailedEquip(client.Character, 645); // 85 02
            }
            else
            {
                if (toEquip == null)
                {
                    pClient.Character.EquipItem(fromItem);
                }
                else
                {
                    pClient.Character.SwapEquips(toEquip, fromItem);
                }
            }
        }
Пример #13
0
 public static void DeleteCharacterHandler(WorldClient client, Packet packet)
 {
     byte slot;
     if (!packet.TryReadByte(out slot) || slot > 10 || !client.Characters.ContainsKey(slot))
     {
         Log.WriteLine(LogLevel.Warn, "{0} tried to delete character out of range.", client.Username);
         return;
     }
     WorldCharacter todelete = client.Characters[slot];
     if (todelete.Delete())
     {
         client.Characters.Remove(slot);
         SendCharDeleteOKResponse(client, slot);
     }
     else
     {
         Handler3.SendError(client, ServerError.DATABASE_ERROR);
     }
 }
Пример #14
0
        public static void getWhisperMessage(WorldClient client, Packet packet)
        {
            string toChar;
            byte len;
            string mess;
            if (!packet.TryReadString(out toChar, 16) || !packet.TryReadByte(out len) || !packet.TryReadString(out mess, len))
            {
                Log.WriteLine(LogLevel.Error, "WhisperChat :: Can not parse Whisper request from {0}", client.Character.Character.Name);
                return;
            }

            WorldClient wclient = ClientManager.Instance.GetClientByCharname(toChar);

            if (wclient != null)
            {
                using (var ppacket = new Packet(SH8Type.WhisperTo))
                {
                    ppacket.WriteString(toChar, 16);
                    ppacket.WriteByte(len);
                    ppacket.WriteString(mess, len);
                    client.SendPacket(ppacket);
                }

                using (var ppacket = new Packet(SH8Type.WhisperFrom))
                {
                    ppacket.WriteString(client.Character.Character.Name, 16);
                    ppacket.WriteByte(0); // unk
                    ppacket.WriteByte(len);
                    ppacket.WriteString(mess, len);
                    wclient.SendPacket(ppacket);
                }
            }
            else
            {
                using (var ppacket = new Packet(SH8Type.WhisperErrAnswer))
                {
                    ppacket.WriteUShort(3945);
                    ppacket.WriteString(toChar, 16);
                    client.SendPacket(ppacket);
                }
            }
        }
Пример #15
0
        public static void MasterRequestResponse(WorldClient client, Packet packet)
        {
            string requester = string.Empty;
            string target = string.Empty;
            byte response;
            if (!packet.TryReadString(out requester, 16))
                return;
            if (!packet.TryReadString(out target, 16))
                return;

            if (!packet.TryReadByte(out response))
                return;
            if (response == 0)
            {
                MasterManager.Instance.RemoveMasterRequest(client);
            }
            else if(response == 1)
            {
                MasterManager.Instance.MasterRequestAccept(requester, target);
            }
        }
Пример #16
0
 public static void NormalChatHandler(ZoneClient client, Packet packet)
 {
     byte len;
     string text;
     if (!packet.TryReadByte(out len) || !packet.TryReadString(out text, len))
     {
         Log.WriteLine(LogLevel.Warn, "Could not parse normal chat from {0}.", client.Character.Name);
         return;
     }
     if (client.Admin > 0 && (text.StartsWith("&") || text.StartsWith("/")))
     {
         CommandLog.Instance.LogCommand(client.Character.Name, text);
         CommandStatus status = CommandHandler.Instance.ExecuteCommand(client.Character, text.Split(' '));
         switch (status)
         {
             case CommandStatus.ERROR:
                 client.Character.DropMessage("Error executing command.");
                 break;
             case CommandStatus.GM_LEVEL_TOO_LOW:
                 client.Character.DropMessage("You do not have the privileges for this command.");
                 break;
             case CommandStatus.NOT_FOUND:
                 client.Character.DropMessage("Command not found.");
                 break;
         }
     }
     else
     {
         int chatblock = client.Character.ChatCheck();
         if (chatblock == -1)
         {
             ChatLog.Instance.LogChat(client.Character.Name, text, false);
             SendNormalChat(client.Character, text, client.Admin > 0 ? (byte)0x03 : (byte)0x2a);
         }
         else
         {
             Handler2.SendChatBlock(client.Character, chatblock);
         }
     }
 }
Пример #17
0
        public static void UseTeleporter(ZoneClient client, Packet packet)
        {
            byte anwser;
            if (packet.TryReadByte(out anwser))
            {
                using (Packet Packet = new Packet(SH6Type.TelePorter))
                {
                    Packet.WriteShort(6593);//code for normal teleport
                    client.SendPacket(Packet);
                }
                switch (anwser)
                {
                    case 0:
                        client.Character.ChangeMap(0, 4199, 4769);//Roumen

                        break;
                    case 1:
                        client.Character.ChangeMap(9, 11802, 10466);//Eldrine

                        break;
                    case 2:
                        client.Character.ChangeMap(75, 9069, 9312);//EldGbl02
                        break;
                    case 3:
                        client.Character.ChangeMap(5,13658,7812);//RouVal01

                        break;
                    default:
                        Log.WriteLine(LogLevel.Warn,"Unkown Teleport Answer {1}",anwser);
                        break;
                }
            }
        }
Пример #18
0
 public static void UseHandler(ZoneClient client, Packet packet)
 {
     byte slot;
     if (!packet.TryReadByte(out slot))
     {
         Log.WriteLine(LogLevel.Warn, "Error reading used item slot.");
         return;
     }
     client.Character.UseItem(slot);
 }
Пример #19
0
        public static void ShoutHandler(ZoneClient client, Packet packet)
        {
            ZoneCharacter character = client.Character;
            byte len;
            string message;
            if (!packet.TryReadByte(out len) ||
                !packet.TryReadString(out message, len))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read shout from {0}.", character.Name);
                return;
            }

            int shoutcheck = character.ShoutCheck();
            if (shoutcheck > 0)
            {
                Handler2.SendChatBlock(character, shoutcheck);
            }
            else
            {
                ChatLog.Instance.LogChat(client.Character.Name, message, true);
                using (var broad = Shout(character.Name, message))
                {
                    character.Map.Broadcast(broad);
                }
            }
        }
Пример #20
0
        public static void SellItem(ZoneClient client, Packet packet)
        {
            byte slot;
            int sellcount;
            ZoneCharacter character = client.Character;
            if (packet.TryReadByte(out slot) && packet.TryReadInt(out sellcount))
            {

                Item item;
                character.Inventory.InventoryItems.TryGetValue(slot, out item);
                if (item != null)
                {

                    long fullSellPrice = sellcount * item.ItemInfo.SellPrice;
                    if (item.Ammount > 1)
                    {
                        item.Ammount -= (ushort)sellcount;
                        byte Slot = (byte)item.Slot;
                        Handler12.ModifyInventorySlot(character, 0x24, Slot, Slot, item);
                        character.Inventory.Money += fullSellPrice;
                        character.ChangeMoney(character.Inventory.Money);
                    }
                    else
                    {
                        character.Inventory.Money += fullSellPrice;
                        character.ChangeMoney(character.Inventory.Money);
                        character.Inventory.InventoryItems.Remove(slot);
                        ResetInventorySlot(character, slot);
                    }
                    System.Console.WriteLine(item.ItemInfo.Type);
                }
            }
        }
Пример #21
0
        public static void EmoteHandler(ZoneClient client, Packet packet)
        {
            ZoneCharacter character = client.Character;
            byte action;
            if (!packet.TryReadByte(out action))
            {
                Log.WriteLine(LogLevel.Warn, "{0} did empty emote.", character.Name);
                return;
            }

            if (action > 74)
            {
                character.CheatTracker.AddCheat(CheatTypes.EMOTE, 500);
                return;
            }

            using (var broad = Animation(character, action))
            {
                character.Broadcast(broad, true);
            }
        }
Пример #22
0
        public static void GetPremiumItemList(ZoneClient pClient, Packet pPacket)
        {
            byte PageID;
            if (!pPacket.TryReadByte(out PageID))
                return;

            pClient.Character.WritePremiumList(PageID);
        }
Пример #23
0
        public static void MoveItemHandler(ZoneClient pClient, Packet pPacket)
        {
            byte oldslot, oldstate, newslot, newstate;
            if (!pPacket.TryReadByte(out oldslot) ||
                !pPacket.TryReadByte(out oldstate) ||
                !pPacket.TryReadByte(out newslot) ||
                !pPacket.TryReadByte(out newstate))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read item move.");
                return;
            }

            if (oldslot == newslot)
            {
                Log.WriteLine(LogLevel.Warn, "Client tried to dupe an item.");
                return;
            }

            Item source;
            if (!pClient.Character.Inventory.InventoryItems.TryGetValue(oldslot, out source) && newstate != 0x00 && oldstate != 0x00 || newstate == 0x00)
            {
                if (pClient.Character.Guild != null)
                {
                   if(newstate == 0x00 && oldstate == 0x24)
                    {
                        source.Flags = Data.ItemFlags.GuildItem;
                    }
                   else if(newstate == 0x24 && oldstate == 0x00)
                   {
                       source.Flags = Data.ItemFlags.Normal;
                   }
                    else if (source == null || newstate != 0x24)
                    {
                        if (!pClient.Character.Guild.GuildStore.GuildStorageItems.TryGetValue(oldslot, out source))
                        {
                            return;
                        }
                    }
                }
                if (source == null)
                {
                    Log.WriteLine(LogLevel.Warn, "Client tried to move empty slot.");
                    return;
                }
            }
            if (newslot == 0xff || newstate == 0xff)
            {
                pClient.Character.Inventory.InventoryItems.Remove(oldslot);
                source.Delete(); //TODO: make a drop
                Handler12.ModifyInventorySlot(pClient.Character, oldslot, oldstate, (byte)source.Slot, null);
            }
            else if(newstate == 0x00 && oldstate == 0x24 && pClient.Character.Guild != null)
            {

                if (!pClient.Character.Guild.GuildStore.GetHasFreeGuildStoreSlot())
                    //todo GuildStorefuell
                    return;
                pClient.Character.Inventory.RemoveInventory(source);
                pClient.Character.Guild.GuildStore.GuildStorageItems.Add(newslot, source);
                pClient.Character.Guild.GuildStore.SendAddGuildStore(Data.GuildStoreAddFlags.Item, pClient.Character.Character.Name, source.Ammount, 0, source.ItemInfo.ItemID);
                pClient.Character.Guild.GuildStore.SaveStoreItem(pClient.Character.Guild.ID, source.ItemInfo.ItemID, newslot);
                Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, oldslot, null);
                Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, oldslot, newslot, source);
                return;
            }
            else if(oldstate == 0x00 && newstate == 0x24 && pClient.Character.Guild != null)
            {
                if (!pClient.Character.Guild.GuildStore.GuildStorageItems.TryGetValue(oldslot, out source))
                    return;
                source.Slot = (sbyte)newslot;
                pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(oldslot);
                pClient.Character.Inventory.AddToInventory(source);
                pClient.Character.Guild.GuildStore.SendRemoveFromGuildStore (Data.GuildStoreAddFlags.Item, pClient.Character.Character.Name, source.Ammount, 0, source.ItemInfo.ItemID);
                pClient.Character.Guild.GuildStore.RemoveStoreItem(pClient.Character.Guild.ID, source.ItemInfo.ItemID);
                Handler12.ModifyInventorySlot(pClient.Character, newstate,oldstate, newslot, oldslot, null);
                Handler12.ModifyInventorySlot(pClient.Character, newstate, newstate, newstate, newslot, source);
                return;
            }
            if (source.Flags == Data.ItemFlags.Normal)
            {
                Item destination;
                if (pClient.Character.Inventory.InventoryItems.TryGetValue(newslot, out destination))
                {
                    //item swap
                    pClient.Character.Inventory.InventoryItems.Remove(oldslot);
                    pClient.Character.Inventory.InventoryItems.Remove(newslot);
                    source.Slot = (sbyte)newslot;
                    destination.Slot = (sbyte)oldslot;
                    pClient.Character.Inventory.InventoryItems.Add(newslot, source);
                    pClient.Character.Inventory.InventoryItems.Add(oldslot, destination);
                    source.Save();
                    destination.Save();
                    Handler12.ModifyInventorySlot(pClient.Character, newslot, 0x24, oldslot, destination);
                    Handler12.ModifyInventorySlot(pClient.Character, oldslot, 0x24, newslot, source);
                }
                else
                {
                    //item moved to empty slot
                    pClient.Character.Inventory.InventoryItems.Remove(oldslot);
                    pClient.Character.Inventory.InventoryItems.Add(newslot, source);
                    source.Slot = (sbyte)newslot;
                    source.Save();
                    Handler12.ModifyInventorySlot(pClient.Character, newslot, 0x24, oldslot, null);
                    Handler12.ModifyInventorySlot(pClient.Character, oldslot, 0x24, newslot, source);
                }
            }
            else if (source.Flags == Data.ItemFlags.GuildItem)
            {
                Item destination;
                if (pClient.Character.Guild.GuildStore.GuildStorageItems.TryGetValue(newslot, out destination))
                {
                    //item swap
                    pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(oldslot);
                    pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(newslot);
                    source.Slot = (sbyte)newslot;
                    destination.Slot = (sbyte)oldslot;
                    pClient.Character.Guild.GuildStore.GuildStorageItems.Add(newslot, source);
                    pClient.Character.Guild.GuildStore.GuildStorageItems.Add(oldslot, destination);
                    Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, newslot, oldslot, destination);
                    Handler12.ModifyInventorySlot(pClient.Character, oldstate, oldstate, newstate, newslot, source);
                }
                else
                {
                    //item moved to empty slot
                    pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(oldslot);
                    pClient.Character.Guild.GuildStore.GuildStorageItems.Add(newslot, source);
                    source.Slot = (sbyte)newslot;

                    Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, newslot, oldslot,null);
                    Handler12.ModifyInventorySlot(pClient.Character, newstate, oldstate, newstate, newslot, source);
                }
            }
        }
Пример #24
0
 public static void EnhancementHandler(ZoneClient client, Packet packet)
 {
     byte weapslot, stoneslot;
     if (!packet.TryReadByte(out weapslot) ||
         !packet.TryReadByte(out stoneslot))
     {
         Log.WriteLine(LogLevel.Warn, "Invalid item enhance request.");
         return;
     }
     client.Character.UpgradeItem(weapslot, stoneslot);
 }
Пример #25
0
 public static void DropItemHandler(ZoneClient client, Packet packet)
 {
     byte slot;
     if (!packet.TryReadByte(out slot))
     {
         Log.WriteLine(LogLevel.Warn, "Invalid drop request.");
         return;
     }
     client.Character.DropItemRequest(slot);
 }
Пример #26
0
        public static void ClientUnequippedItem(ZoneClient pClient, Packet pPacket)
        {
            byte sourceSlot, destinationSlot;
            if (!pPacket.TryReadByte(out sourceSlot) ||
                !pPacket.TryReadByte(out destinationSlot))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read unequip values.");
                return;
            }

            Item sourceEquip = pClient.Character.Inventory.EquippedItems.Find(e => (byte)e.ItemInfo.Slot == sourceSlot);
            //Item destinationItem = pClient.Character.Inventory.EquippedItems.Find(i => i.Slot == destinationSlot);// Item was searched from wrong place
            Item destinationItem;
            pClient.Character.Inventory.InventoryItems.TryGetValue(destinationSlot, out destinationItem);       // check if something there
            if (destinationItem != null && (destinationItem.ItemInfo.Slot == ItemSlot.None))
            {
                Log.WriteLine(LogLevel.Warn, "Equipping an item, not possible.");
                // Failed to unequip message here, no need to log it
                return;
            }

            // TODO: If source and destination types are different return.
            // Except rings and costumes (But that can be done later).
            /*
            if( sourceEquip.Type != destinationItem.Type ) {
                Log.WriteLine(LogLevel.Warn, "SourceType != DestinationType, just debugging message, not important");
                // Failed to unequip message here, no need to log it
                return;
            }
            */

            if (destinationItem != null)
            {
                Item destinationEquip = (Item)destinationItem;
                pClient.Character.SwapEquips(sourceEquip, destinationEquip);
            }
            else
            {
                if (sourceEquip == null)
                {
                    Handler12.UpdateEquipSlot(pClient.Character, destinationSlot, 0x24, 0, null);
                    return;
                }
                pClient.Character.UnequipItem(sourceEquip, destinationSlot);
            }
        }
Пример #27
0
        public static void WorldSelectHandler(LoginClient pClient, Packet pPacket)
        {
            if (!pClient.IsAuthenticated || pClient.IsTransferring)
            {
                Log.WriteLine(LogLevel.Warn, "Invalid world select request.");
                SendFailedLogin(pClient, ServerError.EXCEPTION);
                return;
            }

            byte id;
            if (!pPacket.TryReadByte(out id))
            {
                Log.WriteLine(LogLevel.Warn, "Invalid world select.");
                return;
            }
            WorldConnection world;
            if (WorldManager.Instance.Worlds.TryGetValue(id, out world))
            {
                switch (world.Status)
                {
                    case WorldStatus.MAINTENANCE:
                        Log.WriteLine(LogLevel.Warn, "{0} tried to join world in maintentance.", pClient.Username);
                        SendFailedLogin(pClient, ServerError.SERVER_MAINTENANCE);
                        return;
                    case WorldStatus.OFFLINE:
                        Log.WriteLine(LogLevel.Warn, "{0} tried to join offline world.", pClient.Username);
                        SendFailedLogin(pClient, ServerError.SERVER_MAINTENANCE);
                        return;
                    default: Log.WriteLine(LogLevel.Debug, "{0} joins world {1}", pClient.Username, world.Name); break;
                }
                string hash = System.Guid.NewGuid().ToString().Replace("-", "");
                world.SendTransferClientFromWorld(pClient.AccountID, pClient.Username, pClient.Admin, pClient.Host, hash);
                Log.WriteLine(LogLevel.Debug, "Transferring login client {0}.", pClient.Username);
                pClient.IsTransferring = true;
                SendWorldServerIP(pClient, world, hash);
            }
            else
            {
                Log.WriteLine(LogLevel.Warn, "{0} selected invalid world {1}.", pClient.Username, id);
                return;
            }
        }
Пример #28
0
 public static void MoveItemHandler(ZoneClient client, Packet packet)
 {
     byte from, oldstate, to, newstate;
     if(!packet.TryReadByte(out from) ||
         !packet.TryReadByte(out oldstate) ||
         !packet.TryReadByte(out to) ||
         !packet.TryReadByte(out newstate))
     {
             Log.WriteLine(LogLevel.Warn, "Invalid item move received.");
             return;
     }
     client.Character.MoveItem((sbyte)from, (sbyte)to);
 }
Пример #29
0
        public static void UnequipHandler(ZoneClient client, Packet packet)
        {
            ZoneCharacter character = client.Character;

            byte sourceSlot;
            sbyte destinationSlot; //not so sure about this one anymore
            if (!packet.TryReadByte(out sourceSlot) ||
                !packet.TryReadSByte(out destinationSlot))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read unequip values from {0}.", character.Name);
                return;
            }
            character.UnequipItem((ItemSlot)sourceSlot, destinationSlot);
        }
Пример #30
0
        public static void On_GameClient_AcademyChat(WorldClient Client, Packet Packet)
        {
            byte len;
            string msg;
            if (!Packet.TryReadByte(out len)
                || !Packet.TryReadString(out msg, len))
            {
                return;
            }

            if (Client.Character.IsInGuildAcademy
                || Client.Character.IsInGuild)
            {
                if (Client.Character.IsInGuildAcademy
                    && Client.Character.GuildAcademyMember.IsChatBlocked)
                {
                    using (var packet = new Packet(SH38Type.AcademyChatBlocked))
                    {
                        packet.WriteUShort(6140);

                        Client.SendPacket(packet);
                    }

                    return;
                }

                using (var packet = new Packet(SH38Type.AcademyChat))
                {
                    packet.WriteInt(Client.Character.Guild.ID);
                    packet.WriteString(Client.Character.Character.Name, 16);
                    packet.WriteByte(len);
                    packet.WriteString(msg, len);

                    Client.Character.Guild.Broadcast(packet);

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