private static void Register(Packet inPacket)
        {
            ServerRegsitrationResponse response = (ServerRegsitrationResponse)inPacket.ReadByte();

            switch (response)
            {
            case ServerRegsitrationResponse.Valid:
            {
                WvsGame.WorldID        = inPacket.ReadByte();
                WvsGame.WorldName      = inPacket.ReadString();
                WvsGame.TickerMessage  = inPacket.ReadString();
                WvsGame.ChannelID      = inPacket.ReadByte();
                WvsGame.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, inPacket.ReadUShort());
                WvsGame.Listen();

                WvsGame.AllowMultiLeveling = inPacket.ReadBool();
                Log.Inform("Characters will {0}be able to continuously level-up.", WvsGame.AllowMultiLeveling ? "" : "not ");

                WvsGame.ExperienceRate           = inPacket.ReadInt();
                WvsGame.QuestExperienceRate      = inPacket.ReadInt();
                WvsGame.PartyQuestExperienceRate = inPacket.ReadInt();
                WvsGame.MesoRate = inPacket.ReadInt();
                WvsGame.DropRate = inPacket.ReadInt();
                Log.Inform("Rates: \n ExpRate: {0}x \n QuestExpRate: {1}x \n PartyQuestExpRate: {2}x \n MesoRate: {3}x \n DropRate: {4}x",
                           WvsGame.ExperienceRate,
                           WvsGame.QuestExperienceRate,
                           WvsGame.PartyQuestExperienceRate,
                           WvsGame.MesoRate,
                           WvsGame.DropRate);

                Log.SkipLine();
                Log.Success("Registered Channel: {0}-{2} on World: {0}-{1}.", WvsGame.WorldName, WvsGame.WorldID, (WvsGame.ChannelID + 1));
                Log.SkipLine();
            }
            break;

            case ServerRegsitrationResponse.InvalidType:
                break;

            case ServerRegsitrationResponse.InvalidCode:
                break;

            case ServerRegsitrationResponse.Full:
                break;

            default:
            {
                Log.SkipLine();
                Log.Error("Unable to register as Channel Server: {0}", ServerRegistrationResponseResolver.Explain(response));
                Log.SkipLine();

                WvsGame.Stop();
            }
            break;
            }

            WvsGame.CenterConnectionDone.Set();
        }
Beispiel #2
0
        public static void Main()
        {
            try
            {
                WvsGame.CenterConnection = new CenterServer(new IPEndPoint(
                                                                Settings.GetIPAddress("Center/IP"),
                                                                Settings.GetInt("Center/Port")),
                                                            Settings.GetString("Center/SecurityCode"));

                WvsGame.CenterConnection.Loop();
            }
            catch (Exception e)
            {
                Log.Error("Server connection failed: \n{0}", e.Message);

                WvsGame.Stop();
            }
            finally
            {
                WvsGame.CenterConnectionDone.Set();
            }
        }
Beispiel #3
0
 protected override void Terminate()
 {
     WvsGame.Stop();
 }
Beispiel #4
0
 protected override void StopServer()
 {
     WvsGame.Stop();
 }
