示例#1
0
        //! TODO Implement server side addon & banned addon handling
        public static void HandleAddonInfo(CharacterSession session, byte[] addonData)
        {
            var addonInfo       = new AddonInfo();
            var addonDataReader = new Packet(addonData, 0);

            var addons = addonDataReader.Read <uint>();

            for (var i = 0; i < addons; i++)
            {
                var addonName         = addonDataReader.Read <string>(0, true);
                var addonInfoProvided = addonDataReader.Read <bool>();
                var addonCRC          = addonDataReader.Read <uint>();
                var urlCRC            = addonDataReader.Read <uint>();

                Log.Message(LogType.Debug, "AddonData: Name '{0}', Info Provided '{1}', CRC '0x{2:X}', URL CRC '0x{3:X}'.",
                            addonName, addonInfoProvided, addonCRC, urlCRC);

                addonInfo.Addons.Add(new AddonInfoData
                {
                    InfoProvided = addonInfoProvided,
                    KeyProvided  = true,
                    KeyData      = addonPublicKey
                });
            }

            session.Send(addonInfo);
        }
示例#2
0
        //! TODO Implement server side addon & banned addon handling
        public static async void HandleAddonInfo(CharacterSession session, byte[] addonData)
        {
            var addonInfo       = new AddonInfo();
            var addonDataReader = new Packet(addonData, 0);

            var addons = addonDataReader.Read <uint>();

            for (var i = 0; i < addons; i++)
            {
                var addonName         = addonDataReader.ReadString();
                var addonInfoProvided = addonDataReader.Read <bool>();
                var addonCRC          = addonDataReader.Read <uint>();
                var urlCRC            = addonDataReader.Read <uint>();

                Log.Debug($"AddonData: Name '{addonName}', Info Provided '{addonInfoProvided}', CRC '0x{addonCRC:X}', URL CRC '0x{urlCRC:X}'.");

                addonInfo.Addons.Add(new AddonInfoData
                {
                    InfoProvided = addonInfoProvided,
                    KeyProvided  = true,
                    KeyData      = addonPublicKey
                });
            }

            await session.Send(addonInfo);
        }
示例#3
0
        public static void HandleDeleteChar(CharacterSession session, SmartGuid guid)
        {
            var gameAccount = session.GameAccount;
            var deleteChar  = new Packet(ServerMessage.DeleteChar);

            if (DB.Character.Delete <Character>(c => c.Guid == guid.Low && c.GameAccountId == gameAccount.Id))
            {
                deleteChar.Write(CharDeleteCode.Success);
            }
            else
            {
                deleteChar.Write(CharDeleteCode.Failed);
            }

            session.Send(deleteChar);
        }
        public static void HandleGenerateRandomCharacterName(GenerateRandomCharacterName generateRandomCharacterName, CharacterSession session)
        {
            var rand = new Random(Environment.TickCount);
            var generateRandomCharacterNameResult = new GenerateRandomCharacterNameResult();

            var names = ClientDB.NameGens.Where(n => n.RaceId == generateRandomCharacterName.Race && n.Sex == generateRandomCharacterName.Sex).Select(n => n.Name).ToList();

            do
            {
                generateRandomCharacterNameResult.Name = names[rand.Next(names.Count)];
            } while (DB.Character.Any <Character>(c => c.Name == generateRandomCharacterNameResult.Name));

            generateRandomCharacterNameResult.Success = generateRandomCharacterNameResult.Name != "";

            session.Send(generateRandomCharacterNameResult);
        }
