Ejemplo n.º 1
0
 public void SendBackNext(string Message)
 {
     mLines.Add(new NpcUsedLines(1, Message));
     mState++;
     mRealState++;
     NpcPacket.SendNPCChatTextSimple(mCharacter, mID, Message, true, true);
 }
Ejemplo n.º 2
0
 public void SendOK(string Message)
 {
     mLines.Add(new NpcUsedLines(3, Message));
     mState++;
     mRealState++;
     NpcPacket.SendNPCChatTextSimple(mCharacter, mID, Message, false, false);
 }
Ejemplo n.º 3
0
        public void SendNextMessage()
        {
            //Program.MainForm.LogAppend("SENDNEXTMESSAGE START");
            if (mLines.Count == mState + 1)
            {
                HandleThing(mRealState, 0, "", 0);
            }
            else
            {
                mState++;
                if (mLines.Count < mState)
                {
                    return;
                }

                WaitingForResponse = true;
                NpcUsedLines line = mLines[mState];
                switch (line.mWhat)
                {
                case 0: NpcPacket.SendNPCChatTextSimple(mCharacter, mID, line.mText, false, true); break;

                case 1: NpcPacket.SendNPCChatTextSimple(mCharacter, mID, line.mText, true, true); break;

                case 2: NpcPacket.SendNPCChatTextSimple(mCharacter, mID, line.mText, true, false); break;

                case 3: NpcPacket.SendNPCChatTextSimple(mCharacter, mID, line.mText, false, false); break;

                default: Stop(); return;
                }
            }
        }
Ejemplo n.º 4
0
        public static void HandleNPCChat(Character chr, Packet packet)
        {
            int npcId = packet.ReadInt();
            var Npc   = chr.Field.GetNPC(npcId);

            if (chr.AssertForHack(!chr.CanAttachAdditionalProcess, "Tried to chat to npc while not able to attach additional process"))
            {
                InventoryPacket.NoChange(chr);
                return;
            }

            // Npc doesnt exist
            if (Npc == null)
            {
                InventoryPacket.NoChange(chr);
                return;
            }

            int RealID = Npc.ID;

            if (!DataProvider.NPCs.TryGetValue(RealID, out NPCData npc))
            {
                return;
            }

            if (npc.Shop.Count > 0)
            {
                // It's a shop!
                chr.ShopNPCID = RealID;
                NpcPacket.SendShowNPCShop(chr, RealID);
            }
            else if (npc.Trunk > 0)
            {
                chr.TrunkNPCID = RealID;
                StoragePacket.SendShowStorage(chr, chr.TrunkNPCID);
            }
            else
            {
                Action <string> errorHandlerFnc = null;
                if (chr.IsGM)
                {
                    errorHandlerFnc = (script) =>
                    {
                        MessagePacket.SendNotice("Error compiling script '" + script + "'!", chr);
                    };
                }

                INpcScript NPC = null;
                if (NPC == null && npc.Quest != null)
                {
                    NPC = Server.Instance.TryGetOrCompileScript(npc.Quest, errorHandlerFnc);
                }
                if (NPC == null)
                {
                    NPC = Server.Instance.TryGetOrCompileScript(npc.ID.ToString(), errorHandlerFnc);
                }

                NpcChatSession.Start(RealID, NPC, chr);
            }
        }
Ejemplo n.º 5
0
        public void SendPreviousMessage()
        {
            if (mState == 0 || mLines.Count == 0)
            {
                return;
            }
            mState--;
            if (mLines.Count < mState)
            {
                return;
            }

            WaitingForResponse = true;
            NpcUsedLines line = mLines[mState];

            switch (line.mWhat)
            {
            case 0: NpcPacket.SendNPCChatTextSimple(mCharacter, mID, line.mText, false, true); break;

            case 1: NpcPacket.SendNPCChatTextSimple(mCharacter, mID, line.mText, true, true); break;

            case 2: NpcPacket.SendNPCChatTextSimple(mCharacter, mID, line.mText, true, false); break;

            case 3: NpcPacket.SendNPCChatTextSimple(mCharacter, mID, line.mText, false, false); break;

            default: Stop(); return;
            }
        }
Ejemplo n.º 6
0
 public void SendNext(string Message)
 {
     // First line, always clear
     mLines.Clear();
     mLines.Add(new NpcUsedLines(0, Message));
     mState = 0;
     mRealState++;
     NpcPacket.SendNPCChatTextSimple(mCharacter, mID, Message, false, true);
 }
