Skip to content

Commit 5f430ff

Browse files
committed
Server: Commands: Listed connected sockets and matches now include time of connection/creation
1 parent 6e51d4b commit 5f430ff

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

InternetGamesServer/Command.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,20 @@ DWORD WINAPI CommandHandler(void*)
101101
std::cout
102102
<< std::endl
103103
<< std::left << std::setw(17) << "IP"
104+
<< std::setw(21) << "Connected since"
104105
<< std::setw(31) << "Type"
105106
<< std::setw(27) << "State"
106107
<< "Match Joined (GUID)" << std::endl
107-
<< std::string(115, '-') << std::endl;
108+
<< std::string(134, '-') << std::endl;
108109
for (const Socket* socket : Socket::GetList())
109110
{
111+
const std::time_t connectionTime = socket->GetConnectionTime();
112+
std::tm localConnectionTime;
113+
localtime_s(&localConnectionTime, &connectionTime);
114+
110115
std::cout
111116
<< std::setw(15) << socket->GetAddressString() << " "
117+
<< std::put_time(&localConnectionTime, "%d/%m/%Y %H:%M:%S") << " "
112118
<< std::setw(29) << Socket::TypeToString(socket->GetType()) << " ";
113119
if (socket->GetPlayerSocket())
114120
{
@@ -144,17 +150,23 @@ DWORD WINAPI CommandHandler(void*)
144150
{
145151
std::cout
146152
<< std::endl
147-
<< std::left << std::setw(8) << "Index"
153+
<< std::left << std::setw(12) << "Index"
148154
<< std::setw(40) << "GUID"
155+
<< std::setw(21) << "Created on"
149156
<< std::setw(7) << "Type"
150157
<< std::setw(25) << "State"
151158
<< "Game" << std::endl
152-
<< std::string(105, '-') << std::endl;
159+
<< std::string(130, '-') << std::endl;
153160
for (const auto& match : MatchManager::Get().GetMatchesWin7())
154161
{
162+
const std::time_t creationTime = match->GetCreationTime();
163+
std::tm localCreationTime;
164+
localtime_s(&localCreationTime, &creationTime);
165+
155166
std::cout
156-
<< std::right << std::setw(6) << match->GetIndex() << " "
167+
<< std::right << std::setw(10) << match->GetIndex() << " "
157168
<< std::left << match->GetGUID() << " "
169+
<< std::put_time(&localCreationTime, "%d/%m/%Y %H:%M:%S") << " "
158170
<< std::setw(7) << "Win7"
159171
<< std::setw(25) << Win7::Match::StateToString(match->GetState())
160172
<< Win7::Match::GameToNameString(match->GetGame())
@@ -163,9 +175,14 @@ DWORD WINAPI CommandHandler(void*)
163175
}
164176
for (const auto& match : MatchManager::Get().GetMatchesWinXP())
165177
{
178+
const std::time_t creationTime = match->GetCreationTime();
179+
std::tm localCreationTime;
180+
localtime_s(&localCreationTime, &creationTime);
181+
166182
std::cout
167-
<< std::right << std::setw(6) << match->GetIndex() << " "
183+
<< std::right << std::setw(10) << match->GetIndex() << " "
168184
<< std::left << match->GetGUID() << " "
185+
<< std::put_time(&localCreationTime, "%d/%m/%Y %H:%M:%S") << " "
169186
<< std::setw(7) << "WinXP"
170187
<< std::setw(25) << WinXP::Match::StateToString(match->GetState())
171188
<< WinXP::Match::GameToNameString(match->GetGame())

InternetGamesServer/Match.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Match
3030
virtual int8_t GetRequiredPlayerCount() const { return 2; }
3131
inline unsigned int GetIndex() const { return m_index; }
3232
inline REFGUID GetGUID() const { return m_guid; }
33+
inline std::time_t GetCreationTime() const { return m_creationTime; }
3334

3435
protected:
3536
void AddPlayer(P& player)

InternetGamesServer/Socket.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ Socket::GetAddressString(SOCKET socket, const char portSeparator)
241241
Socket::Socket(SOCKET socket, std::ostream& log) :
242242
m_socket(socket),
243243
m_log(log),
244+
m_connectionTime(std::time(nullptr)),
244245
m_disconnected(false),
245246
m_type(UNKNOWN),
246247
m_playerSocket(nullptr)

InternetGamesServer/Socket.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ class Socket final
6767
Socket(SOCKET socket, std::ostream& log);
6868
~Socket();
6969

70-
inline Type GetType() const { return m_type; }
71-
inline PlayerSocket* GetPlayerSocket() const { return m_playerSocket; }
72-
7370
void Disconnect();
7471

7572
/** Receive data */
@@ -193,10 +190,14 @@ class Socket final
193190
inline SOCKET GetRaw() const { return m_socket; }
194191
inline std::string GetAddressString() const { return GetAddressString(m_socket); }
195192
inline bool IsDisconnected() const { return m_disconnected; }
193+
inline std::time_t GetConnectionTime() const { return m_connectionTime; }
194+
inline Type GetType() const { return m_type; }
195+
inline PlayerSocket* GetPlayerSocket() const { return m_playerSocket; }
196196

197197
private:
198198
const SOCKET m_socket;
199199
std::ostream& m_log;
200+
const std::time_t m_connectionTime;
200201

201202
bool m_disconnected;
202203

0 commit comments

Comments
 (0)