Exemplo n.º 1
0
        public void PersonalShopChangeTitle(ChannelClient client, Packet packet)
        {
            var title = packet.GetString();

            var creature = client.GetCreatureSafe(packet.Id);
            var shop     = creature.Temp.ActivePersonalShop;

            // Check shop
            if (shop == null)
            {
                Log.Warning("PersonalShopChangeTitle: User '{0}' tried to change title of non-existent shop.", client.Account.Id);
                return;
            }

            // Check title
            if (!Math2.Between(title.Length, 0, 80))
            {
                Log.Warning("PersonalShopChangeTitle: User '{0}' tried to set invalid title '{1}'.", client.Account.Id, title);
                return;
            }

            shop.ChangeTitle(title);
        }
Exemplo n.º 2
0
        public void PersonalShopChangeDescription(ChannelClient client, Packet packet)
        {
            var description = packet.GetString();

            var creature = client.GetCreatureSafe(packet.Id);
            var shop     = creature.Temp.ActivePersonalShop;

            // Check shop
            if (shop == null)
            {
                Log.Warning("PersonalShopChangeDescription: User '{0}' tried to change description of non-existent shop.", client.Account.Id);
                return;
            }

            // Check description
            if (!Math2.Between(description.Length, 0, 80))
            {
                Log.Warning("PersonalShopChangeDescription: User '{0}' tried to set invalid description '{1}'.", client.Account.Id, description);
                return;
            }

            shop.ChangeDescription(description);
        }
Exemplo n.º 3
0
        public void ChannelLogin(ChannelClient client, Packet packet)
        {
            // Refuse connection if the ChannelServer is currently shutting down
            if (ChannelServer.Instance.ShuttingDown)
            {
                Log.Info("Refused connection because the server is currently shutting down.");
                client.Kill();
                return;
            }

            var accountId = packet.GetString();
            // [160XXX] Double account name
            {
                packet.GetString();
            }
            var sessionKey  = packet.GetLong();
            var characterId = packet.GetLong();

            // Check state
            if (client.State != ClientState.LoggingIn)
            {
                return;
            }

            // Check account
            var account = ChannelServer.Instance.Database.GetAccount(accountId);

            if (account == null || account.SessionKey != sessionKey)
            {
                // This doesn't autoban because the client is not yet "authenticated",
                // so an evil person might be able to use it to inflate someone's
                // autoban score without knowing their password
                Log.Warning("ChannelLogin handler: Invalid account ({0}) or session ({1}).", accountId, sessionKey);
                client.Kill();
                return;
            }

            // Check character
            var character = account.GetCharacterOrPetSafe(characterId) as Creature;

            // Free premium
            account.PremiumServices.EvaluateFreeServices(ChannelServer.Instance.Conf.Premium);

            client.Account     = account;
            client.Controlling = character;
            client.Creatures.Add(character.EntityId, character);
            character.Client = client;

            client.State = ClientState.LoggedIn;

            // Per-character specific initialization
            NPC npcchar = character as NPC;

            if (npcchar != null && npcchar.OnNPCLoggedIn != null)
            {
                // Seems like officials send here packet-per-packet adding equipment,
                // skills and probably other initialization info for RP NPCs
                // Long story short, a lot of StatUpdate, SkillRankUp, ItemNew, etc. packets
                npcchar.OnNPCLoggedIn();
            }

            Send.ChannelLoginR(client, character.EntityId);

            // Special login to Soul Stream for new chars and on birthdays
            if (!character.Has(CreatureStates.Initialized) || character.CanReceiveBirthdayPresent)
            {
                var npcEntityId = (character.IsCharacter ? MabiId.Nao : MabiId.Tin);
                var npc         = ChannelServer.Instance.World.GetCreature(npcEntityId);
                if (npc == null)
                {
                    Log.Warning("ChannelLogin: Intro NPC not found ({0:X16}).", npcEntityId);
                }

                character.Temp.InSoulStream = true;
                character.Activate(CreatureStates.Initialized);

                Send.SpecialLogin(character, 1000, 3200, 3200, npcEntityId);
            }
            // Log into world
            else
            {
                // Fallback for invalid region ids, like 0, dynamics, and dungeons.
                if (character.RegionId == 0 || Math2.Between(character.RegionId, 35000, 40000) || Math2.Between(character.RegionId, 10000, 11000))
                {
                    character.SetLocation(1, 12800, 38100);
                }

                character.Warp(character.GetLocation());
            }
        }
