Inheritance: Connection
        public static bool HandleAuthLogonChallenge(AuthConnection client, BinaryReader br)
        {
            client.LogonChallenge = PacketHelper.Parse<C_AuthLogonChallenge>(br);

            //Console.WriteLine("<- {0} connecting ({1}.{2}.{3}.{4})", client.LogonChallenge.Identifier, client.LogonChallenge.Version1, client.LogonChallenge.Version2, client.LogonChallenge.Version3, client.LogonChallenge.Build);

            // Check ban
            // client.SendPacket(AuthOpcodes.AuthLogonChallenge, PacketHelper.Build(new S_AuthLogonChallenge { Error = (byte)AuthResult.Banned }));

            // Check suspend
            // client.SendPacket(AuthOpcodes.AuthLogonChallenge, PacketHelper.Build(new S_AuthLogonChallenge { Error = (byte)AuthResult.Suspended }));

            // Account doesn't exist!
            if (!LoginService.ExistsAccount(client.LogonChallenge.Identifier))
            {
                client.SendPacket(AuthOpcodes.AuthLogonChallenge, PacketHelper.Build(new S_AuthLogonChallenge { Error = AuthResult.UnknownAccount }));
                return true;
            }
            client.SRP = LoginService.GetAccountSecurity(client.LogonChallenge.Identifier);

            client.SendPacket(AuthOpcodes.AuthLogonChallenge, PacketHelper.Build(new S_AuthLogonChallenge
            {
                Error = (byte)AuthResult.Success,
                unk1 = 0,
                ServerEphemeral = client.SRP.ServerEphemeral.ToProperByteArray().Pad(32),
                GeneratorLength = 1,
                Generator = client.SRP.Generator.ToByteArray(),
                ModulusLength = 32,
                Modulus = client.SRP.Modulus.ToProperByteArray().Pad(32),
                Salt = client.SRP.Salt.ToProperByteArray().Pad(32),
                unk2 = new byte[17]
            }));

            return true;
        }
Beispiel #2
0
        public static bool HandleReconnectChallenge(AuthConnection client, BinaryReader br)
        {
            // Packet structure is the same, except for opcode.
            client.LogonChallenge = PacketHelper.Parse <C_AuthLogonChallenge>(br);

            client.SendPacket(AuthOpcodes.AuthReconnectChallenge, PacketHelper.Build(new S_AuthReconnectChallenge
            {
                Error         = AuthResult.Success,
                ChallengeData = client.ChallengeData = RandomGenerator.RandomBytes(16),
            }));

            return(true);
        }
Beispiel #3
0
        public static bool HandleRealmlist(AuthConnection client, BinaryReader br)
        {
            var realms = AuthServer.Instance.Service.RealmStates.Select(r => r.Realm);

            var data = PacketHelper.Build(new S_RealmList
            {
                RealmCount = (byte)realms.Count(),
                Realms     = realms.ToArray()
            });


            client.SendPacket(AuthOpcodes.RealmList, BitConverter.GetBytes((ushort)data.Length).Concat(data).ToArray());

            return(true);
        }
Beispiel #4
0
        public static bool HandleReconnectProof(AuthConnection client, BinaryReader br)
        {
            var pkt = PacketHelper.Parse <C_AuthReconnectProof>(br);

            var serverProof = HashUtil.ComputeHash(
                Encoding.ASCII.GetBytes(client.LogonChallenge.Identifier),
                pkt.ProofData,
                client.ChallengeData,
                client.SRP.SessionKey.ToProperByteArray());

            if (!serverProof.SequenceEqual(pkt.ClientProof))
            {
                return(true); // Drop client here
            }
            client.SendPacket(AuthOpcodes.AuthReconnectProof, PacketHelper.Build(new S_AuthReconnectProof
            {
                Error = AuthResult.Success
            }));

            return(true);
        }
Beispiel #5
0
        public static bool HandleAuthLogonChallenge(AuthConnection client, BinaryReader br)
        {
            client.LogonChallenge = PacketHelper.Parse <C_AuthLogonChallenge>(br);

            //Console.WriteLine("<- {0} connecting ({1}.{2}.{3}.{4})", client.LogonChallenge.Identifier, client.LogonChallenge.Version1, client.LogonChallenge.Version2, client.LogonChallenge.Version3, client.LogonChallenge.Build);

            // Check ban
            // client.SendPacket(AuthOpcodes.AuthLogonChallenge, PacketHelper.Build(new S_AuthLogonChallenge { Error = (byte)AuthResult.Banned }));

            // Check suspend
            // client.SendPacket(AuthOpcodes.AuthLogonChallenge, PacketHelper.Build(new S_AuthLogonChallenge { Error = (byte)AuthResult.Suspended }));

            // Account doesn't exist!
            if (!LoginService.ExistsAccount(client.LogonChallenge.Identifier))
            {
                client.SendPacket(AuthOpcodes.AuthLogonChallenge, PacketHelper.Build(new S_AuthLogonChallenge {
                    Error = AuthResult.UnknownAccount
                }));
                return(true);
            }
            client.SRP = LoginService.GetAccountSecurity(client.LogonChallenge.Identifier);

            client.SendPacket(AuthOpcodes.AuthLogonChallenge, PacketHelper.Build(new S_AuthLogonChallenge
            {
                Error           = (byte)AuthResult.Success,
                unk1            = 0,
                ServerEphemeral = client.SRP.ServerEphemeral.ToProperByteArray().Pad(32),
                GeneratorLength = 1,
                Generator       = client.SRP.Generator.ToByteArray(),
                ModulusLength   = 32,
                Modulus         = client.SRP.Modulus.ToProperByteArray().Pad(32),
                Salt            = client.SRP.Salt.ToProperByteArray().Pad(32),
                unk2            = new byte[17]
            }));

            return(true);
        }
