Example #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);
            }
        }
Example #2
0
 public void AddTradeRequest(ZoneClient pClient,ushort  MapObjectIDto)
 {
     Log.WriteLine(LogLevel.Debug, "{0} AddTradeReqest {1}", pClient.Character.Character.Name, MapObjectIDto);
        TradeReqest pRequest = new TradeReqest(pClient.Character, MapObjectIDto);
        this.TradeReqests.Add(pRequest);
        SendTradeRequest(pRequest);
 }
Example #3
0
 public static void TradeReqest(ZoneClient pClient, Packet pPacket)
 {
     ushort MapObjectID;
     if (!pPacket.TryReadUShort(out MapObjectID))
         return;
     TradeManager.Instance.AddTradeRequest(pClient, MapObjectID);
 }
Example #4
0
 public static void SendPing(ZoneClient character)
 {
     using (var packet = new Packet(SH2Type.Ping))
     {
         character.SendPacket(packet);
     }
 }
Example #5
0
 public static void TradeLock(ZoneClient pClient, Packet pPacket)
 {
     if (pClient.Character.Trade != null)
     {
         pClient.Character.Trade.TradeLock(pClient.Character);
     }
 }
Example #6
0
        public static void TradeAgree(ZoneClient pClient, Packet pPacket)
        {
            if (pClient.Character.Trade == null)
                return;

            pClient.Character.Trade.AcceptTrade(pClient.Character);
        }
Example #7
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);
            }
        }
Example #8
0
        public static void ClientReadyHandler(ZoneClient client, Packet packet)
        {
            if (client.Admin > 0)
            {
                client.Character.DropMessage("AdminLevel = {0}; ClientLoad = {1};", client.Admin, ClientManager.Instance.ZoneLoad);
            }

            Handler4.SendUsablePoints(client);

            if (!client.Character.IsDead)
            {
                // Just logged on.
                client.Character.Map.FinalizeAdd(client.Character);
            }
            else
            {
                // Reviving, not readding for this one!
                MapInfo mi;
                if (DataProvider.Instance.MapsByID.TryGetValue(client.Character.MapID, out mi))
                {
                    client.Character.State = PlayerState.Normal;
                    client.Character.Map.SendCharacterLeftMap(client.Character, false);
                    client.Character.Position.X = mi.RegenX;
                    client.Character.Position.Y = mi.RegenY;
                    client.Character.Map.SendCharacterEnteredMap(client.Character);
                }
                client.Character.SetHP(client.Character.MaxHP / 4);
            }
        }
Example #9
0
        public static void TradeBreak(ZoneClient pClient, Packet pPacket)
        {
            if (pClient.Character.Trade == null)
                return;

            pClient.Character.Trade.TradeBreak(pClient.Character);
            pClient.Character.Trade = null;
        }
Example #10
0
        public override void OnClientConnect(Socket socket)
        {
            ZoneClient client = new ZoneClient(socket);

             //  ClientManager.Instance.AddClient(client); //They register once authenticated now
            Log.WriteLine(LogLevel.Debug, "Client connected from {0}", client.Host);
               // ClientManager.Instance.AddClient(client); //They register once authenticated now
        }
Example #11
0
 public void RemoveReqest(ZoneClient pClient)
 {
     TradeReqest Request = TradeReqests.Find(r => r.MapID == pClient.Character.MapID && r.pToTradeClient.MapObjectID== pClient.Character.MapObjectID);
        if (TradeReqests.Contains(Request))
        {
        TradeReqests.Remove(Request);
        }
 }
Example #12
0
 public static void SendError(ZoneClient client, ServerError error)
 {
     using (Packet pack = new Packet(SH3Type.Error))
     {
         pack.WriteShort((byte)error);
         client.SendPacket(pack);
     }
 }
Example #13
0
 public static void BackTo(ZoneClient client, Packet packet)
 {
     using(var iacket = new InterPacket(InterHeader.ClientDisconect))
     {
         iacket.WriteString(client.Character.Character.Name, 16);
         InterServer.WorldConnector.Instance.SendPacket(iacket);
     }
 }
Example #14
0
 public void AcceptTrade(ZoneClient pClient)
 {
     TradeReqest Request = GetTradeRquestByChar(pClient.Character);
     if (Request != null)
     {
     TradeReqests.Remove(Request);
     Trade pTrade = new Trade(Request.pFromTradeClient, pClient.Character);
     }
 }
