From b19220d62d4b9eb06e5b4537552d63d6289d2368 Mon Sep 17 00:00:00 2001 From: evgen1137 <30495180+evgen1137@users.noreply.github.com> Date: Fri, 28 Jul 2017 19:35:34 +0600 Subject: [PATCH] add size column in the server list adds a new column to the server list that displays the total size of all currently loaded resources on the server --- Client/core/Serverbrowser/CServerBrowser.cpp | 52 ++++++++++++++++++- Client/core/Serverbrowser/CServerBrowser.h | 1 + Client/core/Serverbrowser/CServerList.cpp | 8 ++- Client/core/Serverbrowser/CServerList.h | 2 + Server/mods/deathmatch/logic/ASE.cpp | 5 +- Server/mods/deathmatch/logic/CResource.cpp | 3 ++ Server/mods/deathmatch/logic/CResource.h | 2 + .../deathmatch/logic/CResourceManager.cpp | 15 ++++++ .../mods/deathmatch/logic/CResourceManager.h | 1 + 9 files changed, 85 insertions(+), 4 deletions(-) diff --git a/Client/core/Serverbrowser/CServerBrowser.cpp b/Client/core/Serverbrowser/CServerBrowser.cpp index 58f1285a599..f1ec5c22ef1 100644 --- a/Client/core/Serverbrowser/CServerBrowser.cpp +++ b/Client/core/Serverbrowser/CServerBrowser.cpp @@ -458,15 +458,17 @@ void CServerBrowser::CreateTab ( ServerBrowserType type, const char* szName ) m_hPlayers [ type ] = m_pServerList [ type ]->AddColumn ( _("Players"), 0.2f ); m_hPing [ type ] = m_pServerList [ type ]->AddColumn ( _("Ping"), 0.2f ); m_hGame [ type ] = m_pServerList [ type ]->AddColumn ( _("Gamemode"), 0.2f ); + m_hResSize [ type ] = m_pServerList [ type ]->AddColumn ( _("Size"), 0.2f ); // NB. SetColumnWidth seems to start from 0 m_pServerList [ type ]->SetColumnWidth ( m_hVersion [ type ], 25, false ); m_pServerList [ type ]->SetColumnWidth ( m_hLocked [ type ], 16, false ); m_pServerList [ type ]->SetColumnWidth ( m_hPlayers [ type ], 70, false ); m_pServerList [ type ]->SetColumnWidth ( m_hPing [ type ], 35, false ); + m_pServerList [ type ]->SetColumnWidth ( m_hResSize[ type ], 70, false ); // We give Name and Gamemode 65% and 35% of the remaining length respectively - float fRemainingWidth = fWidth - 25 - 16 - 70 - 35 - 50; // All the fixed sizes plus 50 for the scrollbar + float fRemainingWidth = fWidth - 25 - 16 - 70 - 35 - 70 - 50; // All the fixed sizes plus 50 for the scrollbar m_pServerList [ type ]->SetColumnWidth ( m_hGame [ type ], fRemainingWidth*0.35, false ); m_pServerList [ type ]->SetColumnWidth ( m_hName [ type ], fRemainingWidth*0.65, false ); @@ -965,6 +967,50 @@ void CServerBrowser::UpdateHistoryList ( void ) } } +SString GetDataUnit(unsigned long long ullInput) +{ + // Convert it to a float + float fInput = static_cast < float > (ullInput); + + // Bytes per sec? + if (fInput < 1024) + { + return SString("%u B", (uint)ullInput); + } + + // Kilobytes per sec? + fInput /= 1024; + if (fInput < 1024) + { + return SString("%.2f kB", fInput); + } + + // Megabytes per sec? + fInput /= 1024; + if (fInput < 1024) + { + return SString("%.2f MB", fInput); + } + + // Gigabytes per sec? + fInput /= 1024; + if (fInput < 1024) + { + return SString("%.2f GB", fInput); + } + + // Terrabytes per sec? + fInput /= 1024; + if (fInput < 1024) + { + return SString("%.2f TB", fInput); + } + + // Unknown + SString strUnknown = "X"; + return strUnknown; +} + void CServerBrowser::AddServerToList ( const CServerListItem * pServer, const ServerBrowserType Type ) { bool bIncludeEmpty = m_pIncludeEmpty [ Type ]->GetSelected (); @@ -1075,12 +1121,16 @@ void CServerBrowser::AddServerToList ( const CServerListItem * pServer, const Se const SString strPing = pServer->nPing == 9999 ? "" : SString ( "%d", pServer->nPing ); const SString strPingSortKey = SString ( "%04d-", pServer->nPing ) + pServer->strTieBreakSortKey; + const SString strResSize = GetDataUnit(static_cast < unsigned long long > ( pServer->fResSize * 1024 ) ); + const SString strResSizeSortKey = SString ( "-", 0 ) + pServer->strTieBreakSortKey; // TODO + // The row index could change at any point here if list sorting is enabled iIndex = m_pServerList [ Type ]->SetItemText ( iIndex, m_hVersion [ Type ], strVersion, false, false, true, strVersionSortKey ); iIndex = m_pServerList [ Type ]->SetItemText ( iIndex, m_hName [ Type ], pServer->strName, false, false, true, pServer->strNameSortKey ); iIndex = m_pServerList [ Type ]->SetItemText ( iIndex, m_hGame [ Type ], pServer->strGameMode, false, false, true ); iIndex = m_pServerList [ Type ]->SetItemText ( iIndex, m_hPlayers [ Type ], strPlayers, false, false, true, strPlayersSortKey ); iIndex = m_pServerList [ Type ]->SetItemText ( iIndex, m_hPing [ Type ], strPing, false, false, true, strPingSortKey ); + iIndex = m_pServerList [ Type ]->SetItemText ( iIndex, m_hResSize [ Type ], strResSize, false, false, true, strResSizeSortKey ); // Locked icon m_pServerList [ Type ]->SetItemImage ( iIndex, m_hLocked [ Type ], pServer->bPassworded ? m_pLockedIcon : NULL ); diff --git a/Client/core/Serverbrowser/CServerBrowser.h b/Client/core/Serverbrowser/CServerBrowser.h index e2eb86f3189..2378655381b 100644 --- a/Client/core/Serverbrowser/CServerBrowser.h +++ b/Client/core/Serverbrowser/CServerBrowser.h @@ -188,6 +188,7 @@ class CServerBrowser : public CSingleton < CServerBrowser > // Server list columns CGUIHandle m_hVersion [ SERVER_BROWSER_TYPE_COUNT ]; CGUIHandle m_hLocked [ SERVER_BROWSER_TYPE_COUNT ]; + CGUIHandle m_hResSize [ SERVER_BROWSER_TYPE_COUNT ]; CGUIHandle m_hName [ SERVER_BROWSER_TYPE_COUNT ]; CGUIHandle m_hPing [ SERVER_BROWSER_TYPE_COUNT ]; CGUIHandle m_hPlayers [ SERVER_BROWSER_TYPE_COUNT ]; diff --git a/Client/core/Serverbrowser/CServerList.cpp b/Client/core/Serverbrowser/CServerList.cpp index 70b3e57c451..e03352a1b12 100644 --- a/Client/core/Serverbrowser/CServerList.cpp +++ b/Client/core/Serverbrowser/CServerList.cpp @@ -635,12 +635,12 @@ bool CServerListItem::ParseQuery ( const char * szBuffer, unsigned int nLength ) // Get player nicks vecPlayers.clear (); - while ( i < nLength ) + while ( i < nLength - 4 ) { std::string strPlayer; try { - if ( ReadString ( strPlayer, szBuffer, i, nLength ) ) + if ( ReadString ( strPlayer, szBuffer, i, nLength - 4 ) ) { // Remove color code, unless that results in an empty string SString strResult = RemoveColorCodes ( strPlayer.c_str () ); @@ -656,6 +656,10 @@ bool CServerListItem::ParseQuery ( const char * szBuffer, unsigned int nLength ) return false; } } + if (i + 4 == nLength) + { + fResSize = *(float*)&szBuffer[i]; + } bScanned = true; diff --git a/Client/core/Serverbrowser/CServerList.h b/Client/core/Serverbrowser/CServerList.h index 2361ffa090b..72a6cacb132 100644 --- a/Client/core/Serverbrowser/CServerList.h +++ b/Client/core/Serverbrowser/CServerList.h @@ -139,6 +139,7 @@ class CServerListItem nPlayers = 0; nMaxPlayers = 0; nPing = 9999; + fResSize = 0; uiCacheNoReplyCount = 0; m_ElapsedTime.SetMaxIncrement ( 500 ); m_ElapsedTime.Reset (); @@ -191,6 +192,7 @@ class CServerListItem unsigned short nPlayers; // Current players unsigned short nMaxPlayers; // Maximum players unsigned short nPing; // Ping time + float fResSize; // Resources size bool bPassworded; // Password protected bool bSerials; // Serial verification on bool bScanned; diff --git a/Server/mods/deathmatch/logic/ASE.cpp b/Server/mods/deathmatch/logic/ASE.cpp index f8b392b695d..cbac895dc0d 100644 --- a/Server/mods/deathmatch/logic/ASE.cpp +++ b/Server/mods/deathmatch/logic/ASE.cpp @@ -477,7 +477,7 @@ std::string ASE::QueryLight ( void ) CPlayer* pPlayer = NULL; // Keep the packet under 1350 bytes to try to avoid fragmentation - int iBytesLeft = 1340 - (int)reply.tellp (); + int iBytesLeft = 1336 - (int)reply.tellp (); int iPlayersLeft = iJoinedPlayers; list < CPlayer* > ::const_iterator pIter = m_pPlayerManager->IterBegin (); @@ -501,6 +501,9 @@ std::string ASE::QueryLight ( void ) } } + float fResSize = g_pGame->GetResourceManager()->GetTotalResourcesSize() / ( float ) 1024; + reply.write(reinterpret_cast < const char* > ( &fResSize ), sizeof ( float ) ); + return reply.str(); } diff --git a/Server/mods/deathmatch/logic/CResource.cpp b/Server/mods/deathmatch/logic/CResource.cpp index ccc32c06c9f..04c38d9f43f 100644 --- a/Server/mods/deathmatch/logic/CResource.cpp +++ b/Server/mods/deathmatch/logic/CResource.cpp @@ -599,6 +599,7 @@ void CResource::SetInfoValue ( const char * szKey, const char * szValue, bool bS bool CResource::GenerateChecksums ( void ) { bool bOk = true; + uint64 uiResourceSize = 0; list < CResourceFile* > ::iterator iterf = m_resourceFiles.begin (); for ( ; iterf != m_resourceFiles.end (); iterf++ ) @@ -657,6 +658,7 @@ bool CResource::GenerateChecksums ( void ) if ( pResourceFile->IsNoClientCache () ) FileDelete ( pResourceFile->GetCachedPathFilename ( true ) ); } + uiResourceSize += uiFileSize; } break; @@ -672,6 +674,7 @@ bool CResource::GenerateChecksums ( void ) { m_metaChecksum = CChecksum::GenerateChecksumFromFile ( strPath ); } + m_uiResourceSize = uiResourceSize; return bOk; } diff --git a/Server/mods/deathmatch/logic/CResource.h b/Server/mods/deathmatch/logic/CResource.h index 17c28ce0182..27dd44de23c 100644 --- a/Server/mods/deathmatch/logic/CResource.h +++ b/Server/mods/deathmatch/logic/CResource.h @@ -205,6 +205,7 @@ class CResource : public EHS bool m_bSyncMapElementDataDefined; CChecksum m_metaChecksum; // Checksum of meta.xml last time this was loaded, generated in GenerateChecksums() + uint64 m_uiResourceSize; unsigned short m_usNetID; // resource ID uint m_uiScriptID; @@ -292,6 +293,7 @@ class CResource : public EHS bool StopAllResourceItems ( void ); bool GenerateChecksums ( void ); + uint64 GetResourceSize ( void ) { return m_uiResourceSize; } const CChecksum& GetLastMetaChecksum ( void ) { return m_metaChecksum; } bool HasResourceChanged ( void ); void ApplyUpgradeModifications ( void ); diff --git a/Server/mods/deathmatch/logic/CResourceManager.cpp b/Server/mods/deathmatch/logic/CResourceManager.cpp index a082e83e700..9fbb932cf71 100644 --- a/Server/mods/deathmatch/logic/CResourceManager.cpp +++ b/Server/mods/deathmatch/logic/CResourceManager.cpp @@ -725,6 +725,21 @@ bool CResourceManager::StopAllResources ( void ) return true; } +uint64 CResourceManager::GetTotalResourcesSize(void) +{ + uint64 uiTotalSize = 0; + list < CResource* > ::const_iterator iter = m_resources.begin(); + for (; iter != m_resources.end(); iter++) + { + CResource* pResource = *iter; + if (pResource->IsActive()) + { + uiTotalSize += pResource->GetResourceSize(); + } + } + return uiTotalSize; +} + void CResourceManager::QueueResource ( CResource* pResource, eResourceQueue eQueueType, const sResourceStartFlags* Flags, list < CResource* > * dependents ) { diff --git a/Server/mods/deathmatch/logic/CResourceManager.h b/Server/mods/deathmatch/logic/CResourceManager.h index f884746d02f..a782ef7726c 100644 --- a/Server/mods/deathmatch/logic/CResourceManager.h +++ b/Server/mods/deathmatch/logic/CResourceManager.h @@ -88,6 +88,7 @@ class CResourceManager bool StartResource ( CResource* pResource, list < CResource* > * dependents = NULL, bool bStartedManually = false, bool bStartIncludedResources = true, bool bConfigs = true, bool bMaps = true, bool bScripts = true, bool bHTML = true, bool bClientConfigs = true, bool bClientScripts = true, bool bClientFiles = true ); bool Reload ( CResource* pResource ); bool StopAllResources ( void ); + uint64 GetTotalResourcesSize ( void ); void QueueResource ( CResource* pResource, eResourceQueue eQueueType, const sResourceStartFlags* Flags, list < CResource* > * dependents = NULL ); void ProcessQueue ( void );