Remove: Debug redirect over network

It does not work for dedicated servers because upon starting the process to
resolve the address to redirect to gets killed. Also with all the async going
on in the network code, the debug redirection will start very late in the
process.
This commit is contained in:
Rubidium 2024-01-14 21:07:35 +01:00 committed by rubidium42
parent a6873ef7dd
commit 564441e822
6 changed files with 0 additions and 55 deletions

View File

@ -16,7 +16,6 @@
.Op Fl g Op Ar savegame .Op Fl g Op Ar savegame
.Op Fl G Ar seed .Op Fl G Ar seed
.Op Fl I Ar graphicsset .Op Fl I Ar graphicsset
.Op Fl l Ar host Ns Op : Ns Ar port
.Op Fl m Ar driver .Op Fl m Ar driver
.Op Fl M Ar musicset .Op Fl M Ar musicset
.Op Fl n Ar host Ns Oo : Ns Ar port Oc Ns Op # Ns Ar company .Op Fl n Ar host Ns Oo : Ns Ar port Oc Ns Op # Ns Ar company
@ -82,9 +81,6 @@ Select the graphics set
see see
.Fl h .Fl h
for a full list. for a full list.
.It Fl l Ar host Ns Op : Ns Ar port
Redirect debug output; see
.Fl d .
.It Fl m Ar driver .It Fl m Ar driver
Select the music driver Select the music driver
.Ar driver ; .Ar driver ;

View File

