예제 #1
0
        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);
            }
        }
예제 #2
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);
        }
예제 #3
0
        public static void OnPing(AuthPacket packet, Client client)
        {
            var pong = new AuthPacket(AuthServerMessage.Pong, AuthChannel.Creep);

            client.SendPacket(pong);
        }
예제 #4
0
        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;
                }
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }