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
 
@@ -13,13 +13,12 @@
 
.Op Fl c Ar config_file
 
.Op Fl d Op Ar level | Ar cat Ns = Ns Ar lvl Ns Op , Ns Ar ...
 
.Op Fl D Oo Ar host Oc Ns Op : Ns Ar port
 
.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
 
.Op Fl p Ar password
 
.Op Fl P Ar password
 
.Op Fl q Ar savegame
 
@@ -79,15 +78,12 @@ sound, music and video drivers, graphics
 
.It Fl I Ar graphicsset
 
Select the graphics set
 
.Ar graphicsset ;
 
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 ;
 
see
 
.Fl h
 
for a full list.
src/debug.cpp
Show inline comments
 
@@ -19,13 +19,12 @@
 
#include "os/windows/win32.h"
 
#endif
 

	
 
#include "3rdparty/fmt/chrono.h"
 

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

	
 
#include "safeguards.h"
 

	
 
/** Element in the queue of debug messages that have to be passed to either NetworkAdminConsole or IConsolePrint.*/
 
struct QueuedDebugItem {
 
	std::string level;   ///< The used debug level.
 
@@ -108,24 +107,12 @@ void DumpDebugFacilityNames(std::back_in
 
 * Internal function for outputting the debug line.
 
 * @param level Debug category.
 
 * @param message The message to output.
 
 */
 
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;
 

	
 
		fmt::print(f, "{}{}\n", GetLogPrefix(), message);
 
		fflush(f);
src/network/core/config.h
Show inline comments
 
@@ -21,13 +21,12 @@ const char *NetworkSurveyUriString();
 
static const uint16_t NETWORK_COORDINATOR_SERVER_PORT = 3976;           ///< The default port of the Game Coordinator server (TCP)
 
static const uint16_t NETWORK_STUN_SERVER_PORT        = 3975;           ///< The default port of the STUN server (TCP)
 
static const uint16_t NETWORK_TURN_SERVER_PORT        = 3974;           ///< The default port of the TURN 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_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 std::string NETWORK_SURVEY_DETAILS_LINK = "https://survey.openttd.org/participate"; ///< Link with more details & privacy statement of the survey.
 
/*
 
 * Technically a TCP packet could become 64kiB, however the high bit is kept so it becomes possible in the future
src/network/network.cpp
Show inline comments
 
@@ -1215,38 +1215,12 @@ void NetworkGameLoop()
 

	
 
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()
 
{
 
	Debug(net, 3, "Starting network");
 

	
 
	/* Network is available */
src/network/network_func.h
Show inline comments
 
@@ -44,13 +44,12 @@ bool NetworkCompanyHasClients(CompanyID 
 
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password);
 
void NetworkReboot();
 
void NetworkDisconnect(bool close_admins = true);
 
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);
 
void NetworkClientsToSpectators(CompanyID cid);
 
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password = "", const std::string &join_company_password = "");
 
void NetworkClientJoinGame();
src/openttd.cpp
Show inline comments
 
@@ -166,13 +166,12 @@ static void ShowHelp()
 
		"  -g [savegame]       = Start new/save game immediately\n"
 
		"  -G seed             = Set random seed\n"
 
		"  -n host[:port][#company]= Join network game\n"
 
		"  -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
 
		"  -I graphics_set     = Force the graphics set (see below)\n"
 
		"  -S sounds_set       = Force the sounds set (see below)\n"
 
		"  -M music_set        = Force the music set (see below)\n"
 
@@ -486,13 +485,12 @@ static const OptionData _options[] = {
 
	 GETOPT_SHORT_VALUE('m'),
 
	 GETOPT_SHORT_VALUE('s'),
 
	 GETOPT_SHORT_VALUE('v'),
 
	 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)
 
	 GETOPT_SHORT_NOVAL('f'),
 
#endif
 
	 GETOPT_SHORT_VALUE('r'),
 
@@ -525,13 +523,12 @@ int openttd_main(int argc, char *argv[])
 
	std::string graphics_set;
 
	std::string sounds_set;
 
	std::string music_set;
 
	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;
 
	_dedicated_forks = false;
 

	
 
	_game_mode = GM_MENU;
 
@@ -562,15 +559,12 @@ int openttd_main(int argc, char *argv[])
 
			}
 
			break;
 
		case 'f': _dedicated_forks = true; break;
 
		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;
 
		case 'P':
 
			scanner->join_company_password = mgo.opt;
 
			break;
 
@@ -759,16 +753,12 @@ int openttd_main(int argc, char *argv[])
 

	
 
	/* The video driver is now selected, now initialise GUI zoom */
 
	AdjustGUIZoom(false);
 

	
 
	NetworkStartUp(); // initialize network-core
 

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

	
 
	if (!HandleBootstrap()) {
 
		ShutdownGame();
 
		return ret;
 
	}
 

	
 
	VideoDriver::GetInstance()->ClaimMousePointer();
0 comments (0 inline, 0 general)