Changeset - r28449:548e1fdb09a4
[Not reviewed]
master
0 6 0
Rubidium - 11 months ago 2024-01-14 20:07:35
rubidium@openttd.org
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.
6 files changed with 0 insertions and 55 deletions:
0 comments (0 inline, 0 general)
docs/openttd.6
Show inline comments
 
@@ -16,7 +16,6 @@
 
.Op Fl g Op Ar savegame
 
.Op Fl G Ar seed
 
.Op Fl I Ar graphicsset
 
.Op Fl l Ar host Ns Op : Ns Ar port
 
.Op Fl m Ar driver
 
.Op Fl M Ar musicset
 
.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
 
.Fl h
 
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
 
Select the music driver
 
.Ar driver ;
src/debug.cpp
Show inline comments
 
@@ -22,7 +22,6 @@
 
#include "3rdparty/fmt/chrono.h"
 

	
 
#include "network/network_admin.h"
 
SOCKET _debug_socket = INVALID_SOCKET;
 

	
 
#include "safeguards.h"
 

	
 
@@ -111,18 +110,6 @@ void DumpDebugFacilityNames(std::back_in
 
 */
 
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) {
 
		static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
 
		if (f == nullptr) return;
src/network/core/config.h
Show inline comments
 
@@ -24,7 +24,6 @@ static const uint16_t NETWORK_TURN_SERVE
 
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_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
 

	
src/network/network.cpp
Show inline comments
 
@@ -1218,32 +1218,6 @@ static void NetworkGenerateServerId()
 
	_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 */
 
void NetworkStartUp()
 
{
src/network/network_func.h
Show inline comments
 
@@ -47,7 +47,6 @@ void NetworkDisconnect(bool close_admins
 
void NetworkGameLoop();
 
void NetworkBackgroundLoop();
 
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 NetworkUpdateClientInfo(ClientID client_id);
src/openttd.cpp
Show inline comments
 
@@ -169,7 +169,6 @@ static void ShowHelp()
 
		"  -p password         = Password to join server\n"
 
		"  -P password         = Password to join company\n"
 
		"  -D [host][:port]    = Start dedicated server\n"
 
		"  -l host[:port]      = Redirect Debug()\n"
 
#if !defined(_WIN32)
 
		"  -f                  = Fork into the background (dedicated only)\n"
 
#endif
 
@@ -489,7 +488,6 @@ static const OptionData _options[] = {
 
	 GETOPT_SHORT_VALUE('b'),
 
	GETOPT_SHORT_OPTVAL('D'),
 
	 GETOPT_SHORT_VALUE('n'),
 
	 GETOPT_SHORT_VALUE('l'),
 
	 GETOPT_SHORT_VALUE('p'),
 
	 GETOPT_SHORT_VALUE('P'),
 
#if !defined(_WIN32)
 
@@ -528,7 +526,6 @@ int openttd_main(int argc, char *argv[])
 
	Dimension resolution = {0, 0};
 
	std::unique_ptr<AfterNewGRFScan> scanner(new AfterNewGRFScan());
 
	bool dedicated = false;
 
	char *debuglog_conn = nullptr;
 
	bool only_local_path = false;
 

	
 
	extern bool _dedicated_forks;
 
@@ -565,9 +562,6 @@ int openttd_main(int argc, char *argv[])
 
		case 'n':
 
			scanner->connection_string = mgo.opt; // host:port#company parameter
 
			break;
 
		case 'l':
 
			debuglog_conn = mgo.opt;
 
			break;
 
		case 'p':
 
			scanner->join_server_password = mgo.opt;
 
			break;
 
@@ -762,10 +756,6 @@ int openttd_main(int argc, char *argv[])
 

	
 
	NetworkStartUp(); // initialize network-core
 

	
 
	if (debuglog_conn != nullptr && _network_available) {
 
		NetworkStartDebugLog(debuglog_conn);
 
	}
 

	
 
	if (!HandleBootstrap()) {
 
		ShutdownGame();
 
		return ret;
0 comments (0 inline, 0 general)