AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optimize and Improve the Code (https://forums.alliedmods.net/showthread.php?t=113697)

JuanCruz.- 12-29-2009 11:06

Optimize and Improve the Code
 
Optimize and Improve the Code.

Aid is saving accounts ammo packs, and I need to stay put rather well to the server.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fvault>
#include <nvault>
#include <zombieplague>
#include <regex>

#define PLUGIN "[ZP] GUARDADO DE CUENTAS"
#define VERSION "1.0"
#define AUTHOR "..."
#define is_valid_player(%1) (1 <= %1 <= 32)
#define VAULTNAME "zp_ammopacks"

new const g_guardar[] = "[REGISTRO]"
new Textcvar_password_prefijoboolg_registrado[33]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /registrarse""menu")
    
register_clcmd("say registrarse""menu")
    
register_clcmd("say_team /registrarse""menu")
    
register_clcmd("say_team registrarse""menu")
    
register_clcmd("ingresar_password""filtro_cuenta")
    
cvar_password_prefijo register_cvar("zp_password_prefijo""_pass")
    
Text get_user_msgid("SayText")
}

public 
menu(id)
{
    if (!
g_registrado[id])
    {
        new 
reg menu_create("\yMenu de Registro^n^n- Guardado de Cuantas [ZP]^n^n""abrir_menu")
        
        
menu_additem(reg"\wRegistrar Cuenta""1"0)
        
menu_additem(reg"\wNo Registrar Cuenta""2"0)
       
        
menu_setprop(regMPROP_EXITNAME"\wSalir.")
        
menu_display(idreg0)
        
        return 
PLUGIN_HANDLED
    
}
    else
    {
        
client_print(idprint_center"[ZP] Ya estas registrado")
    }
    
    return 
PLUGIN_HANDLED
}

public 
abrir_menu(idregitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(reg)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], iName[64]
    new 
accesscallback
    menu_item_getinfo
(regitemaccessdata,5iName63callback)
    switch (
str_to_num(data))
    {
        case 
1:
        {
            
registrar(id)
            
g_registrado[id] = true
        
}
        case 
2:
        {
            
menu_destroy(reg)
        }
    }
    
    
menu_destroy(reg)
    return 
PLUGIN_HANDLED
}

public 
filtro_cuenta(id)
{
    new 
say[300]
    
read_args(saycharsmax(say))
    
    
remove_quotes(say), trim(say)
    
    if(
equal(say""))
        return 
PLUGIN_HANDLED
        
    
if(contain(say" ") != -1)
    {
        
client_print(idprint_chat"[ZP] Password con ESPACIOS, pueden llegar a perder datos")
            return 
PLUGIN_HANDLED
    
}
    
    
crear_cuenta(idsay)
    
    return 
PLUGIN_CONTINUE
}

crear_cuenta(idsay[])
{
    new 
password[32]
    
copy(passwordcharsmax(password), say)
    
    new 
data[64], name[32], prefijo[8]
    
    
get_user_name(idnamecharsmax(name))
    
get_pcvar_string(cvar_password_prefijoprefijocharsmax(prefijo))
    
client_cmd(id"setinfo %s %s"prefijopassword)
    
    
formatex(datacharsmax(data), "%s"password)
    
    
fvault_set_data(g_guardarnamedata)
    
ColorPrint(id"/v[ZP] /nHas sido registrado!. Nick: /t%s - setinfo _pass: /t%s"namepassword)
    
    
g_registrado[id] = true
}

public 
registrar(id)
{
    switch(
load_ammopacks(id))
    {
        case 
1:
        {
            
g_registrado[id] = true
            
            ColorPrint
(id"[ZP] Este nick ya posee una cuenta")
                return 
PLUGIN_HANDLED
        
}
        case 
2:
        {
            
g_registrado[id] = true
            
            ColorPrint
(id"[ZP] Ya estas logueado")
                return 
PLUGIN_HANDLED
        
}
    }
    
    
client_cmd(id"messagemode Ingresar_Password")
    return 
PLUGIN_HANDLED
}

public 
client_connect(id)
{
    
g_registrado[id] = false
    load_ammopacks
(id)
}

public 
client_infochanged(id)
{
    new 
oldname[32], newname[32]
    
get_user_name(idoldname31)
    
get_user_info(id"name"newname31)
    
    if( !
equal(oldnamenewname) )
        
check_user_name(idnewname)
}

stock check_user_name(id, const name[32] = "")
{
    new 
plrname[32]
    
    if(
equal(name""))
    {
        
get_user_name(idplrname31)
    }
    else
    {
        
plrname name
    
}
    
    
load_ammopacks(id)
}

public 
task_ammopacks(taskid)
{
    
load_ammopacks(taskid)
}

