|
@ -65,24 +65,23 @@ int RenX::Server::think() { |
|
|
else { |
|
|
else { |
|
|
auto cycle_player_rdns = [this]() { // Cycles through any pending RDNS resolutions, and fires events as necessary.
|
|
|
auto cycle_player_rdns = [this]() { // Cycles through any pending RDNS resolutions, and fires events as necessary.
|
|
|
if (m_player_rdns_resolutions_pending != 0) { |
|
|
if (m_player_rdns_resolutions_pending != 0) { |
|
|
for (auto node = this->players.begin(); node != this->players.end(); ++node) { |
|
|
for (auto& player : players) { |
|
|
if (node->rdns_thread.joinable() && node->rdns_mutex.try_lock()) { // RDNS event hasn't fired AND RDNS value has been resolved
|
|
|
if (player.rdns_pending && !player.get_rdns().empty()) { // RDNS event hasn't fired AND RDNS value has been resolved
|
|
|
node->rdns_mutex.unlock(); |
|
|
player.rdns_pending = false; |
|
|
node->rdns_thread.join(); |
|
|
|
|
|
--m_player_rdns_resolutions_pending; |
|
|
--m_player_rdns_resolutions_pending; |
|
|
|
|
|
|
|
|
// Check for bans
|
|
|
// Check for bans
|
|
|
banCheck(*node); |
|
|
banCheck(player); |
|
|
|
|
|
|
|
|
// Fire RDNS resolved event
|
|
|
// Fire RDNS resolved event
|
|
|
for (const auto& plugin : RenX::getCore()->getPlugins()) { |
|
|
for (const auto& plugin : RenX::getCore()->getPlugins()) { |
|
|
plugin->RenX_OnPlayerRDNS(*this, *node); |
|
|
plugin->RenX_OnPlayerRDNS(*this, player); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Fire player indentified event if ready
|
|
|
// Fire player indentified event if ready
|
|
|
if (!node->hwid.empty()) { |
|
|
if (!player.hwid.empty()) { |
|
|
for (auto plugin : RenX::getCore()->getPlugins()) { |
|
|
for (auto plugin : RenX::getCore()->getPlugins()) { |
|
|
plugin->RenX_OnPlayerIdentify(*this, *node); |
|
|
plugin->RenX_OnPlayerIdentify(*this, player); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -555,7 +554,7 @@ void RenX::Server::banCheck(RenX::PlayerInfo &player) { |
|
|
if ((m_localSteamBan && entry->steamid != 0 && entry->steamid == player.steamid) |
|
|
if ((m_localSteamBan && entry->steamid != 0 && entry->steamid == player.steamid) |
|
|
|| (m_localIPBan && entry->ip != 0 && (entry->ip & netmask) == (player.ip32 & netmask)) |
|
|
|| (m_localIPBan && entry->ip != 0 && (entry->ip & netmask) == (player.ip32 & netmask)) |
|
|
|| (m_localHWIDBan && !entry->hwid.empty() && entry->hwid == player.hwid) |
|
|
|| (m_localHWIDBan && !entry->hwid.empty() && entry->hwid == player.hwid) |
|
|
|| (m_localRDNSBan && !entry->rdns.empty() && entry->is_rdns_ban() && !player.rdns_thread.joinable() && player.rdns.find(entry->rdns) != std::string::npos) |
|
|
|| (m_localRDNSBan && !entry->rdns.empty() && entry->is_rdns_ban() && player.get_rdns().find(entry->rdns) != std::string::npos) |
|
|
|| (m_localNameBan && !entry->name.empty() && jessilib::equalsi(entry->name, player.name))) { |
|
|
|| (m_localNameBan && !entry->name.empty() && jessilib::equalsi(entry->name, player.name))) { |
|
|
player.ban_flags |= entry->flags; |
|
|
player.ban_flags |= entry->flags; |
|
|
if (entry->is_type_game()) |
|
|
if (entry->is_type_game()) |
|
@ -735,9 +734,8 @@ bool RenX::Server::removePlayer(int id) { |
|
|
--m_bot_count; |
|
|
--m_bot_count; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (node->rdns_thread.joinable()) { // Close the RDNS thread, if one exists
|
|
|
if (node->rdns_pending) { |
|
|
--m_player_rdns_resolutions_pending; |
|
|
--m_player_rdns_resolutions_pending; |
|
|
node->rdns_thread.join(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this->players.erase(node); |
|
|
this->players.erase(node); |
|
@ -1302,14 +1300,17 @@ void RenX::Server::sendLogChan(std::string_view msg) const { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void resolve_rdns(RenX::PlayerInfo *player) { |
|
|
void RenX::PlayerInfo::resolve_rdns(std::string in_ip, std::shared_ptr<std::string> out_rdns) { |
|
|
player->rdns_mutex.lock(); |
|
|
*out_rdns = Jupiter::Socket::resolveHostname(in_ip.c_str(), 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RenX::PlayerInfo::start_resolve_rdns() { |
|
|
|
|
|
rdns_pending = true; |
|
|
|
|
|
|
|
|
// TODO: don't do this
|
|
|
std::string player_ip = ip; |
|
|
char *resolved = Jupiter::Socket::resolveHostname_alloc(static_cast<std::string>(player->ip).c_str(), 0); |
|
|
auto rdns_string = std::make_shared<std::string>(); |
|
|
player->rdns = resolved; |
|
|
m_rdns_ptr = rdns_string; |
|
|
delete[] resolved; |
|
|
std::thread(resolve_rdns, ip, std::move(rdns_string)).detach(); |
|
|
player->rdns_mutex.unlock(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
struct parsed_player_token { |
|
|
struct parsed_player_token { |
|
@ -1519,7 +1520,7 @@ void RenX::Server::processLine(std::string_view line) { |
|
|
// RDNS
|
|
|
// RDNS
|
|
|
if (resolvesRDNS() && player->ip32 != 0) |
|
|
if (resolvesRDNS() && player->ip32 != 0) |
|
|
{ |
|
|
{ |
|
|
player->rdns_thread = std::thread(resolve_rdns, player); |
|
|
player->start_resolve_rdns(); |
|
|
++m_player_rdns_resolutions_pending; |
|
|
++m_player_rdns_resolutions_pending; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1555,7 +1556,7 @@ void RenX::Server::processLine(std::string_view line) { |
|
|
player->ip32 = Jupiter::Socket::pton4(static_cast<std::string>(player->ip).c_str()); |
|
|
player->ip32 = Jupiter::Socket::pton4(static_cast<std::string>(player->ip).c_str()); |
|
|
if (resolvesRDNS()) |
|
|
if (resolvesRDNS()) |
|
|
{ |
|
|
{ |
|
|
player->rdns_thread = std::thread(resolve_rdns, player); |
|
|
player->start_resolve_rdns(); |
|
|
++m_player_rdns_resolutions_pending; |
|
|
++m_player_rdns_resolutions_pending; |
|
|
} |
|
|
} |
|
|
recalcUUID = true; |
|
|
recalcUUID = true; |
|
@ -2847,8 +2848,7 @@ void RenX::Server::processLine(std::string_view line) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if (subHeader == "HWID;"sv) |
|
|
else if (subHeader == "HWID;"sv) { |
|
|
{ |
|
|
|
|
|
// ["player" |] Player | "hwid" | HWID
|
|
|
// ["player" |] Player | "hwid" | HWID
|
|
|
size_t offset = 0; |
|
|
size_t offset = 0; |
|
|
if (getToken(2) == "player"sv) |
|
|
if (getToken(2) == "player"sv) |
|
@ -2865,7 +2865,7 @@ void RenX::Server::processLine(std::string_view line) { |
|
|
plugin->RenX_OnHWID(*this, *player); |
|
|
plugin->RenX_OnHWID(*this, *player); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!player->rdns.empty()) { |
|
|
if (!player->rdns_pending) { |
|
|
for (const auto& plugin : xPlugins) { |
|
|
for (const auto& plugin : xPlugins) { |
|
|
plugin->RenX_OnPlayerIdentify(*this, *player); |
|
|
plugin->RenX_OnPlayerIdentify(*this, *player); |
|
|
} |
|
|
} |
|
@ -3654,14 +3654,10 @@ void RenX::Server::wipePlayers() { |
|
|
for (const auto& plugin : RenX::getCore()->getPlugins()) { |
|
|
for (const auto& plugin : RenX::getCore()->getPlugins()) { |
|
|
plugin->RenX_OnPlayerDelete(*this, this->players.front()); |
|
|
plugin->RenX_OnPlayerDelete(*this, this->players.front()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (this->players.front().rdns_thread.joinable()) { // Close the RDNS thread, if one exists
|
|
|
|
|
|
--m_player_rdns_resolutions_pending; |
|
|
|
|
|
this->players.front().rdns_thread.join(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this->players.pop_front(); |
|
|
this->players.pop_front(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_player_rdns_resolutions_pending = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void RenX::Server::startPing() { |
|
|
void RenX::Server::startPing() { |
|
|