Move NoSteamPlayerCount.
Maybe even yeet, due to being redundant?
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
#include <sourcemod>
|
||||
#include <SteamWorks>
|
||||
#include <connect>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
bool g_bHasFakeClient[MAXPLAYERS + 1] = {false,...};
|
||||
int g_MaxPlayers = 64;
|
||||
|
||||
ConVar g_hCVar_FakeClients;
|
||||
ConVar g_hCVar_SourceTV;
|
||||
ConVar g_hCVar_MaxPlayers;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "NoSteamPlayerCount",
|
||||
author = "Neon",
|
||||
description = "",
|
||||
version = "1.0",
|
||||
url = "https://steamcommunity.com/id/n3ontm"
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnGameFrame()
|
||||
{
|
||||
SteamWorks_SetMaxPlayers(g_MaxPlayers);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_hCVar_FakeClients = CreateConVar("sm_nosteamplayercount_fakeclients", "1", "Increse PlayerCount for Fake Clients", 0, true, 0.0, true, 1.0);
|
||||
g_hCVar_SourceTV = CreateConVar("sm_nosteamplayercount_sourcetv", "1", "Increse PlayerCount for SourceTV", 0, true, 0.0, true, 1.0);
|
||||
g_hCVar_MaxPlayers = CreateConVar("sm_nosteamplayercount_maxplayers", "64", "Max Players to display in the sv browser", 0, true, 1.0, true, 128.0);
|
||||
|
||||
g_hCVar_MaxPlayers.AddChangeHook(OnConVarChanged);
|
||||
|
||||
AutoExecConfig(true, "plugin.NoSteamPlayerCount");
|
||||
|
||||
RegAdminCmd("sm_addfake", Command_AddFake, ADMFLAG_ROOT, "");
|
||||
RegAdminCmd("sm_removefake", Command_RemoveFake, ADMFLAG_ROOT, "");
|
||||
RegAdminCmd("sm_countfakes", Command_CountFakes, ADMFLAG_BAN, "");
|
||||
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(IsValidClient(client) && IsClientAuthorized(client))
|
||||
OnClientAuthorized(client, "");
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnPluginEnd()
|
||||
{
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(IsValidClient(client))
|
||||
OnClientDisconnect(client);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
|
||||
{
|
||||
if(convar == g_hCVar_MaxPlayers)
|
||||
g_MaxPlayers = g_hCVar_MaxPlayers.IntValue;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Command_AddFake(int client, int argc)
|
||||
{
|
||||
SteamWorks_CreateFake("Kaitou Sinbad");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Command_RemoveFake(int client, int argc)
|
||||
{
|
||||
SteamWorks_KickFake();
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Command_CountFakes(int client, int argc)
|
||||
{
|
||||
int iFakes = SteamWorks_CountFakes();
|
||||
ReplyToCommand(client, "There are currently %d Fake Clients active.", iFakes);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientAuthorized(int client, const char[] auth)
|
||||
{
|
||||
if (IsClientSourceTV(client) && (!GetConVarBool(g_hCVar_SourceTV)))
|
||||
return;
|
||||
|
||||
if (IsFakeClient(client) && (!GetConVarBool(g_hCVar_FakeClients)))
|
||||
return;
|
||||
|
||||
char sSteamID[32];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
|
||||
|
||||
char sName[128];
|
||||
GetClientName(client, sName, sizeof(sName));
|
||||
|
||||
if(!SteamClientAuthenticated(sSteamID))
|
||||
{
|
||||
int iFakeID = SteamWorks_CreateFake(sName);
|
||||
g_bHasFakeClient[client] = true;
|
||||
LogMessage("\"%L\" connected as NoSteam. Fake Client with ID: \"%d\" got created.", client, iFakeID);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
if (!g_bHasFakeClient[client])
|
||||
return;
|
||||
|
||||
SteamWorks_KickFake();
|
||||
g_bHasFakeClient[client] = false;
|
||||
LogMessage("\"%L\" left as NoSteam. Fake Client got removed.", client);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public bool IsValidClient(int client)
|
||||
{
|
||||
if (client <= 0)
|
||||
return false;
|
||||
|
||||
if (client > GetMaxClients())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user