diff --git a/ConnectAnnounce/scripting/ConnectAnnounce.sp b/ConnectAnnounce/scripting/ConnectAnnounce.sp index 33b2a773..62344633 100644 --- a/ConnectAnnounce/scripting/ConnectAnnounce.sp +++ b/ConnectAnnounce/scripting/ConnectAnnounce.sp @@ -1,10 +1,10 @@ #pragma semicolon 1 #include -#include #include #include #include +#include #pragma newdecls required @@ -19,6 +19,8 @@ Handle g_hCustomMessageFile2; bool g_bHideCsays[MAXPLAYERS + 1] = { false, ... }; Handle g_hCookieHideCsays = null; +ConVar g_cvHlstatsServerName; + #define MSGLENGTH 100 //---------------------------------------------------------------------------------------------------- @@ -37,20 +39,13 @@ public Plugin myinfo = { //---------------------------------------------------------------------------------------------------- public void OnPluginStart() { + g_cvHlstatsServerName = CreateConVar("sm_connectannounce_hlstats_server_name", "css-ze", "Hlstats server name to check the rank for"); + AutoExecConfig(true); + BuildPath(Path_SM, g_sCustomMessageFile, sizeof(g_sCustomMessageFile), "configs/connect_announce/custom-messages.cfg"); BuildPath(Path_SM, g_sDataFile, sizeof(g_sDataFile), "configs/connect_announce/settings.cfg"); - char error[255]; - - if (SQL_CheckConfig("hlstatsx")) - { - g_hDatabase = SQL_Connect("hlstatsx", true, error, sizeof(error)); - } - - if (g_hDatabase == null) - { - LogError("Could not connect to database: %s", error); - } + Database.Connect(OnDatabaseConnect, "hlstatsx"); RegAdminCmd("sm_joinmsg", Command_JoinMsg, ADMFLAG_CUSTOM1, "Sets a custom message which will be shown upon connecting to the server"); RegAdminCmd("sm_resetjoinmsg", Command_ResetJoinMsg, ADMFLAG_CUSTOM1, "Resets your custom connect message"); @@ -62,6 +57,20 @@ public void OnPluginStart() SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide Connect Csays"); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnDatabaseConnect(Database db, const char[] error, any data) +{ + if(db == INVALID_HANDLE || strlen(error) > 0) + { + LogError("Error connecting to database: %s", error); + return; + } + + g_hDatabase = db; +} + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -228,6 +237,7 @@ public Action Command_JoinMsg(int client, int args) return Plugin_Handled; } + StripQuotes(sArg); if (KvJumpToKey(g_hCustomMessageFile, sAuth, true)) KvSetString(g_hCustomMessageFile, "message", sArg); @@ -365,7 +375,7 @@ public void TQueryCB(Handle owner, Handle rs, const char[] error, any data) if(StrContains(sRawMsg, "{NOSTEAM}")) { - if(!SteamClientAuthenticated(sAuth)) + if(!RevEmu_IsPlayerSteam(client)) ReplaceString(sRawMsg, sizeof(sRawMsg), "{NOSTEAM}", " "); else ReplaceString(sRawMsg, sizeof(sRawMsg), "{NOSTEAM}", ""); @@ -467,12 +477,18 @@ public void OnClientPostAdminCheck(int client) if(IsFakeClient(client)) return; + if(g_hDatabase == INVALID_HANDLE) + return; + static char sAuth[32]; GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth)); strcopy(sAuth, sizeof(sAuth), sAuth[8]); + char sServer[16]; + g_cvHlstatsServerName.GetString(sServer, sizeof(sServer)); + char sQuery[512]; - Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = 'css-ze' AND hideranking = 0 AND skill > (SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = 'css-ze')", sAuth); - SQL_TQuery(g_hDatabase, TQueryCB, sQuery, GetClientUserId(client)); + Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = '%s' AND hideranking = 0 AND skill > (SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = '%s')", sServer, sAuth, sServer); + g_hDatabase.Query(TQueryCB, sQuery, GetClientUserId(client)); } \ No newline at end of file diff --git a/NoSteamManager/scripting/NoSteamManager_RevEmu.sp b/NoSteamManager/scripting/NoSteamManager_RevEmu.sp index 2760543f..24c1160c 100644 --- a/NoSteamManager/scripting/NoSteamManager_RevEmu.sp +++ b/NoSteamManager/scripting/NoSteamManager_RevEmu.sp @@ -60,7 +60,7 @@ public void OnDatabaseConnect(Database db, const char[] error, any data) if(db == INVALID_HANDLE || strlen(error) > 0) { LogError("Error connecting to database: %s", error); - SetFailState("Error connecting to database. Reconnecting on map change."); + return; } g_hDatabaseAntiSpoofing = db; @@ -82,7 +82,7 @@ public Action Command_DisplaySteamStats(int client, int args) { if(IsClientInGame(i) && !IsFakeClient(i)) { - if(!IsSteam(i)) + if(!RevEmu_IsPlayerSteam(i)) { GetClientName(i, aBuf2, sizeof(aBuf2)); StrCat(aBuf, sizeof(aBuf), aBuf2); @@ -101,7 +101,7 @@ public Action Command_DisplaySteamStats(int client, int args) aBuf = "##################################################\n"; for(int i = 1; i <= MaxClients; i++) { - if(IsClientInGame(i) && !IsFakeClient(i) && !IsSteam(i)) + if(IsClientInGame(i) && !IsFakeClient(i) && !RevEmu_IsPlayerSteam(i)) { char sConnectionType[32]; GetConnectionType(i, sConnectionType, sizeof(sConnectionType)); @@ -133,7 +133,7 @@ public bool Filter_Steam(const char[] sPattern, Handle hClients) { if(IsClientInGame(i) && !IsFakeClient(i)) { - if(IsSteam(i)) + if(RevEmu_IsPlayerSteam(i)) PushArrayCell(hClients, i); } } @@ -149,7 +149,7 @@ public bool Filter_NoSteam(const char[] sPattern, Handle hClients) { if(IsClientInGame(i) && !IsFakeClient(i)) { - if(!IsSteam(i)) + if(!RevEmu_IsPlayerSteam(i)) PushArrayCell(hClients, i); } } @@ -170,7 +170,7 @@ public Action OnClientPreAdminCheck(int client) char sSteamID[32]; GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); - if(!IsSteam(client)) + if(!RevEmu_IsPlayerSteam(client)) { char sConnectionType[32]; GetConnectionType(client, sConnectionType, sizeof(sConnectionType)); @@ -206,7 +206,7 @@ public void OnClientPostAdminCheck(int client) if(IsFakeClient(client) || IsClientSourceTV(client)) return; - if(!IsSteam(client)) + if(!RevEmu_IsPlayerSteam(client)) { LogMessage("%L was not authenticated with steam, muting client.", client); BaseComm_SetClientMute(client, true); @@ -224,6 +224,12 @@ public void TQueryCB(Database db, DBResultSet results, const char[] error, any d if ((client = GetClientOfUserId(data)) == 0) return; + if(db == INVALID_HANDLE || strlen(error) > 0) + { + LogError("SQL query errors: %s", error); + return; + } + char sSteamID[32]; GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); @@ -276,7 +282,7 @@ public void GetConnectionType(int client, char[] sConnectionType, int iMaxLength char sConnectionTypeInternal[32]; RevEmu_UserType PlayerType = RevEmu_GetPlayerType(client); - if (PlayerType == Unknown) + if (PlayerType == Invalid) sConnectionTypeInternal = "Error"; else if (PlayerType == SteamLegitUser) sConnectionTypeInternal = "SteamLegit"; @@ -302,14 +308,6 @@ public void GetConnectionType(int client, char[] sConnectionType, int iMaxLength strcopy(sConnectionType, iMaxLength, sConnectionTypeInternal); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public bool IsSteam(int client) -{ - return (RevEmu_GetPlayerType(client) == SteamLegitUser); -} - //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -318,6 +316,6 @@ public void SQL_DoNothing(Database db, DBResultSet results, const char[] error, if(db == INVALID_HANDLE || strlen(error) > 0) { LogError("SQL query errors: %s", error); - SetFailState("Lost connection to database. Reconnecting on map change."); + return; } } \ No newline at end of file diff --git a/VPN-Check/scripting/VPN-Check.sp b/VPN-Check/scripting/VPN-Check.sp new file mode 100644 index 00000000..1827835e --- /dev/null +++ b/VPN-Check/scripting/VPN-Check.sp @@ -0,0 +1,226 @@ +#include +#include +#include +#include + +#pragma newdecls required +#pragma semicolon 1 + +/* INTEGERS */ +int g_bStatus[MAXPLAYERS+1] = {0,...}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Plugin myinfo = +{ + name = "VPN-Check", + author = "Neon", + description = "", + version = "1.0.0" +}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnPluginStart() +{ + RegAdminCmd("sm_vpn", Command_CheckVPN, ADMFLAG_RCON); + for (int client = 1; client <= MaxClients; client++) + { + if (!IsValidClient(client) || IsClientSourceTV(client)) + continue; + + int iSerial = GetClientSerial(client); + + char sIP[32]; + GetClientIP(client, sIP, sizeof(sIP)); + + char sRequest[256]; + FormatEx(sRequest, sizeof(sRequest), "http://proxy.mind-media.com/block/proxycheck.php?ip=%s", sIP); + + Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest); + if (!hRequest || + !SteamWorks_SetHTTPCallbacks(hRequest, OnClientPostAdminCheck_OnTransferComplete) || + !SteamWorks_SetHTTPRequestContextValue(hRequest, iSerial) || + !SteamWorks_SendHTTPRequest(hRequest)) + { + delete hRequest; + } + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action Command_CheckVPN(int client, int args) +{ + char sBuffer[4096]; + char sIP[32]; + char sSteamID[32]; + bool bFound = false; + + Format(sBuffer, sizeof(sBuffer), "VPN STATUS:\n"); + Format(sBuffer, sizeof(sBuffer), "%s#########################################\n", sBuffer); + for (int i = 1; i <= MaxClients; i++) + { + if (!IsValidClient(i)) + continue; + + if (g_bStatus[i] == 0) + continue; + + if (g_bStatus[i] == 1) + { + GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID)); + GetClientIP(i, sIP, sizeof(sIP)); + + if(!RevEmu_IsPlayerSteam(i)) + Format(sBuffer, sizeof(sBuffer), "%s\"%L\"[NOSTEAM] is possibly using a VPN (%s).\n", sBuffer, i, sIP); + else + Format(sBuffer, sizeof(sBuffer), "%s\"%L\"[STEAM] is possibly using a VPN (%s).\n", sBuffer, i, sIP); + + bFound = true; + } + else if (g_bStatus[i] == 2) + { + Format(sBuffer, sizeof(sBuffer), "%s\"%L\" VPN-Check failed due to an API Error.\n", sBuffer, i); + bFound = true; + } + else if (g_bStatus[i] == 3) + { + Format(sBuffer, sizeof(sBuffer), "%s\"%L\" VPN-Check failed due to an Request Error.\n", sBuffer, i); + bFound = true; + } + } + + if (!bFound) + Format(sBuffer, sizeof(sBuffer), "%sCould not find any possible VPNs\n", sBuffer); + + Format(sBuffer, sizeof(sBuffer), "%s#########################################", sBuffer); + ReplyToCommand(client, sBuffer); + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientConnected(int client) +{ + g_bStatus[client] = 0; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientDisconnect(int client) +{ + g_bStatus[client] = 0; +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientPostAdminCheck(int client) +{ + if (!IsValidClient(client) || IsClientSourceTV(client)) + return; + + int iSerial = GetClientSerial(client); + + char sIP[32]; + GetClientIP(client, sIP, sizeof(sIP)); + + char sRequest[256]; + FormatEx(sRequest, sizeof(sRequest), "http://proxy.mind-media.com/block/proxycheck.php?ip=%s", sIP); + + Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest); + if (!hRequest || + !SteamWorks_SetHTTPCallbacks(hRequest, OnClientPostAdminCheck_OnTransferComplete) || + !SteamWorks_SetHTTPRequestContextValue(hRequest, iSerial) || + !SteamWorks_SendHTTPRequest(hRequest)) + { + delete hRequest; + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int OnClientPostAdminCheck_OnTransferComplete(Handle hRequest, bool bFailure, bool bSuccessful, EHTTPStatusCode eStatusCode, int iSerial) +{ + int client = GetClientFromSerial(iSerial); + + if (!client) //Player disconnected. + { + delete hRequest; + return; + } + + if (bFailure || !bSuccessful || eStatusCode != k_EHTTPStatusCode200OK) + { + g_bStatus[client] = 3; + delete hRequest; + return; + } + + SteamWorks_GetHTTPResponseBodyCallback(hRequest, OnClientPostAdminCheck_OnTransferResponse, iSerial); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int OnClientPostAdminCheck_OnTransferResponse(char[] sData, int iSerial) +{ + int client = GetClientFromSerial(iSerial); + + if (!client) //Player disconnected. + return; + + TrimString(sData); + StripQuotes(sData); + + if (strcmp(sData, "Y", false) == 0) + { + g_bStatus[client] = 1; + + char sIP[32]; + GetClientIP(client, sIP, sizeof(sIP)); + + char sSteamID[32]; + GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); + + for(int i = 1; i <= MaxClients; i++) + { + if(IsValidClient(i) && CheckCommandAccess(i, "sm_vpn", ADMFLAG_RCON)) + { + if(!RevEmu_IsPlayerSteam(client)) + { + CPrintToChat(i, "{green}[SM]{default} %L[NOSTEAM] is possibly using a {red}VPN {default}(IP: %s). Client will be kicked.", client, sIP); + KickClient(client, "VPN not allowed"); + LogAction(client, -1, "\"%L\"[NOSTEAM] is possibly using a VPN (IP: %s). Client got kicked.", client, sIP); + } + else + CPrintToChat(i, "{green}[SM]{default} %L[STEAM] is possibly using a {red}VPN {default}(IP: %s).", client, sIP); + } + } + } + else if (strcmp(sData, "N", false) == 0) + { + g_bStatus[client] = 0; + } + else if (strcmp(sData, "X", false) == 0) + { + g_bStatus[client] = 2; + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock int IsValidClient(int client, bool nobots = true) +{ + if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client))) + return false; + + return IsClientInGame(client); +} \ No newline at end of file