public static void OnJoinRequest(AuthPacket packet, Client client)
        {
            var clientSalt = BitConverter.GetBytes(packet.Read<uint>(32));
            var serverSalt = new byte[0].GenerateRandomKey(4);

            client.Session.GenerateSessionKey(clientSalt, serverSalt);

            // Continue if sessionKey is not empty
            if (client.Session.GameAccount.SessionKey != "")
            {
                var joinResponse = new AuthPacket(AuthServerMessage.JoinResponse, AuthChannel.WoW);

                joinResponse.Write(Manager.RealmMgr.RealmList.Count == 0, 1);

                joinResponse.Write(BitConverter.ToUInt32(serverSalt, 0), 32);
                joinResponse.Write(Manager.RealmMgr.RealmList.Count, 5);

                foreach (var realm in Manager.RealmMgr.RealmList)
                {
                    var ip = IPAddress.Parse(realm.Value.IP).GetAddressBytes();
                    var port = BitConverter.GetBytes(realm.Value.Port);

                    Array.Reverse(port);

                    joinResponse.Write(ip);
                    joinResponse.Write(port);
                }

                joinResponse.Write(0, 5);

                client.SendPacket(joinResponse);
            }
        }
Exemple #2
0
        public static void OnHTTPReceive(AuthPacket packet, Client client)
        {
            packet.ReadString();

            var path = packet.ReadString();

            Manager.PatchMgr.Send(path, client);
        }
        public static bool InvokeHandler(AuthPacket reader, Client client)
        {
            var message = (AuthClientMessage)reader.Header.Message;

            Log.Message(LogType.Packet, "Received Opcode: {0} (0x{0:X}), Length: {1}", message, reader.Data.Length);

            if (MessageHandlers.TryGetValue(Tuple.Create(message, reader.Header.Channel), out HandlePacket packet))
            {
                packet.Invoke(reader, client);

                return true;
            }

            return false;
        }
        public static void OnListSubscribeRequest(AuthPacket packet, Client client)
        {
            Log.Debug("Received ListSubscribeRequest.");

            // Battlenet::Client::WoWRealm::ListSubscribeResponse
            var listSubscribeResponse = new AuthPacket(AuthServerMessage.ListSubscribeResponse, AuthChannel.WoWRealm);

            listSubscribeResponse.Write(0, 1);
            listSubscribeResponse.Write(0, 7);

            var realmCounter = 0;

            // Battlenet::Client::WoWRealm::ListUpdate
            foreach (var realm in Manager.RealmMgr.RealmList)
            {
                var listUpdate = new AuthPacket(AuthServerMessage.ListUpdate, AuthChannel.WoWRealm);

                listUpdate.Write(true, 1);
                listUpdate.Write(realm.Value.Category, 32);          // RealmCategory
                listUpdate.Write(0, 32);                             // RealmPopulation, float written as uint32
                listUpdate.Write(realm.Value.State, 8);              // RealmState
                listUpdate.Write(realm.Value.Id, 19);                // RealmId
                listUpdate.Write(0x80000000 + realm.Value.Type, 32); // RealmType
                listUpdate.WriteString(realm.Value.Name, 10, false); // RealmName
                listUpdate.Write(false, 1);                          // Battlenet::VersionString, not used for now
                listUpdate.Write(realm.Value.Flags, 8);              // RealmInfoFlags
                listUpdate.Write(0, 8);
                listUpdate.Write(0, 12);
                listUpdate.Write(0, 8);
                listUpdate.Write(++realmCounter, 32);

                listUpdate.Finish();

                // Write ListUpdate data to ListSubscribeResponse
                listSubscribeResponse.Write(listUpdate.Data);
            }

            // Battlenet::Client::WoWRealm::ListComplete
            var listComplete = new AuthPacket(AuthServerMessage.ListComplete, AuthChannel.WoWRealm);

            listComplete.Finish();

            // Write ListComplete data to ListSubscribeResponse end
            listSubscribeResponse.Write(listComplete.Data);

            client.SendPacket(listSubscribeResponse);
        }
