diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/core/config.h | 1 | ||||
-rw-r--r-- | src/network/network.cpp | 31 | ||||
-rw-r--r-- | src/network/network.h | 1 |
3 files changed, 33 insertions, 0 deletions
diff --git a/src/network/core/config.h b/src/network/core/config.h index 63b54f7ce..93145e426 100644 --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -17,6 +17,7 @@ enum { NETWORK_MASTER_SERVER_PORT = 3978, ///< The default port of the master server (UDP) NETWORK_DEFAULT_PORT = 3979, ///< The default port of the game server (TCP & UDP) + NETWORK_DEFAULT_DEBUGLOG_PORT = 3982, ///< The default port debug-log is sent too (TCP) SEND_MTU = 1460, ///< Number of bytes we can pack in a single packet diff --git a/src/network/network.cpp b/src/network/network.cpp index 76a29f3af..1ea36b50e 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1317,6 +1317,37 @@ static void NetworkGenerateUniqueId(void) snprintf(_network_unique_id, sizeof(_network_unique_id), "%s", hex_output); } +void NetworkStartDebugLog(const char *hostname, uint16 port) +{ + extern SOCKET _debug_socket; // Comes from debug.c + SOCKET s; + struct sockaddr_in sin; + + DEBUG(net, 0, "Redirecting DEBUG() to %s:%d", hostname, port); + + s = socket(AF_INET, SOCK_STREAM, 0); + if (s == INVALID_SOCKET) { + DEBUG(net, 0, "Failed to open socket for redirection DEBUG()"); + return; + } + + if (!SetNoDelay(s)) DEBUG(net, 1, "Setting TCP_NODELAY failed"); + + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = NetworkResolveHost(hostname); + sin.sin_port = htons(port); + + if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) != 0) { + DEBUG(net, 0, "Failed to redirection DEBUG() to %s:%d", hostname, port); + return; + } + + if (!SetNonBlocking(s)) DEBUG(net, 0, "Setting non-blocking mode failed"); + _debug_socket = s; + + DEBUG(net, 0, "DEBUG() is now redirected"); +} + /** This tries to launch the network for a given OS */ void NetworkStartUp(void) { diff --git a/src/network/network.h b/src/network/network.h index 3f4182a92..d5306af30 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -166,6 +166,7 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[]); void NetworkPopulateCompanyInfo(void); void UpdateNetworkGameWindow(bool unselect); void CheckMinPlayers(void); +void NetworkStartDebugLog(const char *hostname, uint16 port); void NetworkStartUp(void); void NetworkUDPCloseAll(); |