Add UserStats to project.
This commit is contained in:
+1
-1
@@ -26,7 +26,7 @@ PROJECT = SteamWorks
|
|||||||
#USEMETA = true
|
#USEMETA = true
|
||||||
USESH = true
|
USESH = true
|
||||||
|
|
||||||
OBJECTS = sdk/smsdk_ext.cpp extension.cpp swgameserver.cpp swgamedata.cpp swforwards.cpp gsnatives.cpp swgshooks.cpp
|
OBJECTS = sdk/smsdk_ext.cpp extension.cpp swgameserver.cpp swgamedata.cpp swforwards.cpp gsnatives.cpp swgshooks.cpp ssnatives.cpp
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
|
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
|
||||||
|
|||||||
@@ -48,11 +48,13 @@ bool SteamWorks::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
|||||||
this->pSWForward = new SteamWorksForwards;
|
this->pSWForward = new SteamWorksForwards;
|
||||||
this->pGSNatives = new SteamWorksGSNatives;
|
this->pGSNatives = new SteamWorksGSNatives;
|
||||||
this->pGSHooks = new SteamWorksGSHooks;
|
this->pGSHooks = new SteamWorksGSHooks;
|
||||||
|
this->pSSNatives = new SteamWorksSSNatives;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SteamWorks::SDK_OnUnload()
|
void SteamWorks::SDK_OnUnload()
|
||||||
{
|
{
|
||||||
|
delete this->pSSNatives;
|
||||||
delete this->pGSHooks;
|
delete this->pGSHooks;
|
||||||
delete this->pGSNatives;
|
delete this->pGSNatives;
|
||||||
delete this->pSWForward;
|
delete this->pSWForward;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include "swforwards.h"
|
#include "swforwards.h"
|
||||||
#include "gsnatives.h"
|
#include "gsnatives.h"
|
||||||
#include "swgshooks.h"
|
#include "swgshooks.h"
|
||||||
|
#include "ssnatives.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sample implementation of the SDK Extension.
|
* @brief Sample implementation of the SDK Extension.
|
||||||
@@ -134,6 +135,7 @@ public:
|
|||||||
SteamWorksGameServer *pSWGameServer;
|
SteamWorksGameServer *pSWGameServer;
|
||||||
SteamWorksGSNatives *pGSNatives;
|
SteamWorksGSNatives *pGSNatives;
|
||||||
SteamWorksGSHooks *pGSHooks;
|
SteamWorksGSHooks *pGSHooks;
|
||||||
|
SteamWorksSSNatives *pSSNatives;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SteamWorks g_SteamWorks;
|
extern SteamWorks g_SteamWorks;
|
||||||
|
|||||||
@@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
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, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
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 "ssnatives.h"
|
||||||
|
|
||||||
|
static bool IsSteamWorksLoaded(void)
|
||||||
|
{
|
||||||
|
return (g_SteamWorks.pSWGameServer->GetSteamClient() != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ISteamGameServerStats *GetServerStatsPointer(void)
|
||||||
|
{
|
||||||
|
return g_SteamWorks.pSWGameServer->GetServerStats();
|
||||||
|
}
|
||||||
|
|
||||||
|
static CSteamID CreateCommonCSteamID(uint32_t authid, const cell_t *params, unsigned char universeplace = 2, unsigned char typeplace = 3)
|
||||||
|
{
|
||||||
|
return g_SteamWorks.CreateCommonCSteamID(authid, params, universeplace, typeplace);
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t sm_RequestStatsAuthID(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
ISteamGameServerStats *pStats = GetServerStatsPointer();
|
||||||
|
|
||||||
|
if (pStats == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSteamID checkid = CreateCommonCSteamID(params[1], params);
|
||||||
|
return pStats->RequestUserStats(checkid) != k_uAPICallInvalid ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t sm_RequestUserStats(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
ISteamGameServerStats *pStats = GetServerStatsPointer();
|
||||||
|
|
||||||
|
if (pStats == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||||
|
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */
|
||||||
|
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSteamID checkid = CreateCommonCSteamID(pPlayer->GetSteamAccountID(false), params);
|
||||||
|
return pStats->RequestUserStats(checkid) != k_uAPICallInvalid ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t sm_GetStatCell(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
ISteamGameServerStats *pStats = GetServerStatsPointer();
|
||||||
|
|
||||||
|
if (pStats == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||||
|
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */
|
||||||
|
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pName;
|
||||||
|
pContext->LocalToString(params[2], &pName);
|
||||||
|
|
||||||
|
cell_t *pValue;
|
||||||
|
pContext->LocalToPhysAddr(params[3], &pValue);
|
||||||
|
CSteamID checkid = CreateCommonCSteamID(pPlayer->GetSteamAccountID(false), params, 4, 5);
|
||||||
|
return pStats->GetUserStat(checkid, pName, pValue) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t sm_GetStatAuthIDCell(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
ISteamGameServerStats *pStats = GetServerStatsPointer();
|
||||||
|
|
||||||
|
if (pStats == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pName;
|
||||||
|
pContext->LocalToString(params[2], &pName);
|
||||||
|
|
||||||
|
cell_t *pValue;
|
||||||
|
pContext->LocalToPhysAddr(params[3], &pValue);
|
||||||
|
CSteamID checkid = CreateCommonCSteamID(params[1], params, 4, 5);
|
||||||
|
return pStats->GetUserStat(checkid, pName, pValue) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t sm_GetStatFloat(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
ISteamGameServerStats *pStats = GetServerStatsPointer();
|
||||||
|
|
||||||
|
if (pStats == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int client = gamehelpers->ReferenceToIndex(params[1]);
|
||||||
|
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */
|
||||||
|
if (pPlayer == NULL || pPlayer->IsConnected() == false)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pName;
|
||||||
|
pContext->LocalToString(params[2], &pName);
|
||||||
|
|
||||||
|
cell_t *pValue;
|
||||||
|
pContext->LocalToPhysAddr(params[3], &pValue);
|
||||||
|
CSteamID checkid = CreateCommonCSteamID(pPlayer->GetSteamAccountID(false), params, 4, 5);
|
||||||
|
|
||||||
|
float fValue;
|
||||||
|
bool bResult = pStats->GetUserStat(checkid, pName, &fValue);
|
||||||
|
|
||||||
|
*pValue = sp_ftoc(fValue);
|
||||||
|
|
||||||
|
return bResult ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t sm_GetStatAuthIDFloat(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
ISteamGameServerStats *pStats = GetServerStatsPointer();
|
||||||
|
|
||||||
|
if (pStats == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pName;
|
||||||
|
pContext->LocalToString(params[2], &pName);
|
||||||
|
|
||||||
|
cell_t *pValue;
|
||||||
|
pContext->LocalToPhysAddr(params[3], &pValue);
|
||||||
|
CSteamID checkid = CreateCommonCSteamID(params[1], params, 4, 5);
|
||||||
|
|
||||||
|
float fValue;
|
||||||
|
bool bResult = pStats->GetUserStat(checkid, pName, &fValue);
|
||||||
|
|
||||||
|
*pValue = sp_ftoc(fValue);
|
||||||
|
|
||||||
|
return bResult ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static sp_nativeinfo_t ssnatives[] = {
|
||||||
|
{"SteamWorks_RequestStatsAuthID", sm_RequestStatsAuthID},
|
||||||
|
{"SteamWorks_RequestStats", sm_RequestUserStats},
|
||||||
|
{"SteamWorks_GetStatCell", sm_GetStatCell},
|
||||||
|
{"SteamWorks_GetStatAuthIDCell", sm_GetStatAuthIDCell},
|
||||||
|
{"SteamWorks_GetStatFloat", sm_GetStatFloat},
|
||||||
|
{"SteamWorks_GetStatAuthIDFloat", sm_GetStatAuthIDFloat},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamWorksSSNatives::SteamWorksSSNatives()
|
||||||
|
{
|
||||||
|
sharesys->AddNatives(myself, ssnatives);
|
||||||
|
}
|
||||||
|
|
||||||
|
SteamWorksSSNatives::~SteamWorksSSNatives()
|
||||||
|
{
|
||||||
|
/* We tragically can't remove ourselves... hopefully no one uses this class, you know, like a class. */
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
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, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
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).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "smsdk_ext.h"
|
||||||
|
|
||||||
|
class SteamWorksSSNatives
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SteamWorksSSNatives();
|
||||||
|
~SteamWorksSSNatives();
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "extension.h"
|
||||||
Reference in New Issue
Block a user