示例#5
0
        public static void HandleAuthChallenge(CharacterSession session)
        {
            var authChallenge = new Packet(ServerMessage.AuthChallenge);

            // Part of the header
            authChallenge.Write<ushort>(0);

            authChallenge.Write(session.Challenge);

            for (int i = 0; i < 8; i++)
                authChallenge.Write<uint>(0);

            authChallenge.Write<byte>(1);

            session.Send(authChallenge);
        }
        public static void HandleEnumCharacters(EnumCharacters enumCharacters, CharacterSession session)
        {
            // ORM seems to have problems with session.GameAccount.Id...
            var gameAccount = session.GameAccount;
            var charList    = DB.Character.Where <Character>(c => c.GameAccountId == gameAccount.Id);

            var enumCharactersResult = new EnumCharactersResult();

            charList.ForEach(c =>
            {
                enumCharactersResult.Characters.Add(new CharacterListEntry
                {
                    Guid = new SmartGuid {
                        Type = GuidType.Player, MapId = (ushort)c.Map, CreationBits = c.Guid
                    },
                    Name            = c.Name,
                    ListPosition    = c.ListPosition,
                    RaceID          = c.Race,
                    ClassID         = c.Class,
                    SexID           = c.Sex,
                    SkinID          = c.Skin,
                    FaceID          = c.Face,
                    HairStyle       = c.HairStyle,
                    HairColor       = c.HairColor,
                    FacialHairStyle = c.FacialHairStyle,
                    ExperienceLevel = c.Level,
                    ZoneID          = (int)c.Zone,
                    MapID           = (int)c.Map,
                    PreloadPos      = new Vector3 {
                        X = c.X, Y = c.Y, Z = c.Z
                    },
                    GuildGUID = new SmartGuid {
                        Type = GuidType.Guild, CreationBits = c.GuildGuid
                    },
                    Flags                = c.CharacterFlags,
                    Flags2               = c.CustomizeFlags,
                    Flags3               = c.Flags3,
                    FirstLogin           = c.FirstLogin == 1,
                    PetCreatureDisplayID = c.PetCreatureDisplayId,
                    PetExperienceLevel   = c.PetLevel,
                    PetCreatureFamilyID  = c.PetCreatureFamily,
                });
            });

            session.Send(enumCharactersResult);
        }
示例#7
0
        public static void HandleLoadingScreenNotify(LoadingScreenNotify loadingScreenNotify, CharacterSession session)
        {
            Log.Message(LogType.Debug, "Loading screen for map '{0}' {1}.", loadingScreenNotify.MapID, loadingScreenNotify.Showing ? "enabled" : "disabled");

            if (loadingScreenNotify.Showing)
            {
                if ((var worldServer = Manager.Redirect.GetWorldServer(loadingScreenNotify.MapID)) != null)
                {
                    NetHandler.SendConnectTo(session, worldServer.Address, worldServer.Port);

                    // Suspend the current connection
                    session.Send(new SuspendComms {
                        Serial = 0x14
                    });
                }
            }
        }
示例#8
0
        public static void HandleAuthChallenge(CharacterSession session)
        {
            var authChallenge = new Packet(ServerMessage.AuthChallenge);

            // Part of the header
            authChallenge.Write <ushort>(0);

            authChallenge.Write(session.Challenge);

            for (int i = 0; i < 8; i++)
            {
                authChallenge.Write <uint>(0);
            }

            authChallenge.Write <byte>(1);

            session.Send(authChallenge);
        }
        public static void HandleCharDelete(CharDelete charDelete, CharacterSession session)
        {
            if (charDelete.Guid.CreationBits > 0 && charDelete.Guid.Type == GuidType.Player)
            {
                var deleteChar  = new DeleteChar();
                var guid        = charDelete.Guid;
                var gameAccount = session.GameAccount;

                if (DB.Character.Delete <Character>(c => c.Guid == guid.Low && c.GameAccountId == gameAccount.Id))
                {
                    deleteChar.Code = CharDeleteCode.Success;
                }
                else
                {
                    deleteChar.Code = CharDeleteCode.Failed;
                }

                session.Send(deleteChar);
            }
            else
            {
                session.Dispose();
            }
        }
示例#10
0
        public static async void HandleEnumCharacters(EnumCharacters enumCharacters, CharacterSession session)
        {
            var charList = DB.Character.Where <Character>(c => c.GameAccountId == session.GameAccount.Id);

            var enumCharactersResult = new EnumCharactersResult();

            charList.ForEach(c =>
            {
                var character = new CharacterListEntry
                {
                    Guid = new CharacterGuid {
                        CreationBits = c.Guid, RealmId = (ushort)c.RealmId
                    },
                    Name            = c.Name,
                    ListPosition    = c.ListPosition,
                    RaceID          = c.Race,
                    ClassID         = c.Class,
                    SexID           = c.Sex,
                    SkinID          = c.Skin,
                    FaceID          = c.Face,
                    HairStyle       = c.HairStyle,
                    HairColor       = c.HairColor,
                    FacialHairStyle = c.FacialHairStyle,
                    ExperienceLevel = c.ExperienceLevel,
                    ZoneID          = (int)c.Zone,
                    MapID           = (int)c.Map,
                    PreloadPos      = new Vector3 {
                        X = c.X, Y = c.Y, Z = c.Z
                    },
                    GuildGUID = new GuildGuid {
                        CreationBits = c.GuildGuid
                    },
                    Flags                = c.CharacterFlags,
                    Flags2               = c.CustomizeFlags,
                    Flags3               = c.Flags3,
                    FirstLogin           = c.FirstLogin == 1,
                    PetCreatureDisplayID = c.PetCreatureDisplayId,
                    PetExperienceLevel   = c.PetLevel,
                    PetCreatureFamilyID  = c.PetCreatureFamily,
                };

                if (c.CharacterItems != null)
                {
                    for (var i = 0; i < character.InventoryItems.Length; i++)
                    {
                        foreach (var ci in c.CharacterItems)
                        {
                            Item item;

                            if ((int)ci.Slot == i && ClientDB.Items.TryGetValue(ci.ItemId, out item) && ci.Equipped)
                            {
                                character.InventoryItems[i].DisplayID = (uint)item.DisplayId;
                                character.InventoryItems[i].InvType   = (byte)item.Slot;

                                break;
                            }
                        }
                    }
                }

                enumCharactersResult.Characters.Add(character);
            });

            await session.Send(enumCharactersResult);
        }
