Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion Client/core/Serverbrowser/CServerBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rogue 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 );
Expand Down
1 change: 1 addition & 0 deletions Client/core/Serverbrowser/CServerBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
8 changes: 6 additions & 2 deletions Client/core/Serverbrowser/CServerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 () );
Expand All @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions Client/core/Serverbrowser/CServerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class CServerListItem
nPlayers = 0;
nMaxPlayers = 0;
nPing = 9999;
fResSize = 0;
uiCacheNoReplyCount = 0;
m_ElapsedTime.SetMaxIncrement ( 500 );
m_ElapsedTime.Reset ();
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion Server/mods/deathmatch/logic/ASE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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();
}

Expand Down
3 changes: 3 additions & 0 deletions Server/mods/deathmatch/logic/CResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++ )
Expand Down Expand Up @@ -657,6 +658,7 @@ bool CResource::GenerateChecksums ( void )
if ( pResourceFile->IsNoClientCache () )
FileDelete ( pResourceFile->GetCachedPathFilename ( true ) );
}
uiResourceSize += uiFileSize;
}
break;

Expand All @@ -672,6 +674,7 @@ bool CResource::GenerateChecksums ( void )
{
m_metaChecksum = CChecksum::GenerateChecksumFromFile ( strPath );
}
m_uiResourceSize = uiResourceSize;

return bOk;
}
Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
15 changes: 15 additions & 0 deletions Server/mods/deathmatch/logic/CResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down