public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_impulse(201, "Fomenu")
register_event("CurWeapon", "FegyverCsere", "be", "1=1");
register_clcmd("say", "sayhook");
register_clcmd("DOLLAR", "lekeres");
//reg
g_iSqlTuple = SQL_MakeDbTuple(SQLINFO[ 0 ], SQLINFO[ 1 ], SQLINFO[ 2 ], SQLINFO[ 3 ] );
new sThread[ 512 ];
formatex( sThread, charsmax( sThread ), "CREATE TABLE IF NOT EXISTS `reg_users` (`username` varchar( 32 ) NOT NULL, `password` varchar( 32 ) NOT NULL, `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY );" );
SQL_ThreadQuery( g_iSqlTuple, "ThreadHandler", sThread, { 0 }, 1 );
register_clcmd( "Felhasznalonev", "GetUserName" );
register_clcmd( "Jelszo", "GetPassword" );
register_clcmd( "say /reg", "cmdReg" );
//reg
}
public plugin_cfg()
{
g_SqlTuple = SQL_MakeDbTuple(SQLINFO[0], SQLINFO[1], SQLINFO[2], SQLINFO[3]);
static Query[10048];
new Len;
Len += formatex(Query[Len], charsmax(Query), "CREATE TABLE IF NOT EXISTS `troyasd_3.0`");
Len += formatex(Query[Len], charsmax(Query)-Len, "(`Nev` varchar(32) NOT NULL, ");
Len += formatex(Query[Len], charsmax(Query)-Len, "`Dollars` int(11) NOT NULL,");
Len += formatex(Query[Len], charsmax(Query)-Len, "`Kulcss` int(11) NOT NULL,");
Len += formatex(Query[Len], charsmax(Query)-Len, "`Masodpercek` int(11) NOT NULL,");
Len += formatex(Query[Len], charsmax(Query)-Len, "`Szint` int(11) NOT NULL,");
Len += formatex(Query[Len], charsmax(Query)-Len, "`Oles` int(11) NOT NULL,");
for(new i;i < 2; i++)
Len += formatex(Query[Len], charsmax(Query)-Len, "`L_%d` int(11) NOT NULL,", i);
for(new i;i < 15; i++)
Len += formatex(Query[Len], charsmax(Query)-Len, "`F_%d` int(11) NOT NULL,", i);
for(new i;i < 1; i++)
Len += formatex(Query[Len], charsmax(Query)-Len, "`Skin_%d` int(11) NOT NULL,", i);
Len += formatex(Query[Len], charsmax(Query)-Len, "`Osszes` int(11) NOT NULL, `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY)");
SQL_ThreadQuery(g_SqlTuple, "createTableThread", Query);
}
public Load(id) {
static Query[10048];
new Data[1], Name[32];
get_user_name(id, Name, 31);
Data[0] = id;
formatex(Query, charsmax(Query), "SELECT * FROM `troyasd_3.0` WHERE Nev = ^"%s^";", Name);
SQL_ThreadQuery(g_SqlTuple, "QuerySelectData", Query, Data, 1);
}
public QuerySelectData(FailState, Handle:Query, Error[], Errcode, Data[], DataSize, Float:Queuetime) {
if(FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED) {
log_amx("%s", Error);
return;
}
else {
new id = Data[0];
if(SQL_NumRows(Query) > 0) {
Dollar[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "Dollars"));
Kulcs[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "Kulcss"));
Masodpercek[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "Masodpercek"));
Szint[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "Szint"));
Oles[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "Oles"));
for(new i=0;i<15;i++)
OsszesNev[i] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "Osszes"));
for(new i=0;i < 2; i++)
{
new String[64];
formatex(String, charsmax(String), "L_%d", i);
Lada[i][id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, String));
}
for(new i=0;i < 15; i++)
{
new String[64];
formatex(String, charsmax(String), "F_%d", i);
OsszesSkin[i][id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, String));
}
for(new i;i < 1; i++)
{
new String[64];
formatex(String, charsmax(String), "Skin_%d", i);
Skin[i][id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, String));
}
}
else
{
Save(id);
}
}
}
public Save(id)
{
static Query[256];
new Name[32]; get_user_name(id, Name, 31);
formatex(Query, charsmax(Query), "INSERT INTO `troyasd_3.0` (`Nev`) VALUES (^"%s^");", Name);
SQL_ThreadQuery(g_SqlTuple, "QuerySetData", Query);
}
public Update(id)
{
static Query[10048];
new Len;
new Name[32]; get_user_name(id, Name, 31);
Len += formatex(Query[Len], charsmax(Query), "UPDATE `troyasd_3.0` SET Dollars = ^"%i^", ",Dollar[id]);
Len += formatex(Query[Len], charsmax(Query)-Len, "Kulcss = ^"%i^", ", Kulcs[id]);
Len += formatex(Query[Len], charsmax(Query)-Len, "Szint = ^"%i^", ", Szint[id]);
Len += formatex(Query[Len], charsmax(Query)-Len, "Oles = ^"%i^", ", Oles[id]);
for(new i=0;i < 15; i++)
Len += formatex(Query[Len], charsmax(Query)-Len, "Osszes = ^"%i^", ", OsszesNev[i]);
for(new i=0;i < 2; i++)
Len += formatex(Query[Len], charsmax(Query)-Len, "L_%d = ^"%i^", ", i, Lada[i][id]);
for(new i=0;i < 15; i++)
Len += formatex(Query[Len], charsmax(Query)-Len, "F_%d = ^"%i^", ", i, OsszesSkin[i][id]);
for(new i;i < 1; i++)
Len += formatex(Query[Len], charsmax(Query)-Len, "Skin_%d = ^"%i^", ", i, Skin[i][id]);
Len += formatex(Query[Len], charsmax(Query)-Len, "Masodpercek = ^"%i^" WHERE Nev = ^"%s^";", Masodpercek[id]+get_user_time(id), Name);
SQL_ThreadQuery(g_SqlTuple, "QuerySetData", Query);
}
public createTableThread(FailState, Handle:Query, Error[], Errcode, Data[], DataSize, Float:Queuetime) {
if(FailState == TQUERY_CONNECT_FAILED)
set_fail_state("[HIBA*] NEM TUDTAM CSATLAKOZNI AZ ADATBAZISHOZ!");
else if(FailState == TQUERY_QUERY_FAILED)
set_fail_state("Query Error");
if(Errcode)
log_amx("[HIBA*] HIBAT DOBTAM: %s",Error);
}
public QuerySetData(FailState, Handle:Query, Error[], Errcode, Data[], DataSize, Float:Queuetime) {
if(FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED) {
log_amx("%s", Error);
return;
}
}
//Regisztráció
public cmdReg( iId ) { MainMenu( iId, 0 ); }
public MainMenu( iId, iMenu )
{
static sTxt[ 256 ], iMenuId, sItemId[ 8 ];
static const iNum = charsmax( sTxt );
formatex( sTxt, iNum, "\r[\w%s\r]\y ", g_sPrefix );
switch( iMenu )
{
case 0:
{
add( sTxt, iNum, "Regisztracios menu" );
iMenuId = menu_create( sTxt, "MainMenuH" );
if ( g_iLoggedIn[ iId ] == 3 ) menu_additem( iMenuId, "Kijelentkezes", "0 0" );
else
{
menu_additem( iMenuId, "Regisztracio", "1 0" );
menu_additem( iMenuId, "Bejelentkezes", "2 0" );
}
}
case 1, 2:
{
add( sTxt, iNum, iMenu == 1 ? "Regisztracio" : "Bejelentkezes" );
iMenuId = menu_create( sTxt, "MainMenuH" );
formatex( sTxt, iNum, "Felhasznalonev: \r%s", g_sUserName[ iId ] );
formatex( sItemId, charsmax( sItemId ), "1 %d", iMenu );
menu_additem( iMenuId, sTxt, sItemId );
formatex( sTxt, iNum, "Jelszo: \r%s^n", g_sPassword[ iId ] );
formatex( sItemId, charsmax( sItemId ), "2 %d", iMenu );
menu_additem( iMenuId, sTxt, sItemId );
formatex( sItemId, charsmax( sItemId ), "3 %d", iMenu );
menu_additem( iMenuId, iMenu == 1 ? "Regisztralas" : "Bejelentkezes", sItemId );
}
}
menu_display( iId, iMenuId, 0 );
}
public MainMenuH( iId, iMenuId, iItem )
{
if ( iItem != MENU_EXIT )
{
new sMenuName[ 78 ], sInfo[ 32 ], sDatas[ 2 ][ 16 ], iKey, iMenuNum;
menu_item_getinfo( iMenuId, iItem, iKey, sInfo, charsmax( sInfo ), sMenuName, charsmax( sMenuName ), iMenuNum );
parse( sInfo, sDatas[ 0 ], charsmax( sDatas[ ] ), sDatas[ 1 ], charsmax( sDatas[ ] ) );
iKey = str_to_num( sDatas[ 0 ] );
iMenuNum = str_to_num( sDatas[ 1 ] );
switch( iMenuNum )
{
case 0:
{
if ( ( g_iLoggedIn[ iId ] = iKey ) == 0 ) ChatColor( iId, "Sikeresen kijelentkeztel." );
else MainMenu( iId, ( g_iLoggedIn[ iId ] = iKey ) );
}
case 1, 2:
{
switch( iKey )
{
case 1: { client_cmd( iId, "messagemode Felhasznalonev" ); }
case 2: { client_cmd( iId, "messagemode Jelszo" ); }
case 3: { LoadDatas( iId, iMenuNum ); }
}
}
}
}
menu_destroy( iMenuId );
return PLUGIN_HANDLED;
}
public SaveDatas( iId )
{
static sText[ 128 ];
formatex( sText, charsmax( sText ), "INSERT INTO `reg_users` (`username`, `password`) VALUES (^"%s^", ^"%s^");", g_sUserName[ iId ], g_sPassword[ iId ] );
SQL_ThreadQuery( g_iSqlTuple, "ThreadHandler", sText, { 0 }, 1 );
}
public LoadDatas( iId, iMode )
{
static sText[ 128 ], iArray[ 1 ];
iArray[ 0 ] = iId;
if ( iMode == 1 )
{
formatex( sText, charsmax( sText ), "SELECT * FROM `reg_users` WHERE username = ^"%s^";", g_sUserName[ iId ] );
iArray[ 0 ] += 100;
}
else formatex( sText, charsmax( sText ), "SELECT * FROM `reg_users` WHERE username = ^"%s^" AND password = ^"%s^";", g_sUserName[ iId ], g_sPassword[ iId ] );
SQL_ThreadQuery( g_iSqlTuple, "ThreadHandler", sText, iArray, sizeof( iArray ) );
}
public ThreadHandler( iFailState, Handle:iQuery, const sErrorMsg[ ], iErrorCode, const iARRAY[ ], iArraySize, Float:fQueueTime )
{
if ( iFailState == TQUERY_CONNECT_FAILED )
{
set_fail_state( "Nem tudtam csatlakozni az adatbazishoz." );
return;
}
else if ( iFailState == TQUERY_QUERY_FAILED )
{
set_fail_state( "Query Error" );
return;
}
if ( iErrorCode )
{
log_amx( "%i - %s", iErrorCode, sErrorMsg );
return;
}
new iId = iARRAY[ 0 ];
if ( iId )
{
if ( iId > 100 )
{
iId -= 100;
if ( SQL_NumResults( iQuery ) > 0 )
{
g_iLoggedIn[ iId ] = 3;
ChatColor( iId, "Sikeresen bejelentkeztel." );
MainMenu( iId, 0 );
}
else
{
ChatColor( iId, "Hibas felhasznalonev es/vagy jelszo." );
MainMenu( iId, 2 );
}
}
else
{
if ( SQL_NumResults( iQuery ) > 0 )
{
ChatColor( iId, "Ez a felhasznalonev mar foglalt." );
MainMenu( iId, 1 );
}
else
{
g_iLoggedIn[ iId ] = 3;
ChatColor( iId, "Sikeresen regisztraltal. Felhasznaloneved: %s, Jelszavad: %s.", g_sUserName[ iId ], g_sPassword[ iId ] );
SaveDatas( iId );
MainMenu( iId, 0 );
}
}
}
return;
}
public GetUserName( iId )
{
static sUser[ 32 ];
read_args( sUser, charsmax( sUser ) );
remove_quotes( sUser );
if ( strlen( sUser ) < 5 )
{
ChatColor( iId, "A felhasznalonevednek hosszabb kell hogy legyen mint 5 karakter!" );
client_cmd( iId, "messagemode Felhasznalonev" );
}
else copy( g_sUserName[ iId ], charsmax( g_sUserName[ ] ), sUser );
MainMenu( iId, g_iLoggedIn[ iId ] );
}
public GetPassword( iId )
{
static sPass[ 32 ];
read_args( sPass, charsmax( sPass ) );
remove_quotes( sPass );
if ( strlen( sPass ) < 5 )
{
ChatColor( iId, "A jelszavad hosszabb kell hogy legyen mint 5 karakter!" );
client_cmd( iId, "messagemode Jelszo" );
}
else copy( g_sPassword[ iId ], charsmax( g_sPassword[ ] ), sPass );
MainMenu( iId, g_iLoggedIn[ iId ] );
}
//regisztárció
public client_putinserver(id)
{
set_task(1.0, "toltes",_,_,_,"b");
Dollar[id] = EOS;
Masodpercek[id] = 0;
Szint[id] = 0;
Kulcs[id] = 0;
Oles[id] = 0;
Fegyo[id] = 1;
for(new i;i < 15; i++)
OsszesNev[i] = EOS;
for(new i;i < 2; i++)
Lada[i][id] = EOS;
for(new i;i < 15; i++)
OsszesSkin[i][id] = EOS;
for(new i;i < 1; i++)
Skin[i][id] = EOS;
if(!is_user_bot(id))
Load(id);
}
public toltes( iId )
{
g_iLoggedIn[ iId ] = 0;
g_sUserName[ iId ] = "";
g_sPassword[ iId ] = "";
}
public plugin_end( ) { SQL_FreeHandle( g_iSqlTuple ); }