示例#11
0
        public static void HandleEnumCharactersResult(CharacterSession session)
        {
            var gameAccount = session.GameAccount;
            var charList = DB.Character.Where<Character>(c => c.GameAccountId == gameAccount.Id);

            var enumCharactersResult = new Packet(ServerMessage.EnumCharactersResult);

            enumCharactersResult.PutBit(1);
            enumCharactersResult.PutBit(0);

            enumCharactersResult.Flush();

            enumCharactersResult.Write(charList.Count);
            enumCharactersResult.Write(0);

            foreach (var c in charList) 
            {
                var guid = new SmartGuid { Type = GuidType.Player, MapId = (ushort)c.Map, CreationBits = c.Guid };
                var guildGuid = new SmartGuid { Type = GuidType.Guild, CreationBits = c.GuildGuid };

                enumCharactersResult.Write(guid);
                enumCharactersResult.Write(c.ListPosition);
                enumCharactersResult.Write(c.Race);
                enumCharactersResult.Write(c.Class);
                enumCharactersResult.Write(c.Sex);
                enumCharactersResult.Write(c.Skin);
                enumCharactersResult.Write(c.Face);
                enumCharactersResult.Write(c.HairStyle);
                enumCharactersResult.Write(c.HairColor);
                enumCharactersResult.Write(c.FacialHairStyle);
                enumCharactersResult.Write(c.Level);
                enumCharactersResult.Write(c.Zone);
                enumCharactersResult.Write(c.Map);
                enumCharactersResult.Write(c.X);
                enumCharactersResult.Write(c.Y);
                enumCharactersResult.Write(c.Z);
                enumCharactersResult.Write(guildGuid);
                enumCharactersResult.Write(c.CharacterFlags);
                enumCharactersResult.Write(c.CustomizeFlags);
                enumCharactersResult.Write(c.Flags3);
                enumCharactersResult.Write(c.PetCreatureDisplayId);
                enumCharactersResult.Write(c.PetLevel);
                enumCharactersResult.Write(c.PetCreatureFamily);
                enumCharactersResult.Write(0);
                enumCharactersResult.Write(0);

                for (var i = 0; i < 23; i++)
                {
                    enumCharactersResult.Write(0);
                    enumCharactersResult.Write(0);
                    enumCharactersResult.Write<byte>(0);
                }

                enumCharactersResult.PutBits(c.Name.Length, 6);
                enumCharactersResult.PutBit(1);
                enumCharactersResult.PutBit(0);

                enumCharactersResult.Write(c.Name);
            }

            session.Send(enumCharactersResult);
        }
