AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   few things about saving nicks(really important to me) (https://forums.alliedmods.net/showthread.php?t=55887)

Voi 06-01-2007 10:28

few things about saving nicks(really important to me)
 
in client_connect i want to grab that players nick, store it(only to memory), and when he connects again check if the same nick is stored, if yes - count to 4 more attempts and then ban(5 minutes), on each round start delete all the nicks stored

i really need this, pls help me guys

Sylwester 06-01-2007 11:14

Re: few things about saving nicks(really important to me)
 
I really dunno why do you need this, but anyway here is code of this simple plugin:

PHP Code:

#include <amxmodx>

#define MAX_NAMES 100
#define MAX_ATTEMPTS 4

new g_stored_names[MAX_NAMES+1][33]
new 
g_attempts[MAX_NAMES+1]
new 
g_last_name_pos 0  //indicates "last used cell" in g_stored_names array

public plugin_init(){
    
register_plugin"BanOn5thAttempt""1.0""Sylwester" )
    
register_logevent("logevent_round_start"2"1=Round_Start")
}

public 
logevent_round_start(){
    
g_last_name_pos 0  //no names stored in array
}

public 
check_name(id){
    new 
name[33]
    
get_user_name(idname32)
    for(new 
i=1i<=g_last_name_posi++){  //search g_stored_names array for specified name (if any stored)
        
if(equal(g_stored_names[i], name)){
            
g_attempts[i] += 1  //name has been found, increase amount of attempts for player with this name by 1
            
if(g_attempts[i] > MAX_ATTEMPTS){  //check if player exceeded the limit
                
g_attempts[i] = 0  //reset amount of attempts, so another player with same name will not be banned instantly

                // insert ban code here
                // ban player with id "id"
            
}
            return 
PLUGIN_CONTINUE
        
}
    }

    if(
g_last_name_pos >= MAX_NAMES)
        return 
PLUGIN_CONTINUE  //don't store any more names if reached the limit

    
g_last_name_pos += 1  //set "last used cell" to "first empty cell"
    
copy(g_stored_names[g_last_name_pos], 32name)  //store player name in "first empty cell"
    
g_attempts[g_last_name_pos] = 1
    
    
return PLUGIN_CONTINUE
}

public 
client_connect(id){
    
check_name(id);



Voi 06-01-2007 11:21

Re: few things about saving nicks(really important to me)
 
thx a lot, ive needed this couse ppl are just bashing with connects to get to my server

Alka 06-01-2007 14:36

Re: few things about saving nicks(really important to me)
 
I tested this and not working:| !...hum...
*I see you check if name was on server,but i don't see where you store the name..:/

_Master_ 06-01-2007 14:59

Re: few things about saving nicks(really important to me)
 
You do g_last_name_pos = 0 in logevent_round_start() but then you do this
Code:

for(new i=1; i<=g_last_name_pos; i++){
You get the idea... will NEVER execute that branch.

Alka 06-01-2007 15:05

Re: few things about saving nicks(really important to me)
 
yeah.... i<0 :|...how should i make?:D

Sylwester 06-01-2007 15:26

Re: few things about saving nicks(really important to me)
 
I coded this in like 10 minutes and then checked with bots and it worked.
All names are stored in g_stored_names[MAX_NAMES+1][33] array (isn't it obvious? - look at name), lines:
Code:
g_last_name_pos += 1 copy(g_stored_names[g_last_name_pos], 32, name)
@_Master_:
You should analyze whole algorithm... I set g_last_name_pos = 0 in logevent_round_start() to reset names (g_last_name_pos==0 means no names stored). "for" loop is for linear search in g_stored_names array. If there are no names stored then it shouldnt start any search, instead it will store player name in first empty cell in g_stored_names array. On next connection attempts g_last_name_pos will be >=1, so it will start the search...

Alka 06-01-2007 15:57

Re: few things about saving nicks(really important to me)
 
hum...i tested my self,with server empty...that should be the problem! :)


All times are GMT -4. The time now is 10:31.

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