void CRemoteCall::DownloadFinishedCallback(const SHttpDownloadResult& result) { CRemoteCall* pCall = (CRemoteCall*)result.pObj; if (!g_pClientGame->GetRemoteCalls()->CallExists(pCall)) return; CLuaArguments arguments; if (pCall->IsLegacy()) { if (result.bSuccess) { if (pCall->IsFetch()) { arguments.PushString(std::string(result.pData, result.dataSize)); arguments.PushNumber(0); } else arguments.ReadFromJSONString(result.pData); } else { arguments.PushString("ERROR"); arguments.PushNumber(result.iErrorCode); } } else { // Append response body arguments.PushString(std::string(result.pData, result.dataSize)); // Append info table CLuaArguments info; info.PushString("success"); info.PushBoolean(result.iErrorCode >= 200 && result.iErrorCode <= 299); info.PushString("statusCode"); info.PushNumber(result.iErrorCode); // Headers as a subtable CLuaArguments headers; for (auto iter : result.headers ) { headers.PushString(iter.first); headers.PushString(iter.second); } info.PushString("headers"); info.PushTable(&headers); arguments.PushTable(&info); } // Append stored arguments if (pCall->IsFetch()) for (uint i = 0; i < pCall->GetFetchArguments().Count(); i++ ) arguments.PushArgument(*(pCall->GetFetchArguments()[i])); arguments.Call(pCall->m_VM, pCall->m_iFunction); g_pClientGame->GetRemoteCalls()->Remove(pCall); }
bool CRemoteCall::ProgressCallback(double sizeJustDownloaded, double totalDownloaded, char * data, size_t dataLength, void * obj, bool complete, int error) { //printf("Progress: %s\n", data); if ( complete ) { CRemoteCall * call = (CRemoteCall*)obj; if ( g_pGame->GetRemoteCalls()->CallExists(call) ) { //printf("RECIEVED: %s\n", data); CLuaArguments arguments; if ( call->IsFetch () ) { arguments.PushString ( std::string ( data, dataLength ) ); arguments.PushNumber ( 0 ); for ( uint i = 0 ; i < call->GetFetchArguments ().Count () ; i++ ) arguments.PushArgument ( *( call->GetFetchArguments ()[i] ) ); } else arguments.ReadFromJSONString ( data ); arguments.Call ( call->m_VM, call->m_iFunction); g_pGame->GetRemoteCalls()->Remove(call); // delete ourselves return true; } } else if ( error ) { CRemoteCall * call = (CRemoteCall*)obj; if ( g_pGame->GetRemoteCalls()->CallExists(call) ) { CLuaArguments arguments; arguments.PushString("ERROR"); arguments.PushNumber(error); if ( call->IsFetch () ) for ( uint i = 0 ; i < call->GetFetchArguments ().Count () ; i++ ) arguments.PushArgument ( *( call->GetFetchArguments ()[i] ) ); arguments.Call ( call->m_VM, call->m_iFunction); g_pGame->GetRemoteCalls()->Remove(call); // delete ourselves return true; } } return false; // Possible problem }