26#include <boost/container/static_vector.hpp>
27#include <boost/uuid/uuid_io.hpp>
33 std::shared_ptr<Trinity::Net::Http::SessionState> state;
34 auto cookieItr = context.
request.find(boost::beast::http::field::cookie);
35 if (cookieItr != context.
request.end())
38 auto sessionIdItr = std::ranges::find_if(cookies, [](std::string_view
const& cookie)
43 if (sessionIdItr != cookies.end())
46 state =
sLoginService.FindAndRefreshSessionState(*sessionIdItr, remoteAddress);
54 if (
size_t port = host.find(
':'); port != std::string_view::npos)
55 host.remove_suffix(host.length() - port);
57 context.
response.insert(boost::beast::http::field::set_cookie,
Trinity::StringFormat(
"{}{}; Path=/bnetserver; Domain={}; Secure; HttpOnly; SameSite=None",
63template<
typename SocketImpl>
64class LoginHttpSocketImpl final :
public SocketImpl
67 using BaseSocket = SocketImpl;
70 : BaseSocket(
std::move(socket)), _owner(owner)
74 LoginHttpSocketImpl(LoginHttpSocketImpl
const&) =
delete;
75 LoginHttpSocketImpl(LoginHttpSocketImpl&&) =
delete;
76 LoginHttpSocketImpl& operator=(LoginHttpSocketImpl
const&) =
delete;
77 LoginHttpSocketImpl& operator=(LoginHttpSocketImpl&&) =
delete;
79 ~LoginHttpSocketImpl() =
default;
84 boost::container::static_vector<std::shared_ptr<Trinity::Net::SocketConnectionInitializer>, 4> initializers;
88 if constexpr (std::is_same_v<BaseSocket, Trinity::Net::Http::SslSocket>)
99 return sLoginService.HandleRequest(_owner.shared_from_this(), context);
105 return ::ObtainSessionState(context, this->GetRemoteIpAddress());
113 : BaseSocket(
std::move(socket),
Battlenet::SslContext::instance()), _owner(owner)
121 : _socket(!
SslContext::UsesDevWildcardCertificate()
122 ?
std::shared_ptr<AbstractSocket>(
std::make_shared<LoginHttpSocketImpl<
Trinity::Net::Http::SslSocket>>(
std::move(socket), *this))
123 :
std::shared_ptr<AbstractSocket>(
std::make_shared<LoginHttpSocketImpl<
Trinity::Net::Http::Socket>>(
std::move(socket), *this)))
#define TC_LOG_TRACE(filterType__, message__,...)
T & AddCallback(T &&query)
void ProcessReadyCallbacks()
static constexpr std::string_view SESSION_ID_COOKIE
void QueueQuery(QueryCallback &&queryCallback)
std::string GetClientInfo() const override
LoginHttpSession(Trinity::Net::IoContextTcpSocket &&socket)
std::shared_ptr< Trinity::Net::Http::AbstractSocket > _socket
QueryCallbackProcessor _queryProcessor
std::string_view ToStdStringView(boost::beast::string_view bsw)
boost::asio::basic_stream_socket< boost::asio::ip::tcp, boost::asio::io_context::executor_type > IoContextTcpSocket
TC_COMMON_API std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args) noexcept
Default TC string format function.
static std::shared_ptr< SocketConnectionInitializer > & SetupChain(std::span< std::shared_ptr< SocketConnectionInitializer > > initializers)