Files
A1m` a86fc4af91 Fix circular includes and include cleanup (#3)
* Fix circular includes and include cleanup

Fixed a bug where other *.h header files would include extension.h, which itself
was already included in those same headers, creating a circular dependency cycle.
This caused build errors and made compilation unpredictable.

To resolve this:
- Moved implementation-only includes to .cpp files where they are actually needed.
- Added forward declarations where possible to avoid pulling in unnecessary headers.
- Ensured extension.h only contains declarations that require full type definitions.

This improves build stability and compilation time.

* Clean up includes and fix build errors

- Replaced full includes with forward declarations where possible
- Moved implementation-only includes from .h to .cpp files
- Added missing includes for stdint.h and Steam interfaces
- This significantly reduces compilation time and prevents future dependency issues

* Switch to SourceMod SDK smsdk_ext instead of local copy
2026-07-13 21:43:05 +00:00

110 lines
3.0 KiB
C++

/*
This file is part of SourcePawn SteamWorks.
SourcePawn SteamWorks is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, as per version 3 of the License.
SourcePawn SteamWorks is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SourcePawn SteamWorks. If not, see <http://www.gnu.org/licenses/>.
Author: Kyle Sanderson (KyleS).
*/
#include "swhttp.h"
#include "extension.h"
#include "swgameserver.h"
#include "swhttprequest.h"
static ISteamHTTP *GetHTTPPointer()
{
return g_SteamWorks.pSWGameServer->GetHTTP();
}
SteamWorksHTTP::SteamWorksHTTP() :
m_CallbackHeadersReceived(this, &SteamWorksHTTP::OnHTTPHeadersReceived),
m_CallbackDataReceived(this, &SteamWorksHTTP::OnHTTPDataReceived)
{
this->typeHTTP = handlesys->CreateType("HTTPHandle", this, 0, NULL, NULL, myself->GetIdentity(), NULL);
}
SteamWorksHTTP::~SteamWorksHTTP()
{
handlesys->RemoveType(this->typeHTTP, myself->GetIdentity());
}
HandleType_t SteamWorksHTTP::GetHTTPHandle(void)
{
return this->typeHTTP;
}
void SteamWorksHTTP::RegisterRequest(SteamWorksHTTPRequest *pRequest)
{
if (pRequest->request != INVALID_HTTPREQUEST_HANDLE)
{
this->m_Requests[pRequest->request] = pRequest;
}
}
void SteamWorksHTTP::UnregisterRequest(SteamWorksHTTPRequest *pRequest)
{
if (pRequest->request != INVALID_HTTPREQUEST_HANDLE)
{
this->m_Requests.erase(pRequest->request);
}
}
SteamWorksHTTPRequest *SteamWorksHTTP::FindRequest(HTTPRequestHandle request)
{
auto it = this->m_Requests.find(request);
return (it == this->m_Requests.end()) ? NULL : it->second;
}
void SteamWorksHTTP::OnHTTPHeadersReceived(HTTPRequestHeadersReceived_t *pParam)
{
SteamWorksHTTPRequest *pRequest = this->FindRequest(pParam->m_hRequest);
if (pRequest != NULL)
{
pRequest->OnHTTPHeadersReceived(pParam);
}
}
void SteamWorksHTTP::OnHTTPDataReceived(HTTPRequestDataReceived_t *pParam)
{
SteamWorksHTTPRequest *pRequest = this->FindRequest(pParam->m_hRequest);
if (pRequest != NULL)
{
pRequest->OnHTTPDataReceived(pParam);
}
}
static void DelayedDeleteSteamWorksHTTPRequest(void *object)
{
SteamWorksHTTPRequest *pRequest = reinterpret_cast<SteamWorksHTTPRequest *>(object);
delete pRequest;
}
void SteamWorksHTTP::OnHandleDestroy(HandleType_t type, void *object)
{
if (type == this->typeHTTP) /* Heaven forbid we ever offer another handle. */
{
smutils->AddFrameAction(DelayedDeleteSteamWorksHTTPRequest, object);
}
}
bool SteamWorksHTTP::GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize)
{
if (type == this->typeHTTP && pSize) /* Heaven forbid we ever offer another handle. */
{
*pSize = sizeof(SteamWorksHTTPRequest);
return true;
}
return false;
}