Beispiel #6
0
        public static bool HandleLogonProof(AuthConnection client, BinaryReader br)
        {
            client.LogonProof = PacketHelper.Parse <C_AuthLogonProof>(br);


            client.SRP.ClientEphemeral = client.LogonProof.A.ToPositiveBigInteger();
            client.SRP.ClientProof     = client.LogonProof.M1.ToPositiveBigInteger();

            // Check versions
            if (client.LogonChallenge.Build != 5875)
            {
                client.SendPacket(AuthOpcodes.AuthLogonProof, PacketHelper.Build(new S_AuthLogonProof {
                    Error = AuthResult.InvalidVersion
                }));
                return(true);
            }

            // Check password
            if (!client.IsAuthenticated) // TODO: Send response
            {
                // Increment password fail counter?
                client.SendPacket(AuthOpcodes.AuthLogonProof, PacketHelper.Build(new S_AuthLogonProof {
                    Error = AuthResult.IncorrectPassword
                }));
                return(true);
            }

            LoginService.UpdateSessionKey(client.LogonChallenge.Identifier, client.SRP.SessionKey.ToProperByteArray());
            client.SendPacket(AuthOpcodes.AuthLogonProof, PacketHelper.Build(new S_AuthLogonProof
            {
                Error = (byte)AuthResult.Success,
                M2    = client.SRP.ServerProof.ToByteArray().Pad(20),
                unk2  = 0
            }));
            return(true);
        }
        public static bool HandleLogonProof(AuthConnection client, BinaryReader br)
        {
            client.LogonProof = PacketHelper.Parse<C_AuthLogonProof>(br);

            client.SRP.ClientEphemeral = client.LogonProof.A.ToPositiveBigInteger();
            client.SRP.ClientProof = client.LogonProof.M1.ToPositiveBigInteger();

            // Check versions
            if (client.LogonChallenge.Build != 5875)
            {
                client.SendPacket(AuthOpcodes.AuthLogonProof, PacketHelper.Build(new S_AuthLogonProof { Error = AuthResult.InvalidVersion }));
                return true;
            }

            // Check password
            if (!client.IsAuthenticated) // TODO: Send response
            {
                // Increment password fail counter?
                client.SendPacket(AuthOpcodes.AuthLogonProof, PacketHelper.Build(new S_AuthLogonProof { Error = AuthResult.IncorrectPassword }));
                return true;
            }

            LoginService.UpdateSessionKey(client.LogonChallenge.Identifier, client.SRP.SessionKey.ToProperByteArray());
            client.SendPacket(AuthOpcodes.AuthLogonProof, PacketHelper.Build(new S_AuthLogonProof
            {
                Error = (byte)AuthResult.Success,
                M2 = client.SRP.ServerProof.ToByteArray().Pad(20),
                unk2 = 0
            }));
            return true;
        }
        public static bool HandleReconnectProof(AuthConnection client, BinaryReader br)
        {
            var pkt = PacketHelper.Parse<C_AuthReconnectProof>(br);

            var serverProof = HashUtil.ComputeHash(
                Encoding.ASCII.GetBytes(client.LogonChallenge.Identifier),
                pkt.ProofData,
                client.ChallengeData,
                client.SRP.SessionKey.ToProperByteArray());
            if (!serverProof.SequenceEqual(pkt.ClientProof))
                return true; // Drop client here

            client.SendPacket(AuthOpcodes.AuthReconnectProof, PacketHelper.Build(new S_AuthReconnectProof
            {
                Error = AuthResult.Success
            }));

            return true;
        }
        public static bool HandleReconnectChallenge(AuthConnection client, BinaryReader br)
        {
            // Packet structure is the same, except for opcode.
            client.LogonChallenge = PacketHelper.Parse<C_AuthLogonChallenge>(br);

            client.SendPacket(AuthOpcodes.AuthReconnectChallenge, PacketHelper.Build(new S_AuthReconnectChallenge
            {
                Error = AuthResult.Success,
                ChallengeData = client.ChallengeData = RandomGenerator.RandomBytes(16),
            }));

            return true;
        }
        public static bool HandleRealmlist(AuthConnection client, BinaryReader br)
        {
            var realms = AuthServer.Instance.Service.RealmStates.Select(r => r.Realm);

            var data = PacketHelper.Build(new S_RealmList
            {
                RealmCount = (byte)realms.Count(),
                Realms = realms.ToArray()
            });

            client.SendPacket(AuthOpcodes.RealmList, BitConverter.GetBytes((ushort)data.Length).Concat(data).ToArray());

            return true;
        }