Raised This Month: $ Target: $400
 0% 

plugin improvement - anti name flood


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 02-02-2009 , 14:01   plugin improvement - anti name flood
Reply With Quote #1

I made this plugin because i didn't find one that suits my needs.

Functionality:

-scans for name change & it increments the counter (ct)
-when ct reaches 3 within 20s form the first change it displays a message
-when ct reaches 4 within 20s from the first change it kicks the player

Although it works, it seems that the print_chat message & the default game message "x changed name to y" appear with a small time delay on my machine.

I would like to know if there are any performance changes that can be made.
I'm still in the process of learning so i may induced some cpu intensive or inefficient code.

Thank you.
Attached Files
File Type: sma Get Plugin or Get Source (name_flood.sma - 949 views - 1.4 KB)
__________________

Last edited by ehha; 02-03-2009 at 19:01.
ehha is offline
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 02-16-2009 , 19:20   Re: plugin improvement - anti name flood
Reply With Quote #2

Bump!
So i made no mistakes? Nothing to improve? Just tell me and I'll move along
__________________
ehha is offline
Speed!
BANNED
Join Date: Jan 2009
Old 02-16-2009 , 19:58   Re: plugin improvement - anti name flood
Reply With Quote #3

Quote:
Originally Posted by ehha View Post
Bump!
So i made no mistakes? Nothing to improve? Just tell me and I'll move along
rewrote for you
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "name flood"
#define VERSION "0.1"
#define AUTHOR "camper"
#define ID_FLOOD (taskid - TASK_FLOOD)
//#pragma semicolon 1 useless :(

enum (+= 100)
{
    
TASK_FLOOD
}

new 
ct[33], nft;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
nft register_cvar("amx_name_flood_time""20");
}

public 
client_putinserver(id)
{
    
set_task(nft"decrease_flood"id+TASK_FLOOD)
    
ct[id] = 0;
}

public 
decrease_flood(taskid)
{
    if (
ct[ID_FLOOD] > 0)
        
ct[ID_FLOOD]  -= 1
    set_task
(nft"decrease_flood"ID_FLOOD+TASK_FLOOD)
}

public 
client_disconnect(id)
{
    
remove_task(id+TASK_FLOOD)
}

public 
client_infochanged(id)
{
    new 
newname[32], oldname[32];
    
get_user_info(id"name"newname,31);
    
get_user_name(idoldname31);
        
    if(
equal(newnameoldname))
        return 
PLUGIN_HANDLED;
    
    
ct[id]++
    switch (
ct[id])
    {
        case 
3:
        {
            
client_print(idprint_chat"*** Nick change flood! Stop or you will be kicked! ***");
            
client_print(idprint_chat"*** Nick change flood! Stop or you will be kicked! ***");
        }
        case 
4:
        {
            
server_cmd("kick #%d ^"%s^""get_user_userid(id), "Kicked due to name change flood.");
            return 
PLUGIN_HANDLED
        
}
    }
    return 
PLUGIN_HANDLED

look at the changes, how simple is now, and how better (using tasks for decreasing flood count, and removing them.)
Speed! is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-16-2009 , 20:49   Re: plugin improvement - anti name flood
Reply With Quote #4

@Speed!

PHP Code:
set_task(nft"decrease_flood"id+TASK_FLOOD
ntf is a cvar pointer not a floating point number, you can't use it there.
fysiks is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 02-16-2009 , 20:53   Re: plugin improvement - anti name flood
Reply With Quote #5

Code:
set_task(float(get_pcvar_num(nft)), "decrease_flood", id + TASK_FLOOD)
Spunky is offline
Send a message via AIM to Spunky
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-16-2009 , 21:05   Re: plugin improvement - anti name flood
Reply With Quote #6

You can use get_pcvar_float(nft)
fysiks is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 02-17-2009 , 01:33   Re: plugin improvement - anti name flood
Reply With Quote #7

Whoa, I didn't know you can use 'goto' in Pawn. Ethier way, don't use tasks.
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "name flood" #define VERSION "0.1" #define AUTHOR "camper" new ct[33] new Float:g_LastTime[33] new nft public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     nft = register_cvar("amx_name_flood_time", "20"); } public client_putinserver(id) {     ct[id]=0;     g_LastTime[id] = 0.0 } public client_infochanged(id) {     static sNewName[33],sOldName[33]     get_user_info(id,"name",sNewName,32)     get_user_name(id,sOldName,32);             if(equal(sNewName,sOldName))         return PLUGIN_HANDLED;         new Float:Time = get_gametime();     switch(++ct[id])     {         case 3:         {             if(Time - g_LastTime[id] <= get_pcvar_float(nft))             {                 client_print(id, print_chat, "*** Nick change flood! Stop or you will be kicked! ***");                 client_print(id, print_chat, "*** Nick change flood! Stop or you will be kicked! ***");             }         }         case 4:         {             if(Time - g_LastTime[id] <= get_pcvar_float(nft))             {                 server_cmd("kick #%d ^"%s^"", get_user_userid(id), "Kicked due to name change flood.");                 ct[id] = 0             }         }     }     g_LastTime[id] = Time     return PLUGIN_CONTINUE }
__________________
Oh yeah

Last edited by Drak; 02-17-2009 at 19:02.
Drak is offline
Send a message via MSN to Drak
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 02-17-2009 , 09:15   Re: plugin improvement - anti name flood
Reply With Quote #8

@Drak: I don't know why i didn't use a switch & nice job incrementing the counter in the switch condition

Thank you all.
__________________
ehha is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 02-17-2009 , 12:46   Re: plugin improvement - anti name flood
Reply With Quote #9

Oops, you might want to move "g_LastTime[id] = Time" AFTER the switch.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 02-17-2009 , 17:53   Re: plugin improvement - anti name flood
Reply With Quote #10

I might? I must , perhaps you might want to edit the post if somebody (inexperienced) wants to use this.
__________________
ehha is offline
Reply


Thread Tools
Display Modes

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 01:38.


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