@ -22,7 +22,6 @@
#include "3rdparty/fmt/chrono.h" #include "3rdparty/fmt/chrono.h"
#include "network/network_admin.h" #include "network/network_admin.h"
SOCKET _debug_socket = INVALID_SOCKET;
#include "safeguards.h" #include "safeguards.h"
@ -111,18 +110,6 @@ void DumpDebugFacilityNames(std::back_insert_iterator<std::string> &output_itera
*/ */
void DebugPrint(const char *level, const std::string &message) void DebugPrint(const char *level, const std::string &message)
{ {
if (_debug_socket != INVALID_SOCKET) {
std::string msg = fmt::format("{}dbg: [{}] {}\n", GetLogPrefix(), level, message);
/* Prevent sending a message concurrently, as that might cause interleaved messages. */
static std::mutex _debug_socket_mutex;
std::lock_guard<std::mutex> lock(_debug_socket_mutex);
/* Sending out an error when this fails would be nice, however... the error
* would have to be send over this failing socket which won't work. */
send(_debug_socket, msg.c_str(), (int)msg.size(), 0);
return;
}
if (strcmp(level, "desync") == 0) { if (strcmp(level, "desync") == 0) {
static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR); static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
if (f == nullptr) return; if (f == nullptr) return;

View File

@ -24,7 +24,6 @@ static const uint16_t NETWORK_TURN_SERVER_PORT = 3974; ///< The
static const uint16_t NETWORK_CONTENT_SERVER_PORT = 3978; ///< The default port of the content server (TCP) static const uint16_t NETWORK_CONTENT_SERVER_PORT = 3978; ///< The default port of the content server (TCP)
static const uint16_t NETWORK_DEFAULT_PORT = 3979; ///< The default port of the game server (TCP & UDP) static const uint16_t NETWORK_DEFAULT_PORT = 3979; ///< The default port of the game server (TCP & UDP)
static const uint16_t NETWORK_ADMIN_PORT = 3977; ///< The default port for admin network static const uint16_t NETWORK_ADMIN_PORT = 3977; ///< The default port for admin network
static const uint16_t NETWORK_DEFAULT_DEBUGLOG_PORT = 3982; ///< The default port debug-log is sent to (TCP)
static const uint16_t UDP_MTU = 1460; ///< Number of bytes we can pack in a single UDP packet static const uint16_t UDP_MTU = 1460; ///< Number of bytes we can pack in a single UDP packet

View File

@ -1218,32 +1218,6 @@ static void NetworkGenerateServerId()
_settings_client.network.network_id = GenerateUid("OpenTTD Server ID"); _settings_client.network.network_id = GenerateUid("OpenTTD Server ID");
} }
class TCPNetworkDebugConnecter : TCPConnecter {
private:
std::string connection_string;
public:
TCPNetworkDebugConnecter(const std::string &connection_string) : TCPConnecter(connection_string, NETWORK_DEFAULT_DEBUGLOG_PORT), connection_string(connection_string) {}
void OnFailure() override
{
Debug(net, 0, "Failed to open connection to {} for redirecting Debug()", this->connection_string);
}
void OnConnect(SOCKET s) override
{
Debug(net, 3, "Redirecting Debug() to {}", this->connection_string);
extern SOCKET _debug_socket;
_debug_socket = s;
}
};
void NetworkStartDebugLog(const std::string &connection_string)
{
new TCPNetworkDebugConnecter(connection_string);
}
/** This tries to launch the network for a given OS */ /** This tries to launch the network for a given OS */
void NetworkStartUp() void NetworkStartUp()
{ {

View File

@ -47,7 +47,6 @@ void NetworkDisconnect(bool close_admins = true);
void NetworkGameLoop(); void NetworkGameLoop();
void NetworkBackgroundLoop(); void NetworkBackgroundLoop();
std::string_view ParseFullConnectionString(const std::string &connection_string, uint16_t &port, CompanyID *company_id = nullptr); std::string_view ParseFullConnectionString(const std::string &connection_string, uint16_t &port, CompanyID *company_id = nullptr);
void NetworkStartDebugLog(const std::string &connection_string);
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats); void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
void NetworkUpdateClientInfo(ClientID client_id); void NetworkUpdateClientInfo(ClientID client_id);

View File

@ -169,7 +169,6 @@ static void ShowHelp()
" -p password = Password to join server\n" " -p password = Password to join server\n"
" -P password = Password to join company\n" " -P password = Password to join company\n"
" -D [host][:port] = Start dedicated server\n" " -D [host][:port] = Start dedicated server\n"
" -l host[:port] = Redirect Debug()\n"
#if !defined(_WIN32) #if !defined(_WIN32)
" -f = Fork into the background (dedicated only)\n" " -f = Fork into the background (dedicated only)\n"
#endif #endif
@ -489,7 +488,6 @@ static const OptionData _options[] = {
GETOPT_SHORT_VALUE('b'), GETOPT_SHORT_VALUE('b'),
GETOPT_SHORT_OPTVAL('D'), GETOPT_SHORT_OPTVAL('D'),
GETOPT_SHORT_VALUE('n'), GETOPT_SHORT_VALUE('n'),
GETOPT_SHORT_VALUE('l'),
GETOPT_SHORT_VALUE('p'), GETOPT_SHORT_VALUE('p'),
GETOPT_SHORT_VALUE('P'), GETOPT_SHORT_VALUE('P'),
#if !defined(_WIN32) #if !defined(_WIN32)
@ -528,7 +526,6 @@ int openttd_main(int argc, char *argv[])
Dimension resolution = {0, 0}; Dimension resolution = {0, 0};
std::unique_ptr<AfterNewGRFScan> scanner(new AfterNewGRFScan()); std::unique_ptr<AfterNewGRFScan> scanner(new AfterNewGRFScan());
bool dedicated = false; bool dedicated = false;
char *debuglog_conn = nullptr;
bool only_local_path = false; bool only_local_path = false;
extern bool _dedicated_forks; extern bool _dedicated_forks;
@ -565,9 +562,6 @@ int openttd_main(int argc, char *argv[])
case 'n': case 'n':
scanner->connection_string = mgo.opt; // host:port#company parameter scanner->connection_string = mgo.opt; // host:port#company parameter
break; break;
case 'l':
debuglog_conn = mgo.opt;
break;
case 'p': case 'p':
scanner->join_server_password = mgo.opt; scanner->join_server_password = mgo.opt;
break; break;
@ -762,10 +756,6 @@ int openttd_main(int argc, char *argv[])
NetworkStartUp(); // initialize network-core NetworkStartUp(); // initialize network-core
if (debuglog_conn != nullptr && _network_available) {
NetworkStartDebugLog(debuglog_conn);
}
if (!HandleBootstrap()) { if (!HandleBootstrap()) {
ShutdownGame(); ShutdownGame();
return ret; return ret;