mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
let the demoplayer check for the correct net version (prevents crash) and show the reason within the error popup
This commit is contained in:
parent
3a0b017619
commit
b69417f3aa
|
@ -2094,15 +2094,16 @@ void CClient::Con_RemoveFavorite(IConsole::IResult *pResult, void *pUserData)
|
|||
const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
||||
{
|
||||
int Crc;
|
||||
const char *pError;
|
||||
|
||||
Disconnect();
|
||||
m_NetClient.ResetErrorString();
|
||||
|
||||
// try to start playback
|
||||
m_DemoPlayer.SetListner(this);
|
||||
|
||||
if(m_DemoPlayer.Load(Storage(), m_pConsole, pFilename, StorageType))
|
||||
return "error loading demo";
|
||||
const char *pError = m_DemoPlayer.Load(Storage(), m_pConsole, pFilename, StorageType, GameClient()->NetVersion());
|
||||
if(pError)
|
||||
return pError;
|
||||
|
||||
// load map
|
||||
Crc = (m_DemoPlayer.Info()->m_Header.m_aMapCrc[0]<<24)|
|
||||
|
|
|
@ -319,6 +319,7 @@ void CDemoRecorder::AddDemoMarker()
|
|||
CDemoPlayer::CDemoPlayer(class CSnapshotDelta *pSnapshotDelta)
|
||||
{
|
||||
m_File = 0;
|
||||
m_aErrorMsg[0] = 0;
|
||||
m_pKeyFrames = 0;
|
||||
|
||||
m_pSnapshotDelta = pSnapshotDelta;
|
||||
|
@ -577,16 +578,16 @@ void CDemoPlayer::Unpause()
|
|||
}
|
||||
}
|
||||
|
||||
int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType)
|
||||
const char *CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType, const char *pNetversion)
|
||||
{
|
||||
m_pConsole = pConsole;
|
||||
m_aErrorMsg[0] = 0;
|
||||
m_File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
|
||||
if(!m_File)
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "could not open '%s'", pFilename);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", aBuf);
|
||||
return -1;
|
||||
str_format(m_aErrorMsg, sizeof(m_aErrorMsg), "could not open '%s'", pFilename);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", m_aErrorMsg);
|
||||
return m_aErrorMsg;
|
||||
}
|
||||
|
||||
// store the filename
|
||||
|
@ -607,22 +608,29 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
io_read(m_File, &m_Info.m_Header, sizeof(m_Info.m_Header));
|
||||
if(mem_comp(m_Info.m_Header.m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) != 0)
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "'%s' is not a demo file", pFilename);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", aBuf);
|
||||
str_format(m_aErrorMsg, sizeof(m_aErrorMsg), "'%s' is not a demo file", pFilename);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", m_aErrorMsg);
|
||||
io_close(m_File);
|
||||
m_File = 0;
|
||||
return -1;
|
||||
return m_aErrorMsg;
|
||||
}
|
||||
|
||||
if(m_Info.m_Header.m_Version < gs_ActVersion)
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "demo version %d is not supported", m_Info.m_Header.m_Version);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", aBuf);
|
||||
str_format(m_aErrorMsg, sizeof(m_aErrorMsg), "demo version %d is not supported", m_Info.m_Header.m_Version);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", m_aErrorMsg);
|
||||
io_close(m_File);
|
||||
m_File = 0;
|
||||
return -1;
|
||||
return m_aErrorMsg;
|
||||
}
|
||||
|
||||
if(str_comp(m_Info.m_Header.m_aNetversion, pNetversion) != 0)
|
||||
{
|
||||
str_format(m_aErrorMsg, sizeof(m_aErrorMsg), "net version '%s' is not supported", m_Info.m_Header.m_aNetversion);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", m_aErrorMsg);
|
||||
io_close(m_File);
|
||||
m_File = 0;
|
||||
return m_aErrorMsg;
|
||||
}
|
||||
|
||||
// get demo type
|
||||
|
|
|
@ -86,6 +86,7 @@ private:
|
|||
class IConsole *m_pConsole;
|
||||
IOHANDLE m_File;
|
||||
char m_aFilename[256];
|
||||
char m_aErrorMsg[256];
|
||||
CKeyFrame *m_pKeyFrames;
|
||||
|
||||
CPlaybackInfo m_Info;
|
||||
|
@ -105,7 +106,7 @@ public:
|
|||
|
||||
void SetListner(IListner *pListner);
|
||||
|
||||
int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType);
|
||||
const char *Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType, const char *pNetversion);
|
||||
int Play();
|
||||
void Pause();
|
||||
void Unpause();
|
||||
|
|
|
@ -1248,6 +1248,7 @@ int CMenus::Render()
|
|||
pTitle = m_aMessageTopic;
|
||||
pExtraText = m_aMessageBody;
|
||||
pButtonText = m_aMessageButton;
|
||||
ExtraAlign = -1;
|
||||
}
|
||||
else if(m_Popup == POPUP_CONNECTING)
|
||||
{
|
||||
|
|
|
@ -668,7 +668,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
|||
str_format(aBuf, sizeof(aBuf), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
|
||||
const char *pError = Client()->DemoPlayer_Play(aBuf, m_lDemos[m_DemolistSelectedIndex].m_StorageType);
|
||||
if(pError)
|
||||
PopupMessage(Localize("Error"), str_comp(pError, "error loading demo") ? pError : Localize("Error loading demo"), Localize("Ok"));
|
||||
PopupMessage(Localize("Error loading demo"), pError, Localize("Ok"));
|
||||
else
|
||||
{
|
||||
UI()->SetActiveItem(0);
|
||||
|
|
Loading…
Reference in a new issue