示例#12
0
        public static async void SendConnectTo(CharacterSession session, string ip, ushort port, byte connection = 0)
        {
            var connectTo = new ConnectTo
            {
                Key    = Manager.Redirect.CreateRedirectKey(session.GameAccount.Id),
                Serial = 0xE,
                Con    = connection
            };

            // Fail
            if (connectTo.Key == 0)
            {
                session.Dispose();

                return;
            }

            var payloadData = new byte[0xFF];
            var ipBytes     = IPAddress.Parse(ip).GetAddressBytes();

            // 0 - 15, Address, IPv6 not supported for now
            payloadData[0] = ipBytes[0];
            payloadData[1] = ipBytes[1];
            payloadData[2] = ipBytes[2];
            payloadData[3] = ipBytes[3];

            // 16
            payloadData[16] = 0x01;

            // 17 - 20, adler32, changes with compression seed.
            // Let's use a static one for now
            payloadData[17] = 0x43;
            payloadData[18] = 0xfd;
            payloadData[19] = 0xb8;
            payloadData[20] = 0x22;

            // 21
            payloadData[21] = 0x2A;

            var portBytes = BitConverter.GetBytes(port);

            // 22 - 23, Port
            payloadData[22] = portBytes[0];
            payloadData[23] = portBytes[1];

            var msg = "Blossom opens above\nSpines rising to the air\nArctium grows stronger\n\0\0\0\0";

            // 24 - 94, Haiku
            Array.Copy(Encoding.ASCII.GetBytes(msg), 0, payloadData, 24, 71);

            // 94 - 125, static for now...
            Array.Copy(new byte[] { 0xD6, 0xAC, 0x21, 0xE6, 0xB2, 0x7B, 0x06, 0x3D, 0xA9, 0x9C, 0x09, 0x4B, 0xC7, 0x30, 0x48, 0x34, 0xD4, 0xF0, 0x55, 0x3B, 0x1B, 0x1D, 0xC9, 0x5B, 0xFD, 0x3C, 0xB9, 0x30, 0x9D, 0xF5, 0x40, 0xC0 }, 0, payloadData, 94, 32);

            // 126 - 233, 0 for now
            Array.Copy(new byte[108], 0, payloadData, 126, 108);

            // 234 - 253, ranodm for now
            Array.Copy(new byte[0].GenerateRandomKey(20), 0, payloadData, 234, 20);

            var dataOrder = new byte[payloadData.Length];

            for (var i = 0; i < payloadData.Length; i++)
            {
                dataOrder[i] = payloadData[ConnectTo.PayloadOrder[i]];
            }

            var encrypted = Manager.Redirect.Crypt.Encrypt(dataOrder);

            Array.Copy(encrypted, connectTo.Where, 0x100);

            await session.Send(connectTo);
        }
示例#13
0
        public static void HandleAuthResponse(AuthResult result, CharacterSession session)
        {
            var gameAccount = session.GameAccount;
            var realm = session.Realm;

            var authResponse = new Packet(ServerMessage.AuthResponse);

            var hasSuccessInfo = result == AuthResult.Ok;
            var hasWaitInfo    = result == AuthResult.WaitQueue;

            authResponse.Write(result);

            authResponse.PutBit(hasSuccessInfo);
            authResponse.PutBit(hasWaitInfo);
            authResponse.Flush();

            if (hasSuccessInfo)
            {
                var allowedRaces = Manager.GameAccount.GetAvailableRaces(gameAccount, realm);
                var allowedClasses = Manager.GameAccount.GetAvailableClasses(gameAccount, realm);
                var charTemplates = Manager.GameAccount.GetAvailableCharacterTemplates(gameAccount, realm);

                authResponse.Write<uint>(0);
                authResponse.Write<uint>(0);
                authResponse.Write<uint>(0);
                authResponse.Write<uint>(0);
                authResponse.Write<uint>(0);
                authResponse.Write(gameAccount.BoxLevel);
                authResponse.Write(gameAccount.BoxLevel);
                authResponse.Write<uint>(0);
                authResponse.Write(allowedRaces.Count);
                authResponse.Write(allowedClasses.Count);
                authResponse.Write(charTemplates.Count);
                authResponse.Write<uint>(0);

                foreach (var r in allowedRaces)
                {
                    authResponse.Write(r.Key);
                    authResponse.Write(r.Value);
                }

                foreach (var c in allowedClasses)
                {
                    authResponse.Write(c.Key);
                    authResponse.Write(c.Value);
                }

                foreach (var set in charTemplates)
                { 
                    authResponse.Write(set.Id);
                    authResponse.Write(set.CharacterTemplateClasses.Count);

                    foreach (var c in set.CharacterTemplateClasses)
                    {
                        authResponse.Write(c.ClassId);
                        authResponse.Write(c.FactionGroup);
                    }

                    authResponse.PutBits(set.Name.Length, 7);
                    authResponse.PutBits(set.Description.Length, 10);

                    authResponse.Flush();

                    authResponse.Write(set.Name);
                    authResponse.Write(set.Description);
                }

                authResponse.PutBit(0);
                authResponse.PutBit(0);
                authResponse.PutBit(0);
                authResponse.PutBit(0);
                authResponse.PutBit(0);

                authResponse.Flush();
            }

            session.Send(authResponse);
        }