Ejemplo n.º 7
0
        public void AskYesNo(string Message)
        {
            if (mCharacter.NpcSession == null)
            {
                throw new Exception("NpcSession has been nulled already!!!!");
            }

            mState = 0;
            mRealState++;
            WaitingForResponse = true;
            NpcPacket.SendNPCChatTextYesNo(mCharacter, mID, Message);
        }
Ejemplo n.º 8
0
        public void AskText(string Message, string Default, short MinLength, short MaxLength)
        {
            if (mCharacter.NpcSession == null)
            {
                throw new Exception("NpcSession has been nulled already!!!!");
            }

            mState = 0;
            mRealState++;
            WaitingForResponse = true;
            NpcPacket.SendNPCChatTextRequestText(mCharacter, mID, Message, Default, MinLength, MaxLength);
        }
Ejemplo n.º 9
0
        public void AskStyle(string Message, List <int> Values)
        {
            if (mCharacter.NpcSession == null)
            {
                throw new Exception("NpcSession has been nulled already!!!!");
            }

            mState = 0;
            mRealState++;
            WaitingForResponse = true;
            NpcPacket.SendNPCChatTextRequestStyle(mCharacter, mID, Message, Values);
        }
Ejemplo n.º 10
0
        public void AskInteger(string Message, int Default, int MinValue, int MaxValue)
        {
            if (mCharacter.NpcSession == null)
            {
                throw new Exception("NpcSession has been nulled already!!!!");
            }

            mState = 0;
            mRealState++;
            WaitingForResponse = true;
            NpcPacket.SendNPCChatTextRequestInteger(mCharacter, mID, Message, Default, MinValue, MaxValue);
        }
Ejemplo n.º 11
0
        public void SendBackOK(string Message)
        {
            if (mCharacter.NpcSession == null)
            {
                throw new Exception("NpcSession has been nulled already!!!!");
            }

            mLines.Add(new NpcUsedLines(2, Message));
            mState++;
            mRealState++;
            WaitingForResponse = true;
            NpcPacket.SendNPCChatTextSimple(mCharacter, mID, Message, true, false);
        }
Ejemplo n.º 12
0
        public void SendNext(string Message)
        {
            if (mCharacter.NpcSession == null)
            {
                throw new Exception("NpcSession has been nulled already!!!!");
            }

            // First line, always clear
            mLines.Clear();
            mLines.Add(new NpcUsedLines(0, Message));
            mState = 0;
            mRealState++;
            WaitingForResponse = true;
            NpcPacket.SendNPCChatTextSimple(mCharacter, mID, Message, false, true);
        }
