#include <sourcemod>
#include <basecomm>
#include <PlayerManager>
#include <geoip>

public Plugin myinfo =
{
	name         = "Display nosteamers",
	author       = "jenz",
	description  = "displaying nosteamers as the old playermanager did.",
	version      = "1.0"
};

public void OnPluginStart()
{
	LoadTranslations("common.phrases");

	AddMultiTargetFilter("@steam", Filter_Steam, "Steam Players", false);
	AddMultiTargetFilter("@nosteam", Filter_NoSteam, "No-Steam Players", false);

	RegConsoleCmd("sm_steam", Command_DisplaySteamStats, "Shows No-Steam players");
	RegConsoleCmd("sm_nosteam", Command_DisplaySteamStats, "Shows No-Steam players");
	RegAdminCmd("sm_debugnosteam", Command_DebugNoSteam, ADMFLAG_GENERIC, "Retreives the amount of No-Steam players");

	AutoExecConfig();
}

public void OnPluginEnd()
{
	RemoveMultiTargetFilter("@steam", Filter_Steam);
	RemoveMultiTargetFilter("@nosteam", Filter_NoSteam);
}

public bool Filter_Steam(const char[] sPattern, Handle hClients)
{
	for(int i = 1; i <= MaxClients; i++)
	{
		if(IsClientInGame(i) && !IsFakeClient(i))
		{
			char sAuthID[32];
			GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);

			if(SteamClientAuthenticatedEx(sAuthID, i))
				PushArrayCell(hClients, i);
		}
	}
	return true;
}

//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool Filter_NoSteam(const char[] sPattern, Handle hClients)
{
	for(int i = 1; i <= MaxClients; i++)
	{
		if(IsClientInGame(i) && !IsFakeClient(i))
		{
			char sAuthID[32];
			GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);

			if(!SteamClientAuthenticatedEx(sAuthID, i))
				PushArrayCell(hClients, i);
		}
	}
	return true;
}

public Action Command_DebugNoSteam(int client, int args)
{
	int iNoSteamAmount;

	for(int i = 1; i <= MaxClients; i++)
	{
		if(IsClientInGame(i) && !IsFakeClient(i))
		{
			char sAuthID[32];
			GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);

			if(!SteamClientAuthenticatedEx(sAuthID, i))
				iNoSteamAmount++;
		}
	}

	ReplyToCommand(client, "[SM] There are currently %d No-Steam Clients online.", iNoSteamAmount);

	return Plugin_Handled;
}

public Action Command_DisplaySteamStats(int client, int args)
{
	char aBuf[1024];
	char aBuf2[MAX_NAME_LENGTH];

	for(int i = 1; i <= MaxClients; i++)
	{
		if(IsClientInGame(i) && !IsFakeClient(i))
		{
			char sAuthID[32];
			GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);

			if(!SteamClientAuthenticatedEx(sAuthID, i))
			{
				GetClientName(i, aBuf2, sizeof(aBuf2));
				StrCat(aBuf, sizeof(aBuf), aBuf2);
				StrCat(aBuf, sizeof(aBuf), ", ");
			}
		}
	}

	if(strlen(aBuf))
	{
		aBuf[strlen(aBuf) - 2] = 0;
		ReplyToCommand(client, "[SM] No-Steam clients online: %s", aBuf);
	}
	else
		ReplyToCommand(client, "[SM] No-Steam clients online: none");

	return Plugin_Handled;
}
public bool SteamClientAuthenticatedEx(const char[] sAuthID, int client)
{
    //neons steam ID. he got a vac ban, this lets him avoid it. told him he should get a new account but he never got a new one.
	if (StrEqual(sAuthID, "STEAM_0:1:32247009")) 
		return true;

	return PM_IsPlayerSteam(client);
}

