From 3fe93e9a1c6b33772981a2126b317eb10735f9c2 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 18 Sep 2022 15:24:59 -0400 Subject: [PATCH] Core/bnetserver: Implemented reconnecting with launcherlogin Port From (https://github.com/TrinityCore/TrinityCore/commit/8a183a6e5ee1cd394aabb9df4e34064466bd3946) --- .../Networking/Services/Authentication.cs | 26 ++++++++++++++++++- .../Database/Databases/LoginDatabase.cs | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Source/BNetServer/Networking/Services/Authentication.cs b/Source/BNetServer/Networking/Services/Authentication.cs index 95b49e005..b907e034d 100644 --- a/Source/BNetServer/Networking/Services/Authentication.cs +++ b/Source/BNetServer/Networking/Services/Authentication.cs @@ -42,7 +42,7 @@ namespace BNetServer.Networking var endpoint = Global.LoginServiceMgr.GetAddressForClient(GetRemoteIpEndPoint().Address); ChallengeExternalRequest externalChallenge = new(); - externalChallenge.PayloadType = "web_auth_url"; + externalChallenge.PayloadType = "web_auth_url"; externalChallenge.Payload = ByteString.CopyFromUtf8($"https://{endpoint.Address}:{endpoint.Port}/bnetserver/login/"); SendRequest((uint)OriginalHash.ChallengeListener, 3, externalChallenge); @@ -164,5 +164,29 @@ namespace BNetServer.Networking SendRequest((uint)OriginalHash.AuthenticationListener, 5, logonResult); return BattlenetRpcErrorCode.Ok; } + + [Service(OriginalHash.AuthenticationService, 8)] + BattlenetRpcErrorCode HandleGenerateWebCredentials(GenerateWebCredentialsRequest request, GenerateWebCredentialsResponse response) + { + if (!authed) + return BattlenetRpcErrorCode.Denied; + + if (request.Program != 0x576F57) + { + Log.outDebug(LogFilter.Session, $"[Battlenet::HandleGenerateWebCredentials] {GetClientInfo()} attempted to generate web cretentials with game other than WoW (using {(request.Program >> 24) & 0xFF}{(request.Program >> 16) & 0xFF}{(request.Program >> 8) & 0xFF}{request.Program & 0xFF})!"); + return BattlenetRpcErrorCode.BadProgram; + } + + PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_BNET_EXISTING_AUTHENTICATION_BY_ID); + stmt.AddValue(0, accountInfo.Id); + + queryProcessor.AddCallback(DB.Login.AsyncQuery(stmt).WithCallback(result => + { + // just send existing credentials back (not the best but it works for now with them being stored in db) + response.WebCredentials = ByteString.CopyFromUtf8(result.Read(0)); + })); + + return BattlenetRpcErrorCode.Ok; + } } } \ No newline at end of file diff --git a/Source/Framework/Database/Databases/LoginDatabase.cs b/Source/Framework/Database/Databases/LoginDatabase.cs index a38ed3ebd..c3c808c37 100644 --- a/Source/Framework/Database/Databases/LoginDatabase.cs +++ b/Source/Framework/Database/Databases/LoginDatabase.cs @@ -114,6 +114,7 @@ namespace Framework.Database PrepareStatement(LoginStatements.SelBnetAuthentication, "SELECT ba.id, ba.sha_pass_hash, ba.failed_logins, ba.LoginTicket, ba.LoginTicketExpiry, bab.unbandate > UNIX_TIMESTAMP() OR bab.unbandate = bab.bandate FROM battlenet_accounts ba LEFT JOIN battlenet_account_bans bab ON ba.id = bab.id WHERE email = ?"); PrepareStatement(LoginStatements.UpdBnetAuthentication, "UPDATE battlenet_accounts SET LoginTicket = ?, LoginTicketExpiry = ? WHERE id = ?"); + PrepareStatement(LoginStatements.SEL_BNET_EXISTING_AUTHENTICATION_BY_ID, "SELECT LoginTicket FROM battlenet_accounts WHERE id = ?"); PrepareStatement(LoginStatements.SelBnetAccountInfo, "SELECT " + BnetAccountInfo + ", " + BnetGameAccountInfo + " FROM battlenet_accounts ba LEFT JOIN battlenet_account_bans bab ON ba.id = bab.id LEFT JOIN account a ON ba.id = a.battlenet_account" + " LEFT JOIN account_banned ab ON a.id = ab.id AND ab.active = 1 LEFT JOIN account_access aa ON a.id = aa.AccountID AND aa.RealmID = -1 WHERE ba.LoginTicket = ? ORDER BY a.id"); @@ -264,6 +265,7 @@ namespace Framework.Database SelBnetAuthentication, UpdBnetAuthentication, + SEL_BNET_EXISTING_AUTHENTICATION_BY_ID, SelBnetAccountInfo, UpdBnetLastLoginInfo, UPD_BNET_GAME_ACCOUNT_LOGIN_INFO,