示例#14
0
        public static void HandleAuthResponse(AuthResult result, CharacterSession session)
        {
            var gameAccount = session.GameAccount;
            var realm       = session.Realm;

            var authResponse = new Packet(ServerMessage.AuthResponse);

            var hasSuccessInfo = result == AuthResult.Ok;
            var hasWaitInfo    = result == AuthResult.WaitQueue;

            authResponse.Write(result);

            authResponse.PutBit(hasSuccessInfo);
            authResponse.PutBit(hasWaitInfo);
            authResponse.Flush();

            if (hasSuccessInfo)
            {
                var allowedRaces   = Manager.GameAccount.GetAvailableRaces(gameAccount, realm);
                var allowedClasses = Manager.GameAccount.GetAvailableClasses(gameAccount, realm);
                var charTemplates  = Manager.GameAccount.GetAvailableCharacterTemplates(gameAccount, realm);

                authResponse.Write <uint>(0);
                authResponse.Write <uint>(0);
                authResponse.Write <uint>(0);
                authResponse.Write <uint>(0);
                authResponse.Write <uint>(0);
                authResponse.Write(gameAccount.BoxLevel);
                authResponse.Write(gameAccount.BoxLevel);
                authResponse.Write <uint>(0);
                authResponse.Write(allowedRaces.Count);
                authResponse.Write(allowedClasses.Count);
                authResponse.Write(charTemplates.Count);
                authResponse.Write <uint>(0);

                foreach (var r in allowedRaces)
                {
                    authResponse.Write(r.Key);
                    authResponse.Write(r.Value);
                }

                foreach (var c in allowedClasses)
                {
                    authResponse.Write(c.Key);
                    authResponse.Write(c.Value);
                }

                foreach (var set in charTemplates)
                {
                    authResponse.Write(set.Id);
                    authResponse.Write(set.CharacterTemplateClasses.Count);

                    foreach (var c in set.CharacterTemplateClasses)
                    {
                        authResponse.Write(c.ClassId);
                        authResponse.Write(c.FactionGroup);
                    }

                    authResponse.PutBits(set.Name.Length, 7);
                    authResponse.PutBits(set.Description.Length, 10);

                    authResponse.Flush();

                    authResponse.Write(set.Name);
                    authResponse.Write(set.Description);
                }

                authResponse.PutBit(0);
                authResponse.PutBit(0);
                authResponse.PutBit(0);
                authResponse.PutBit(0);
                authResponse.PutBit(0);

                authResponse.Flush();
            }

            session.Send(authResponse);
        }
示例#15
0
        public static void HandleEnumCharactersResult(CharacterSession session)
        {
            var gameAccount = session.GameAccount;
            var charList    = DB.Character.Where <Character>(c => c.GameAccountId == gameAccount.Id);

            var enumCharactersResult = new Packet(ServerMessage.EnumCharactersResult);

            enumCharactersResult.PutBit(1);
            enumCharactersResult.PutBit(0);

            enumCharactersResult.Flush();

            enumCharactersResult.Write(charList.Count);
            enumCharactersResult.Write(0);

            foreach (var c in charList)
            {
                var guid = new SmartGuid {
                    Type = GuidType.Player, MapId = (ushort)c.Map, CreationBits = c.Guid
                };
                var guildGuid = new SmartGuid {
                    Type = GuidType.Guild, CreationBits = c.GuildGuid
                };

                enumCharactersResult.Write(guid);
                enumCharactersResult.Write(c.ListPosition);
                enumCharactersResult.Write(c.Race);
                enumCharactersResult.Write(c.Class);
                enumCharactersResult.Write(c.Sex);
                enumCharactersResult.Write(c.Skin);
                enumCharactersResult.Write(c.Face);
                enumCharactersResult.Write(c.HairStyle);
                enumCharactersResult.Write(c.HairColor);
                enumCharactersResult.Write(c.FacialHairStyle);
                enumCharactersResult.Write(c.Level);
                enumCharactersResult.Write(c.Zone);
                enumCharactersResult.Write(c.Map);
                enumCharactersResult.Write(c.X);
                enumCharactersResult.Write(c.Y);
                enumCharactersResult.Write(c.Z);
                enumCharactersResult.Write(guildGuid);
                enumCharactersResult.Write(c.CharacterFlags);
                enumCharactersResult.Write(c.CustomizeFlags);
                enumCharactersResult.Write(c.Flags3);
                enumCharactersResult.Write(c.PetCreatureDisplayId);
                enumCharactersResult.Write(c.PetLevel);
                enumCharactersResult.Write(c.PetCreatureFamily);
                enumCharactersResult.Write(0);
                enumCharactersResult.Write(0);

                for (var i = 0; i < 23; i++)
                {
                    enumCharactersResult.Write(0);
                    enumCharactersResult.Write(0);
                    enumCharactersResult.Write <byte>(0);
                }

                enumCharactersResult.PutBits(c.Name.Length, 6);
                enumCharactersResult.PutBit(1);
                enumCharactersResult.PutBit(0);

                enumCharactersResult.Write(c.Name);
            }

            session.Send(enumCharactersResult);
        }
示例#16
0
 public static void HandlePlayerLogin(PlayerLogin playerLogin, CharacterSession session)
 {
     session.Send(new CharacterLoginFailed {
         Code = CharLoginCode.NoWorld
     });
 }
示例#17
0
        public static void OnCreateCharacter(Packet packet, CharacterSession session)
        {
            var nameLength     = packet.GetBits<int>(6);
            var useTemplateSet = packet.GetBit();

            var raceId            = packet.Read<Race>();
            var classId           = packet.Read<Class>();
            var sexId             = packet.Read<byte>();
            var skinId            = packet.Read<byte>();
            var faceId            = packet.Read<byte>();
            var hairStyleId       = packet.Read<byte>();
            var hairColorId       = packet.Read<byte>();
            var facialHairStyleId = packet.Read<byte>();

            packet.Skip(1);

            var name = packet.Read<string>(nameLength).ToLowerEnd();

            var createChar = new Packet(ServerMessage.CreateChar);

            if (!ClientDB.ChrRaces.Any(c => c.Id == raceId) || !ClientDB.ChrClasses.Any(c => c.Id == classId))
            {
                createChar.Write(CharCreateCode.Failed);

                session.Send(createChar);
                return;
            }

            if (!ClientDB.CharBaseInfo.Any(c => c.RaceId == raceId && c.ClassId == classId))
            {
                createChar.Write(CharCreateCode.Failed);

                session.Send(createChar);
                return;
            }

            if (DB.Character.Any<Character>(c => c.Name == name))
            {
                createChar.Write(CharCreateCode.NameInUse);

                session.Send(createChar);
                return;
            }

            if (useTemplateSet)
            {
                var templateSetId = packet.Read<int>();
                var accTemplate = session.GameAccount.GameAccountCharacterTemplates.Any(t => t.SetId == templateSetId);
                var realmTemplate = session.Realm.RealmCharacterTemplates.Any(t => t.SetId == templateSetId);

                if (accTemplate || realmTemplate)
                {
                    var template = DB.Character.Single<CharacterTemplateSet>(s => s.Id == templateSetId);
                    
                    // Implement...
                }
                else
                    createChar.Write(CharCreateCode.Failed);
            }
            else
            {
                var creationData = DB.Character.Single<CharacterCreationData>(d => d.Race == raceId && d.Class == classId);
                var creationData2 = DB.Character.Select<CharacterCreationData>();

                if (creationData != null)
                {
                    var newChar = new Character
                    {
                        Name            = name,
                        GameAccountId   = session.GameAccount.Id,
                        RealmId         = session.Realm.Id,
                        Race            = raceId,
                        Class           = classId,
                        Sex             = sexId,
                        Skin            = skinId,
                        Face            = faceId,
                        HairStyle       = hairStyleId,
                        HairColor       = hairColorId,
                        FacialHairStyle = facialHairStyleId,
                        Level           = 1,
                        Map             = creationData.Map,
                        X               = creationData.X,
                        Y               = creationData.Y,
                        Z               = creationData.Z,
                        O               = creationData.O,
                        CharacterFlags  = CharacterFlags.Decline,
                        FirstLogin      = true
                    };

                    if (DB.Character.Add(newChar))
                    {
                        createChar.Write(CharCreateCode.Success);

                        Manager.Character.LearnStartAbilities(newChar);
                    }
                    else
                        createChar.Write(CharCreateCode.Failed);
                }
                else
                    createChar.Write(CharCreateCode.Failed);
            }

            session.Send(createChar);
        }