Ejemplo n.º 13
0
        public override void AC_OnPacketInbound(Packet packet)
        {
            ClientMessages header = 0;

            try
            {
                header = (ClientMessages)packet.ReadByte();

                if (!Loaded || Player?.Character == null)
                {
                    switch (header)
                    {
                    case ClientMessages.MIGRATE_IN:
                        OnPlayerLoad(packet);
                        break;     //updated
                    }
                }
                // Block packets as we are migrating
                else if (Server.Instance.InMigration == false || Server.Instance.IsNewServerInMigration)
                {
                    var character = Player.Character;

                    if (logPackets.Contains(header))
                    {
                        PacketLog.ReceivedPacket(packet, (byte)header, Server.Instance.Name, IP);
                    }

                    switch (header)
                    {
                    case ClientMessages.ENTER_PORTAL:
                        MapPacket.OnEnterPortal(packet, character);
                        break;

                    case ClientMessages.CHANGE_CHANNEL:
                        OnChangeChannel(character, packet);
                        break;

                    case ClientMessages.ENTER_CASH_SHOP:
                        OnEnterCashShop(character);
                        break;

                    case ClientMessages.MOVE_PLAYER:
                        MapPacket.HandleMove(character, packet);
                        break;

                    case ClientMessages.SIT_REQUEST:
                        MapPacket.HandleSitChair(character, packet);
                        break;

                    case ClientMessages.ENTER_TOWN_PORTAL:
                        MapPacket.HandleDoorUse(character, packet);
                        break;

                    case ClientMessages.CLOSE_RANGE_ATTACK:
                        AttackPacket.HandleMeleeAttack(character, packet);
                        break;

                    case ClientMessages.RANGED_ATTACK:
                        AttackPacket.HandleRangedAttack(character, packet);
                        break;

                    case ClientMessages.MAGIC_ATTACK:
                        AttackPacket.HandleMagicAttack(character, packet);
                        break;

                    case ClientMessages.TAKE_DAMAGE:
                        CharacterStatsPacket.HandleCharacterDamage(character, packet);
                        break;

                    case ClientMessages.CHAT:
                        MessagePacket.HandleChat(character, packet);
                        break;

                    case ClientMessages.GROUP_MESSAGE:
                        MessagePacket.HandleSpecialChat(character, packet);
                        break;

                    case ClientMessages.WHISPER:
                        MessagePacket.HandleCommand(character, packet);
                        break;

                    case ClientMessages.EMOTE:
                        MapPacket.SendEmotion(character, packet.ReadInt());
                        break;

                    case ClientMessages.NPC_TALK:
                        MapPacket.HandleNPCChat(character, packet);
                        break;

                    case ClientMessages.NPC_TALK_MORE:
                        NpcPacket.HandleNPCChat(character, packet);
                        break;

                    case ClientMessages.SHOP_ACTION:
                        NpcPacket.HandleNPCShop(character, packet);
                        break;

                    case ClientMessages.STORAGE_ACTION:
                        StoragePacket.HandleStorage(character, packet);
                        break;

                    case ClientMessages.ITEM_MOVE:
                        InventoryPacket.HandleInventoryPacket(character, packet);
                        break;

                    case ClientMessages.ITEM_USE:
                        InventoryPacket.HandleUseItemPacket(character, packet);
                        break;

                    case ClientMessages.SUMMON_BAG_USE:
                        InventoryPacket.HandleUseSummonSack(character, packet);
                        break;

                    case ClientMessages.CASH_ITEM_USE:
                        CashPacket.HandleCashItem(character, packet);
                        break;

                    case ClientMessages.RETURN_SCROLL_USE:
                        InventoryPacket.HandleUseReturnScroll(character, packet);
                        break;

                    case ClientMessages.SCROLL_USE:
                        InventoryPacket.HandleScrollItem(character, packet);
                        break;

                    case ClientMessages.DISTRIBUTE_AP:
                        CharacterStatsPacket.HandleStats(character, packet);
                        break;

                    case ClientMessages.HEAL_OVER_TIME:
                        CharacterStatsPacket.HandleHeal(character, packet);
                        break;

                    case ClientMessages.DISTRIBUTE_SP:
                        SkillPacket.HandleAddSkillLevel(character, packet);
                        break;

                    case ClientMessages.PREPARE_SKILL:
                        SkillPacket.HandlePrepareSkill(character, packet);
                        break;

                    case ClientMessages.GIVE_BUFF:
                        SkillPacket.HandleUseSkill(character, packet);
                        break;

                    case ClientMessages.CANCEL_BUFF:
                        SkillPacket.HandleStopSkill(character, packet);
                        break;

                    case ClientMessages.DROP_MESOS:
                        DropPacket.HandleDropMesos(character, packet.ReadInt());
                        break;

                    case ClientMessages.GIVE_FAME:
                        FamePacket.HandleFame(character, packet);
                        break;

                    case ClientMessages.CHAR_INFO_REQUEST:
                        MapPacket.SendPlayerInfo(character, packet);
                        break;

                    case ClientMessages.SPAWN_PET:
                        PetsPacket.HandleSpawnPet(character, packet.ReadShort());
                        break;

                    case ClientMessages.SUMMON_MOVE:
                        MapPacket.HandleSummonMove(character, packet);
                        break;

                    case ClientMessages.SUMMON_ATTACK:
                        AttackPacket.HandleSummonAttack(character, packet);
                        break;

                    case ClientMessages.SUMMON_DAMAGED:
                        MapPacket.HandleSummonDamage(character, packet);
                        break;

                    case ClientMessages.MOB_MOVE:
                        MobPacket.HandleMobControl(character, packet);
                        break;

                    case ClientMessages.NPC_ANIMATE:
                        MapPacket.HandleNPCAnimation(character, packet);
                        break;

                    case ClientMessages.PET_MOVE: PetsPacket.HandleMovePet(character, packet); break;

                    case ClientMessages.PET_INTERACTION: PetsPacket.HandleInteraction(character, packet); break;

                    case ClientMessages.PET_ACTION: PetsPacket.HandlePetAction(character, packet); break;

                    case ClientMessages.FIELD_CONTIMOVE_STATE:
                        MapPacket.OnContiMoveState(character, packet);
                        break;

                    case ClientMessages.DROP_PICK_UP:
                        DropPacket.HandlePickupDrop(character, packet);
                        break;

                    case ClientMessages.MESSENGER:
                        MessengerHandler.HandleMessenger(character, packet);
                        break;

                    case ClientMessages.MINI_ROOM_OPERATION:
                        MiniRoomPacket.HandlePacket(character, packet);
                        break;

                    case ClientMessages.FRIEND_OPERATION:
                        BuddyHandler.HandleBuddy(character, packet);
                        break;

                    case ClientMessages.PARTY_OPERATION:
                        PartyHandler.HandleParty(character, packet);
                        break;

                    case ClientMessages.DENY_PARTY_REQUEST:
                        PartyHandler.HandleDecline(character, packet);
                        break;

                    case ClientMessages.REACTOR_HIT:
                        ReactorPacket.HandleReactorHit(character, packet);
                        break;

                    case ClientMessages.REPORT_USER:
                        MiscPacket.ReportPlayer(character, packet);
                        break;


                    //this is a garbage opcode that i use when doing janky client packet workarounds. This is where packets go to die.
                    case ClientMessages.JUNK:
                        Program.MainForm.LogDebug("received junk packet");
                        break;

                    // eh.. ignore?
                    // Happens when one of the following buffs are set:
                    // Stun, Poison, Seal, Darkness, Weakness, Curse
                    // Maybe patch out of the client
                    case ClientMessages.CHARACTER_IS_DEBUFFED: break;

                    // TODO: Implement???
                    case ClientMessages.MOB_APPLY_CONTROL: break;

                    case ClientMessages.CLIENT_HASH: break;

                    case ClientMessages.PONG:
                        // Make sure we update the player online thing
                        RedisBackend.Instance.SetPlayerOnline(
                            character.UserID,
                            Server.Instance.GetOnlineId()
                            );

                        // Cleanup expired items
                        character.Inventory.CheckExpired();
                        break;

                    default:
                        if (character.Field.HandlePacket(character, packet, header) == false)
                        {
                            Program.MainForm.LogAppend(
                                "[{0}] Unknown packet received! " + packet,
                                header
                                );
                        }

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Program.MainForm.LogAppend($"---- ERROR ----\r\n{ex}");
                Program.MainForm.LogAppend($"Packet: {packet}");
                FileWriter.WriteLine(@"etclog\ExceptionCatcher.log", "[Game Server " + Server.Instance.ID + "][" + DateTime.Now + "] Exception caught: " + ex, true);
                //Disconnect();
            }


#if DEBUG
            if (packet.Length != packet.Position)
            {
                var packetStr = packet.ToString();
                packetStr = packetStr.Substring(0, packet.Position * 3 - 1) + "-x-" + packetStr.Substring(packet.Position * 3);

                log.Debug($"Did not read full message in packet: {header} {packetStr}");
            }
#endif
        }
Ejemplo n.º 14
0
 public void AskStyle(string Message, List <int> Values)
 {
     mState = 0;
     mRealState++;
     NpcPacket.SendNPCChatTextRequestStyle(mCharacter, mID, Message, Values);
 }
Ejemplo n.º 15
0
 public void AskInteger(string Message, int Default, int MinValue, int MaxValue)
 {
     mState = 0;
     mRealState++;
     NpcPacket.SendNPCChatTextRequestInteger(mCharacter, mID, Message, Default, MinValue, MaxValue);
 }
Ejemplo n.º 16
0
 public void AskText(string Message, string Default, short MinLenght, short MaxLength)
 {
     mState = 0;
     mRealState++;
     NpcPacket.SendNPCChatTextRequestText(mCharacter, mID, Message, Default, MinLenght, MaxLength);
 }
Ejemplo n.º 17
0
 public void AskYesNo(string Message)
 {
     mState = 0;
     mRealState++;
     NpcPacket.SendNPCChatTextYesNo(mCharacter, mID, Message);
 }