load_ammopacks(id)
{
    new 
data[64], name[32], password[32], password_en_archivo[32], ap[8]
    
    
get_datos(idnamepassword)
    
    if(!
fvault_get_data(g_guardarnamedatacharsmax(data)))
    {   
        return 
0
    
}
    
parse(datapassword_en_archivocharsmax(password_en_archivo), apcharsmax(ap))
    
    if(
equali(password_en_archivopassword))
    {
        
g_registrado[id] = true
        client_print
(idprint_console"* [ZP] Contrasenia Aceptada")
        return 
2
    
}
    else
    {
        
g_registrado[id] = false
        
        
new lReason[64]
        
        
server_cmd("kick #%d ^"Contrasenia Incorrecta.^""get_user_userid(id), lReason)
        
client_print(idprint_console"* [ZP] Contrasenia Incorrecta")
    }
    
    return 
1
}

get_datos(idname[32], password[32])
{
    new 
prefijo[8]
    
    
get_user_name(idnamecharsmax(name))
    
    
get_pcvar_string(cvar_password_prefijoprefijocharsmax(prefijo))
    
    
get_user_info(idprefijopasswordcharsmax(password))
}

stock ColorPrint(const id, const input[], any:...)
{
    new 
count 1players[32]
    
    static 
msg[191]
    
vformat(msgcharsmax(msg), input3)
    
    
replace_all(msg190"/v""^4"// texto verde
    
replace_all(msg190"/n""^1"// texto naranja
    
replace_all(msg190"/t""^3"// texto team
    
replace_all(msg190"/c""^0"// ""      ""
    
    
if(idplayers[0] = id
    
else get_players(playerscount"ch")
    
    for (new 
0counti++)
    {
        if (
is_user_connected(players[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEText_players[i])
            
write_byte(players[i])
            
write_string(msg)
            
message_end()
        }
    }
}

public 
client_disconnect(id)
{
    new 
g_vault nvault_open(VAULTNAME
    
    if(
g_vault == INVALID_HANDLE
        
set_fail_state("Vault returned Invalid Handle")
    
    new 
szKey[62], szValue[10], szName[32]
    
    
get_user_name(idszName31)
    
    
format(szKey61,"%sAP"szName)  
    
    
format(szValue9,"%i",zp_get_user_ammo_packs(id))
    
    
nvault_set(g_vaultszKeyszValue)
    
    
nvault_close(g_vault)
    
    return 
PLUGIN_CONTINUE
}

public 
client_putinserver(id)
{
    
set_task(5.0,"cmdLoad",id)
}

public 
cmdLoad(id)
{
    new 
g_vault nvault_open(VAULTNAME)
    
    if(
g_vault == INVALID_HANDLE)
        
set_fail_state("Vault returned Invalid Handle")
    
    new 
szKey[100], szName[32]
    
    
get_user_name(idszName31)
    
    
format(szKey99,"%sAP"szName)  
    
    new 
iAp nvault_get(g_vaultszKey)
    
    if(
iAp)
    {
        
zp_set_user_ammo_packs(id iAp)
        
client_print(id,print_chat,"[ZP] Login Exitoso.")
        
client_print(id,print_chat,"[ZP] Recuerda antes de entrar al server poner en consola: [ setinfo _pass password ].")
        
client_print(id,print_chat,"[ZP] Recuerda que tu nick no deve tener espacios para que se guarden tus datos.")
        
nvault_remove(g_vault szKey)
    }
    
    
nvault_close(g_vault)
    
    return 
PLUGIN_CONTINUE;
    



Arkshine 12-29-2009 11:20

Re: Optimize and Improve the Code
 
I don't see no major optimization to do.

[M]istics 12-29-2009 18:27

Re: Optimize and Improve the Code
 
this code okay?

AfteR. 12-30-2009 09:40

Re: Optimize and Improve the Code
 
Why

#include <fvault>
#include <nvault>

I think you should only use one.

DruGzOG 12-30-2009 13:18

Re: Optimize and Improve the Code
 
Quote:

Originally Posted by AfteR. (Post 1036420)
Why

#include <fvault>
#include <nvault>

I think you should only use one.

I think they should get banned for non-steam.

matsi 12-30-2009 20:39

Re: Optimize and Improve the Code
 
I don't really understand the last two post since they were already banned. :)

AppStore 12-31-2009 08:20

Re: Optimize and Improve the Code
 
The code is fine, but that's not the best way to save ammo packs

DruGzOG 01-01-2010 18:38

Re: Optimize and Improve the Code
 
He got banned cuz of mah fun way of finding these crabs.

YamiKaitou 01-01-2010 18:47

Re: Optimize and Improve the Code
 
Quote:

Originally Posted by DruGzOG (Post 1039447)
He got banned cuz of mah fun way of finding these crabs.

Actually, they were ban evading from an ES ban


All times are GMT -4. The time now is 04:12.

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