1 Commits
Author SHA1 Message Date
A1m` 8a4cb31f8d Add forwards SteamWorks_OnUserStatsReceived, SteamWorks_OnUserStatsStored, SteamWorks_OnUserStatsUnloaded (#7)
* Add SteamWorks_OnUserStatsReceived forward

This forward is triggered when Steam responds to a RequestUserStats call.

* Add a game ID parameter to forward 'SteamWorks_OnUserStatsReceived'

* Added SteamWorks_OnUserStatsStored and SteamWorks_OnUserStatsUnloaded forwards

* Fix steamworkds callback 'OnUserStatsReceived'
2026-08-29 19:04:58 +00:00
3 changed files with 102 additions and 18 deletions
+46 -2
View File
@@ -26,7 +26,10 @@ SteamWorksForwards::SteamWorksForwards() :
m_CallbackSteamConnected(this, &SteamWorksForwards::OnSteamServersConnected),
m_CallbackSteamConnectFailure(this, &SteamWorksForwards::OnSteamServersConnectFailure),
m_CallbackSteamDisconnected(this, &SteamWorksForwards::OnSteamServersDisconnected),
m_CallbackGroupStatus(this, &SteamWorksForwards::OnGroupStatusResult)
m_CallbackGroupStatus(this, &SteamWorksForwards::OnGroupStatusResult),
m_CallbackUserStatsReceived(this, &SteamWorksForwards::OnUserStatsReceived),
m_CallbackUserStatsUnloaded(this, &SteamWorksForwards::OnUserStatsUnloaded),
m_CallbackUserStatsStored(this, &SteamWorksForwards::OnUserStatsStored)
{
this->pFOVC_Old = forwards->CreateForward("SW_OnValidateClient", ET_Ignore, 2, NULL, Param_Cell, Param_Cell);
this->pFOVC = forwards->CreateForward("SteamWorks_OnValidateClient", ET_Ignore, 2, NULL, Param_Cell, Param_Cell);
@@ -34,6 +37,10 @@ SteamWorksForwards::SteamWorksForwards() :
this->pFOSSCF = forwards->CreateForward("SteamWorks_SteamServersConnectFailure", ET_Ignore, 1, NULL, Param_Cell);
this->pFOSSD = forwards->CreateForward("SteamWorks_SteamServersDisconnected", ET_Ignore, 1, NULL, Param_Cell);
this->pFOCGS = forwards->CreateForward("SteamWorks_OnClientGroupStatus", ET_Ignore, 4, NULL, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
this->pFUserStatsReceived = forwards->CreateForward("SteamWorks_OnUserStatsReceived", ET_Ignore, 2, NULL, Param_Cell, Param_Cell);
this->pFUserStatsUnloaded = forwards->CreateForward("SteamWorks_OnUserStatsUnloaded", ET_Ignore, 1, NULL, Param_Cell);
this->pFUserStatsStored = forwards->CreateForward("SteamWorks_OnUserStatsStored", ET_Ignore, 2, NULL, Param_Cell, Param_Cell);
}
SteamWorksForwards::~SteamWorksForwards()
@@ -44,6 +51,10 @@ SteamWorksForwards::~SteamWorksForwards()
forwards->ReleaseForward(this->pFOSSCF);
forwards->ReleaseForward(this->pFOSSD);
forwards->ReleaseForward(this->pFOCGS);
forwards->ReleaseForward(this->pFUserStatsReceived);
forwards->ReleaseForward(this->pFUserStatsUnloaded);
forwards->ReleaseForward(this->pFUserStatsStored);
}
void SteamWorksForwards::NotifyPawnValidateClient(Account_t parent, Account_t child)
@@ -117,4 +128,37 @@ void SteamWorksForwards::OnGroupStatusResult(GSClientGroupStatus_t *pResponse)
this->pFOCGS->PushCell(pResponse->m_bMember);
this->pFOCGS->PushCell(pResponse->m_bOfficer);
this->pFOCGS->Execute(NULL);
}
}
void SteamWorksForwards::OnUserStatsReceived(GSStatsReceived_t* pCallback)
{
if (this->pFUserStatsReceived->GetFunctionCount() == 0)
{
return;
}
this->pFUserStatsReceived->PushCell(pCallback->m_steamIDUser.GetAccountID());
this->pFUserStatsReceived->PushCell(pCallback->m_eResult);
this->pFUserStatsReceived->Execute(NULL);
}
void SteamWorksForwards::OnUserStatsUnloaded(GSStatsUnloaded_t* pCallback)
{
if (this->pFUserStatsUnloaded->GetFunctionCount() == 0)
{
return;
}
this->pFUserStatsUnloaded->PushCell(pCallback->m_steamIDUser.GetAccountID());
this->pFUserStatsUnloaded->Execute(NULL);
}
void SteamWorksForwards::OnUserStatsStored(GSStatsStored_t* pCallback)
{
if (this->pFUserStatsStored->GetFunctionCount() == 0)
return;
this->pFUserStatsStored->PushCell(pCallback->m_steamIDUser.GetAccountID());
this->pFUserStatsStored->PushCell(pCallback->m_eResult);
this->pFUserStatsStored->Execute(NULL);
}
+8
View File
@@ -43,6 +43,10 @@ class SteamWorksForwards
STEAM_GAMESERVER_CALLBACK(SteamWorksForwards, OnSteamServersConnectFailure, SteamServerConnectFailure_t, m_CallbackSteamConnectFailure);
STEAM_GAMESERVER_CALLBACK(SteamWorksForwards, OnSteamServersDisconnected, SteamServersDisconnected_t, m_CallbackSteamDisconnected);
STEAM_GAMESERVER_CALLBACK(SteamWorksForwards, OnGroupStatusResult, GSClientGroupStatus_t, m_CallbackGroupStatus);
STEAM_GAMESERVER_CALLBACK(SteamWorksForwards, OnUserStatsReceived, GSStatsReceived_t, m_CallbackUserStatsReceived);
STEAM_GAMESERVER_CALLBACK(SteamWorksForwards, OnUserStatsUnloaded, GSStatsUnloaded_t, m_CallbackUserStatsUnloaded);
STEAM_GAMESERVER_CALLBACK(SteamWorksForwards, OnUserStatsStored, GSStatsStored_t, m_CallbackUserStatsStored);
private:
SourceMod::IForward *pFOVC; /* Forward On Validate Client */
@@ -51,4 +55,8 @@ class SteamWorksForwards
SourceMod::IForward *pFOSSCF; /* Forward On Steam Servers Connect Failure */
SourceMod::IForward *pFOSSD; /* Forward On Steam Servers Disconnected */
SourceMod::IForward *pFOCGS; /* Forward On Client Group Status */
SourceMod::IForward* pFUserStatsReceived; // On User Stats Received
SourceMod::IForward* pFUserStatsUnloaded;
SourceMod::IForward* pFUserStatsStored;
};
+48 -16
View File
@@ -3,6 +3,8 @@
#endif
#define _SteamWorks_Included
/* Constants */
/* results from UserHasLicenseForApp */
enum EUserHasLicenseForAppResult
{
@@ -245,6 +247,18 @@ enum EHTTPStatusCode
k_EHTTPStatusCode5xxUnknown = 599,
};
/* list of possible return values from the ISteamGameCoordinator API */
enum EGCResults
{
k_EGCResultOK = 0,
k_EGCResultNoMessage = 1, // There is no message in the queue
k_EGCResultBufferTooSmall = 2, // The buffer is too small for the requested message
k_EGCResultNotLoggedOn = 3, // The client is not logged onto Steam
k_EGCResultInvalidMessage = 4, // Something was wrong with the message being sent with SendMessage
};
/* Natives */
/**
* Returns whether an HTTP status code represents success (a 2xx code).
*
@@ -256,16 +270,6 @@ stock bool IsHTTPStatusSuccess(EHTTPStatusCode eStatusCode)
return (eStatusCode >= k_EHTTPStatusCode200OK && eStatusCode < k_EHTTPStatusCode300MultipleChoices);
}
/* list of possible return values from the ISteamGameCoordinator API */
enum EGCResults
{
k_EGCResultOK = 0,
k_EGCResultNoMessage = 1, // There is no message in the queue
k_EGCResultBufferTooSmall = 2, // The buffer is too small for the requested message
k_EGCResultNotLoggedOn = 3, // The client is not logged onto Steam
k_EGCResultInvalidMessage = 4, // Something was wrong with the message being sent with SendMessage
};
/**
* Returns whether the server is VAC (Valve Anti-Cheat) secured.
*
@@ -828,6 +832,16 @@ native bool SteamWorks_GetHTTPResponseBodyCallback(Handle hRequest, SteamWorksHT
*/
native bool SteamWorks_WriteHTTPResponseBodyToFile(Handle hRequest, const char[] sFileName);
/**
* Sends a message to the Game Coordinator.
*
* @param unMsgType Message type.
* @param pubData Message payload.
* @param cubData Size of the payload, in bytes.
* @return An EGCResults value; k_EGCResultNotLoggedOn if not connected to Steam.
*/
native EGCResults SteamWorks_SendMessageToGC(int unMsgType, const char[] pubData, int cubData);
methodmap SteamWorksHTTPRequest < Handle
{
/**
@@ -1075,6 +1089,8 @@ methodmap SteamWorksHTTPRequest < Handle
public native bool WriteResponseBodyToFile(const char[] sFileName);
};
/* Forwards */
/**
* Deprecated alias for SteamWorks_OnValidateClient, kept for backwards compatibility.
* Use SteamWorks_OnValidateClient in new code.
@@ -1174,14 +1190,30 @@ forward void SteamWorks_GCMsgAvailable(int cubData);
forward EGCResults SteamWorks_GCRetrieveMessage(int punMsgType, const char[] pubDest, int cubDest, int pcubMsgSize);
/**
* Sends a message to the Game Coordinator.
* Called when a user's stats have been received in response to
* SteamWorks_RequestStats or SteamWorks_RequestStatsAuthID.
*
* @param unMsgType Message type.
* @param pubData Message payload.
* @param cubData Size of the payload, in bytes.
* @return An EGCResults value; k_EGCResultNotLoggedOn if not connected to Steam.
* @param authid 32-bit account ID of the user whose stats were requested.
* @param result EResult code; k_EResultOK (1) indicates success.
* @param gameid Game ID (AppID) of the game the stats were requested for.
*/
native EGCResults SteamWorks_SendMessageToGC(int unMsgType, const char[] pubData, int cubData);
forward void SteamWorks_OnUserStatsReceived(int authid, EResult result, int gameid);
/**
* Called when Steam unloads user stats from the cache.
* After this, stats for this user are no longer available until RequestStats is called again.
*
* @param authid 32-bit account ID of the user.
*/
forward void SteamWorks_OnUserStatsUnloaded(int authid);
/**
* Called when a request to store user stats has completed.
*
* @param authid 32-bit account ID of the user.
* @param result EResult code; k_EResultOK (1) indicates success.
*/
forward void SteamWorks_OnUserStatsStored(int authid, EResult result);
public Extension __ext_SteamWorks =
{