Skip to content

Commit

Permalink
Removed unnessesary checks
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Jan 4, 2019
1 parent 67500ac commit c107463
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 164 deletions.
42 changes: 15 additions & 27 deletions Client/mods/deathmatch/logic/CRemoteCalls.cpp
Expand Up @@ -34,27 +34,21 @@ CRemoteCall* CRemoteCalls::Call(const char* szServerHost, const char* szResource
{
CRemoteCall* pRemoteCall = new CRemoteCall(szServerHost, szResourceName, szFunctionName, arguments, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs);

if (pRemoteCall)
{
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();
return pRemoteCall;
}
return nullptr;
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();

return pRemoteCall;
}

CRemoteCall* CRemoteCalls::Call(const char* szURL, CLuaArguments* arguments, CLuaMain* luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName,
uint uiConnectionAttempts, uint uiConnectTimeoutMs)
{
CRemoteCall* pRemoteCall = new CRemoteCall(szURL, arguments, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs);

if (pRemoteCall)
{
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();
return pRemoteCall;
}
return nullptr;
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();

return pRemoteCall;
}

CRemoteCall* CRemoteCalls::Call(const char* szURL, CLuaArguments* fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain* luaMain,
Expand All @@ -63,12 +57,9 @@ CRemoteCall* CRemoteCalls::Call(const char* szURL, CLuaArguments* fetchArguments
CRemoteCall* pRemoteCall =
new CRemoteCall(szURL, fetchArguments, strPostData, bPostBinary, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs);

if (pRemoteCall)
{
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();
return pRemoteCall;
}
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();

return nullptr;
}

Expand All @@ -78,13 +69,10 @@ CRemoteCall* CRemoteCalls::Call(const char* szURL, CLuaArguments* fetchArguments
{
CRemoteCall* pRemoteCall = new CRemoteCall(szURL, fetchArguments, luaMain, iFunction, strQueueName, options);

if (pRemoteCall)
{
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();
return pRemoteCall;
}
return nullptr;
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();

return pRemoteCall;
}

void CRemoteCalls::Remove(CLuaMain* lua)
Expand Down
95 changes: 45 additions & 50 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.World.cpp
Expand Up @@ -1871,11 +1871,8 @@ int CLuaFunctionDefs::FetchRemote(lua_State* luaVM)
httpRequestOptions.bIsLegacy = true;
CRemoteCall* pRemoteCall = g_pClientGame->GetRemoteCalls()->Call(strURL, &callbackArguments, luaMain, iLuaFunction, strQueueName, httpRequestOptions);

if (pRemoteCall)
{
lua_pushuserdata(luaVM, pRemoteCall);
return 1;
}
lua_pushuserdata(luaVM, pRemoteCall);
return 1;
}
}
}
Expand Down Expand Up @@ -1913,11 +1910,8 @@ int CLuaFunctionDefs::FetchRemote(lua_State* luaVM)
{
CRemoteCall* pRemoteCall = g_pClientGame->GetRemoteCalls()->Call(strURL, &callbackArguments, luaMain, iLuaFunction, strQueueName, httpRequestOptions);

if (pRemoteCall)
{
lua_pushuserdata(luaVM, pRemoteCall);
return 1;
}
lua_pushuserdata(luaVM, pRemoteCall);
return 1;
}
}
}
Expand Down Expand Up @@ -1962,51 +1956,55 @@ int CLuaFunctionDefs::GetNetworkRequestInfo(lua_State* luaVM)
CScriptArgReader argStream(luaVM);
CLuaArguments info, requestedHeaders;
CRemoteCall* pRemoteCall = nullptr;

argStream.ReadUserData(pRemoteCall);

