Senior Member
Join Date: Nov 2011
Location: Granada, Andalucia, Spai
|
02-04-2012
, 01:39
[ZP] Guardado MySQL
|
#1
|
Decidme pues cual de los dos guardados es mejor ?
Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <zombieplague>
#define PLUGIN "Sistema De Registro"
#define VERSION "1.0"
#define AUTHOR "Sambuseti"
#define LOGIN_FULL 3
//Variables Info
new g_login[33]
new g_personaje_nombre[33][6][33]
new g_personaje[33]
new cuenta[33][33]
new password[33][33]
new g_date[33][33]
//Variables (Común)
new g_nivel[33]
new g_reset[33]
new g_ammopacks[33]
new g_playername[33][32]
new g_MsgSync
/*================================================================================
[MYSQL]
=================================================================================*/
new Handle:g_hTuple
new ErrorCode
new g_Error[514]
// MYSQL
#define MYSQL_HOST "127.0.0.1"
#define MYSQL_USER "root"
#define MYSQL_PASS ""
#define MYSQL_DB "DataBase"
const KEYSMENU = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
//Comandos
register_clcmd("Crear_Cuenta", "filtro_crear_cuenta")
register_clcmd("Crear_Contrasenia", "filtro_crear_contrasenia")
register_clcmd("Verificar_Contrasenia", "filtro_crear_contrasenia_v")
register_clcmd("Verifica_Contrasenia", "filtro_cambiar_contrasenia_v")
register_clcmd("Cuenta", "filtro_login_cuenta")
register_clcmd("Contrasenia", "filtro_login_contrasenia")
register_clcmd("Cambiar_Contrasenia", "filtro_cambiar_contrasenia")
// Messages Hooks
register_message(get_user_msgid("VGUIMenu"), "Menu_Hook")
register_message(get_user_msgid("ShowMenu"), "Menu_Hook")
register_menu("Cuenta Menu", KEYSMENU, "menu_cuenta")
register_menu("Personajes Menu", KEYSMENU, "menu_personajes")
register_menu("Personaje Crear Menu", KEYSMENU, "menu_personaje_crear")
register_menu("Personaje Load Menu", KEYSMENU, "menu_personaje_load")
// Create the HUD Sync Objects
g_MsgSync = CreateHudSyncObj()
// Iniciar MYSQL
mysql_init()
}
public client_putinserver(id)
{
get_user_name(id, g_playername[id], charsmax(g_playername[]))
replace_all(g_playername[id], charsmax(g_playername), "'", "")
g_nivel[id] = zp_get_use_level(id)
g_reset[id] = zp_get_use_reset(id)
g_ammopacks[id] = zp_get_user_ammo_packs(id)
}
public client_disconnect(id)
{
save(id, 1)
}
// menu cuentas
show_menu_cuenta(id)
{
static menu[250], len
len = 0
// Title
len += formatex(menu[len], sizeof menu - 1 - len, "wBienvenido a rZombie Plague Niveles^n")
len += formatex(menu[len], sizeof menu - 1 - len, "wEstas jugando en el yZP Levels^n")
len += formatex(menu[len], sizeof menu - 1 - len, "wCreado por rSambuseti^n^n")
len += formatex(menu[len], sizeof menu - 1 - len, "r1. wLoguearme^n")
len += formatex(menu[len], sizeof menu - 1 - len, "r2. wCrear yCUENTA^n")
show_menu(id, KEYSMENU, menu, -1, "Cuenta Menu")
}
// menu personajes
show_menu_personajes(id)
{
new nivel[33][5], personaje[33][5]
static menu[500], len
len = 0
if(!equal(g_personaje_nombre[id][1], ""))
personaje[id][0] = true
if(!equal(g_personaje_nombre[id][2], ""))
personaje[id][1] = true
if(!equal(g_personaje_nombre[id][3], ""))
personaje[id][2] = true
if(!equal(g_personaje_nombre[id][4], ""))
personaje[id][3] = true
if(!equal(g_personaje_nombre[id][5], ""))
personaje[id][4] = true
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
// Create Handle
new Handle:Query
if(personaje[id][0] || personaje[id][1] || personaje[id][2] || personaje[id][3] || personaje[id][4])
{
for (new i = 0; i < 5; i++)
{
if(personaje[id][i])
{
Query = SQL_PrepareQuery(SqlConnect, "SELECT `nivel` FROM `personajes` WHERE (`nombre` = '%s')", g_personaje_nombre[id][i+1])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
client_print(id, print_center, "Hubo un error en el personaje %s ha sido borrado", g_personaje_nombre[id][i+1])
formatex(g_personaje_nombre[id][i+1], charsmax(g_personaje_nombre), "")
}
else
{
nivel[id][i] = SQL_ReadResult(Query, 0)
}
}
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
}
if(equal(g_date[id], ""))
get_time("%d/%m/%Y", g_date[id],10)
// Title
len += formatex(menu[len], sizeof menu - 1 - len, "yCUENTA: r%s -- wCreada el y%s^n^n", cuenta[id], g_date[id])
if(equal(g_personaje_nombre[id][1], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "r1. wCrear Personaje r(Slot 1)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "r1. w%s y[Nivel: %d]^n^n", g_personaje_nombre[id][1], nivel[id][0])
if(equal(g_personaje_nombre[id][2], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "r2. wCrear Personaje r(Slot 2)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "r2. w%s w[Nivel: %d]^n^n", g_personaje_nombre[id][2], nivel[id][1])
if(equal(g_personaje_nombre[id][3], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "r3. wCrear Personaje r(Slot 3)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "r3. w%s w[Nivel: %d]^n^n", g_personaje_nombre[id][3], nivel[id][2])
if(equal(g_personaje_nombre[id][4], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "r4. wCrear Personaje r(Slot 4)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "r4. w%s y[Nivel: %d]^n^n", g_personaje_nombre[id][4], nivel[id][3])
if(equal(g_personaje_nombre[id][5], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "r5. wCrear Personaje r(Slot 5)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "r5. w%s y[Nivel %d]^n^n", g_personaje_nombre[id][5], nivel[id][4])
len += formatex(menu[len], sizeof menu - 1 - len, "^nr7. wCambiar contraseña^n")
show_menu(id, KEYSMENU, menu, -1, "Personajes Menu")
return PLUGIN_HANDLED
}
// crear personaje
show_menu_personaje_crear(id)
{
static menu[250], len
len = 0
// Title
len += formatex(menu[len], sizeof menu - 1 - len, "wDESEAS CREAR UN PJ CON EL NOMBRE r%s w?^n^n^n", g_playername[id])
len += formatex(menu[len], sizeof menu - 1 - len, "r1. wSi^n")
len += formatex(menu[len], sizeof menu - 1 - len, "r2. wNo^n")
show_menu(id, KEYSMENU, menu, -1, "Personaje Crear Menu")
}
// cargar personaje
show_menu_personaje_load(id)
{
static menu[250], len
len = 0
// Title
len += formatex(menu[len], sizeof menu - 1 - len, "wPersonaje: r%s^n^n", g_personaje_nombre[id][0])
len += formatex(menu[len], sizeof menu - 1 - len, "wEstadisticas^nwNivel: r%d^n^n", g_nivel[id])
len += formatex(menu[len], sizeof menu - 1 - len, "r1. wEntrar^n")
len += formatex(menu[len], sizeof menu - 1 - len, "r9. wBorrar yPersonaje^n")
show_menu(id, KEYSMENU, menu, -1, "Personaje Load Menu")
return PLUGIN_HANDLED
}
public menu_cuenta(id, key)
{
if(key != 0 && key != 1)
{
show_menu_cuenta(id)
return PLUGIN_HANDLED
}
switch (key)
{
case 0: login_cuenta(id)
case 1: crear_cuenta(id)
}
return PLUGIN_HANDLED;
}
public menu_personajes(id, key)
{
if(key == 0 || key == 1 || key == 2 || key == 3 || key == 4)
{
g_personaje[id] = key+1
if(equal(g_personaje_nombre[id][key+1], ""))
show_menu_personaje_crear(id)
else
{
new personaje[33][5]
if(!equal(g_personaje_nombre[id][1], ""))
personaje[id][0] = true
if(!equal(g_personaje_nombre[id][2], ""))
personaje[id][1] = true
if(!equal(g_personaje_nombre[id][3], ""))
personaje[id][2] = true
if(!equal(g_personaje_nombre[id][4], ""))
personaje[id][3] = true
if(!equal(g_personaje_nombre[id][5], ""))
personaje[id][4] = true
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), g_personaje_nombre[id][key+1])
load(id, 1)
}
return PLUGIN_HANDLED
}
if(key == 6)
cambiar_contrasenia(id)
return PLUGIN_HANDLED;
}
public menu_personaje_crear(id, key)
{
if(key == 0)
crear_personaje(id)
else if(key == 1)
show_menu_personajes(id)
return PLUGIN_HANDLED;
}
public menu_personaje_load(id, key)
{
switch(key)
{
case 0:
{
g_login[id] = LOGIN_FULL
client_cmd(id, "chooseteam")
}
case 8:
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect,"DELETE FROM `personajes` WHERE `nombre` = '%s'", g_personaje_nombre[id][0])
if(SQL_Execute(Query))
{
SQL_FreeHandle(SqlConnect)
SQL_FreeHandle(Query)
client_print(id, print_console, "Personaje %s borrado exitosamente", g_personaje_nombre[id][0])
}
else
client_print(id, print_console, "Error al borrar el personaje")
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][g_personaje[id]], charsmax(g_personaje_nombre), "")
save(id, 0)
g_login[id] = 2
show_menu_personajes(id)
}
}
return PLUGIN_HANDLED;
}
public Menu_Hook(iMsgid, iDest, id)
{
if(g_login[id] == 0)
show_menu_cuenta(id)
else if(g_login[id] == 1)
show_menu_personajes(id)
else if(g_login[id] == 2)
show_menu_personaje_load(id)
else if(g_login[id] == LOGIN_FULL)
return PLUGIN_CONTINUE
return PLUGIN_HANDLED
}
public mysql_init()
g_hTuple = SQL_MakeDbTuple(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
public crear_cuenta(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Crear_Cuenta")
mensajes_cuenta(id, 2)
}
public filtro_crear_cuenta(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(cuenta[id], charsmax(cuenta))
// Lo preparamos para analizar
remove_quotes(cuenta[id]), trim(cuenta[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(cuenta[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(cuenta[id], " ") != -1)
{
client_print(id, print_center, "La cuenta debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "SELECT 'cuenta' FROM `cuentas` WHERE (`cuenta` = '%s')", cuenta[id])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
crear_contrasenia(id)
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED;
}
else
{
mensajes_cuenta(id, 1)
client_print(id, print_center, "Esa cuenta ya existe!")
show_menu_cuenta(id)
return PLUGIN_HANDLED;
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_CONTINUE
}
public crear_contrasenia(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Crear_Contrasenia")
mensajes_cuenta(id, 3)
}
public filtro_crear_contrasenia(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(password[id], charsmax(password))
// Lo preparamos para analizar
remove_quotes(password[id]), trim(password[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(password[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
verificar_contrasenia(id)
return PLUGIN_CONTINUE
}
public verificar_contrasenia(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Verificar_Contrasenia")
mensajes_cuenta(id, 4)
}
public filtro_crear_contrasenia_v(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
new password_v[33][33]
// Obtenemos en un string lo que escribio como password
read_args(password_v[id], charsmax(password_v))
// Lo preparamos para analizar
remove_quotes(password_v[id]), trim(password_v[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(password_v[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password_v[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
if(!equal(password[id], password_v[id]))
{
client_print(id, print_center, "Las contraseñas no coinciden")
crear_contrasenia(id)
return PLUGIN_HANDLED
}
get_time("%d/%m/%Y", g_date[id],10)
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "INSERT INTO `cuentas` VALUES ('%s', '%s', '', '', '', '', '', '%s');", cuenta[id], password_v[id], g_date[id])
// Query Execute ?
if (SQL_Execute(Query))
{
g_login[id] = 1
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][1], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][2], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][3], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][4], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][5], charsmax(g_personaje_nombre), "")
client_print(id, print_center, "Has sido registrado!. Cuenta %s - Contraseña %s", cuenta[id], password[id])
client_cmd(id, "chooseteam")
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
}
return PLUGIN_CONTINUE
}
public login_cuenta(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Cuenta")
mensajes_cuenta(id, 2)
}
public filtro_login_cuenta(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(cuenta[id], charsmax(cuenta))
// Lo preparamos para analizar
remove_quotes(cuenta[id]), trim(cuenta[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(cuenta[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(cuenta[id], " ") != -1)
{
client_print(id, print_center, "La cuenta debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
login_contrasenia(id)
return PLUGIN_CONTINUE
}
public login_contrasenia(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Contrasenia")
mensajes_cuenta(id, 3)
}
public filtro_login_contrasenia(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(password[id], charsmax(password))
// Lo preparamos para analizar
remove_quotes(password[id]), trim(password[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(password[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
logear(id)
return PLUGIN_HANDLED
}
public logear(id)
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "SELECT `personaje1`, `personaje2`, `personaje3`, `personaje4`, `personaje5`, `date` FROM `cuentas` WHERE (`cuenta` = '%s' AND `password` = '%s')", cuenta[id], password[id])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
client_print(id, print_center, "Login Erroneo")
show_menu_cuenta(id)
}
else
{
SQL_ReadResult(Query, 0, g_personaje_nombre[id][1], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 1, g_personaje_nombre[id][2], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 2, g_personaje_nombre[id][3], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 3, g_personaje_nombre[id][4], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 4, g_personaje_nombre[id][5], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 5, g_date[id], charsmax(g_date))
g_login[id] = 1
client_cmd(id, "chooseteam")
client_print(id, print_center, "Login Exitoso!")
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
}
}
return PLUGIN_HANDLED
}
public cambiar_contrasenia(id)
{
if(g_login[id] != 1)
return;
client_cmd(id, "messagemode Cambiar_Contrasenia")
mensajes_cuenta(id, 5)
}
public filtro_cambiar_contrasenia(id)
{
if(g_login[id] != 1)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(password[id], charsmax(password))
// Lo preparamos para analizar
remove_quotes(password[id]), trim(password[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(password[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
show_menu_personajes(id)
return PLUGIN_HANDLED
}
cambiar_contrasenia_v(id)
return PLUGIN_CONTINUE
}
public cambiar_contrasenia_v(id)
{
if(g_login[id] != 1)
return;
client_cmd(id, "messagemode Verifica_Contrasenia")
mensajes_cuenta(id, 6)
}
public filtro_cambiar_contrasenia_v(id)
{
if(g_login[id] != 1)
return PLUGIN_HANDLED
new password_v[33][33]
// Obtenemos en un string lo que escribio como password
read_args(password_v[id], charsmax(password_v))
// Lo preparamos para analizar
remove_quotes(password_v[id]), trim(password_v[id])
mensajes_cuenta(id, 1)
show_menu_personajes(id)
// Si solamente apreto enter lo omitiremos
if(equal(password_v[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password_v[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
show_menu_personajes(id)
return PLUGIN_HANDLED
}
if(!equal(password[id], password_v[id]))
{
client_print(id, print_center, "Las contraseñas no coinciden")
show_menu_personajes(id)
return PLUGIN_HANDLED
}
client_print(id, print_center, "Tu contraseña nueva es: %s |- Recomendamos que hagas retry -|", password[id])
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "UPDATE `cuentas` SET `password` = '%s' WHERE `cuenta` = '%s'", password_v[id], cuenta[id])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED;
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_CONTINUE
}
public crear_personaje(id)
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "SELECT 'nombre' FROM `personajes` WHERE (`nombre` = '%s')", g_playername[id])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_MoreResults(Query))
{
Query = SQL_PrepareQuery(SqlConnect, "INSERT INTO `personajes` VALUES ('%s','1','0','0');", g_playername[id])
// Query Execute ?
if (SQL_Execute(Query))
{
g_login[id] = 2
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), g_playername[id])
copy(g_personaje_nombre[id][g_personaje[id]], charsmax(g_personaje_nombre), g_playername[id])
save(id, 0)
client_print(id, print_center, "Personaje %s creado con exito", g_personaje_nombre[id][0])
client_cmd(id, "chooseteam")
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED
}
else
client_print(id, print_center, "Error al crear el personaje")
}
else
{
client_print(id, print_center, "Ese personaje ya existe usa otro nombre!")
show_menu_personajes(id)
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED;
}
public save(id, reset)
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
// Create Handle
new Handle:Query, Handle:Query2
if(g_login[id] > 0)
{
Query = SQL_PrepareQuery(SqlConnect, "UPDATE `cuentas` SET `personaje1` = '%s', `personaje2` = '%s', `personaje3` = '%s', `personaje4` = '%s', `personaje5` = '%s', `date` = '%s' WHERE `cuenta` = '%s' AND `password` = '%s'",
g_personaje_nombre[id][1], g_personaje_nombre[id][2], g_personaje_nombre[id][3], g_personaje_nombre[id][4], g_personaje_nombre[id][5], g_date[id], cuenta[id], password[id])
}
if(g_login[id] > 1)
{
Query2 = SQL_PrepareQuery(SqlConnect, "UPDATE `personajes` SET nivel=%d,ammopacks=%d,resets=%d WHERE `nombre` = '%s'",
g_nivel[id],g_ammopacks[id],g_reset[id],g_personaje_nombre[id][0])
}
if(g_login[id] > 0)
if(SQL_Execute(Query))
SQL_FreeHandle(Query)
if(g_login[id] > 1)
if(SQL_Execute(Query2))
SQL_FreeHandle(Query2)
// Connection Closed
SQL_FreeHandle(SqlConnect)
if(reset == 1)
reset_variables(id, 1)
return PLUGIN_HANDLED
}
public load(id, tipo)
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
// Create Handle
new Handle:Query
if(tipo == 1)
Query = SQL_PrepareQuery(SqlConnect, "SELECT `nivel`,`ammopacks`,`resets` FROM `personajes` WHERE (`nombre` = '%s')", g_personaje_nombre[id][0])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
client_print(id, print_center, "Personaje Erroneo")
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][g_personaje[id]], charsmax(g_personaje_nombre), "")
return PLUGIN_HANDLED
}
else
{
if(tipo == 1)
{
g_nivel[id] = SQL_ReadResult(Query, 0)
g_ammopacks[id] = SQL_ReadResult(Query, 1)
g_reset[id] = SQL_ReadResult(Query, 2)
copy(g_playername[id], charsmax(g_playername), g_personaje_nombre[id][0])
client_cmd(id, "name ^"%s^" ", g_personaje_nombre[id][0])
// Cache player's name
get_user_name(id, g_playername[id], charsmax(g_playername[]))
replace_all(g_playername[id], charsmax(g_playername), "'", "")
g_login[id] = 2
client_print(id, print_center, "Personaje %s Cargado con exito!", g_personaje_nombre[id][0])
client_cmd(id, "chooseteam")
}
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED
}
public mensajes_cuenta(id, mensaje)
{
set_hudmessage(255, 0, 0, 0.01, 0.03, 1, 0.1, 100.0, 0.1, 0.1)
if(mensaje == 1)
ShowSyncHudMsg(id, g_MsgSync, "")
if(mensaje == 2)
ShowSyncHudMsg(id, g_MsgSync, "Ingresa tu cuenta")
if(mensaje == 3)
ShowSyncHudMsg(id, g_MsgSync, "Ingresa tu contraseña")
if(mensaje == 4)
ShowSyncHudMsg(id, g_MsgSync, "Vuelve a ingresar tu contraseña")
if(mensaje == 5)
ShowSyncHudMsg(id, g_MsgSync, "Ingresa tu nueva contraseña")
if(mensaje == 6)
ShowSyncHudMsg(id, g_MsgSync, "Vuelve a ingresar tu nueva contraseña")
client_cmd(id, "spk Ui/buttonclickrelease")
}
public reset_variables(id, reset)
{
if(reset == 1)
{
copy(cuenta[id], charsmax(cuenta), "")
copy(password[id], charsmax(password), "")
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][1], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][2], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][3], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][4], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][5], charsmax(g_personaje_nombre), "")
copy(g_date[id], charsmax(g_date), "")
}
g_login[id] = 0
g_personaje[id] = 0
g_nivel[id] = 1
g_reset[id] = 0
g_ammopacks[id] = 0
}
Code:
/* Plugin generaed by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <zombieplague>
#define PLUGIN "Sistema De Registro Con Slot De Pj"
#define VERSION "1.0"
#define AUTHOR ""
#define LOGIN_FULL 3
//Variables Info
new g_login[33]
new g_personaje_nombre[33][6][33]
new g_personaje[33]
new cuenta[33][33]
new password[33][33]
new g_date[33][33]
//Variables (Común)
new g_nivel[33]
new g_reset[33]
new g_ammopacks[33]
new g_playername[33][32]
new g_MsgSync
/*================================================================================
[MYSQL]
=================================================================================*/
new Handle:g_hTuple
new ErrorCode
new g_Error[514]
// MYSQL
#define MYSQL_HOST "localhost:3306"
#define MYSQL_USER "mysql55"
#define MYSQL_PASS "kill125"
#define MYSQL_DB "databasezp"
const KEYSMENU = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
//Comandos
register_clcmd("Crear_Cuenta", "filtro_crear_cuenta")
register_clcmd("Crear_Contrasenia", "filtro_crear_contrasenia")
register_clcmd("Verificar_Contrasenia", "filtro_crear_contrasenia_v")
register_clcmd("Verifica_Contrasenia", "filtro_cambiar_contrasenia_v")
register_clcmd("Cuenta", "filtro_login_cuenta")
register_clcmd("Contrasenia", "filtro_login_contrasenia")
register_clcmd("Cambiar_Contrasenia", "filtro_cambiar_contrasenia")
// Messages Hooks
register_message(get_user_msgid("VGUIMenu"), "Menu_Hook")
register_message(get_user_msgid("ShowMenu"), "Menu_Hook")
register_menu("Cuenta Menu", KEYSMENU, "menu_cuenta")
register_menu("Personajes Menu", KEYSMENU, "menu_personajes")
register_menu("Personaje Crear Menu", KEYSMENU, "menu_personaje_crear")
register_menu("Personaje Load Menu", KEYSMENU, "menu_personaje_load")
// Create the HUD Sync Objects
g_MsgSync = CreateHudSyncObj()
// Iniciar MYSQL
mysql_init()
}
public client_putinserver(id)
{
get_user_name(id, g_playername[id], charsmax(g_playername[]))
replace_all(g_playername[id], charsmax(g_playername), "'", "")
g_nivel[id] = zp_get_user_level(id)
g_reset[id] = zp_get_user_reset(id)
g_ammopacks[id] = zp_get_user_ammo_packs(id)
}
public client_disconnect(id)
{
save(id, 1)
}
show_menu_cuenta(id)
{
static menu[250], len
len = 0
// Title
len += formatex(menu[len], sizeof menu - 1 - len, "\wBienvenido a \rZombie Plague Niveles^n^n")
len += formatex(menu[len], sizeof menu - 1 - len, "\r1. \wLoguearme^n")
len += formatex(menu[len], sizeof menu - 1 - len, "\r2. \wCrear \yCUENTA^n")
show_menu(id, KEYSMENU, menu, -1, "Cuenta Menu")
}
show_menu_personajes(id)
{
new nivel[33][5], resets[33][5], personaje[33][5]
static menu[500], len
len = 0
if(!equal(g_personaje_nombre[id][1], ""))
personaje[id][0] = true
if(!equal(g_personaje_nombre[id][2], ""))
personaje[id][1] = true
if(!equal(g_personaje_nombre[id][3], ""))
personaje[id][2] = true
if(!equal(g_personaje_nombre[id][4], ""))
personaje[id][3] = true
if(!equal(g_personaje_nombre[id][5], ""))
personaje[id][4] = true
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
if(personaje[id][0] || personaje[id][1] || personaje[id][2] || personaje[id][3] || personaje[id][4])
{
for (new i = 0; i < 5; i++)
{
if(personaje[id][i])
{
Query = SQL_PrepareQuery(SqlConnect, "SELECT `Level`, `Resets` FROM `Personajes` WHERE (`Nombre` = '%s')", g_personaje_nombre[id][i+1])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
client_print(id, print_center, "Hubo un error en el personaje %s ha sido borrado", g_personaje_nombre[id][i+1])
formatex(g_personaje_nombre[id][i+1], charsmax(g_personaje_nombre), "")
}
else
{
nivel[id][i] = SQL_ReadResult(Query, 0)
resets[id][i] = SQL_ReadResult(Query, 1)
}
}
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
}
if(equal(g_date[id], ""))
get_time("%d/%m/%Y", g_date[id],10)
// Title
len += formatex(menu[len], sizeof menu - 1 - len, "\yCUENTA: \r%s -- \wCreada el \y%s^n^n", cuenta[id], g_date[id])
if(equal(g_personaje_nombre[id][1], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "\r1. \wCrear Personaje \r(Slot 1)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r1. \w%s \y[Nivel: %d] \y[Resets: %d]^n^n", g_personaje_nombre[id][1], nivel[id][0], resets[id][0])
if(equal(g_personaje_nombre[id][2], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "\r2. \wCrear Personaje \r(Slot 2)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r2. \w%s \w[Nivel: %d] \w[Resets: %d]^n^n", g_personaje_nombre[id][2], nivel[id][1], resets[id][1])
if(equal(g_personaje_nombre[id][3], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "\r3. \wCrear Personaje \r(Slot 3)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r3. \w%s \w[Nivel: %d] \w[Resets: %d]^n^n", g_personaje_nombre[id][3], nivel[id][2], resets[id][2])
if(equal(g_personaje_nombre[id][4], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "\r4. \wCrear Personaje \r(Slot 4)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r4. \w%s \y[Nivel: %d] \y[Resets: %d]^n^n", g_personaje_nombre[id][4], nivel[id][3], resets[id][3])
if(equal(g_personaje_nombre[id][5], ""))
len += formatex(menu[len], sizeof menu - 1 - len, "\r5. \wCrear Personaje \r(Slot 5)^n^n")
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r5. \w%s \y[Nivel %d] \y[Resets %d]^n^n", g_personaje_nombre[id][5], nivel[id][4], resets[id][4])
len += formatex(menu[len], sizeof menu - 1 - len, "^n\r7. \wCambiar contraseña^n")
show_menu(id, KEYSMENU, menu, -1, "Personajes Menu")
return PLUGIN_HANDLED
}
show_menu_personaje_crear(id)
{
static menu[250], len
len = 0
// Title
len += formatex(menu[len], sizeof menu - 1 - len, "\wDESEAS CREAR UN PJ CON EL NOMBRE \r%s \w?^n^n^n", g_playername[id])
len += formatex(menu[len], sizeof menu - 1 - len, "\r1. \wSi^n")
len += formatex(menu[len], sizeof menu - 1 - len, "\r2. \wNo^n")
show_menu(id, KEYSMENU, menu, -1, "Personaje Crear Menu")
}
show_menu_personaje_load(id)
{
static menu[250], len
len = 0
// Title
len += formatex(menu[len], sizeof menu - 1 - len, "\wPersonaje: \r%s^n^n", g_personaje_nombre[id][0])
len += formatex(menu[len], sizeof menu - 1 - len, "\wEstadisticas^n\wNivel: \r%d^n\wAmmoPacks: \r%d^n\wResets \r%d^n^n", g_nivel[id], g_ammopacks[id], g_reset[id])
len += formatex(menu[len], sizeof menu - 1 - len, "\r1. \wEntrar^n")
len += formatex(menu[len], sizeof menu - 1 - len, "\r9. \wBorrar \yPersonaje^n")
show_menu(id, KEYSMENU, menu, -1, "Personaje Load Menu")
return PLUGIN_HANDLED
}
public menu_cuenta(id, key)
{
if(key != 0 && key != 1)
{
show_menu_cuenta(id)
return PLUGIN_HANDLED
}
switch (key)
{
case 0: login_cuenta(id)
case 1: crear_cuenta(id)
}
return PLUGIN_HANDLED;
}
public menu_personajes(id, key)
{
if(key == 0 || key == 1 || key == 2 || key == 3 || key == 4)
{
g_personaje[id] = key+1
if(equal(g_personaje_nombre[id][key+1], ""))
show_menu_personaje_crear(id)
else
{
new personaje[33][5]
if(!equal(g_personaje_nombre[id][1], ""))
personaje[id][0] = true
if(!equal(g_personaje_nombre[id][2], ""))
personaje[id][1] = true
if(!equal(g_personaje_nombre[id][3], ""))
personaje[id][2] = true
if(!equal(g_personaje_nombre[id][4], ""))
personaje[id][3] = true
if(!equal(g_personaje_nombre[id][5], ""))
personaje[id][4] = true
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), g_personaje_nombre[id][key+1])
load(id, 1)
}
return PLUGIN_HANDLED
}
if(key == 6)
cambiar_contrasenia(id)
return PLUGIN_HANDLED;
}
public menu_personaje_crear(id, key)
{
if(key == 0)
crear_personaje(id)
else if(key == 1)
show_menu_personajes(id)
return PLUGIN_HANDLED;
}
public menu_personaje_load(id, key)
{
switch(key)
{
case 0:
{
g_login[id] = LOGIN_FULL
client_cmd(id, "chooseteam")
}
case 8:
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect,"DELETE FROM `Personajes` WHERE `Nombre` = '%s'", g_personaje_nombre[id][0])
if(SQL_Execute(Query))
{
SQL_FreeHandle(SqlConnect)
SQL_FreeHandle(Query)
client_print(id, print_console, "Personaje %s borrado exitosamente", g_personaje_nombre[id][0])
}
else
client_print(id, print_console, "Error al borrar el personaje")
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][g_personaje[id]], charsmax(g_personaje_nombre), "")
save(id, 0)
g_login[id] = 2
show_menu_personajes(id)
}
}
return PLUGIN_HANDLED;
}
public Menu_Hook(iMsgid, iDest, id)
{
if(g_login[id] == 0)
show_menu_cuenta(id)
else if(g_login[id] == 1)
show_menu_personajes(id)
else if(g_login[id] == 2)
show_menu_personaje_load(id)
else if(g_login[id] == LOGIN_FULL)
return PLUGIN_CONTINUE
return PLUGIN_HANDLED
}
public mysql_init()
g_hTuple = SQL_MakeDbTuple(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
public crear_cuenta(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Crear_Cuenta")
mensajes_cuenta(id, 2)
}
public filtro_crear_cuenta(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(cuenta[id], charsmax(cuenta))
// Lo preparamos para analizar
remove_quotes(cuenta[id]), trim(cuenta[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(cuenta[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(cuenta[id], " ") != -1)
{
client_print(id, print_center, "La cuenta debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "SELECT * FROM `cuentas` WHERE (`Nombre` = '%s')", cuenta[id])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
crear_contrasenia(id)
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED;
}
else
{
mensajes_cuenta(id, 1)
client_print(id, print_center, "Esa cuenta ya existe!")
show_menu_cuenta(id)
return PLUGIN_HANDLED;
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_CONTINUE
}
public crear_contrasenia(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Crear_Contrasenia")
mensajes_cuenta(id, 3)
}
public filtro_crear_contrasenia(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(password[id], charsmax(password))
// Lo preparamos para analizar
remove_quotes(password[id]), trim(password[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(password[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
verificar_contrasenia(id)
return PLUGIN_CONTINUE
}
public verificar_contrasenia(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Verificar_Contrasenia")
mensajes_cuenta(id, 4)
}
public filtro_crear_contrasenia_v(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
new password_v[33][33]
// Obtenemos en un string lo que escribio como password
read_args(password_v[id], charsmax(password_v))
// Lo preparamos para analizar
remove_quotes(password_v[id]), trim(password_v[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(password_v[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password_v[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
if(!equal(password[id], password_v[id]))
{
client_print(id, print_center, "Las contraseñas no coinciden")
crear_contrasenia(id)
return PLUGIN_HANDLED
}
get_time("%d/%m/%Y", g_date[id],10)
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "INSERT INTO `cuentas` VALUES ('%s', '%s', '%s');", cuenta[id], password_v[id], g_date[id])
// Query Execute ?
if (SQL_Execute(Query))
{
g_login[id] = 1
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][1], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][2], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][3], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][4], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][5], charsmax(g_personaje_nombre), "")
client_print(id, print_center, "Has sido registrado!. Cuenta %s - Contraseña %s", cuenta[id], password[id])
client_cmd(id, "chooseteam")
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
}
return PLUGIN_CONTINUE
}
public login_cuenta(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Cuenta")
mensajes_cuenta(id, 2)
}
public filtro_login_cuenta(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(cuenta[id], charsmax(cuenta))
// Lo preparamos para analizar
remove_quotes(cuenta[id]), trim(cuenta[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(cuenta[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(cuenta[id], " ") != -1)
{
client_print(id, print_center, "La cuenta debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
login_contrasenia(id)
return PLUGIN_CONTINUE
}
public login_contrasenia(id)
{
if(g_login[id] != 0)
return;
client_cmd(id, "messagemode Contrasenia")
mensajes_cuenta(id, 3)
}
public filtro_login_contrasenia(id)
{
if(g_login[id] != 0)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(password[id], charsmax(password))
// Lo preparamos para analizar
remove_quotes(password[id]), trim(password[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(password[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
return PLUGIN_HANDLED
}
logear(id)
return PLUGIN_HANDLED
}
public logear(id)
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "SELECT `Personaje1`, `Personaje2`, `Personaje3`, `Personaje4`, `Personaje5`, `Fecha` FROM `cuentas` WHERE (`Nombre` = '%s' AND `Password` = '%s')", cuenta[id], password[id])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
client_print(id, print_center, "Login Erroneo")
show_menu_cuenta(id)
}
else
{
SQL_ReadResult(Query, 0, g_personaje_nombre[id][1], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 1, g_personaje_nombre[id][2], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 2, g_personaje_nombre[id][3], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 3, g_personaje_nombre[id][4], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 4, g_personaje_nombre[id][5], charsmax(g_personaje_nombre))
SQL_ReadResult(Query, 5, g_date[id], charsmax(g_date))
g_login[id] = 1
client_cmd(id, "chooseteam")
client_print(id, print_center, "Login Exitoso!")
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
}
}
return PLUGIN_HANDLED
}
public cambiar_contrasenia(id)
{
if(g_login[id] != 1)
return;
client_cmd(id, "messagemode Cambiar_Contrasenia")
mensajes_cuenta(id, 5)
}
public filtro_cambiar_contrasenia(id)
{
if(g_login[id] != 1)
return PLUGIN_HANDLED
// Obtenemos en un string lo que escribio como password
read_args(password[id], charsmax(password))
// Lo preparamos para analizar
remove_quotes(password[id]), trim(password[id])
mensajes_cuenta(id, 1)
// Si solamente apreto enter lo omitiremos
if(equal(password[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
show_menu_personajes(id)
return PLUGIN_HANDLED
}
cambiar_contrasenia_v(id)
return PLUGIN_CONTINUE
}
public cambiar_contrasenia_v(id)
{
if(g_login[id] != 1)
return;
client_cmd(id, "messagemode Verifica_Contrasenia")
mensajes_cuenta(id, 6)
}
public filtro_cambiar_contrasenia_v(id)
{
if(g_login[id] != 1)
return PLUGIN_HANDLED
new password_v[33][33]
// Obtenemos en un string lo que escribio como password
read_args(password_v[id], charsmax(password_v))
// Lo preparamos para analizar
remove_quotes(password_v[id]), trim(password_v[id])
mensajes_cuenta(id, 1)
show_menu_personajes(id)
// Si solamente apreto enter lo omitiremos
if(equal(password_v[id], ""))
return PLUGIN_HANDLED
// Verificamos que la password solo contenga una palabra
if(contain(password_v[id], " ") != -1)
{
client_print(id, print_center, "La contraseña debe ser 1 (una) palabra")
show_menu_personajes(id)
return PLUGIN_HANDLED
}
if(!equal(password[id], password_v[id]))
{
client_print(id, print_center, "Las contraseñas no coinciden")
show_menu_personajes(id)
return PLUGIN_HANDLED
}
client_print(id, print_center, "Tu contraseña nueva es: %s", password[id])
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "UPDATE `cuentas` SET `Password` = '%s' WHERE `Nombre` = '%s'", password_v[id], cuenta[id])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED;
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_CONTINUE
}
public crear_personaje(id)
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
Query = SQL_PrepareQuery(SqlConnect, "SELECT 'Nombre' FROM `Personajes` WHERE (`nombre` = '%s')", g_playername[id])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_MoreResults(Query))
{
Query = SQL_PrepareQuery(SqlConnect, "INSERT INTO `Personajes` VALUES ('%s','1','0','0');", g_playername[id])
// Query Execute ?
if (SQL_Execute(Query))
{
g_login[id] = 2
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), g_playername[id])
copy(g_personaje_nombre[id][g_personaje[id]], charsmax(g_personaje_nombre), g_playername[id])
save(id, 0)
client_print(id, print_center, "Personaje %s creado con exito", g_personaje_nombre[id][0])
client_cmd(id, "chooseteam")
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED
}
else
client_print(id, print_center, "Error al crear el personaje")
}
else
{
client_print(id, print_center, "Ese personaje ya existe usa otro nombre!")
show_menu_personajes(id)
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED;
}
public save(id, reset)
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query, Handle:Query2
if(g_login[id] > 0)
{
Query = SQL_PrepareQuery(SqlConnect, "UPDATE `cuentas` SET `Personaje1` = '%s', `Personaje2` = '%s', `Personaje3` = '%s', `Personaje4` = '%s', `Personaje5` = '%s', `Fecha` = '%s' WHERE `Nombre` = '%s' AND `Password` = '%s'",
g_personaje_nombre[id][1], g_personaje_nombre[id][2], g_personaje_nombre[id][3], g_personaje_nombre[id][4], g_personaje_nombre[id][5], g_date[id], cuenta[id], password[id])
}
if(g_login[id] > 1)
{
Query2 = SQL_PrepareQuery(SqlConnect, "UPDATE `Personajes` SET Level=%d,AmmoPacks=%d,Resets=%d WHERE `Nombre` = '%s'",
g_nivel[id],g_ammopacks[id],g_reset[id],g_personaje_nombre[id][0])
}
if(g_login[id] > 0)
if(SQL_Execute(Query))
SQL_FreeHandle(Query)
if(g_login[id] > 1)
if(SQL_Execute(Query2))
SQL_FreeHandle(Query2)
// Connection Closed
SQL_FreeHandle(SqlConnect)
if(reset == 1)
reset_variables(id, 1)
return PLUGIN_HANDLED
}
public load(id, tipo)
{
// Connect to SQL
new Handle:SqlConnect = SQL_Connect(g_hTuple, ErrorCode, g_Error, 511)
if(SqlConnect == Empty_Handle)
{
log_amx("SQL Error: %s", g_Error)
return PLUGIN_HANDLED;
}
// Create Handle
new Handle:Query
if(tipo == 1)
Query = SQL_PrepareQuery(SqlConnect, "SELECT `Level`,`Ammopacks`,`Resets` FROM `Personajes` WHERE (`Nombre` = '%s')", g_personaje_nombre[id][0])
// Query Execute ?
if (SQL_Execute(Query))
{
if (!SQL_NumResults(Query))
{
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
client_print(id, print_center, "Personaje Erroneo")
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][g_personaje[id]], charsmax(g_personaje_nombre), "")
return PLUGIN_HANDLED
}
else
{
if(tipo == 1)
{
g_nivel[id] = SQL_ReadResult(Query, 0)
g_ammopacks[id] = SQL_ReadResult(Query, 1)
g_reset[id] = SQL_ReadResult(Query, 2)
copy(g_playername[id], charsmax(g_playername), g_personaje_nombre[id][0])
client_cmd(id, "name ^"%s^" ", g_personaje_nombre[id][0])
// Cache player's name
get_user_name(id, g_playername[id], charsmax(g_playername[]))
replace_all(g_playername[id], charsmax(g_playername), "'", "")
g_login[id] = 2
client_print(id, print_center, "Personaje %s Cargado con exito!", g_personaje_nombre[id][0])
client_cmd(id, "chooseteam")
}
}
}
// Connection Closed
SQL_FreeHandle(Query)
SQL_FreeHandle(SqlConnect)
return PLUGIN_HANDLED
}
public mensajes_cuenta(id, mensaje)
{
set_hudmessage(255, 0, 0, 0.01, 0.03, 1, 0.1, 100.0, 0.1, 0.1)
if(mensaje == 1)
ShowSyncHudMsg(id, g_MsgSync, "")
if(mensaje == 2)
ShowSyncHudMsg(id, g_MsgSync, "Ingresa tu cuenta")
if(mensaje == 3)
ShowSyncHudMsg(id, g_MsgSync, "Ingresa tu contraseña")
if(mensaje == 4)
ShowSyncHudMsg(id, g_MsgSync, "Vuelve a ingresar tu contraseña")
if(mensaje == 5)
ShowSyncHudMsg(id, g_MsgSync, "Ingresa tu nueva contraseña")
if(mensaje == 6)
ShowSyncHudMsg(id, g_MsgSync, "Vuelve a ingresar tu nueva contraseña")
client_cmd(id, "spk Ui/buttonclickrelease")
}
public reset_variables(id, reset)
{
if(reset == 1)
{
copy(cuenta[id], charsmax(cuenta), "")
copy(password[id], charsmax(password), "")
copy(g_personaje_nombre[id][0], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][1], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][2], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][3], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][4], charsmax(g_personaje_nombre), "")
copy(g_personaje_nombre[id][5], charsmax(g_personaje_nombre), "")
copy(g_date[id], charsmax(g_date), "")
}
g_login[id] = 0
g_personaje[id] = 0
g_nivel[id] = 1
g_reset[id] = 0
g_ammopacks[id] = 0
}
__________________
|
|