My plugin allows clients on a TF2 server to type a command in their console to have their steamID added to a text file on the server. Then admins can run an sm_pubkick command and it will kick the player with the lowest score not registered in this file. I have it check the player's steamID against the text file when they connect and it stores their status as a bool to a global array. This all works fine.
I have another global bool array counting how many times each player has tried to register this session. After they try 21 times, it kicks them. This is so they can't lag the server by spamming registration attempts. But sometimes it increments the registration attempts counter multiple times when the player only types it once, even though I have return Plugin_Handled; immediately following where it tells them they are already registered. As best as I can tell, it repeats the action as many times as however many maps the player has played since they first tried to register.
Here's the console output for a client attempting to register multiple times. Note the repetition of
Code:
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
following only a single execution of REGISTERCOMMAND and note the map changes at the end of the blocks of register attempts. Each repetition does increase the registration attempt timer. So when it says 'already registered blah blah' five times in a row, it thinks they tried to register five times.
Code:
A connected
Redownloading all lightmaps
High Interp
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
.
.
.
16 more attempts
.
.
.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
A : !map cp_badlands
[SM] Changing map to cp_badlands...
Team Fortress
Map: cp_badlands
Players: 2 / 25
Build: 4127
Server Number: 2
Got pure server whitelist: sv_pure = 1.
A connected
Redownloading all lightmaps
High Interp
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
.
.
.
6 more attempts
.
.
.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[SM] Next Map: cp_gravelpit
A : nextmap
A : !map cp_badlands
[SM] Changing map to cp_badlands...
Team Fortress
Map: cp_badlands
Players: 2 / 25
Build: 4127
Server Number: 3
Got pure server whitelist: sv_pure = 1.
A connected
Redownloading all lightmaps
High Interp
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
.
.
.
3 more attempts
.
.
.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] sm_map cp_badlands
[SM] Changing map to cp_badlands...
Team Fortress
Map: cp_badlands
Players: 2 / 25
Build: 4127
Server Number: 4
Got pure server whitelist: sv_pure = 1.
A connected
Redownloading all lightmaps
High Interp
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
.
.
.
3 more attempts
.
.
.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] sm_map cp_badlands
[SM] Changing map to cp_badlands...
Team Fortress
Map: cp_badlands
Players: 2 / 25
Build: 4127
Server Number: 5
Got pure server whitelist: sv_pure = 1.
A connected
Redownloading all lightmaps
High Interp
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] retry
Commencing connection retry to 67.202.71.169:27015
Connecting to 67.202.71.169:27015...
Connected to 67.202.71.169:27015
Team Fortress
Map: cp_badlands
Players: 2 / 25
Build: 4127
Server Number: 5
Got pure server whitelist: sv_pure = 1.
A connected
Redownloading all lightmaps
High Interp
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
[PK] STEAM_ID already registered.
[PK] Try reconnecting if it's not working.
[PK] Test with command pubkick_registered in console.
] REGISTERCOMMAND
Disconnect: [PK] Tried to register too many times this session.
Disconnect: [PK] Tried to register too many times this session.
Here is the relevant code (public Action:Command_Register(client,args) being where the action happens):
PHP Code:
#include <sourcemod>
#include <tf2_stocks>
#pragma semicolon 1
public Plugin:myinfo =
{
name = "Pub Kicker",
author = "aurens",
description = "Automatically kicks worst pub",
version = SOURCEMOD_VERSION,
url = "http://www.endoftheinter.net/"
};
new Handle:g_Cvar_RegisterCommand = INVALID_HANDLE;
/*
Other CVar handle declarations
*/
new bool:g_IsMember[MAXPLAYERS+1] = {true, ...};
new g_RegisterThisSession[MAXPLAYERS+1] = {0, ...};
/*
Other global declarations
*/
new String:g_RegisterCommand[32] = "pkregister";
/*
Other CVar globals default declarations
*/
public OnPluginStart()
{
g_Cvar_RegisterCommand = CreateConVar("sm_pubkick_registercommand", "pkregister", "Command for clients to enter in console to register as member. (set to DISABLE to disable)");
RegConsoleCmd("pubkick_registered", Command_RegisterCheck);
RegConsoleCmd("sm_pubkick_registered", Command_RegisterCheck);
/*
Other CreateConVars, RegAdminCmds for admin commands, etc.
*/
}
.
.
.
public OnConfigsExecuted()
{
.
.
.
GetConVarString(g_Cvar_RegisterCommand, g_RegisterCommand, 64);
if (strcmp(g_RegisterCommand,"DISABLE",false) == 0)
{}
else
RegConsoleCmd(g_RegisterCommand, Command_Register);
.
.
.
}
.
.
.
public OnClientConnected(client)
{
g_NumPlayers++;
g_RegisterThisSession[client] = 0;
return;
}
.
.
.
public OnClientDisconnect(client)
{
g_IsMember[client] = true;
g_RegisterThisSession[client] = 0;
g_NumPlayers--;
return;
}
.
.
.
//called when a client uses the register command in console
public Action:Command_Register(client,args)
{
decl String:buffer[64];
decl String:name[64];
decl String:time[64];
time[0] = '\0';
name[0] = '\0';
buffer[0] = '\0';
decl String:auth[32];
auth[0] = '\0';
if (IsClientAuthorized(client))
GetClientAuthString(client,auth,32);
else
{
ReplyToCommand(client,"[PK] STEAM_ID not yet authorized. Try reconnecting or just wait and try again.");
return Plugin_Handled;
}
g_RegisterThisSession[client]++;
if (g_RegisterThisSession[client] > 20)
{
KickClient(client,"[PK] Tried to register too many times this session");
return Plugin_Handled;
}
if (g_RegisterThisSession[client] > 2)
{
ReplyToCommand(client,"[PK] STEAM_ID already registered.");
ReplyToCommand(client,"[PK] Try reconnecting if it's not working.");
ReplyToCommand(client,"[PK] Test with command pubkick_registered in console.");
return Plugin_Handled;
}
if (g_IsMember[client])
{
ReplyToCommand(client,"[PK] STEAM_ID already registered.");
ReplyToCommand(client,"[PK] Try reconnecting if it's not working.");
ReplyToCommand(client,"[PK] Test with command pubkick_registered in console.");
return Plugin_Handled;
}
new Handle:members = OpenFile(g_MembersFile, "a+");
if (members != INVALID_HANDLE)
{
/*
Write steamID to membersFile and set g_IsMember[client] = true
*/
CloseHandle(members);
}
return Plugin_Handled;
}