if (!argStream.HasErrors())
{
if (pRemoteCall)
CResource* pResource = pRemoteCall->GetVM()->GetResource();
info.PushString("type");
info.PushString((pRemoteCall->IsFetch() ? "fetch" : "call"));
info.PushString("url");
info.PushString(pRemoteCall->GetURL().c_str());
info.PushString("queue");
info.PushString(pRemoteCall->GetQueueName().c_str());
info.PushString("resource");

if (pResource)
info.PushResource(pResource);
else
info.PushBoolean(false);

info.PushString("start");
info.PushNumber(pRemoteCall->GetStartTime());

info.PushString("post_data");
info.PushString(pRemoteCall->GetOptions().strPostData.c_str());
info.PushString("method");
info.PushString((pRemoteCall->GetOptions().strRequestMethod.length() >= 1 ? pRemoteCall->GetOptions().strRequestMethod.ToUpper().c_str() : "POST"));

info.PushString("connection_attempts");
info.PushNumber(pRemoteCall->GetOptions().uiConnectionAttempts);
info.PushString("connection_timeout");
info.PushNumber(pRemoteCall->GetOptions().uiConnectTimeoutMs);
// requested headers
info.PushString("headers");

for (auto const& header : pRemoteCall->GetOptions().requestHeaders)
{
CResource* pResource = pRemoteCall->GetVM()->GetResource();
info.PushString("type");
info.PushString((pRemoteCall->IsFetch() ? "fetch" : "call"));
info.PushString("url");
info.PushString(pRemoteCall->GetURL().c_str());
info.PushString("queue");
info.PushString(pRemoteCall->GetQueueName().c_str());
info.PushString("resource");
if (pResource)
info.PushResource(pResource);
else
info.PushBoolean(false);
info.PushString("start");
info.PushNumber(pRemoteCall->GetStartTime());

info.PushString("post_data");
info.PushString(pRemoteCall->GetOptions().strPostData.c_str());
info.PushString("method");
info.PushString((pRemoteCall->GetOptions().strRequestMethod.length() >= 1 ? pRemoteCall->GetOptions().strRequestMethod.ToUpper().c_str() : "POST"));

info.PushString("connection_attempts");
info.PushNumber(pRemoteCall->GetOptions().uiConnectionAttempts);
info.PushString("connection_timeout");
info.PushNumber(pRemoteCall->GetOptions().uiConnectTimeoutMs);
// requested headers
info.PushString("headers");
for (auto const& header : pRemoteCall->GetOptions().requestHeaders)
{
requestedHeaders.PushString(header.first.c_str());
requestedHeaders.PushString(header.second.c_str());
}
info.PushTable(&requestedHeaders);
info.PushAsTable(luaVM);
return 1;
requestedHeaders.PushString(header.first.c_str());
requestedHeaders.PushString(header.second.c_str());
}

info.PushTable(&requestedHeaders);
info.PushAsTable(luaVM);
return 1;
}
else
{
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
}

lua_pushboolean(luaVM, false);
return 1;
}
Expand All @@ -2020,11 +2018,8 @@ int CLuaFunctionDefs::AbortNetworkRequest(lua_State* luaVM)

if (!argStream.HasErrors())
{
if (pRemoteCall)
{
lua_pushboolean(luaVM, pRemoteCall->CancelDownload());
return 1;
}
lua_pushboolean(luaVM, pRemoteCall->CancelDownload());
return 1;
}
else
{
Expand Down
44 changes: 16 additions & 28 deletions Server/mods/deathmatch/logic/CRemoteCalls.cpp
Expand Up @@ -35,27 +35,21 @@ CRemoteCall* CRemoteCalls::Call(const char* szServerHost, const char* szResource
CRemoteCall* pRemoteCall =
new CRemoteCall(szServerHost, szResourceName, szFunctionName, arguments, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs);

if (pRemoteCall)
{
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();
return pRemoteCall;
}
return nullptr;
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();

return pRemoteCall;
}

CRemoteCall* CRemoteCalls::Call(const char* szURL, CLuaArguments* arguments, CLuaMain* luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName,
uint uiConnectionAttempts, uint uiConnectTimeoutMs)
{
CRemoteCall* pRemoteCall = new CRemoteCall(szURL, arguments, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs);

if (pRemoteCall)
{
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();
return pRemoteCall;
}
return nullptr;
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();

return pRemoteCall;
}

CRemoteCall* CRemoteCalls::Call(const char* szURL, CLuaArguments* fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain* luaMain,
Expand All @@ -64,27 +58,21 @@ CRemoteCall* CRemoteCalls::Call(const char* szURL, CLuaArguments* fetchArguments
CRemoteCall* pRemoteCall =
new CRemoteCall(szURL, fetchArguments, strPostData, bPostBinary, luaMain, iFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs);

if (pRemoteCall)
{
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();
return pRemoteCall;
}
return nullptr;
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();

return pRemoteCall;
}

CRemoteCall* CRemoteCalls::Call(const char* szURL, CLuaArguments* fetchArguments, CLuaMain* luaMain, const CLuaFunctionRef& iFunction,
const SString& strQueueName, const SHttpRequestOptions& options)
{
CRemoteCall* pRemoteCall = new CRemoteCall(szURL, fetchArguments, luaMain, iFunction, strQueueName, options);

if (pRemoteCall)
{
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();
return pRemoteCall;
}
return nullptr;
m_calls.push_back(pRemoteCall);
m_calls.back()->MakeCall();

return pRemoteCall;
}

void CRemoteCalls::Remove(CLuaMain* lua)
Expand Down

0 comments on commit c107463

Please sign in to comment.