Raised This Month: $32 Target: $400
 8% 

Action: running multiple times despite returning Plugin_Handled


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
aurens
Junior Member
Join Date: Feb 2010
Old 03-08-2010 , 07:57   Action: running multiple times despite returning Plugin_Handled
Reply With Quote #1

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_RegisterCommandg_RegisterCommand64);    
    if (
strcmp(g_RegisterCommand,"DISABLE",false) == 0)
        {}
    else
        
RegConsoleCmd(g_RegisterCommandCommand_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;

aurens is offline
aurens
Junior Member
Join Date: Feb 2010
Old 03-09-2010 , 14:53   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #2

Simply switching all my Plugin_Handleds to Plugin_Stops fixed the issues. Not sure why that wasn't the first thing I tried. Still a bit hazy on what exactly the difference is though.
aurens is offline
retsam
Veteran Member
Join Date: Aug 2008
Location: so-cal
Old 03-09-2010 , 18:05   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #3

Ya, cause youre returning plugin_stop, so it stops all other stuff. That isnt fixing your problem, its just making it so you cant see the problem now heh. Its supposed to be return handled for commands.


Anyways, I think this is your problem.......


Code:
public OnConfigsExecuted()
{    

    .
    .
    .
    
    GetConVarString(g_Cvar_RegisterCommand, g_RegisterCommand, 64);    
    if (strcmp(g_RegisterCommand,"DISABLE",false) == 0)
        {}
    else
        RegConsoleCmd(g_RegisterCommand, Command_Register);

    .
    .
    .
}
Look at what is happening there. I didnt look at it in detail, but your reging a console command in onconfigsexecuted. If its working the way I think, thats going to reg the console command every time the map changes. So if it changes twice, it will duplicate output twice, changes 3 times, three outputs, etc.....

I think that might be your issue, but I could be wrong.

Last edited by retsam; 03-09-2010 at 18:15.
retsam is offline
aurens
Junior Member
Join Date: Feb 2010
Old 03-09-2010 , 21:32   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #4

Well then where should I RegConsoleCmd? It's set in the cfg so it has to be in or after OnConfigsExecuted. I thought putting it in OnConfigsExecuted was fine because when the map ends, the plugins would be unloaded and thus the console command will be unregistered.
aurens is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 03-09-2010 , 22:34   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #5

Quote:
Originally Posted by aurens View Post
Well then where should I RegConsoleCmd? It's set in the cfg so it has to be in or after OnConfigsExecuted. I thought putting it in OnConfigsExecuted was fine because when the map ends, the plugins would be unloaded and thus the console command will be unregistered.

Use RegConsoleCmd in OnPluginStart()
Afronanny is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 03-09-2010 , 23:08   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #6

Quote:
Originally Posted by Afronanny View Post
Use RegConsoleCmd in OnPluginStart()
He can't. He bases the command name off a cvar set right before OnConfigsExecuted.

Once a command is registered, it is never unregistered. Furthermore, plugins aren't unloaded when the map changes, unless the binary has been changed during runtime.

You need to create a global cvar and check it like so:

Code:
new bool:g_bCommandCreated = false;
public OnConfigsExecuted()
{
    if (!_bCommandCreated)
    {
        RegConsoleCmd(...);
        g_bCommandCreated = true;
    }
}
__________________
Greyscale is offline
Cooltad
Veteran Member
Join Date: Apr 2008
Old 03-10-2010 , 06:57   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #7

What about Plugin_Changed?
__________________
Please, give me some rep if you found what I posted useful. :]
Cooltad is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 03-10-2010 , 21:14   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #8

Quote:
Originally Posted by Cooltad View Post
What about Plugin_Changed?
Plugin_Changed is to be used when you change the values of an event in the callback AFAIK
Afronanny is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 03-11-2010 , 04:09   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #9

Quote:
Originally Posted by Afronanny View Post
Plugin_Changed is to be used when you change the values of an event in the callback AFAIK
Plugin_Changed it is not a documented return value in SM and do the same thing as Plugin_Handled. The only place where it can be used is in the SDKHooks extension.
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-11-2010 , 05:22   Re: Action: running multiple times despite returning Plugin_Handled
Reply With Quote #10

It is a documented return, it's just very sparsely used. (I think the only info on it is in SM's source code, along with it's corresponding entry in an include file).
Most of the older/original forwards are coded to handle changes upon the return of Plugin_Handled as well, IIRC.
__________________
asherkin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode