Revert "Fix thread safety issues in network admin socket console logging"
This reverts commit ad15d4fd8f
.
This commit is contained in:
@@ -20,12 +20,6 @@
|
|||||||
#include "../map_func.h"
|
#include "../map_func.h"
|
||||||
#include "../rev.h"
|
#include "../rev.h"
|
||||||
#include "../game/game.hpp"
|
#include "../game/game.hpp"
|
||||||
#include "../thread.h"
|
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#if defined(__MINGW32__)
|
|
||||||
#include "../3rdparty/mingw-std-threads/mingw.mutex.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
|
|
||||||
@@ -45,17 +39,6 @@ INSTANTIATE_POOL_METHODS(NetworkAdminSocket)
|
|||||||
/** The timeout for authorisation of the client. */
|
/** The timeout for authorisation of the client. */
|
||||||
static const std::chrono::seconds ADMIN_AUTHORISATION_TIMEOUT(10);
|
static const std::chrono::seconds ADMIN_AUTHORISATION_TIMEOUT(10);
|
||||||
|
|
||||||
static void NetworkAdminConsoleIntl(const char *origin, const char *string);
|
|
||||||
|
|
||||||
struct NetworkAdminConsoleQueueItem {
|
|
||||||
std::string origin;
|
|
||||||
std::string string;
|
|
||||||
};
|
|
||||||
std::atomic<bool> _network_admin_console_logging;
|
|
||||||
std::mutex _network_admin_console_mutex;
|
|
||||||
std::vector<NetworkAdminConsoleQueueItem> _network_admin_console_queue;
|
|
||||||
std::vector<NetworkAdminConsoleQueueItem> _network_admin_console_queue_spare;
|
|
||||||
|
|
||||||
|
|
||||||
/** Frequencies, which may be registered for a certain update type. */
|
/** Frequencies, which may be registered for a certain update type. */
|
||||||
static const AdminUpdateFrequency _admin_update_type_frequencies[] = {
|
static const AdminUpdateFrequency _admin_update_type_frequencies[] = {
|
||||||
@@ -111,17 +94,6 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
|
|||||||
/** Send the packets for the server sockets. */
|
/** Send the packets for the server sockets. */
|
||||||
/* static */ void ServerNetworkAdminSocketHandler::Send()
|
/* static */ void ServerNetworkAdminSocketHandler::Send()
|
||||||
{
|
{
|
||||||
if (_network_admin_console_logging.load()) {
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(_network_admin_console_mutex);
|
|
||||||
std::swap(_network_admin_console_queue, _network_admin_console_queue_spare);
|
|
||||||
}
|
|
||||||
for (auto &item : _network_admin_console_queue_spare) {
|
|
||||||
NetworkAdminConsoleIntl(item.origin.c_str(), item.string.c_str());
|
|
||||||
}
|
|
||||||
_network_admin_console_queue_spare.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::Iterate()) {
|
for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::Iterate()) {
|
||||||
if (as->status == ADMIN_STATUS_INACTIVE && std::chrono::steady_clock::now() > as->connect_time + ADMIN_AUTHORISATION_TIMEOUT) {
|
if (as->status == ADMIN_STATUS_INACTIVE && std::chrono::steady_clock::now() > as->connect_time + ADMIN_AUTHORISATION_TIMEOUT) {
|
||||||
DEBUG(net, 1, "[admin] Admin did not send its authorisation within %d seconds", (uint32)std::chrono::duration_cast<std::chrono::seconds>(ADMIN_AUTHORISATION_TIMEOUT).count());
|
DEBUG(net, 1, "[admin] Admin did not send its authorisation within %d seconds", (uint32)std::chrono::duration_cast<std::chrono::seconds>(ADMIN_AUTHORISATION_TIMEOUT).count());
|
||||||
@@ -736,10 +708,6 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENC
|
|||||||
|
|
||||||
this->update_frequency[type] = freq;
|
this->update_frequency[type] = freq;
|
||||||
|
|
||||||
if (type == ADMIN_UPDATE_CONSOLE && (freq & ADMIN_FREQUENCY_AUTOMATIC)) {
|
|
||||||
_network_admin_console_logging.store(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -972,15 +940,6 @@ void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code,
|
|||||||
ServerNetworkAdminSocketHandler::Get(admin_index)->SendRcon(colour_code, string);
|
ServerNetworkAdminSocketHandler::Get(admin_index)->SendRcon(colour_code, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NetworkAdminConsoleIntl(const char *origin, const char *string)
|
|
||||||
{
|
|
||||||
for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
|
|
||||||
if (as->update_frequency[ADMIN_UPDATE_CONSOLE] & ADMIN_FREQUENCY_AUTOMATIC) {
|
|
||||||
as->SendConsole(origin, string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send console to the admin network (if they did opt in for the respective update).
|
* Send console to the admin network (if they did opt in for the respective update).
|
||||||
* @param origin the origin of the message.
|
* @param origin the origin of the message.
|
||||||
@@ -988,15 +947,11 @@ static void NetworkAdminConsoleIntl(const char *origin, const char *string)
|
|||||||
*/
|
*/
|
||||||
void NetworkAdminConsole(const char *origin, const char *string)
|
void NetworkAdminConsole(const char *origin, const char *string)
|
||||||
{
|
{
|
||||||
if (!_network_admin_console_logging.load()) return;
|
for (ServerNetworkAdminSocketHandler *as : ServerNetworkAdminSocketHandler::IterateActive()) {
|
||||||
|
if (as->update_frequency[ADMIN_UPDATE_CONSOLE] & ADMIN_FREQUENCY_AUTOMATIC) {
|
||||||
if (IsNonGameThread()) {
|
as->SendConsole(origin, string);
|
||||||
std::lock_guard<std::mutex> lock(_network_admin_console_mutex);
|
}
|
||||||
_network_admin_console_queue.push_back({ origin, string });
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkAdminConsoleIntl(origin, string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user