nosteam detection WIP

This commit is contained in:
BotoX 2018-03-22 19:37:12 +01:00 committed by BotoX
parent 90a8a1e3a4
commit 5d04944952
4 changed files with 76 additions and 23 deletions

View File

@ -195,6 +195,8 @@ public:
uint64 ullSteamID; uint64 ullSteamID;
ValidateAuthTicketResponse_t ValidateAuthTicketResponse; ValidateAuthTicketResponse_t ValidateAuthTicketResponse;
bool GotValidateAuthTicketResponse; bool GotValidateAuthTicketResponse;
bool SteamLegal;
bool SteamAuthFailed;
ConnectClientStorage() { } ConnectClientStorage() { }
ConnectClientStorage(netadr_t address, int nProtocol, int iChallenge, int iClientChallenge, int nAuthProtocol, const char *pchName, const char *pchPassword, const char *pCookie, int cbCookie) ConnectClientStorage(netadr_t address, int nProtocol, int iChallenge, int iClientChallenge, int nAuthProtocol, const char *pchName, const char *pchPassword, const char *pCookie, int cbCookie)
@ -209,6 +211,8 @@ public:
strncpy(this->pCookie, pCookie, sizeof(this->pCookie)); strncpy(this->pCookie, pCookie, sizeof(this->pCookie));
this->cbCookie = cbCookie; this->cbCookie = cbCookie;
this->GotValidateAuthTicketResponse = false; this->GotValidateAuthTicketResponse = false;
this->SteamLegal = false;
this->SteamAuthFailed = false;
} }
}; };
StringHashMap<ConnectClientStorage> g_ConnectClientStorage; StringHashMap<ConnectClientStorage> g_ConnectClientStorage;
@ -222,11 +226,19 @@ DETOUR_DECL_MEMBER1(CSteam3Server__OnValidateAuthTicketResponse, int, ValidateAu
char aSteamID[32]; char aSteamID[32];
V_strncpy(aSteamID, pResponse->m_SteamID.Render(), sizeof(aSteamID)); V_strncpy(aSteamID, pResponse->m_SteamID.Render(), sizeof(aSteamID));
bool SteamLegal = pResponse->m_eAuthSessionResponse == k_EAuthSessionResponseOK;
bool force = g_SvNoSteam.GetInt() || g_SvForceSteam.GetInt() || !BLoggedOn();
if(!SteamLegal && force)
pResponse->m_eAuthSessionResponse = k_EAuthSessionResponseOK;
printf("SteamLegal: %d\n", SteamLegal);
ConnectClientStorage Storage; ConnectClientStorage Storage;
if(g_ConnectClientStorage.retrieve(aSteamID, &Storage)) if(g_ConnectClientStorage.retrieve(aSteamID, &Storage))
{ {
Storage.GotValidateAuthTicketResponse = true; Storage.GotValidateAuthTicketResponse = true;
Storage.ValidateAuthTicketResponse = *pResponse; Storage.ValidateAuthTicketResponse = *pResponse;
Storage.SteamLegal = SteamLegal;
g_ConnectClientStorage.replace(aSteamID, Storage); g_ConnectClientStorage.replace(aSteamID, Storage);
} }
@ -269,7 +281,7 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address,
// This can happen if the async ClientPreConnectEx takes too long to be called // This can happen if the async ClientPreConnectEx takes too long to be called
// and the client auto-retries. // and the client auto-retries.
bool AsyncWaiting = false; bool AsyncWaiting = false;
ConnectClientStorage Storage; ConnectClientStorage Storage(address, nProtocol, iChallenge, iClientChallenge, nAuthProtocol, pchName, pchPassword, pCookie, cbCookie);
if(g_ConnectClientStorage.retrieve(aSteamID, &Storage)) if(g_ConnectClientStorage.retrieve(aSteamID, &Storage))
{ {
g_ConnectClientStorage.remove(aSteamID); g_ConnectClientStorage.remove(aSteamID);
@ -281,13 +293,18 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address,
AsyncWaiting = true; AsyncWaiting = true;
} }
bool noSteam = g_SvNoSteam.GetInt() || !BLoggedOn(); bool NoSteam = g_SvNoSteam.GetInt() || !BLoggedOn();
bool SteamAuthFailed = false;
EBeginAuthSessionResult result = BeginAuthSession(pvTicket, cbTicket, g_lastClientSteamID); EBeginAuthSessionResult result = BeginAuthSession(pvTicket, cbTicket, g_lastClientSteamID);
if(result != k_EBeginAuthSessionResultOK && !noSteam) if(result != k_EBeginAuthSessionResultOK)
{
if(!NoSteam)
{ {
RejectConnection(address, iClientChallenge, "#GameUI_ServerRejectSteam"); RejectConnection(address, iClientChallenge, "#GameUI_ServerRejectSteam");
return NULL; return NULL;
} }
Storage.SteamAuthFailed = SteamAuthFailed = true;
}
char rejectReason[255]; char rejectReason[255];
cell_t retVal = 1; cell_t retVal = 1;
@ -305,19 +322,19 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address,
pchPassword = passwordBuffer; pchPassword = passwordBuffer;
} }
printf("SteamAuthFailed: %d | retVal = %d\n", SteamAuthFailed, retVal);
// k_OnClientPreConnectEx_Reject // k_OnClientPreConnectEx_Reject
if(retVal == 0) if(retVal == 0)
{ {
g_ConnectClientStorage.remove(aSteamID);
RejectConnection(address, iClientChallenge, rejectReason); RejectConnection(address, iClientChallenge, rejectReason);
return NULL; return NULL;
} }
// k_OnClientPreConnectEx_Async
if(retVal == -1)
{
ConnectClientStorage Storage(address, nProtocol, iChallenge, iClientChallenge, nAuthProtocol, pchName, pchPassword, pCookie, cbCookie);
Storage.pThis = this; Storage.pThis = this;
Storage.ullSteamID = ullSteamID; Storage.ullSteamID = ullSteamID;
Storage.SteamAuthFailed = SteamAuthFailed;
if(!g_ConnectClientStorage.replace(aSteamID, Storage)) if(!g_ConnectClientStorage.replace(aSteamID, Storage))
{ {
@ -325,6 +342,9 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address,
return NULL; return NULL;
} }
// k_OnClientPreConnectEx_Async
if(retVal == -1)
{
return NULL; return NULL;
} }
@ -332,11 +352,11 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient *, netadr_t &, address,
g_bSuppressCheckChallengeType = true; g_bSuppressCheckChallengeType = true;
IClient *pClient = 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 || g_SvForceSteam.GetInt())) if(pClient && SteamAuthFailed)
{ {
ValidateAuthTicketResponse_t Response; ValidateAuthTicketResponse_t Response;
Response.m_SteamID = g_lastClientSteamID; Response.m_SteamID = g_lastClientSteamID;
Response.m_eAuthSessionResponse = k_EAuthSessionResponseOK; Response.m_eAuthSessionResponse = k_EAuthSessionResponseAuthTicketInvalid;
Response.m_OwnerSteamID = Response.m_SteamID; Response.m_OwnerSteamID = Response.m_SteamID;
DETOUR_MEMBER_MCALL_CALLBACK(CSteam3Server__OnValidateAuthTicketResponse, g_pSteam3Server)(&Response); DETOUR_MEMBER_MCALL_CALLBACK(CSteam3Server__OnValidateAuthTicketResponse, g_pSteam3Server)(&Response);
} }
@ -527,8 +547,6 @@ cell_t ClientPreConnectEx(IPluginContext *pContext, const cell_t *params)
if(!g_ConnectClientStorage.retrieve(pSteamID, &Storage)) if(!g_ConnectClientStorage.retrieve(pSteamID, &Storage))
return 1; return 1;
g_ConnectClientStorage.remove(pSteamID);
if(retVal == 0) if(retVal == 0)
{ {
RejectConnection(Storage.address, Storage.iClientChallenge, rejectReason); RejectConnection(Storage.address, Storage.iClientChallenge, rejectReason);
@ -542,8 +560,10 @@ cell_t ClientPreConnectEx(IPluginContext *pContext, const cell_t *params)
if(!pClient) if(!pClient)
return 1; return 1;
if(g_SvNoSteam.GetInt() || g_SvForceSteam.GetInt() || !BLoggedOn()) bool force = g_SvNoSteam.GetInt() || g_SvForceSteam.GetInt() || !BLoggedOn();
if(Storage.SteamAuthFailed && force && !Storage.GotValidateAuthTicketResponse)
{ {
printf("Force ValidateAuthTicketResponse\n");
Storage.ValidateAuthTicketResponse.m_SteamID = CSteamID(Storage.ullSteamID); Storage.ValidateAuthTicketResponse.m_SteamID = CSteamID(Storage.ullSteamID);
Storage.ValidateAuthTicketResponse.m_eAuthSessionResponse = k_EAuthSessionResponseOK; Storage.ValidateAuthTicketResponse.m_eAuthSessionResponse = k_EAuthSessionResponseOK;
Storage.ValidateAuthTicketResponse.m_OwnerSteamID = Storage.ValidateAuthTicketResponse.m_SteamID; Storage.ValidateAuthTicketResponse.m_OwnerSteamID = Storage.ValidateAuthTicketResponse.m_SteamID;
@ -552,14 +572,32 @@ cell_t ClientPreConnectEx(IPluginContext *pContext, const cell_t *params)
// Make sure this is always called in order to verify the client on the server // Make sure this is always called in order to verify the client on the server
if(Storage.GotValidateAuthTicketResponse) if(Storage.GotValidateAuthTicketResponse)
{
printf("Replay ValidateAuthTicketResponse\n");
DETOUR_MEMBER_MCALL_ORIGINAL(CSteam3Server__OnValidateAuthTicketResponse, g_pSteam3Server)(&Storage.ValidateAuthTicketResponse); DETOUR_MEMBER_MCALL_ORIGINAL(CSteam3Server__OnValidateAuthTicketResponse, g_pSteam3Server)(&Storage.ValidateAuthTicketResponse);
}
return 0; return 0;
} }
cell_t SteamClientAuthenticated(IPluginContext *pContext, const cell_t *params)
{
char *pSteamID;
pContext->LocalToString(params[1], &pSteamID);
ConnectClientStorage Storage;
if(g_ConnectClientStorage.retrieve(pSteamID, &Storage))
{
return Storage.SteamLegal;
}
return false;
}
const sp_nativeinfo_t MyNatives[] = const sp_nativeinfo_t MyNatives[] =
{ {
{ "ClientPreConnectEx", ClientPreConnectEx }, { "ClientPreConnectEx", ClientPreConnectEx },
{ "SteamClientAuthenticated", SteamClientAuthenticated },
{ NULL, NULL } { NULL, NULL }
}; };
@ -567,3 +605,13 @@ void Connect::SDK_OnAllLoaded()
{ {
sharesys->AddNatives(myself, MyNatives); sharesys->AddNatives(myself, MyNatives);
} }
void Connect::OnClientDisconnecting(int client)
{
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
if(pPlayer)
{
const char *pSteamID = pPlayer->GetSteam2Id(false);
g_ConnectClientStorage.remove(pSteamID);
}
}

View File

@ -46,7 +46,8 @@
*/ */
class Connect : class Connect :
public SDKExtension, public SDKExtension,
public IConCommandBaseAccessor public IConCommandBaseAccessor,
public IClientListener
{ {
public: public:
/** /**
@ -119,6 +120,9 @@ public:
public: // IConCommandBaseAccessor public: // IConCommandBaseAccessor
virtual bool RegisterConCommandBase(ConCommandBase *pVar); virtual bool RegisterConCommandBase(ConCommandBase *pVar);
public: // IClientListener
void OnClientDisconnecting(int client);
}; };
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ #endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_

View File

@ -13,6 +13,7 @@ enum EConnect
forward EConnect OnClientPreConnectEx(const char[] sName, char sPassword[255], const char[] sIP, const char[] sSteam32ID, char sRejectReason[255]); forward EConnect OnClientPreConnectEx(const char[] sName, char sPassword[255], const char[] sIP, const char[] sSteam32ID, char sRejectReason[255]);
native bool ClientPreConnectEx(const char[] sSteam32ID, EConnect RetVal, char sRejectReason[255]); native bool ClientPreConnectEx(const char[] sSteam32ID, EConnect RetVal, char sRejectReason[255]);
native bool SteamClientAuthenticated(const char[] sSteam32ID);
/** /**
* Do not edit below this line! * Do not edit below this line!

View File

@ -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.2" #define SMEXT_CONF_VERSION "2.3"
#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"
@ -61,7 +61,7 @@
/** Enable interfaces you want to use here by uncommenting lines */ /** Enable interfaces you want to use here by uncommenting lines */
#define SMEXT_ENABLE_FORWARDSYS #define SMEXT_ENABLE_FORWARDSYS
//#define SMEXT_ENABLE_HANDLESYS //#define SMEXT_ENABLE_HANDLESYS
//#define SMEXT_ENABLE_PLAYERHELPERS #define SMEXT_ENABLE_PLAYERHELPERS
//#define SMEXT_ENABLE_DBMANAGER //#define SMEXT_ENABLE_DBMANAGER
#define SMEXT_ENABLE_GAMECONF #define SMEXT_ENABLE_GAMECONF
//#define SMEXT_ENABLE_MEMUTILS //#define SMEXT_ENABLE_MEMUTILS