示例#18
0
        public static void HandleCreateCharacter(CreateCharacter createCharacter, CharacterSession session)
        {
            var createChar = new CreateChar {
                Code = CharCreateCode.InProgress
            };

            if (!ClientDB.ChrRaces.Any(c => c.Id == createCharacter.RaceID) || !ClientDB.ChrClasses.Any(c => c.Id == createCharacter.ClassID))
            {
                createChar.Code = CharCreateCode.Failed;
            }
            else if (!ClientDB.CharBaseInfo.Any(c => c.RaceId == createCharacter.RaceID && c.ClassId == createCharacter.ClassID))
            {
                createChar.Code = CharCreateCode.Failed;
            }
            else if (DB.Character.Any <Character>(c => c.Name == createCharacter.Name))
            {
                createChar.Code = CharCreateCode.NameInUse;
            }
            else if (createChar.Code == CharCreateCode.InProgress)
            {
                if (createCharacter.TemplateSetID != 0)
                {
                    var accTemplate   = session.GameAccount.GameAccountCharacterTemplates.Any(t => t.SetId == createCharacter.TemplateSetID);
                    var realmTemplate = session.Realm.RealmCharacterTemplates.Any(t => t.SetId == createCharacter.TemplateSetID);

                    if (accTemplate || realmTemplate)
                    {
                        var template = DB.Character.Single <CharacterTemplateSet>(s => s.Id == createCharacter.TemplateSetID);

                        // Not implemented = creation failed
                        createChar.Code = CharCreateCode.Failed;
                    }
                    else
                    {
                        createChar.Code = CharCreateCode.Failed;
                    }
                }
                else
                {
                    var creationData = DB.Character.Single <CharacterCreationData>(d => d.Race == createCharacter.RaceID && d.Class == createCharacter.ClassID);

                    if (creationData != null)
                    {
                        var newChar = new Character
                        {
                            Name            = createCharacter.Name,
                            GameAccountId   = session.GameAccount.Id,
                            RealmId         = session.Realm.Id,
                            Race            = createCharacter.RaceID,
                            Class           = createCharacter.ClassID,
                            Sex             = createCharacter.SexID,
                            Skin            = createCharacter.SkinID,
                            Face            = createCharacter.FaceID,
                            HairStyle       = createCharacter.HairStyleID,
                            HairColor       = createCharacter.HairColorID,
                            FacialHairStyle = createCharacter.FacialHairStyleID,
                            Level           = 1,
                            Map             = creationData.Map,
                            X = creationData.X,
                            Y = creationData.Y,
                            Z = creationData.Z,
                            O = creationData.O,
                            CharacterFlags = CharacterFlags.Decline,
                            FirstLogin     = 1
                        };

                        if (DB.Character.Add(newChar))
                        {
                            createChar.Code = CharCreateCode.Success;

                            Manager.Character.LearnStartAbilities(newChar);
                        }
                        else
                        {
                            createChar.Code = CharCreateCode.Success;
                        }
                    }
                    else
                    {
                        createChar.Code = CharCreateCode.Failed;
                    }
                }
            }

            session.Send(createChar);
        }
示例#19
0
        public static void HandleDeleteChar(CharacterSession session, SmartGuid guid)
        {
            var gameAccount = session.GameAccount;
            var deleteChar = new Packet(ServerMessage.DeleteChar);

            if (DB.Character.Delete<Character>(c => c.Guid == guid.Low && c.GameAccountId == gameAccount.Id))
                deleteChar.Write(CharDeleteCode.Success);
            else
                deleteChar.Write(CharDeleteCode.Failed);

            session.Send(deleteChar);
        }
示例#20
0
        public static async void AuthSessionHandler(AuthSession authSession, CharacterSession session)
        {
            var accountParts = authSession.Account.Split(new[] { '#' });
            var authResult   = AuthResult.Ok;

            if (accountParts.Length == 2)
            {
                var accountId = int.Parse(accountParts[0]);
                var gameIndex = byte.Parse(accountParts[1]);

                session.Account = DB.Auth.Single <Account>(a => a.Id == accountId);

                if (session.Account != null)
                {
                    session.GameAccount = session.Account.GameAccounts.SingleOrDefault(ga => ga.Index == gameIndex);
                }

                if (session.GameAccount != null)
                {
                    session.Crypt = new WoWCrypt(session.GameAccount.SessionKey.ToByteArray());
                }
                else
                {
                    authResult = AuthResult.Failed;
                }
            }

            session.Realm = DB.Auth.Single <Realm>(r => r.Id == authSession.RealmID);

            if (authSession.LoginServerType != (sbyte)LoginServerTypes.Battlenet || session.Realm == null)
            {
                authResult = AuthResult.Reject;
            }

            if (authResult == AuthResult.Ok)
            {
                var sha1 = new Sha1();

                sha1.Process(authSession.Account);
                sha1.Process(0u);
                sha1.Process(authSession.LocalChallenge);
                sha1.Process(session.Challenge);
                sha1.Finish(session.GameAccount.SessionKey.ToByteArray(), 40);

                // Check the password digest.
                if (!sha1.Digest.Compare(authSession.Digest))
                {
                    authResult = AuthResult.Failed;
                }
            }

            var authResponse = new AuthResponse
            {
                Result         = authResult,
                HasSuccessInfo = authResult == AuthResult.Ok,
            };

            if (authResponse.HasSuccessInfo)
            {
                session.State = SessionState.Authenticated;

                var addonData = AddonHandler.GetAddonInfoData(session, authSession.AddonInfo, authSession.CompressedAddonInfoSize, authSession.UncompressedAddonInfoSize);

                if (addonData != null && addonData.Length != authSession.UncompressedAddonInfoSize)
                {
                    Log.Error("Addon Info data size mismatch.");

                    session.Dispose();

                    return;
                }

                authResponse.SuccessInfo.ActiveExpansionLevel  = session.GameAccount.BoxLevel;
                authResponse.SuccessInfo.AccountExpansionLevel = session.GameAccount.BoxLevel;
                authResponse.SuccessInfo.AvailableRaces        = Manager.GameAccount.GetAvailableRaces(session.GameAccount, session.Realm);
                authResponse.SuccessInfo.AvailableClasses      = Manager.GameAccount.GetAvailableClasses(session.GameAccount, session.Realm);
                authResponse.SuccessInfo.Templates             = Manager.GameAccount.GetAvailableCharacterTemplates(session.GameAccount, session.Realm);

                await session.Send(authResponse);

                AddonHandler.HandleAddonInfo(session, addonData);

                await session.Send(new TutorialFlags());
            }
            else
            {
                await session.Send(authResponse);
            }
        }