Example #15
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);
 }
Example #16
0
 public static void DeselectObjectHandler(ZoneClient client, Packet packet)
 {
     if (client.Character.SelectedObject != null)
     {
         client.Character.SelectedObject.SelectedBy.Remove(client.Character);
         client.Character.CharacterInTarget = null;
         client.Character.SelectedObject = null;
     }
 }
Example #17
0
 public static void TradeChangeMoney(ZoneClient pClient, Packet pPacket)
 {
     long money;
     if(!pPacket.TryReadLong(out money))
         return;
     if (pClient.Character.Trade != null)
     {
         pClient.Character.Trade.ChangeMoneyToTrade(pClient.Character, money);
     }
 }
Example #18
0
 public static void HandleReviveToTown(ZoneClient character, Packet packet)
 {
     if (character.Character.IsDead)
     {
         // Lets revive.
         MapInfo mi;
         if (DataProvider.Instance.MapsByID.TryGetValue(character.Character.MapID, out mi))
         {
             SendRevive(character, mi.ID, mi.RegenX, mi.RegenY); // Will resend the loaded packet
         }
     }
 }
Example #19
0
        public static void MasterRequestAcceptCoper(ZoneClient client, Packet pPacket)
        {
            client.Character.Character.ReviveCoper = 0;
             InterServer.InterHandler.SendReciveCoper(client.Character.Character.Name, client.Character.Character.ReviveCoper,true);
             using(var packet = new Packet(37,65))
             {

                packet.WriteUShort(7272);//unk
                packet.WriteLong(client.Character.RecviveCoper);
                client.SendPacket(packet);
             }
        }
Example #20
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);
     }
 }
Example #21
0
 public static void BySPStoneHandler(ZoneClient client, Packet packet)
 {
     short Amount;
     if (packet.TryReadShort(out Amount))
     {
         client.Character.ChangeMoney(client.Character.Character.Money -= client.Character.BaseStats.PriceSPStone);
         short Am = Amount += client.Character.StonesSP;
         client.Character.StonesHP = Am;
         using (var p = new Packet(SH20Type.ChangeSPStones))
         {
             p.WriteShort(Am);
             client.SendPacket(p);
         }
     }
 }
Example #22
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);
        }
Example #23
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;
        }
Example #24
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);
                }
            }
        }
Example #25
0
        public static void UseSPStoneHandler(ZoneClient client, Packet packet)
        {
            if (client.Character.StonesSP == 0)
            {
                using (var p = new Packet(SH20Type.ErrorUseStone))
                {
                    client.SendPacket(p);
                }
            }
            else
            {
                client.Character.HealSP((uint)client.Character.BaseStats.SoulSP);

                using (var p = new Packet(SH20Type.StartSPStoneCooldown))
                {
                    client.SendPacket(p);
                }
            }
        }
Example #26
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);
        }
Example #27
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;
             }
         }
     }
 }
Example #28
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);
            }
        }
Example #29
0
        public bool AddClient(ZoneClient client)
        {
            ClientManagerMutex.WaitOne();
            try
            {

                if (client.Character.Character == null)
                {
                    Log.WriteLine(LogLevel.Warn, "ClientManager trying to add character = null.", client.Username);
                    return false;
                }
                else if (clientsByName.ContainsKey(client.Character.Character.Name))
                {
                    Log.WriteLine(LogLevel.Warn, "Character {0} is already registered to client manager!", client.Character.Character.Name);
                    return false;
                }
                else
                {
                    if (!this.clientsByID.TryAdd(client.Character.Character.ID, client))
                    {
                        Log.WriteLine(LogLevel.Warn, "Could not add client to idlist!");
                        return false;
                    }
                    if (!clientsByName.TryAdd(client.Character.Character.Name, client))
                    {
                        Log.WriteLine(LogLevel.Warn, "Could not add client to list!");
                        return false;
                    }
                }
                return true;
            }
            finally
            {
                ClientManagerMutex.ReleaseMutex();
            }
        }
Example #30
0
 private void SendTradeLock(ZoneClient pClient)
 {
     using (var packet = new Packet(SH19Type.SendTradeLock))
     {
         pClient.SendPacket(packet);
     }
 }