mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Refresh server browser immediately when updated ddnet info arrived
At the moment it only happens the next time you press refresh. Before we had it so that it always reloaded once the ddnet info arrived, causing a quick flickering and lots of packets having to be resent every time someone pressed refresh, even if nothing changed. The new approach combines the advantages of both without the disadvantages. An even nicer way would be to compare the json objects, so that news and version updates don't matter, but our json library doesn't seem to support that.
This commit is contained in:
parent
ddc4b74354
commit
279deffa86
|
@ -2381,11 +2381,60 @@ void CClient::ResetDDNetInfo()
|
|||
}
|
||||
}
|
||||
|
||||
bool CClient::IsDDNetInfoChanged()
|
||||
{
|
||||
IOHANDLE OldFile = m_pStorage->OpenFile(DDNET_INFO, IOFLAG_READ, IStorage::TYPE_SAVE);
|
||||
|
||||
if(!OldFile)
|
||||
return true;
|
||||
|
||||
IOHANDLE NewFile = m_pStorage->OpenFile(m_aDDNetInfoTmp, IOFLAG_READ, IStorage::TYPE_SAVE);
|
||||
|
||||
if(NewFile)
|
||||
{
|
||||
char aOldData[4096];
|
||||
char aNewData[4096];
|
||||
unsigned OldBytes;
|
||||
unsigned NewBytes;
|
||||
|
||||
do
|
||||
{
|
||||
OldBytes = io_read(OldFile, aOldData, sizeof(aOldData));
|
||||
NewBytes = io_read(NewFile, aNewData, sizeof(aNewData));
|
||||
|
||||
if(OldBytes != NewBytes || mem_comp(aOldData, aNewData, OldBytes) != 0)
|
||||
{
|
||||
io_close(NewFile);
|
||||
io_close(OldFile);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
while(OldBytes > 0);
|
||||
|
||||
io_close(NewFile);
|
||||
}
|
||||
|
||||
io_close(OldFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
void CClient::FinishDDNetInfo()
|
||||
{
|
||||
ResetDDNetInfo();
|
||||
m_pStorage->RenameFile(m_aDDNetInfoTmp, DDNET_INFO, IStorage::TYPE_SAVE);
|
||||
LoadDDNetInfo();
|
||||
if(IsDDNetInfoChanged())
|
||||
{
|
||||
m_pStorage->RenameFile(m_aDDNetInfoTmp, DDNET_INFO, IStorage::TYPE_SAVE);
|
||||
LoadDDNetInfo();
|
||||
|
||||
if(g_Config.m_UiPage == CMenus::PAGE_DDNET)
|
||||
m_ServerBrowser.Refresh(IServerBrowser::TYPE_DDNET);
|
||||
else if(g_Config.m_UiPage == CMenus::PAGE_KOG)
|
||||
m_ServerBrowser.Refresh(IServerBrowser::TYPE_KOG);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pStorage->RemoveFile(m_aDDNetInfoTmp, IStorage::TYPE_SAVE);
|
||||
}
|
||||
}
|
||||
|
||||
typedef std::tuple<int, int, int> Version;
|
||||
|
|
|
@ -343,6 +343,7 @@ public:
|
|||
|
||||
void RequestDDNetInfo();
|
||||
void ResetDDNetInfo();
|
||||
bool IsDDNetInfoChanged();
|
||||
void FinishDDNetInfo();
|
||||
void LoadDDNetInfo();
|
||||
|
||||
|
|
Loading…
Reference in a new issue