Cleaned up, added nosteam functionality and force validation when steam servers are down.
This commit is contained in:
parent
c0f5bee161
commit
d196f352c2
@ -19,8 +19,7 @@ WinLinux = ['windows', 'linux']
|
|||||||
WinLinuxMac = ['windows', 'linux', 'mac']
|
WinLinuxMac = ['windows', 'linux', 'mac']
|
||||||
|
|
||||||
PossibleSDKs = {
|
PossibleSDKs = {
|
||||||
'ep2': SDK('HL2SDKOB', '2.ep2', '3', 'ORANGEBOX', WinLinux, 'orangebox'),
|
'sdk2013': SDK('HL2SDK2013', '2.sdk2013', '9', 'SDK2013', WinLinuxMac, 'sdk2013'),
|
||||||
'css': SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinuxMac, 'css'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def ResolveEnvPath(env, folder):
|
def ResolveEnvPath(env, folder):
|
||||||
@ -124,7 +123,7 @@ class ExtensionConfig(object):
|
|||||||
'-pipe',
|
'-pipe',
|
||||||
'-fno-strict-aliasing',
|
'-fno-strict-aliasing',
|
||||||
'-Wall',
|
'-Wall',
|
||||||
'-Werror',
|
# '-Werror',
|
||||||
'-Wno-unused',
|
'-Wno-unused',
|
||||||
'-Wno-switch',
|
'-Wno-switch',
|
||||||
'-Wno-array-bounds',
|
'-Wno-array-bounds',
|
||||||
|
@ -17,7 +17,7 @@ project.sources += [
|
|||||||
for sdk_name in SM.sdks:
|
for sdk_name in SM.sdks:
|
||||||
sdk = SM.sdks[sdk_name]
|
sdk = SM.sdks[sdk_name]
|
||||||
|
|
||||||
binary = SM.HL2Config(project, projectName + '.ext.' + sdk.ext, sdk)
|
binary = SM.HL2Config(project, projectName + '.ext', sdk)
|
||||||
binary.compiler.cxxincludes += [
|
binary.compiler.cxxincludes += [
|
||||||
os.path.join(SM.sm_root, 'public', 'extensions'),
|
os.path.join(SM.sm_root, 'public', 'extensions'),
|
||||||
os.path.join(SM.sm_root, 'public', 'sourcepawn'),
|
os.path.join(SM.sm_root, 'public', 'sourcepawn'),
|
||||||
|
138
extension.cpp
138
extension.cpp
@ -31,9 +31,8 @@
|
|||||||
|
|
||||||
#include "extension.h"
|
#include "extension.h"
|
||||||
#include "CDetour/detours.h"
|
#include "CDetour/detours.h"
|
||||||
#include "steam/steamclientpublic.h"
|
#include "steam/steam_gameserver.h"
|
||||||
#include "steam/isteamuser.h"
|
#include "sm_namehashset.h"
|
||||||
#include <sm_stringhashmap.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file extension.cpp
|
* @file extension.cpp
|
||||||
@ -45,6 +44,7 @@ Connect g_Connect; /**< Global singleton for extension's main interface */
|
|||||||
SMEXT_LINK(&g_Connect);
|
SMEXT_LINK(&g_Connect);
|
||||||
|
|
||||||
ConVar g_ConnectVersion("connect_version", SMEXT_CONF_VERSION, FCVAR_REPLICATED|FCVAR_NOTIFY, SMEXT_CONF_DESCRIPTION " Version");
|
ConVar g_ConnectVersion("connect_version", SMEXT_CONF_VERSION, FCVAR_REPLICATED|FCVAR_NOTIFY, SMEXT_CONF_DESCRIPTION " Version");
|
||||||
|
ConVar g_SvNoSteam("sv_nosteam", "0", FCVAR_NOTIFY, "Disable steam validation");
|
||||||
|
|
||||||
IGameConfig *g_pGameConf = NULL;
|
IGameConfig *g_pGameConf = NULL;
|
||||||
IForward *g_pConnectForward = NULL;
|
IForward *g_pConnectForward = NULL;
|
||||||
@ -61,16 +61,6 @@ typedef enum EAuthProtocol
|
|||||||
k_EAuthProtocolSteam = 3,
|
k_EAuthProtocolSteam = 3,
|
||||||
} EAuthProtocol;
|
} EAuthProtocol;
|
||||||
|
|
||||||
typedef enum EBeginAuthSessionResult
|
|
||||||
{
|
|
||||||
k_EBeginAuthSessionResultOK = 0, // Ticket is valid for this game and this steamID.
|
|
||||||
k_EBeginAuthSessionResultInvalidTicket = 1, // Ticket is not valid.
|
|
||||||
k_EBeginAuthSessionResultDuplicateRequest = 2, // A ticket has already been submitted for this steamID
|
|
||||||
k_EBeginAuthSessionResultInvalidVersion = 3, // Ticket is from an incompatible interface version
|
|
||||||
k_EBeginAuthSessionResultGameMismatch = 4, // Ticket is not for this game
|
|
||||||
k_EBeginAuthSessionResultExpiredTicket = 5, // Ticket has expired
|
|
||||||
} EBeginAuthSessionResult;
|
|
||||||
|
|
||||||
typedef struct netadr_s
|
typedef struct netadr_s
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -91,14 +81,14 @@ public:
|
|||||||
const char *CSteamID::Render() const
|
const char *CSteamID::Render() const
|
||||||
{
|
{
|
||||||
static char szSteamID[64];
|
static char szSteamID[64];
|
||||||
V_snprintf(szSteamID, sizeof(szSteamID), "STEAM_0:%u:%u", (m_unAccountID % 2) ? 1 : 0, (int32)m_unAccountID/2);
|
V_snprintf(szSteamID, sizeof(szSteamID), "STEAM_0:%u:%u", (m_steamid.m_comp.m_unAccountID % 2) ? 1 : 0, (int32)m_steamid.m_comp.m_unAccountID/2);
|
||||||
return szSteamID;
|
return szSteamID;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CSteam3Server
|
class CSteam3Server
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void *m_pSteamGameServer;
|
ISteamGameServer *m_pSteamGameServer;
|
||||||
void *m_pSteamGameServerUtils;
|
void *m_pSteamGameServerUtils;
|
||||||
void *m_pSteamGameServerNetworking;
|
void *m_pSteamGameServerNetworking;
|
||||||
void *m_pSteamGameServerStats;
|
void *m_pSteamGameServerStats;
|
||||||
@ -157,71 +147,28 @@ void SetSteamID(CBaseClient *pClient, const CSteamID &steamID)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
class VFuncEmptyClass{};
|
|
||||||
|
|
||||||
int g_nBeginAuthSessionOffset = 0;
|
|
||||||
int g_nEndAuthSessionOffset = 0;
|
|
||||||
|
|
||||||
EBeginAuthSessionResult BeginAuthSession(const void *pAuthTicket, int cbAuthTicket, CSteamID steamID)
|
EBeginAuthSessionResult BeginAuthSession(const void *pAuthTicket, int cbAuthTicket, CSteamID steamID)
|
||||||
{
|
{
|
||||||
if(!g_pSteam3Server || !g_pSteam3Server->m_pSteamGameServer || g_nBeginAuthSessionOffset == 0)
|
if(!g_pSteam3Server || !g_pSteam3Server->m_pSteamGameServer)
|
||||||
return k_EBeginAuthSessionResultOK;
|
return k_EBeginAuthSessionResultOK;
|
||||||
|
|
||||||
void **this_ptr = *(void ***)&g_pSteam3Server->m_pSteamGameServer;
|
return g_pSteam3Server->m_pSteamGameServer->BeginAuthSession(pAuthTicket, cbAuthTicket, steamID);
|
||||||
void **vtable = *(void ***)g_pSteam3Server->m_pSteamGameServer;
|
|
||||||
void *func = vtable[g_nBeginAuthSessionOffset];
|
|
||||||
|
|
||||||
union {
|
|
||||||
EBeginAuthSessionResult (VFuncEmptyClass::*mfpnew)(const void *, int, CSteamID);
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
struct {
|
|
||||||
void *addr;
|
|
||||||
intptr_t adjustor;
|
|
||||||
} s;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.s.addr = func;
|
|
||||||
u.s.adjustor = 0;
|
|
||||||
#else
|
|
||||||
void *addr;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.addr = func;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (EBeginAuthSessionResult)(reinterpret_cast<VFuncEmptyClass*>(this_ptr)->*u.mfpnew)(pAuthTicket, cbAuthTicket, steamID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndAuthSession(CSteamID steamID)
|
void EndAuthSession(CSteamID steamID)
|
||||||
{
|
{
|
||||||
if(!g_pSteam3Server || !g_pSteam3Server->m_pSteamGameServer || g_nEndAuthSessionOffset == 0)
|
if(!g_pSteam3Server || !g_pSteam3Server->m_pSteamGameServer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
void **this_ptr = *(void ***)&g_pSteam3Server->m_pSteamGameServer;
|
g_pSteam3Server->m_pSteamGameServer->EndAuthSession(steamID);
|
||||||
void **vtable = *(void ***)g_pSteam3Server->m_pSteamGameServer;
|
}
|
||||||
void *func = vtable[g_nEndAuthSessionOffset];
|
|
||||||
|
|
||||||
union {
|
bool BLoggedOn()
|
||||||
void (VFuncEmptyClass::*mfpnew)(CSteamID);
|
{
|
||||||
|
if(!g_pSteam3Server || !g_pSteam3Server->m_pSteamGameServer)
|
||||||
|
return false;
|
||||||
|
|
||||||
#ifndef WIN32
|
return g_pSteam3Server->m_pSteamGameServer->BLoggedOn();
|
||||||
struct {
|
|
||||||
void *addr;
|
|
||||||
intptr_t adjustor;
|
|
||||||
} s;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.s.addr = func;
|
|
||||||
u.s.adjustor = 0;
|
|
||||||
#else
|
|
||||||
void *addr;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.addr = func;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (void)(reinterpret_cast<VFuncEmptyClass*>(this_ptr)->*u.mfpnew)(steamID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CDetour *g_Detour_CBaseServer__ConnectClient = NULL;
|
CDetour *g_Detour_CBaseServer__ConnectClient = NULL;
|
||||||
@ -268,6 +215,21 @@ bool g_bEndAuthSessionOnRejectConnection = false;
|
|||||||
CSteamID g_lastClientSteamID;
|
CSteamID g_lastClientSteamID;
|
||||||
bool g_bSuppressCheckChallengeType = false;
|
bool g_bSuppressCheckChallengeType = false;
|
||||||
|
|
||||||
|
DETOUR_DECL_MEMBER1(CSteam3Server__OnValidateAuthTicketResponse, int, CSteamID *, steamID)
|
||||||
|
{
|
||||||
|
char aSteamID[32];
|
||||||
|
V_strncpy(aSteamID, steamID->Render(), sizeof(aSteamID));
|
||||||
|
|
||||||
|
ConnectClientStorage Storage;
|
||||||
|
if(g_ConnectClientStorage.retrieve(aSteamID, &Storage))
|
||||||
|
{
|
||||||
|
Storage.Validated = true;
|
||||||
|
g_ConnectClientStorage.replace(aSteamID, Storage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DETOUR_MEMBER_CALL(CSteam3Server__OnValidateAuthTicketResponse)(steamID);
|
||||||
|
}
|
||||||
|
|
||||||
DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address, int, nProtocol, int, iChallenge, int, iClientChallenge, int, nAuthProtocol, const char *, pchName, const char *, pchPassword, const char *, pCookie, int, cbCookie)
|
DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address, int, nProtocol, int, iChallenge, int, iClientChallenge, int, nAuthProtocol, const char *, pchName, const char *, pchPassword, const char *, pCookie, int, cbCookie)
|
||||||
{
|
{
|
||||||
if(nAuthProtocol != k_EAuthProtocolSteam)
|
if(nAuthProtocol != k_EAuthProtocolSteam)
|
||||||
@ -316,12 +278,18 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address,
|
|||||||
AsyncWaiting = true;
|
AsyncWaiting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool noSteam = false;
|
||||||
EBeginAuthSessionResult result = BeginAuthSession(pvTicket, cbTicket, g_lastClientSteamID);
|
EBeginAuthSessionResult result = BeginAuthSession(pvTicket, cbTicket, g_lastClientSteamID);
|
||||||
if(result != k_EBeginAuthSessionResultOK)
|
if(result != k_EBeginAuthSessionResultOK)
|
||||||
|
{
|
||||||
|
if(g_SvNoSteam.GetInt() || !BLoggedOn())
|
||||||
|
noSteam = true;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
RejectConnection(address, iClientChallenge, "#GameUI_ServerRejectSteam");
|
RejectConnection(address, iClientChallenge, "#GameUI_ServerRejectSteam");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char rejectReason[255];
|
char rejectReason[255];
|
||||||
cell_t retVal = 1;
|
cell_t retVal = 1;
|
||||||
@ -364,7 +332,12 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address,
|
|||||||
|
|
||||||
// k_OnClientPreConnectEx_Accept
|
// k_OnClientPreConnectEx_Accept
|
||||||
g_bSuppressCheckChallengeType = true;
|
g_bSuppressCheckChallengeType = true;
|
||||||
return DETOUR_MEMBER_CALL(CBaseServer__ConnectClient)(address, nProtocol, iChallenge, iClientChallenge, nAuthProtocol, pchName, pchPassword, pCookie, cbCookie);
|
IClient *pClient = DETOUR_MEMBER_CALL(CBaseServer__ConnectClient)(address, nProtocol, iChallenge, iClientChallenge, nAuthProtocol, pchName, pchPassword, pCookie, cbCookie);
|
||||||
|
|
||||||
|
if(pClient && (noSteam || !BLoggedOn()))
|
||||||
|
DETOUR_MEMBER_MCALL_CALLBACK(CSteam3Server__OnValidateAuthTicketResponse, g_pSteam3Server)(&g_lastClientSteamID);
|
||||||
|
|
||||||
|
return pClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
DETOUR_DECL_MEMBER3(CBaseServer__RejectConnection, void, netadr_t &, address, int, iClientChallenge, const char *, pchReason)
|
DETOUR_DECL_MEMBER3(CBaseServer__RejectConnection, void, netadr_t &, address, int, iClientChallenge, const char *, pchReason)
|
||||||
@ -393,21 +366,6 @@ DETOUR_DECL_MEMBER7(CBaseServer__CheckChallengeType, bool, CBaseClient *, pClien
|
|||||||
return DETOUR_MEMBER_CALL(CBaseServer__CheckChallengeType)(pClient, nUserID, address, nAuthProtocol, pCookie, cbCookie, iClientChallenge);
|
return DETOUR_MEMBER_CALL(CBaseServer__CheckChallengeType)(pClient, nUserID, address, nAuthProtocol, pCookie, cbCookie, iClientChallenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
DETOUR_DECL_MEMBER1(CSteam3Server__OnValidateAuthTicketResponse, int, CSteamID *, steamID)
|
|
||||||
{
|
|
||||||
char aSteamID[32];
|
|
||||||
V_strncpy(aSteamID, steamID->Render(), sizeof(aSteamID));
|
|
||||||
|
|
||||||
ConnectClientStorage Storage;
|
|
||||||
if(g_ConnectClientStorage.retrieve(aSteamID, &Storage))
|
|
||||||
{
|
|
||||||
Storage.Validated = true;
|
|
||||||
g_ConnectClientStorage.replace(aSteamID, Storage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DETOUR_MEMBER_CALL(CSteam3Server__OnValidateAuthTicketResponse)(steamID);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connect::SDK_OnLoad(char *error, size_t maxlen, bool late)
|
bool Connect::SDK_OnLoad(char *error, size_t maxlen, bool late)
|
||||||
{
|
{
|
||||||
char conf_error[255] = "";
|
char conf_error[255] = "";
|
||||||
@ -469,18 +427,6 @@ bool Connect::SDK_OnLoad(char *error, size_t maxlen, bool late)
|
|||||||
META_CONPRINTF("ISteamGameServerStats: %p\n", g_pSteam3Server->m_pSteamGameServerStats);
|
META_CONPRINTF("ISteamGameServerStats: %p\n", g_pSteam3Server->m_pSteamGameServerStats);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(!g_pGameConf->GetOffset("ISteamGameServer__BeginAuthSession", &g_nBeginAuthSessionOffset) || g_nBeginAuthSessionOffset == 0)
|
|
||||||
{
|
|
||||||
snprintf(error, maxlen, "Failed to find ISteamGameServer__BeginAuthSession offset.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!g_pGameConf->GetOffset("ISteamGameServer__EndAuthSession", &g_nEndAuthSessionOffset) || g_nEndAuthSessionOffset == 0)
|
|
||||||
{
|
|
||||||
snprintf(error, maxlen, "Failed to find ISteamGameServer__EndAuthSession offset.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);
|
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);
|
||||||
|
|
||||||
g_Detour_CBaseServer__ConnectClient = DETOUR_CREATE_MEMBER(CBaseServer__ConnectClient, "CBaseServer__ConnectClient");
|
g_Detour_CBaseServer__ConnectClient = DETOUR_CREATE_MEMBER(CBaseServer__ConnectClient, "CBaseServer__ConnectClient");
|
||||||
|
@ -8,23 +8,6 @@
|
|||||||
"engine" "css"
|
"engine" "css"
|
||||||
}
|
}
|
||||||
|
|
||||||
"Offsets"
|
|
||||||
{
|
|
||||||
"ISteamGameServer__BeginAuthSession"
|
|
||||||
{
|
|
||||||
"linux" "29"
|
|
||||||
"mac" "29"
|
|
||||||
"windows" "29"
|
|
||||||
}
|
|
||||||
|
|
||||||
"ISteamGameServer__EndAuthSession"
|
|
||||||
{
|
|
||||||
"linux" "30"
|
|
||||||
"mac" "30"
|
|
||||||
"windows" "30"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"Signatures"
|
"Signatures"
|
||||||
{
|
{
|
||||||
"CBaseServer__ConnectClient"
|
"CBaseServer__ConnectClient"
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
/* Basic information exposed publicly */
|
/* Basic information exposed publicly */
|
||||||
#define SMEXT_CONF_NAME "Connect"
|
#define SMEXT_CONF_NAME "Connect"
|
||||||
#define SMEXT_CONF_DESCRIPTION "Forward for early connection"
|
#define SMEXT_CONF_DESCRIPTION "Forward for early connection"
|
||||||
#define SMEXT_CONF_VERSION "2.0"
|
#define SMEXT_CONF_VERSION "2.1"
|
||||||
#define SMEXT_CONF_AUTHOR "Asher \"asherkin\" Baker + BotoX"
|
#define SMEXT_CONF_AUTHOR "Asher \"asherkin\" Baker + BotoX"
|
||||||
#define SMEXT_CONF_URL "https://github.com/CSSZombieEscape/sm-ext-connect"
|
#define SMEXT_CONF_URL "https://github.com/CSSZombieEscape/sm-ext-connect"
|
||||||
#define SMEXT_CONF_LOGTAG "CONNECT"
|
#define SMEXT_CONF_LOGTAG "CONNECT"
|
||||||
|
Loading…
Reference in New Issue
Block a user