Skip to content

Commit

Permalink
CRemoteCall tweaks. Incremented NET_MODULE_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
ccw808 committed Jul 7, 2019
1 parent 764664d commit e77c8cd
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
17 changes: 12 additions & 5 deletions Client/mods/deathmatch/logic/CRemoteCalls.cpp
Expand Up @@ -235,6 +235,11 @@ void CRemoteCall::DownloadFinishedCallback(const SHttpDownloadResult& result)
CRemoteCall* pCall = (CRemoteCall*)result.pObj;
if (!g_pClientGame->GetRemoteCalls()->CallExists(pCall))
return;

// Save final download status
pCall->m_lastDownloadStatus.uiAttemptNumber = result.uiAttemptNumber;
pCall->m_lastDownloadStatus.uiContentLength = result.uiContentLength;
pCall->m_lastDownloadStatus.uiBytesReceived = result.dataSize;
pCall->m_downloadMode = EDownloadModeType::NONE;

CLuaArguments arguments;
Expand Down Expand Up @@ -306,13 +311,15 @@ bool CRemoteCall::CancelDownload()
return false;
}

// Return true if outDownloadStatus contains valid data
bool CRemoteCall::GetDownloadStatus(SDownloadStatus& outDownloadStatus)
const SDownloadStatus& CRemoteCall::GetDownloadStatus()
{
if (m_downloadMode != EDownloadModeType::NONE)
{
return g_pNet->GetHTTPDownloadManager(m_downloadMode)->GetDownloadStatus(this, DownloadFinishedCallback, outDownloadStatus);
SDownloadStatus newDownloadStatus;
if (g_pNet->GetHTTPDownloadManager(m_downloadMode)->GetDownloadStatus(this, DownloadFinishedCallback, newDownloadStatus))
{
m_lastDownloadStatus = newDownloadStatus;
}
}
outDownloadStatus = {0};
return false;
return m_lastDownloadStatus;
}
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CRemoteCalls.h
Expand Up @@ -28,6 +28,7 @@ class CRemoteCall
CLuaArguments m_FetchArguments;
SHttpRequestOptions m_options;
EDownloadModeType m_downloadMode = EDownloadModeType::NONE;
SDownloadStatus m_lastDownloadStatus;

public:
CRemoteCall(const char* szServerHost, const char* szResourceName, const char* szFunctionName, CLuaArguments* arguments, CLuaMain* luaMain,
Expand All @@ -42,7 +43,7 @@ class CRemoteCall
void MakeCall();
static void DownloadFinishedCallback(const SHttpDownloadResult& result);
bool CancelDownload();
bool GetDownloadStatus(SDownloadStatus& outDownloadStatus);
const SDownloadStatus& GetDownloadStatus();
CLuaMain* GetVM() { return m_VM; };
bool IsFetch() { return m_bIsFetch; }
bool IsLegacy() { return m_options.bIsLegacy; }
Expand Down
2 changes: 1 addition & 1 deletion Client/version.h
Expand Up @@ -72,7 +72,7 @@

#define _ASE_VERSION QUOTE_DEFINE(MTASA_VERSION_MAJOR) "." QUOTE_DEFINE(MTASA_VERSION_MINOR)
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
#define _CLIENT_NET_MODULE_VERSION 0x0AA // (0x000 - 0xfff) Lvl9 wizards only
#define _CLIENT_NET_MODULE_VERSION 0x0AB // (0x000 - 0xfff) Lvl9 wizards only
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
#define MTA_DM_BITSTREAM_VERSION 0x06C // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).

Expand Down
17 changes: 12 additions & 5 deletions Server/mods/deathmatch/logic/CRemoteCalls.cpp
Expand Up @@ -230,6 +230,11 @@ void CRemoteCall::DownloadFinishedCallback(const SHttpDownloadResult& result)
CRemoteCall* pCall = (CRemoteCall*)result.pObj;
if (!g_pGame->GetRemoteCalls()->CallExists(pCall))
return;

// Save final download status
pCall->m_lastDownloadStatus.uiAttemptNumber = result.uiAttemptNumber;
pCall->m_lastDownloadStatus.uiContentLength = result.uiContentLength;
pCall->m_lastDownloadStatus.uiBytesReceived = result.dataSize;
pCall->m_downloadMode = EDownloadModeType::NONE;

CLuaArguments arguments;
Expand Down Expand Up @@ -301,13 +306,15 @@ bool CRemoteCall::CancelDownload()
return false;
}