Beispiel #5
0
        // TODO: Items validation.
        private void CreateCharacter(Packet inPacket)
        {
            int     accountID = inPacket.ReadInt();
            string  name      = inPacket.ReadString();
            JobType jobType   = (JobType)inPacket.ReadInt();
            int     face      = inPacket.ReadInt();
            int     hair      = inPacket.ReadInt();
            int     hairColor = inPacket.ReadInt();
            byte    skin      = (byte)inPacket.ReadInt();
            int     topID     = inPacket.ReadInt();
            int     bottomID  = inPacket.ReadInt();
            int     shoesID   = inPacket.ReadInt();
            int     weaponID  = inPacket.ReadInt();
            Gender  gender    = (Gender)inPacket.ReadByte();

            bool error = false;

            if (ValidCharacterName(name))
            {
                switch (gender) // TODO: these need error catching with item info.
                {
                case Gender.Male:
                    if (!DataProvider.CreationData.MaleSkins.Any(x => x.Item1 == jobType && x.Item2 == skin) ||
                        !DataProvider.CreationData.MaleFaces.Any(x => x.Item1 == jobType && x.Item2 == face) ||
                        !DataProvider.CreationData.MaleHairs.Any(x => x.Item1 == jobType && x.Item2 == hair) ||
                        !DataProvider.CreationData.MaleHairColors.Any(x => x.Item1 == jobType && x.Item2 == hairColor) ||
                        !DataProvider.CreationData.MaleTops.Any(x => x.Item1 == jobType && x.Item2 == topID) ||
                        !DataProvider.CreationData.MaleBottoms.Any(x => x.Item1 == jobType && x.Item2 == bottomID) ||
                        !DataProvider.CreationData.MaleShoes.Any(x => x.Item1 == jobType && x.Item2 == shoesID) ||
                        !DataProvider.CreationData.MaleWeapons.Any(x => x.Item1 == jobType && x.Item2 == weaponID))
                    {
                        error = true;
                    }
                    break;

                case Gender.Female:
                    if (!DataProvider.CreationData.FemaleSkins.Any(x => x.Item1 == jobType && x.Item2 == skin) ||
                        !DataProvider.CreationData.FemaleFaces.Any(x => x.Item1 == jobType && x.Item2 == face) ||
                        !DataProvider.CreationData.FemaleHairs.Any(x => x.Item1 == jobType && x.Item2 == hair) ||
                        !DataProvider.CreationData.FemaleHairColors.Any(x => x.Item1 == jobType && x.Item2 == hairColor) ||
                        !DataProvider.CreationData.FemaleTops.Any(x => x.Item1 == jobType && x.Item2 == topID) ||
                        !DataProvider.CreationData.FemaleBottoms.Any(x => x.Item1 == jobType && x.Item2 == bottomID) ||
                        !DataProvider.CreationData.FemaleShoes.Any(x => x.Item1 == jobType && x.Item2 == shoesID) ||
                        !DataProvider.CreationData.FemaleWeapons.Any(x => x.Item1 == jobType && x.Item2 == weaponID))
                    {
                        error = true;
                    }
                    break;

                default:
                    error = false;
                    break;
                }
            }

            if (error)
            {
                Log.SkipLine();
                Log.Error("Failed to load character items on character creation!");
                Log.SkipLine();

                WvsGame.Stop();
            }

            Character character = new Character
            {
                AccountID     = accountID,
                WorldID       = WvsGame.WorldID,
                Name          = name,
                Gender        = gender,
                Skin          = skin,
                Face          = face,
                Hair          = hair + hairColor,
                Level         = 1,
                Job           = jobType == JobType.Cygnus ? Job.Noblesse : jobType == JobType.Explorer ? Job.Beginner : Job.Aran,
                Strength      = 12,
                Dexterity     = 5,
                Intelligence  = 4,
                Luck          = 4,
                MaxHealth     = 50,
                MaxMana       = 5,
                Health        = 50,
                Mana          = 5,
                AbilityPoints = 0,
                SkillPoints   = 0,
                Experience    = 0,
                Fame          = 0,
                Map           = DataProvider.Maps[jobType == JobType.Cygnus ? 130030000 : jobType == JobType.Explorer ? 10000 : 914000000],
                SpawnPoint    = 0,
                Meso          = 0
            };

            character.Items.Add(new Item(topID, equipped: true));
            character.Items.Add(new Item(bottomID, equipped: true));
            character.Items.Add(new Item(shoesID, equipped: true));
            character.Items.Add(new Item(weaponID, equipped: true));
            character.Items.Add(new Item(jobType == JobType.Cygnus ? 4161047 : jobType == JobType.Explorer ? 4161001 : 4161048), forceGetSlot: true);

            character.Keymap.Add(new Shortcut(KeymapKey.One, KeymapAction.AllChat));
            character.Keymap.Add(new Shortcut(KeymapKey.Two, KeymapAction.PartyChat));
            character.Keymap.Add(new Shortcut(KeymapKey.Three, KeymapAction.BuddyChat));
            character.Keymap.Add(new Shortcut(KeymapKey.Four, KeymapAction.GuildChat));
            character.Keymap.Add(new Shortcut(KeymapKey.Five, KeymapAction.AllianceChat));
            character.Keymap.Add(new Shortcut(KeymapKey.Six, KeymapAction.SpouseChat));
            character.Keymap.Add(new Shortcut(KeymapKey.Q, KeymapAction.QuestMenu));
            character.Keymap.Add(new Shortcut(KeymapKey.W, KeymapAction.WorldMap));
            character.Keymap.Add(new Shortcut(KeymapKey.E, KeymapAction.EquipmentMenu));
            character.Keymap.Add(new Shortcut(KeymapKey.R, KeymapAction.BuddyList));
            character.Keymap.Add(new Shortcut(KeymapKey.I, KeymapAction.ItemMenu));
            character.Keymap.Add(new Shortcut(KeymapKey.O, KeymapAction.PartySearch));
            character.Keymap.Add(new Shortcut(KeymapKey.P, KeymapAction.PartyList));
            character.Keymap.Add(new Shortcut(KeymapKey.BracketLeft, KeymapAction.Shortcut));
            character.Keymap.Add(new Shortcut(KeymapKey.BracketRight, KeymapAction.QuickSlot));
            character.Keymap.Add(new Shortcut(KeymapKey.LeftCtrl, KeymapAction.Attack));
            character.Keymap.Add(new Shortcut(KeymapKey.S, KeymapAction.AbilityMenu));
            character.Keymap.Add(new Shortcut(KeymapKey.F, KeymapAction.FamilyList));
            character.Keymap.Add(new Shortcut(KeymapKey.G, KeymapAction.GuildList));
            character.Keymap.Add(new Shortcut(KeymapKey.H, KeymapAction.WhisperChat));
            character.Keymap.Add(new Shortcut(KeymapKey.K, KeymapAction.SkillMenu));
            character.Keymap.Add(new Shortcut(KeymapKey.L, KeymapAction.QuestHelper));
            character.Keymap.Add(new Shortcut(KeymapKey.Semicolon, KeymapAction.Medal));
            character.Keymap.Add(new Shortcut(KeymapKey.Quote, KeymapAction.ExpandChat));
            character.Keymap.Add(new Shortcut(KeymapKey.Backtick, KeymapAction.CashShop));
            character.Keymap.Add(new Shortcut(KeymapKey.Backslash, KeymapAction.SetKey));
            character.Keymap.Add(new Shortcut(KeymapKey.Z, KeymapAction.PickUp));
            character.Keymap.Add(new Shortcut(KeymapKey.X, KeymapAction.Sit));
            character.Keymap.Add(new Shortcut(KeymapKey.C, KeymapAction.Messenger));
            character.Keymap.Add(new Shortcut(KeymapKey.B, KeymapAction.MonsterBook));
            character.Keymap.Add(new Shortcut(KeymapKey.M, KeymapAction.MiniMap));
            character.Keymap.Add(new Shortcut(KeymapKey.LeftAlt, KeymapAction.Jump));
            character.Keymap.Add(new Shortcut(KeymapKey.Space, KeymapAction.NpcChat));
            character.Keymap.Add(new Shortcut(KeymapKey.F1, KeymapAction.Cockeyed));
            character.Keymap.Add(new Shortcut(KeymapKey.F2, KeymapAction.Happy));
            character.Keymap.Add(new Shortcut(KeymapKey.F3, KeymapAction.Sarcastic));
            character.Keymap.Add(new Shortcut(KeymapKey.F4, KeymapAction.Crying));
            character.Keymap.Add(new Shortcut(KeymapKey.F5, KeymapAction.Outraged));
            character.Keymap.Add(new Shortcut(KeymapKey.F6, KeymapAction.Shocked));
            character.Keymap.Add(new Shortcut(KeymapKey.F7, KeymapAction.Annoyed));

            character.Save();

            using (Packet outPacket = new Packet(InteroperabilityOperationCode.CharacterCreationResponse))
            {
                outPacket.WriteInt(accountID);
                outPacket.WriteBytes(character.ToByteArray());

                this.Send(outPacket);
            }
        }
        // TODO: Items validation.
        private void CreateCharacter(Packet inPacket)
        {
            int    accountID = inPacket.ReadInt();
            string name      = inPacket.ReadString();

            CharacterConstants.JobType jobType = (CharacterConstants.JobType)inPacket.ReadInt();
            int  face      = inPacket.ReadInt();
            int  hair      = inPacket.ReadInt();
            int  hairColor = inPacket.ReadInt();
            byte skin      = (byte)inPacket.ReadInt();
            int  topID     = inPacket.ReadInt();
            int  bottomID  = inPacket.ReadInt();
            int  shoesID   = inPacket.ReadInt();
            int  weaponID  = inPacket.ReadInt();

            CharacterConstants.Gender gender = (CharacterConstants.Gender)inPacket.ReadByte();

            bool error = false;

            if (ValidCharacterName(name))
            {
                switch (gender) // TODO: these need error catching with item info.
                {
                case CharacterConstants.Gender.Male:
                    if (!DataProvider.CreationData.MaleSkins.Any(x => x.Item1 == jobType && x.Item2 == skin) ||
                        !DataProvider.CreationData.MaleFaces.Any(x => x.Item1 == jobType && x.Item2 == face) ||
                        !DataProvider.CreationData.MaleHairs.Any(x => x.Item1 == jobType && x.Item2 == hair) ||
                        !DataProvider.CreationData.MaleHairColors.Any(x => x.Item1 == jobType && x.Item2 == hairColor) ||
                        !DataProvider.CreationData.MaleTops.Any(x => x.Item1 == jobType && x.Item2 == topID) ||
                        !DataProvider.CreationData.MaleBottoms.Any(x => x.Item1 == jobType && x.Item2 == bottomID) ||
                        !DataProvider.CreationData.MaleShoes.Any(x => x.Item1 == jobType && x.Item2 == shoesID) ||
                        !DataProvider.CreationData.MaleWeapons.Any(x => x.Item1 == jobType && x.Item2 == weaponID))
                    {
                        error = true;
                    }
                    break;

                case CharacterConstants.Gender.Female:
                    if (!DataProvider.CreationData.FemaleSkins.Any(x => x.Item1 == jobType && x.Item2 == skin) ||
                        !DataProvider.CreationData.FemaleFaces.Any(x => x.Item1 == jobType && x.Item2 == face) ||
                        !DataProvider.CreationData.FemaleHairs.Any(x => x.Item1 == jobType && x.Item2 == hair) ||
                        !DataProvider.CreationData.FemaleHairColors.Any(x => x.Item1 == jobType && x.Item2 == hairColor) ||
                        !DataProvider.CreationData.FemaleTops.Any(x => x.Item1 == jobType && x.Item2 == topID) ||
                        !DataProvider.CreationData.FemaleBottoms.Any(x => x.Item1 == jobType && x.Item2 == bottomID) ||
                        !DataProvider.CreationData.FemaleShoes.Any(x => x.Item1 == jobType && x.Item2 == shoesID) ||
                        !DataProvider.CreationData.FemaleWeapons.Any(x => x.Item1 == jobType && x.Item2 == weaponID))
                    {
                        error = true;
                    }
                    break;

                case CharacterConstants.Gender.Both:
                    break;

                case CharacterConstants.Gender.Unset:
                    break;

                default:
                    break;
                }
            }

            if (error)
            {
                Log.SkipLine();
                Log.Error("Failed to load character items on character creation!");
                Log.SkipLine();

                WvsGame.Stop();
            }

            Character character = new Character
            {
                AccountID = accountID,
                WorldID   = WvsGame.WorldID,
                Name      = name,

                Appearance =
                {
                    Gender = gender,
                    Skin   = skin,
                    Face   = face,
                    Hair   = hair + hairColor
                },

                Stats =
                {
                    Level         =  1, Experience  = 0,
                    MaxHealth     = 50, MaxMana     = 5,
                    Health        = 50, Mana        = 5,
                    AbilityPoints =  0, SkillPoints = 0,
                    Strength      = 12, Dexterity   = 5,
                    Intelligence  =  4, Luck        = 4,
                    Fame          =  0, Meso        = 0
                },

                Jobs =
                {
                    Job = jobType == CharacterConstants.JobType.Cygnus ? CharacterConstants.Job.Noblesse
                      : jobType == CharacterConstants.JobType.Explorer ? CharacterConstants.Job.Beginner
                      : CharacterConstants.Job.Aran
                },

                Map = DataProvider.Maps[
                    jobType == CharacterConstants.JobType.Cygnus ? 130030000 :
                    jobType == CharacterConstants.JobType.Explorer ? 10000 : 914000000],
                SpawnPoint = 0,
            };

            character.Items.AddItemToInventory(new Item(topID, equipped: true));
            character.Items.AddItemToInventory(new Item(bottomID, equipped: true));
            character.Items.AddItemToInventory(new Item(shoesID, equipped: true));
            character.Items.AddItemToInventory(new Item(weaponID, equipped: true));

            switch (jobType)
            {
            case CharacterConstants.JobType.Cygnus:
                character.Items.AddItemToInventory(new Item(4161047));     // Noblesse Guide
                break;

            case CharacterConstants.JobType.Explorer:
                character.Items.AddItemToInventory(new Item(4161001));     // Beginner's Guide
                break;

            case CharacterConstants.JobType.Aran:                      // Legend
                character.Items.AddItemToInventory(new Item(4161048)); // Legend's Guide
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            character.Keymap.InitiateDefaultKeymap();

            character.Save();

            using (Packet outPacket = new Packet(InteroperabilityOperationCode.CharacterCreationResponse))
            {
                outPacket.WriteInt(accountID);
                outPacket.WriteBytes(character.ToByteArray());

                Send(outPacket);
            }
        }