@@ -31,21 +31,21 @@ CRemoteCalls::~CRemoteCalls()
31
31
}
32
32
33
33
34
- void CRemoteCalls::Call ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
34
+ void CRemoteCalls::Call ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
35
35
{
36
- m_calls.push_back ( new CRemoteCall ( szServerHost, szResourceName, szFunctionName, arguments, luaMain, iFunction, uiConnectionAttempts, uiConnectTimeoutMs ) );
36
+ m_calls.push_back ( new CRemoteCall ( szServerHost, szResourceName, szFunctionName, arguments, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs ) );
37
37
m_calls.back ()->MakeCall ();
38
38
}
39
39
40
- void CRemoteCalls::Call ( const char * szURL, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
40
+ void CRemoteCalls::Call ( const char * szURL, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
41
41
{
42
- m_calls.push_back ( new CRemoteCall ( szURL, arguments, luaMain, iFunction, uiConnectionAttempts, uiConnectTimeoutMs ) );
42
+ m_calls.push_back ( new CRemoteCall ( szURL, arguments, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs ) );
43
43
m_calls.back ()->MakeCall ();
44
44
}
45
45
46
- void CRemoteCalls::Call ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
46
+ void CRemoteCalls::Call ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
47
47
{
48
- m_calls.push_back ( new CRemoteCall ( szURL, fetchArguments, strPostData, bPostBinary, luaMain, iFunction, uiConnectionAttempts, uiConnectTimeoutMs ) );
48
+ m_calls.push_back ( new CRemoteCall ( szURL, fetchArguments, strPostData, bPostBinary, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs ) );
49
49
m_calls.back ()->MakeCall ();
50
50
}
51
51
@@ -86,9 +86,60 @@ bool CRemoteCalls::CallExists ( CRemoteCall * call )
86
86
return false ;
87
87
}
88
88
89
+ // Map queue index into download manager id
90
+ EDownloadModeType CRemoteCalls::GetDownloadModeFromQueueIndex ( uint uiIndex, bool bAnyHost )
91
+ {
92
+ uiIndex %= MAX_CALL_REMOTE_QUEUES;
93
+ uiIndex += bAnyHost ? EDownloadMode::CALL_REMOTE_ANY_HOST : EDownloadMode::CALL_REMOTE_RESTRICTED;
94
+ return (EDownloadModeType)uiIndex;
95
+ }
96
+
97
+ // Map queue name to download manager id
98
+ EDownloadModeType CRemoteCalls::GetDownloadModeForQueueName ( const SString& strQueueName, bool bAnyHost )
99
+ {
100
+ uint* pIndex = MapFind ( m_QueueIndexMap, strQueueName );
101
+ if ( pIndex )
102
+ {
103
+ return GetDownloadModeFromQueueIndex ( *pIndex, bAnyHost );
104
+ }
105
+ else
106
+ {
107
+ // Find lowest unused index
108
+ uint idx = 0 ;
109
+ while ( MapContainsValue ( m_QueueIndexMap, idx ) )
110
+ {
111
+ idx++;
112
+ }
113
+ // Add new mapping
114
+ MapSet ( m_QueueIndexMap, strQueueName, idx );
115
+ return GetDownloadModeFromQueueIndex ( idx, bAnyHost );
116
+ }
117
+ }
118
+
119
+
120
+ void CRemoteCalls::ProcessQueuedFiles ( void )
121
+ {
122
+ for ( auto iter = m_QueueIndexMap.cbegin (); iter != m_QueueIndexMap.cend (); )
123
+ {
124
+ EDownloadModeType downloadMode = GetDownloadModeFromQueueIndex ( iter->second , false );
125
+ EDownloadModeType downloadModeAnyIp = GetDownloadModeFromQueueIndex ( iter->second , true );
126
+ if ( g_pNet->GetHTTPDownloadManager ( downloadMode )->ProcessQueuedFiles ()
127
+ && g_pNet->GetHTTPDownloadManager ( downloadModeAnyIp )->ProcessQueuedFiles () )
128
+ {
129
+ // Queue empty, so remove name mapping if not default queue
130
+ if ( iter->first != CALL_REMOTE_DEFAULT_QUEUE_NAME )
131
+ {
132
+ iter = m_QueueIndexMap.erase ( iter );
133
+ continue ;
134
+ }
135
+ }
136
+ ++iter;
137
+ }
138
+ }
139
+
89
140
// //////////////////////////////////////////////////////////////////////////////
90
141
91
- CRemoteCall::CRemoteCall ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
142
+ CRemoteCall::CRemoteCall ( const char * szServerHost, const char * szResourceName, const char * szFunctionName, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
92
143
{
93
144
m_VM = luaMain;
94
145
m_iFunction = iFunction;
@@ -98,12 +149,13 @@ CRemoteCall::CRemoteCall ( const char * szServerHost, const char * szResourceNam
98
149
m_bIsFetch = false ;
99
150
100
151
m_strURL = SString ( " http://%s/%s/call/%s" , szServerHost, szResourceName, szFunctionName );
152
+ m_strQueueName = strQueueName;
101
153
m_uiConnectionAttempts = uiConnectionAttempts;
102
154
m_uiConnectTimeoutMs = uiConnectTimeoutMs;
103
155
}
104
156
105
157
// arbitary URL version
106
- CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
158
+ CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * arguments, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
107
159
{
108
160
m_VM = luaMain;
109
161
m_iFunction = iFunction;
@@ -113,12 +165,13 @@ CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * arguments, CLuaMa
113
165
m_bIsFetch = false ;
114
166
115
167
m_strURL = szURL;
168
+ m_strQueueName = strQueueName;
116
169
m_uiConnectionAttempts = uiConnectionAttempts;
117
170
m_uiConnectTimeoutMs = uiConnectTimeoutMs;
118
171
}
119
172
120
173
// Fetch version
121
- CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
174
+ CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs )
122
175
: m_FetchArguments ( *fetchArguments )
123
176
{
124
177
m_VM = luaMain;
@@ -129,6 +182,7 @@ CRemoteCall::CRemoteCall ( const char * szURL, CLuaArguments * fetchArguments, c
129
182
m_bIsFetch = true ;
130
183
131
184
m_strURL = szURL;
185
+ m_strQueueName = strQueueName;
132
186
m_uiConnectionAttempts = uiConnectionAttempts;
133
187
m_uiConnectTimeoutMs = uiConnectTimeoutMs;
134
188
}
@@ -140,18 +194,11 @@ CRemoteCall::~CRemoteCall ()
140
194
141
195
void CRemoteCall::MakeCall ()
142
196
{
143
- if (g_pCore->GetWebCore ()->GetDomainState (g_pCore->GetWebCore ()->GetDomainFromURL (m_strURL)) == eURLState::WEBPAGE_ALLOWED)
144
- {
145
- // Bypass IP check if we are allowed to access the URL
146
- CNetHTTPDownloadManagerInterface* pDownloadManager = g_pNet->GetHTTPDownloadManager (EDownloadMode::CALL_REMOTE_ANY_HOST);
147
- pDownloadManager->QueueFile (m_strURL, NULL , 0 , m_strData.c_str (), m_strData.length (), m_bPostBinary, this , DownloadFinishedCallback, false , m_uiConnectionAttempts, m_uiConnectTimeoutMs);
148
- }
149
- else
150
- {
151
- // Proceed with the normal way (IP check in net module)
152
- CNetHTTPDownloadManagerInterface* pDownloadManager = g_pNet->GetHTTPDownloadManager (EDownloadMode::CALL_REMOTE);
153
- pDownloadManager->QueueFile (m_strURL, NULL , 0 , m_strData.c_str (), m_strData.length (), m_bPostBinary, this , DownloadFinishedCallback, false , m_uiConnectionAttempts, m_uiConnectTimeoutMs);
154
- }
197
+ // Bypass net module IP check if we are allowed to access the URL
198
+ bool bAnyHost = (g_pCore->GetWebCore ()->GetDomainState (g_pCore->GetWebCore ()->GetDomainFromURL (m_strURL)) == eURLState::WEBPAGE_ALLOWED);
199
+ EDownloadModeType downloadMode = g_pClientGame->GetRemoteCalls ()->GetDownloadModeForQueueName (m_strQueueName, bAnyHost);
200
+ CNetHTTPDownloadManagerInterface* pDownloadManager = g_pNet->GetHTTPDownloadManager (downloadMode);
201
+ pDownloadManager->QueueFile (m_strURL, NULL , 0 , m_strData.c_str (), m_strData.length (), m_bPostBinary, this , DownloadFinishedCallback, false , m_uiConnectionAttempts, m_uiConnectTimeoutMs);
155
202
}
156
203
157
204
void CRemoteCall::DownloadFinishedCallback ( char * data, size_t dataLength, void * obj, bool bSuccess, int iErrorCode )
0 commit comments