mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-19 13:03:11 +01:00
Log IP address to console
This commit is contained in:
@@ -87,6 +87,8 @@ private:
|
||||
uint16 _listeningPort = 0;
|
||||
SOCKET _socket = INVALID_SOCKET;
|
||||
|
||||
std::string _hostStr;
|
||||
|
||||
SDL_mutex * _connectMutex = nullptr;
|
||||
std::string _error;
|
||||
|
||||
@@ -182,9 +184,11 @@ public:
|
||||
{
|
||||
throw Exception("Socket not listening.");
|
||||
}
|
||||
struct sockaddr_storage client_addr;
|
||||
socklen_t client_len = sizeof(struct sockaddr_storage);
|
||||
|
||||
ITcpSocket * tcpSocket = nullptr;
|
||||
SOCKET socket = accept(_socket, nullptr, nullptr);
|
||||
SOCKET socket = accept(_socket, (struct sockaddr *)&client_addr, &client_len);
|
||||
if (socket == INVALID_SOCKET)
|
||||
{
|
||||
if (LAST_SOCKET_ERROR() != EWOULDBLOCK)
|
||||
@@ -201,8 +205,12 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
char hoststr[NI_MAXHOST];
|
||||
int rc = getnameinfo((struct sockaddr *)&client_addr, client_len, hoststr, sizeof(hoststr), nullptr, 0, NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
SetTCPNoDelay(socket, true);
|
||||
tcpSocket = new TcpSocket(socket);
|
||||
if (rc == 0)
|
||||
tcpSocket->SetHostStr(hoststr);
|
||||
}
|
||||
}
|
||||
return tcpSocket;
|
||||
@@ -403,6 +411,16 @@ public:
|
||||
SDL_UnlockMutex(_connectMutex);
|
||||
}
|
||||
|
||||
const char * GetHostStr() override
|
||||
{
|
||||
return _hostStr.empty() ? nullptr : _hostStr.c_str();
|
||||
}
|
||||
|
||||
void SetHostStr(const char * hostStr) override
|
||||
{
|
||||
_hostStr = std::string(hostStr);
|
||||
}
|
||||
|
||||
private:
|
||||
TcpSocket(SOCKET socket)
|
||||
{
|
||||
|
||||
@@ -58,6 +58,9 @@ public:
|
||||
|
||||
virtual void Disconnect() abstract;
|
||||
virtual void Close() abstract;
|
||||
|
||||
virtual const char * GetHostStr() abstract;
|
||||
virtual void SetHostStr(const char * hostStr) abstract;
|
||||
};
|
||||
|
||||
ITcpSocket * CreateTcpSocket();
|
||||
|
||||
@@ -1408,6 +1408,10 @@ void Network::Server_Client_Joined(const char* name, const std::string &keyhash,
|
||||
if (player) {
|
||||
char text[256];
|
||||
const char * player_name = (const char *) player->name.c_str();
|
||||
//Relay connection information to console
|
||||
auto hostStr = connection.Socket->GetHostStr();
|
||||
log_info("%s has joined from host: %s", player_name, hostStr);
|
||||
//Show join message in chat
|
||||
format_string(text, 256, STR_MULTIPLAYER_PLAYER_HAS_JOINED_THE_GAME, &player_name);
|
||||
chat_history_add(text);
|
||||
Server_Send_MAP(&connection);
|
||||
|
||||
Reference in New Issue
Block a user