Exemplo n.º 4
0
        public void ChannelLogin(ChannelClient client, Packet packet)
        {
            var accountId = packet.GetString();
            // [160XXX] Double account name
            {
                packet.GetString();
            }
            var sessionKey  = packet.GetLong();
            var characterId = packet.GetLong();

            // Check state
            if (client.State != ClientState.LoggingIn)
            {
                return;
            }

            // Check account
            var account = ChannelServer.Instance.Database.GetAccount(accountId);

            if (account == null || account.SessionKey != sessionKey)
            {
                // This doesn't autoban because the client is not yet "authenticated",
                // so an evil person might be able to use it to inflate someone's
                // autoban score without knowing their password
                Log.Warning("ChannelLogin handler: Invalid account ({0}) or session ({1}).", accountId, sessionKey);
                client.Kill();
                return;
            }

            // Check character
            var character = account.GetCharacterOrPetSafe(characterId);

            client.Account     = account;
            client.Controlling = character;
            client.Creatures.Add(character.EntityId, character);
            character.Client = client;

            client.State = ClientState.LoggedIn;

            Send.ChannelLoginR(client, character.EntityId);

            // Log into world
            if (character.Has(CreatureStates.Initialized))
            {
                // Fallback for invalid region ids, like 0, dynamics, and dungeons.
                if (character.RegionId == 0 || Math2.Between(character.RegionId, 35000, 40000) || Math2.Between(character.RegionId, 10000, 11000))
                {
                    character.SetLocation(1, 12800, 38100);
                }

                character.Activate(CreatureStates.EverEnteredWorld);

                character.Warp(character.GetLocation());
            }
            // Special login to Soul Stream for new chars
            else
            {
                var npcEntityId = (character.IsCharacter ? MabiId.Nao : MabiId.Tin);
                var npc         = ChannelServer.Instance.World.GetCreature(npcEntityId);
                if (npc == null)
                {
                    Log.Warning("ChannelLogin: Intro NPC not found ({0}).", npcEntityId.ToString("X16"));
                }

                character.Temp.InSoulStream = true;
                character.Activate(CreatureStates.Initialized);

                Send.SpecialLogin(character, 1000, 3200, 3200, npcEntityId);
            }
        }
Exemplo n.º 5
0
        public void ChannelLogin(ChannelClient client, Packet packet)
        {
            // Refuse connection if the ChannelServer is currently shutting down
            if (ChannelServer.Instance.ShuttingDown)
            {
                Log.Info("Refused connection because the server is currently shutting down.");
                client.Kill();
                return;
            }

            var accountId = packet.GetString();
            // [160XXX] Double account name
            {
                packet.GetString();
            }
            var sessionKey     = packet.GetLong();
            var characterId    = packet.GetLong();
            var secondaryLogin = (packet.Peek() == PacketElementType.Byte && packet.GetByte() == 0x0B);

            // Check state
            if (client.State != ClientState.LoggingIn && !secondaryLogin)
            {
                return;
            }

            // Check account
            var account = ChannelServer.Instance.Database.GetAccount(accountId);

            if (account == null || account.SessionKey != sessionKey)
            {
                // This doesn't autoban because the client is not yet "authenticated",
                // so an evil person might be able to use it to inflate someone's
                // autoban score without knowing their password
                Log.Warning("ChannelLogin handler: Invalid account ({0}) or session ({1}).", accountId, sessionKey);
                client.Kill();
                return;
            }

            // Normal login if not secondary or client isn't logged
            // in yet (fallback).
            if (!secondaryLogin || client.State == ClientState.LoggingIn)
            {
                // Check character
                var character = account.GetCharacterOrPetSafe(characterId) as Creature;

                // Free premium
                account.PremiumServices.EvaluateFreeServices(ChannelServer.Instance.Conf.Premium);

                client.Account     = account;
                client.Controlling = character;
                client.Creatures.Add(character.EntityId, character);
                character.Client = client;

                client.State = ClientState.LoggedIn;

                // Update online status
                ChannelServer.Instance.Database.SetAccountLoggedIn(account.Id, true);

                var playerCreature = character as PlayerCreature;
                if (playerCreature != null)
                {
                    ChannelServer.Instance.Database.UpdateOnlineStatus(playerCreature.CreatureId, true);
                }
                ChannelServer.Instance.Database.UpdateOnlineStatus((character as PlayerCreature).CreatureId, true);

                // Response
                Send.ChannelLoginR(client, character.EntityId);

                // Special login to Soul Stream for new chars and on birthdays
                if (!character.Has(CreatureStates.Initialized) || character.CanReceiveBirthdayPresent)
                {
                    var npcEntityId = (character.IsCharacter ? MabiId.Nao : MabiId.Tin);
                    var npc         = ChannelServer.Instance.World.GetCreature(npcEntityId);
                    if (npc == null)
                    {
                        Log.Warning("ChannelLogin: Intro NPC not found ({0:X16}).", npcEntityId);
                    }

                    character.Temp.InSoulStream = true;
                    character.Activate(CreatureStates.Initialized);

                    Send.SpecialLogin(character, 1000, 3200, 3200, npcEntityId);
                }
                // Log into world
                else
                {
                    // Fallback for invalid region ids, like 0, dynamics, and dungeons.
                    if (character.RegionId == 0 || Math2.Between(character.RegionId, 35000, 40000) || Math2.Between(character.RegionId, 10000, 11000))
                    {
                        character.SetLocation(1, 12800, 38100);
                    }

                    character.Warp(character.GetLocation());
                }
            }
            else
            {
                // Try to get character from controlle creatures.
                Creature character;
                if (!client.Creatures.TryGetValue(characterId, out character))
                {
                    Log.Warning("ChannelLogin: Secondary login failed, creature not found.");
                    client.Kill();
                    return;
                }

                Send.ChannelLoginR(client, character.EntityId);

                character.Warp(character.GetLocation());
            }
        }