Skip to content

Commit

Permalink
fix: use port for http login and allow custom URL (#606)
Browse files Browse the repository at this point in the history
- Fix http login not using port field
- Improve connection function
- Remove hard coded login.php from URL to allow custom URLs.

Signed-off-by: Renato Foot <[email protected]>
  • Loading branch information
Costallat authored Nov 29, 2023
1 parent 818c8e9 commit 8c3d8fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
15 changes: 14 additions & 1 deletion modules/client_entergame/entergame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,16 @@ function EnterGame.tryHttpLogin(clientVersion)
onCharacterList(nil, characters, account)
end

HTTP.post(G.host .. "/login.php",
local host, path = G.host:match("([^/]+)/([^/].*)")
local url = G.host

if G.port ~= nil and path ~= nil then
url = host .. ':' .. G.port .. '/' .. path
elseif path ~= nil then
url = host .. '/' .. path
end

HTTP.post(url,
json.encode({
email = G.account,
password = G.password,
Expand Down Expand Up @@ -452,6 +461,10 @@ function EnterGame.doLogin()
g_settings.set('client-version', clientVersion)

if clientVersion >= 1281 and G.port ~= 7171 then
if G.port == 0 then
G.port = 80
end

EnterGame.tryHttpLogin(clientVersion)
else
protocolLogin = ProtocolLogin.create()
Expand Down
14 changes: 7 additions & 7 deletions src/framework/net/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ void Connection::connect(const std::string_view host, uint16_t port, const std::
m_connectCallback = connectCallback;

const asio::ip::tcp::resolver::query query(host.data(), stdext::unsafe_cast<std::string>(port));
m_resolver.async_resolve(query, [capture0 = asConnection()](auto&& PH1, auto&& PH2) {
capture0->onResolve(std::forward<decltype(PH1)>(PH1),
std::forward<decltype(PH2)>(PH2));
m_resolver.async_resolve(query, [this](auto&& error, auto&& endpointIterator) {
onResolve(std::move(error), std::move(endpointIterator));
});

m_readTimer.cancel();
m_readTimer.expires_from_now(asio::chrono::seconds(static_cast<uint32_t>(READ_TIMEOUT)));
m_readTimer.async_wait([capture0 = asConnection()](auto&& PH1) {
capture0->onTimeout(std::forward<decltype(PH1)>(PH1));
m_readTimer.expires_after(std::chrono::seconds(static_cast<uint32_t>(READ_TIMEOUT)));
m_readTimer.async_wait([this](auto&& error) {
onTimeout(std::move(error));
});
}


void Connection::internal_connect(const asio::ip::basic_resolver<asio::ip::tcp>::iterator& endpointIterator)
{
m_socket.async_connect(*endpointIterator, [capture0 = asConnection()](auto&& PH1) {
Expand Down Expand Up @@ -341,4 +341,4 @@ int Connection::getIp()

g_logger.error("Getting remote ip");
return 0;
}
}

0 comments on commit 8c3d8fc

Please sign in to comment.