示例#21
0
        public static void OnCreateCharacter(Packet packet, CharacterSession session)
        {
            var nameLength     = packet.GetBits <int>(6);
            var useTemplateSet = packet.GetBit();

            var raceId            = packet.Read <Race>();
            var classId           = packet.Read <Class>();
            var sexId             = packet.Read <byte>();
            var skinId            = packet.Read <byte>();
            var faceId            = packet.Read <byte>();
            var hairStyleId       = packet.Read <byte>();
            var hairColorId       = packet.Read <byte>();
            var facialHairStyleId = packet.Read <byte>();

            packet.Skip(1);

            var name = packet.Read <string>(nameLength).ToLowerEnd();

            var createChar = new Packet(ServerMessage.CreateChar);

            if (!ClientDB.ChrRaces.Any(c => c.Id == raceId) || !ClientDB.ChrClasses.Any(c => c.Id == classId))
            {
                createChar.Write(CharCreateCode.Failed);

                session.Send(createChar);
                return;
            }

            if (!ClientDB.CharBaseInfo.Any(c => c.RaceId == raceId && c.ClassId == classId))
            {
                createChar.Write(CharCreateCode.Failed);

                session.Send(createChar);
                return;
            }

            if (DB.Character.Any <Character>(c => c.Name == name))
            {
                createChar.Write(CharCreateCode.NameInUse);

                session.Send(createChar);
                return;
            }

            if (useTemplateSet)
            {
                var templateSetId = packet.Read <int>();
                var accTemplate   = session.GameAccount.GameAccountCharacterTemplates.Any(t => t.SetId == templateSetId);
                var realmTemplate = session.Realm.RealmCharacterTemplates.Any(t => t.SetId == templateSetId);

                if (accTemplate || realmTemplate)
                {
                    var template = DB.Character.Single <CharacterTemplateSet>(s => s.Id == templateSetId);

                    // Implement...
                }
                else
                {
                    createChar.Write(CharCreateCode.Failed);
                }
            }
            else
            {
                var creationData  = DB.Character.Single <CharacterCreationData>(d => d.Race == raceId && d.Class == classId);
                var creationData2 = DB.Character.Select <CharacterCreationData>();

                if (creationData != null)
                {
                    var newChar = new Character
                    {
                        Name            = name,
                        GameAccountId   = session.GameAccount.Id,
                        RealmId         = session.Realm.Id,
                        Race            = raceId,
                        Class           = classId,
                        Sex             = sexId,
                        Skin            = skinId,
                        Face            = faceId,
                        HairStyle       = hairStyleId,
                        HairColor       = hairColorId,
                        FacialHairStyle = facialHairStyleId,
                        Level           = 1,
                        Map             = creationData.Map,
                        X = creationData.X,
                        Y = creationData.Y,
                        Z = creationData.Z,
                        O = creationData.O,
                        CharacterFlags = CharacterFlags.Decline,
                        FirstLogin     = true
                    };

                    if (DB.Character.Add(newChar))
                    {
                        createChar.Write(CharCreateCode.Success);

                        Manager.Character.LearnStartAbilities(newChar);
                    }
                    else
                    {
                        createChar.Write(CharCreateCode.Failed);
                    }
                }
                else
                {
                    createChar.Write(CharCreateCode.Failed);
                }
            }

            session.Send(createChar);
        }