// Return true if outDownloadStatus contains valid data
bool CRemoteCall::GetDownloadStatus(SDownloadStatus& outDownloadStatus)
const SDownloadStatus& CRemoteCall::GetDownloadStatus()
{
if (m_downloadMode != EDownloadModeType::NONE)
{
return g_pNetServer->GetHTTPDownloadManager(m_downloadMode)->GetDownloadStatus(this, DownloadFinishedCallback, outDownloadStatus);
SDownloadStatus newDownloadStatus;
if (g_pNetServer->GetHTTPDownloadManager(m_downloadMode)->GetDownloadStatus(this, DownloadFinishedCallback, newDownloadStatus))
{
m_lastDownloadStatus = newDownloadStatus;
}
}
outDownloadStatus = {0};
return false;
return m_lastDownloadStatus;
}
3 changes: 2 additions & 1 deletion Server/mods/deathmatch/logic/CRemoteCalls.h
Expand Up @@ -28,6 +28,7 @@ class CRemoteCall
CLuaArguments m_FetchArguments;
SHttpRequestOptions m_options;
EDownloadModeType m_downloadMode = EDownloadModeType::NONE;
SDownloadStatus m_lastDownloadStatus;

public:
CRemoteCall(const char* szServerHost, const char* szResourceName, const char* szFunctionName, CLuaArguments* arguments, CLuaMain* luaMain,
Expand All @@ -42,7 +43,7 @@ class CRemoteCall
void MakeCall();
static void DownloadFinishedCallback(const SHttpDownloadResult& result);
bool CancelDownload();
bool GetDownloadStatus(SDownloadStatus& outDownloadStatus);
const SDownloadStatus& GetDownloadStatus();
CLuaMain* GetVM() { return m_VM; };
bool IsFetch() { return m_bIsFetch; }
bool IsLegacy() { return m_options.bIsLegacy; }
Expand Down
2 changes: 1 addition & 1 deletion Server/version.h
Expand Up @@ -75,7 +75,7 @@

#define _ASE_VERSION QUOTE_DEFINE(MTASA_VERSION_MAJOR) "." QUOTE_DEFINE(MTASA_VERSION_MINOR)
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
#define _SERVER_NET_MODULE_VERSION 0x0AA // (0x000 - 0xfff) Lvl9 wizards only
#define _SERVER_NET_MODULE_VERSION 0x0AB // (0x000 - 0xfff) Lvl9 wizards only
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
#define MTA_DM_BITSTREAM_VERSION 0x06C // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).

Expand Down
8 changes: 5 additions & 3 deletions Shared/sdk/net/CNetHTTPDownloadManagerInterface.h
Expand Up @@ -40,6 +40,8 @@ struct SHttpDownloadResult
bool bSuccess;
int iErrorCode;
const char* szHeaders;
uint uiAttemptNumber;
uint uiContentLength;
};

// For transferring SString to net module
Expand Down Expand Up @@ -145,9 +147,9 @@ inline SHttpRequestOptionsTx::SHttpRequestOptionsTx(const SHttpRequestOptions& i

struct SDownloadStatus
{
uint uiAttemptNumber; // 0=Queued 1+=Downloading
uint uiContentLength; // Item total size. Will be 0 if http header 'Content-Length' is missing
uint uiBytesReceived; // Download progress
uint uiAttemptNumber = 0; // 0=Queued 1+=Downloading
uint uiContentLength = 0; // Item total size. Will be 0 if http header 'Content-Length' is missing
uint uiBytesReceived = 0; // Download progress
};

// PFN_DOWNLOAD_FINISHED_CALLBACK is called once at the end of the download.
Expand Down

0 comments on commit e77c8cd

Please sign in to comment.