Exemple #5
0
        public static void SendProofRequest(Client client)
        {
            var session = client.Session;

            client.Modules = Manager.ModuleMgr.Modules.Where(m => m.System == client.OS);

            var thumbprintModule = client.Modules.SingleOrDefault(m => m.Name == "Thumbprint");
            var passwordModule = client.Modules.SingleOrDefault(m => m.Name == "Password");

            var proofRequest = new AuthPacket(AuthServerMessage.ProofRequest);

            // Send two modules (Thumbprint & Password).
            proofRequest.Write(2, 3);

            /// Thumbprint module
            Manager.ModuleMgr.WriteModuleHeader(client, proofRequest, thumbprintModule);

            // Data 
            proofRequest.Write(thumbprintModule.Data.ToByteArray());

            session.SecureRemotePassword = new SRP6a(session.Account.Salt, session.Account.Email, session.Account.PasswordVerifier);
            session.SecureRemotePassword.CalculateB();

            /// Password module
            Manager.ModuleMgr.WriteModuleHeader(client, proofRequest, passwordModule);

            // State
            proofRequest.Flush();
            proofRequest.Write(PasswordModuleState.ServerChallenge, 8);

            // Data
            proofRequest.Write(session.SecureRemotePassword.I);
            proofRequest.Write(session.SecureRemotePassword.S);
            proofRequest.Write(session.SecureRemotePassword.B);
            proofRequest.Write(session.SecureRemotePassword.S2);

            client.SendPacket(proofRequest);
        }
        public static void OnRealmUpdate(AuthPacket packet, Client client)
        {
            Log.Message(LogType.Debug, "Received realm update.");

            var complete = new AuthPacket(AuthServerMessage.RealmComplete, AuthChannel.WoW);

            complete.Flush();
            complete.Write(0, 8);

            var realmCounter = 0;

            foreach (var realm in Manager.RealmMgr.RealmList)
            {
                var realmlist = new AuthPacket(AuthServerMessage.RealmUpdate, AuthChannel.WoW);

                realmlist.Write(true, 1);
                realmlist.Write(1, 32);
                realmlist.Write(0f, 32);
                realmlist.Write(realm.Value.Flags, 8);
                realmlist.Write(realm.Value.Id, 19);
                realmlist.Write(0x80000000 + realm.Value.Type, 32);
                realmlist.WriteString(realm.Value.Name, 10, false);
                realmlist.Write(false, 1);
                realmlist.Write(realm.Value.Status, 8);
                realmlist.Write(0, 12);
                realmlist.Write(0, 8);
                realmlist.Write(0, 32);
                realmlist.Write(++realmCounter, 8);

                // End
                realmlist.Write(new byte[] { 0x43, 0x02 });
                realmlist.Finish();

                complete.Write(realmlist.Data);
            }

            client.SendPacket(complete);
        }
        public static void OnInformationRequest(AuthPacket packet, Client client)
        {
            var session = client.Session;
            if (!Manager.GetState())
            {
                AuthHandler.SendAuthComplete(true, AuthResult.ServerBusy, client);
                return;
            }

            var game = packet.ReadFourCC();
            var os = packet.ReadFourCC();
            var language = packet.ReadFourCC();

            Log.Message(LogType.Debug, "Program: {0}", game);
            Log.Message(LogType.Debug, "Platform: {0}", os);
            Log.Message(LogType.Debug, "Locale: {0}", language);

            var componentCount = packet.Read<int>(6);

            for (int i = 0; i < componentCount; i++)
            {
                var program = packet.ReadFourCC();
                var platform = packet.ReadFourCC();
                var build = packet.Read<int>(32);

                Log.Message(LogType.Debug, "Program: {0}", program);
                Log.Message(LogType.Debug, "Platform: {0}", platform);
                Log.Message(LogType.Debug, "Locale: {0}", build);

                if (DB.Auth.Components.Any(c => c.Program == program && c.Platform == platform && c.Build == build))
                    continue;

                if (!DB.Auth.Components.Any(c => c.Program == program))
                {
                    AuthHandler.SendAuthComplete(true, AuthResult.InvalidProgram, client);
                    return;
                }

                if (!DB.Auth.Components.Any(c => c.Platform == platform))
                {
                    AuthHandler.SendAuthComplete(true, AuthResult.InvalidPlatform, client);
                    return;
                }

                if (!DB.Auth.Components.Any(c => c.Build == build))
                {
                    AuthHandler.SendAuthComplete(true, AuthResult.InvalidGameVersion, client);
                    return;
                }
            }

            var hasAccountName = packet.Read<bool>(1);

            if (hasAccountName)
            {
                var accountLength = packet.Read<int>(9) + 3;
                var accountName = packet.ReadString(accountLength);
                var account = DB.Auth.Accounts.SingleOrDefault(a => a.Email == accountName);

                // First account lookup on database
                if ((session.Account = account) != null)
                {
                    // Global base account.
                    session.Account.IP = session.GetClientInfo();
                    session.Account.Language = language;

                    // Assign the possible game accounts based on the game.
                    //session.GameAccounts.ForEach(ga => ga.OS = os);

                    // Save the last changes
                    DB.Auth.Update();

                    // Used for module identification.
                    client.Game = game;
                    client.OS = os;

                    AuthHandler.SendProofRequest(client);
                }
                else
                    AuthHandler.SendAuthComplete(true, AuthResult.BadLoginInformation, client);
            }
        }
        public static void OnDisconnect(AuthPacket packet, Client client)
        {
            Log.Message(LogType.Debug, "Client '{0}' disconnected.", client.ConnectionInfo);

            Manager.SessionMgr.RemoveClient(client.Id);
        }
        public static void OnPing(AuthPacket packet, Client client)
        {
            var pong = new AuthPacket(AuthServerMessage.Pong, AuthChannel.Creep);

            client.SendPacket(pong);
        }
        public static void OnProofResponse(AuthPacket packet, Client client)
        {
            var session = client.Session;

            var moduleCount = packet.Read<byte>(3);

            for (int i = 0; i < moduleCount; i++)
            {
                var dataSize = packet.Read<int>(10);
                var state = packet.Read<PasswordModuleState>(8);

                switch (state)
                {
                    case PasswordModuleState.ClientChallenge:
                        if (session.GameAccount == null && session.GameAccounts.Count >= 1)
                        {
                            if (session.GameAccounts.Count > 1)
                            {
                                var region = packet.Read<Regions>(8);
                                var gameLength = packet.Read<byte>(8);
                                var game = packet.ReadString(gameLength);

                                session.GameAccount = session.GameAccounts.SingleOrDefault(ga => ga.Game + ga.Index == game && ga.Region == region);

                                var riskFingerprint = new AuthPacket(AuthServerMessage.ProofRequest);

                                riskFingerprint.Write(1, 3);

                                Manager.ModuleMgr.WriteRiskFingerprint(client, riskFingerprint);

                                client.SendPacket(riskFingerprint);

                                return;
                            }
                            else
                                session.GameAccount = session.GameAccounts[0];
                        }

                        if (!session.GameAccount.IsOnline)
                        {
                            if (session.GameAccount == null)
                                SendAuthComplete(true, AuthResult.NoGameAccount, client);
                            else
                                SendAuthComplete(false, AuthResult.GlobalSuccess, client);
                        }

                        break;
                    case PasswordModuleState.ClientProof:
                        // Wrong password module data size
                        if (dataSize != 0x121)
                            return;

                        var a = packet.Read(0x80);
                        var m1 = packet.Read(0x20);
                        var clientChallenge = packet.Read(0x80);

                        session.SecureRemotePassword.CalculateU(a);
                        session.SecureRemotePassword.CalculateClientM(a);

                        if (session.SecureRemotePassword.ClientM.Compare(m1))
                        {
                            session.SecureRemotePassword.CalculateServerM(m1);

                            // Assign valid game accounts for the account
                            if (session.Account.GameAccounts != null)
                                session.GameAccounts = session.Account.GameAccounts.Where(ga => ga.Game == client.Game && ga.Region == session.Account.Region).ToList();

                            SendProofValidation(client, clientChallenge);
                        }
                        else
                            SendAuthComplete(true, AuthResult.BadLoginInformation, client);

                        break;
                    default:
                        break;
                }
            }
        }
        public static void SendProofValidation(Client client, byte[] clientChallenge)
        {
            var passwordModule = client.Modules.SingleOrDefault(m => m.Name == "Password");
            var selectedGameAccountModule = client.Modules.SingleOrDefault(m => m.Name == "SelectGameAccount");

            var proofValidation = new AuthPacket(AuthServerMessage.ProofRequest);

            var moduleCount = 2;

            proofValidation.Write(moduleCount, 3);

            /// Password module
            Manager.ModuleMgr.WriteModuleHeader(client, proofValidation, passwordModule, 161);

            // State
            proofValidation.Flush();
            proofValidation.Write(PasswordModuleState.ValidateProof, 8);

            // Data
            proofValidation.Write(client.Session.SecureRemotePassword.ServerM);
            proofValidation.Write(client.Session.SecureRemotePassword.S2);

            /// SelectGameAccount module
            if (client.Session.GameAccounts.Count > 1)
            {
                var gameAccountBuffer = new AuthPacket();

                gameAccountBuffer.Write(0, 8);
                gameAccountBuffer.Write(client.Session.GameAccounts.Count, 8);

                client.Session.GameAccounts.ForEach(ga =>
                {
                    gameAccountBuffer.Write(ga.Region, 8);
                    gameAccountBuffer.WriteString(ga.Game + ga.Index, 8, false);
                });

                gameAccountBuffer.Finish();

                Manager.ModuleMgr.WriteModuleHeader(client, proofValidation, selectedGameAccountModule, gameAccountBuffer.Data.Length);

                // Data
                proofValidation.Write(gameAccountBuffer.Data);
            }
            else
                Manager.ModuleMgr.WriteRiskFingerprint(client, proofValidation);

            client.SendPacket(proofValidation);
        }
        public static void SendAuthComplete(bool failed, AuthResult result, Client client)
        {
            client.Session.GameAccount.IsOnline = true;

            var complete = new AuthPacket(AuthServerMessage.Complete);

            complete.Write(failed, 1);

            if (failed)
            {
                complete.Write(false, 1);       // false - disable optional modules
                complete.Write(1, 2);           // 1 - enable AuthResults
                complete.Write(result, 16);     // AuthResults (Error codes)
                complete.Write(0x80000000, 32); // Unknown
            }
            else
            {
                // No modules supported here.
                complete.Write(0, 3);

                var pingTimeout = 0x80005000;
                var hasRegulatorRules = true;

                complete.Write(pingTimeout, 32);
                complete.Write(hasRegulatorRules, 1);

                if (hasRegulatorRules)
                {
                    var hasRegulatorInfo = true;

                    complete.Write(hasRegulatorInfo, 1);

                    if (hasRegulatorInfo)
                    {
                        var threshold = 25000000;
                        var rate = 1000;

                        complete.Write(threshold, 32);
                        complete.Write(rate, 32);
                    }
                }

                var haslogonInfo = true;
                var account = client.Session.Account;
                var gameAccount = client.Session.GameAccount;

                complete.Write(!haslogonInfo, 1);

                complete.WriteString(account.GivenName, 8, false);
                complete.WriteString(account.Surname, 8, false);

                complete.Write(account.Id, 32);
                complete.Write((byte)account.Region, 8);
                complete.Write((ulong)account.Flags, 64);

                complete.Write((byte)gameAccount.Region, 8);
                complete.WriteString(gameAccount.AccountId + "#" + gameAccount.Index, 5, false, -1);
                complete.Write((ulong)gameAccount.Flags, 64);

                complete.Write(account.LoginFailures, 32);
                complete.Write(0, 8);
            }

            client.SendPacket(complete);
        }
Exemple #13
0
        public static void OnDisconnect(AuthPacket packet, Client client)
        {
            Log.Debug($"Client '{client.ConnectionInfo}' disconnected.");

            Manager.SessionMgr.RemoveClient(client.Id);
        }