Код:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>
#include <sqlx>
#include <ColorChat>
#define PLUGIN "MYSQL Bank"
#define VERSION "0.1Alpha"
#define AUTHOR "Inline"
#pragma semicolon 1
//#define JBE_INTEGRATE // JBE Integr
#if defined JBE_INTEGRATE
native jbe_informer_offset_up(id);
native jbe_informer_offset_down(id);
native jbe_menu_blocked(id);
native jbe_get_user_money(id);
native jbe_set_user_money(id,iMoney,iFlash);
native jbe_is_special_allowed(id,CheckWanted);
// Special allowed Stock proxy, because I lazy
stock bool:jbe_is_special_allowed_p(id,CheckWanted=1)
{
return bool:jbe_is_special_allowed(id,CheckWanted);
}
stock fm_set_user_money_p(id,iMoney,iFlash = 1)
{
return jbe_set_user_money(id,iMoney,iFlash);
}
#define fm_get_user_money_p(%1) jbe_get_user_money(%1)
#else
#define fm_get_user_money_p(%1) fm_get_user_money(%1)
stock fm_set_user_money_p(id,iMoney,iFlash = 1)
{
return fm_set_user_money(id,iMoney,iFlash);
}
#endif
new Handle:SQL_Tuple;
new g_szTemp[512];
//#define NO_ENUM // No pdata enum, amxmodx enum compiler bug fix
#if defined NO_ENUM
#define PLAYER_DATA_START 0
#define PLAYER_DATA_PASSWORD 0
#define PLAYER_DATA_MONEY 1
#define PLAYER_DATA_REGISTERED 2
#define PLAYER_DATA_AUTH 3
#define PLAYER_DATA_INVALID_PASS 4
#define PLAYER_DATA_REGDATE 5
#define PLAYER_DATA_LASTDATE 6
#define PLAYER_DATA_QUERIED 7
#define PLAYER_DATA_END 7
#define PLAYER_DATA 8
#else
enum PLAYER_DATA
{
PLAYER_DATA_START = 0,
PLAYER_DATA_PASSWORD = 0,
PLAYER_DATA_MONEY = 1,
PLAYER_DATA_REGISTERED = 2,
PLAYER_DATA_AUTH = 3,
PLAYER_DATA_INVALID_PASS = 4,
PLAYER_DATA_REGDATE = 5,
PLAYER_DATA_LASTDATE = 6,
PLAYER_DATA_QUERIED = 7,
PLAYER_DATA_END = 7,
};
#endif
new g_iPlayersData[33][PLAYER_DATA];
new g_pInvalid,g_pMenuStyle;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
g_pInvalid = register_cvar( "mysql_bank_invalid_pass", "3" );
g_pMenuStyle = register_cvar("mysql_bank_new_style","1");
{
enum CONNECT_INFO
{
HOSTNAME,
USERNAME,
PASSWORD,
DATABASE,
};
new pConnectionInfo[CONNECT_INFO];
pConnectionInfo[CONNECT_INFO:HOSTNAME] = register_cvar("mysql_bank_hostname","127.0.0.1");
pConnectionInfo[CONNECT_INFO:USERNAME] = register_cvar("mysql_bank_username","root");
pConnectionInfo[CONNECT_INFO:PASSWORD] = register_cvar("mysql_bank_password","");
pConnectionInfo[CONNECT_INFO:DATABASE] = register_cvar("mysql_bank_database","bank");
{
new szDir[256];
get_configsdir(szDir,charsmax(szDir));
server_cmd("exec %s/mysql_bank.cfg", szDir);
server_exec();
}
new szHostname[33], szUsername[33], szPassword[33], szDatabase[33];
get_pcvar_string(pConnectionInfo[CONNECT_INFO:HOSTNAME], szHostname, charsmax(szHostname));
get_pcvar_string(pConnectionInfo[CONNECT_INFO:USERNAME], szUsername, charsmax(szUsername));
get_pcvar_string(pConnectionInfo[CONNECT_INFO:PASSWORD], szPassword, charsmax(szPassword));
get_pcvar_string(pConnectionInfo[CONNECT_INFO:DATABASE], szDatabase, charsmax(szDatabase));
SQL_Tuple = SQL_MakeDbTuple(szHostname, szUsername, szPassword, szDatabase);
}
formatex(g_szTemp,charsmax(g_szTemp),
"CREATE TABLE IF NOT EXISTS `bank_accounts` ( \
`id` INT( 11 ) NOT NULL AUTO_INCREMENT , \
`name` VARCHAR( 32 ) CHARACTER SET utf8 NOT NULL , \
`steamid` CHAR( 35 ) CHARACTER SET utf8 NOT NULL , \
`password` INT( 11 ) NOT NULL , \
`money` INT( 11 ), \
`registration_date` INT( 11 ), \
`last_date` INT( 11 ), \
PRIMARY KEY ( `id` ) \
) ENGINE = MYISAM AUTO_INCREMENT =246 DEFAULT CHARSET = utf8;");
SQL_ThreadQuery(SQL_Tuple,"IgnoreHandle",g_szTemp);
register_clcmd("say /bank", "Show_MainMenu");
register_clcmd("say_team /bank", "Show_MainMenu");
register_clcmd("borrow_money", "Cmd_Barrow");
register_clcmd("deduce_money", "Cmd_Deduce");
register_clcmd("bank_reg_password", "Cmd_BankRegister");
register_clcmd("bank_auth_password", "Cmd_BankAuth") ;
register_dictionary( "mysql_bank.txt" );
register_menucmd(register_menuid("Show_MainMenu"), (1<<0|1<<1|1<<9), "Handle_MainMenu");
register_menucmd(register_menuid("Show_BarrowMenu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<9), "Handle_BarrowMenu");
register_menucmd(register_menuid("Show_DeduceMenu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<9), "Handle_DeduceMenu");
}
public plugin_end()
{
if(SQL_Tuple != Empty_Handle) SQL_FreeHandle(SQL_Tuple);
}
public client_putinserver(id)
{
check_player(id);
}
stock ZeroPlayerData(id)
{
#if defined NO_ENUM
for(new i = PLAYER_DATA_START;i<=PLAYER_DATA_END;++i)
#else
for(new PLAYER_DATA:i = PLAYER_DATA_START;i<=PLAYER_DATA_END;++i)
#endif
{
g_iPlayersData[id][i] = 0;
}
}
public client_disconnect(id)
{
ZeroPlayerData(id);
}
public check_player(id)
{
static szSteamID[35];
get_user_authid(id,szSteamID,charsmax(szSteamID));
new Data[1];
Data[0] = id;
formatex(g_szTemp,charsmax(g_szTemp),"SELECT * FROM `bank_accounts` WHERE (`bank_accounts`.`steamid` = '%s')", szSteamID);
SQL_ThreadQuery(SQL_Tuple, "register_client",g_szTemp,Data,1);
}
public register_client(eFailState,Handle:hQuery,szError[],iError,szData[],iDataSize)
{
if(eFailState == TQUERY_CONNECT_FAILED)
{
log_to_error("[MySQL Bank] While querying server, connection was lost [%d] - %s", iError, szError );
return PLUGIN_HANDLED;
}
else if(eFailState == TQUERY_QUERY_FAILED)
{
log_to_error("[MySQL Bank] Query failed [%d] - %s", iError, szError);
return PLUGIN_HANDLED;
}
new id;
id = szData[0];
g_iPlayersData[id][PLAYER_DATA_QUERIED] = 1;
if(SQL_NumResults(hQuery) < 1)
{
g_iPlayersData[id][PLAYER_DATA_REGISTERED] = 0;
//SQL_ThreadQuery(SQL_Tuple, "IgnoreHandle","");
}
else
{
g_iPlayersData[id][PLAYER_DATA_REGISTERED] = 1;
g_iPlayersData[id][PLAYER_DATA_PASSWORD] = SQL_ReadResult(hQuery, 3);
g_iPlayersData[id][PLAYER_DATA_MONEY] = SQL_ReadResult(hQuery, 4);
g_iPlayersData[id][PLAYER_DATA_REGDATE] = SQL_ReadResult(hQuery, 5);
g_iPlayersData[id][PLAYER_DATA_LASTDATE] = SQL_ReadResult(hQuery, 6);
}
return PLUGIN_HANDLED;
}
stock database_update(id)
{
if(g_iPlayersData[id][PLAYER_DATA_REGISTERED] && g_iPlayersData[id][PLAYER_DATA_AUTH])
{
static szSteamID[34];
get_user_authid(id,szSteamID,charsmax(szSteamID));
formatex(g_szTemp,charsmax(g_szTemp),"UPDATE `bank_accounts` SET `money`= '%i' WHERE `bank_accounts`.`steamid` = '%s';",g_iPlayersData[id][PLAYER_DATA_MONEY], szSteamID);
SQL_ThreadQuery(SQL_Tuple,"IgnoreHandle",g_szTemp);
formatex(g_szTemp,charsmax(g_szTemp),"UPDATE `bank_accounts` SET `last_date`= '%i' WHERE `bank_accounts`.`steamid` = '%s';",get_systime(), szSteamID);
SQL_ThreadQuery(SQL_Tuple,"IgnoreHandle",g_szTemp);
}
}
public IgnoreHandle(eFailState,Handle:hQuery,szError[],iError,szData[],iDataSize)
{
if(eFailState == TQUERY_CONNECT_FAILED)
{
log_to_error("[MySQL Bank] While querying server, connection was lost [%d] - %s", iError, szError );
}
else if(eFailState == TQUERY_QUERY_FAILED)
{
log_to_error("[MySQL Bank] Query failed [%d] - %s", iError, szError);
}
return PLUGIN_HANDLED;
}
new szMenu[512];
public Show_MainMenu(id)
{
#if defined JBE_INTEGRATE
if(jbe_menu_blocked(id)) return PLUGIN_HANDLED;
jbe_informer_offset_up(id);
#endif
new iMenuStyle = get_pcvar_num(g_pMenuStyle);
#if defined JBE_INTEGRATE
new iNonActive = !jbe_is_special_allowed_p(id) || !g_iPlayersData[id][PLAYER_DATA_QUERIED];
#else
new iNonActive = 0;
#endif
new b = 0;
static szTemplate[64];
if(g_iPlayersData[id][PLAYER_DATA_AUTH])
{
new iKeys = (1<<9), iLen = formatex(szMenu, charsmax(szMenu), iMenuStyle==1 ? "\y%L^n^n" : "\w%L^n^n", id, "MYSQL_BANK_MAIN_MENU_TITLE",g_iPlayersData[id][PLAYER_DATA_MONEY]);
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, iNonActive || fm_get_user_money_p(id)<=0)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id, "MYSQL_BANK_MAIN_MENU_BORROW");
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, iNonActive || g_iPlayersData[id][PLAYER_DATA_MONEY]<=0)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id, "MYSQL_BANK_MAIN_MENU_DEDUCE");
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, 1)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id, "MYSQL_BANK_MAIN_MENU_PROFILE");
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, 1)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id, "MYSQL_BANK_MAIN_MENU_CREDIT");
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, 1)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id, "MYSQL_BANK_MAIN_MENU_SHARE");
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n");
GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, 0);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, 0, id, "MYSQL_MENU_EXIT");
return show_menu(id, iKeys, szMenu, -1, "Show_MainMenu");
}
else
{
if(g_iPlayersData[id][PLAYER_DATA_REGISTERED]==0)
{
new iKeys = (1<<1), iLen = formatex(szMenu, charsmax(szMenu), iMenuStyle==1 ? "\y%L^n^n" : "\w%L^n^n", id, "MYSQL_BANK_REGISTER_MENU_TITLE");
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, iNonActive)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id, "MYSQL_BANK_REGISTER_MENU_REGISTER");
GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, 0);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, 2, id, "MYSQL_MENU_EXIT");
return show_menu(id, iKeys, szMenu, -1, "Show_MainMenu");
}
else
{
new iKeys = (1<<1), iLen = formatex(szMenu, charsmax(szMenu), iMenuStyle==1 ? "\y%L^n^n" : "\w%L^n^n", id, "MYSQL_BANK_AUTH_MENU_TITLE");
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, iNonActive)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id, "MYSQL_BANK_AUTH_MENU_AUTH");
GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, 0);
formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, 2, id, "MYSQL_MENU_EXIT");
return show_menu(id, iKeys, szMenu, -1, "Show_MainMenu");
}
}
return PLUGIN_HANDLED;
}
public Handle_MainMenu(id,iKey)
{
if(g_iPlayersData[id][PLAYER_DATA_AUTH]==1)
{
switch(iKey)
{
case 0:
{
Show_BarrowDeduceMenu(id,1);
}
case 1:
{
Show_BarrowDeduceMenu(id,0);
}
case 9:
{
return PLUGIN_HANDLED;
}
default:
{
Show_MainMenu(id);
}
}
}
else
{
if(g_iPlayersData[id][PLAYER_DATA_REGISTERED]==0)
{
switch(iKey)
{
case 0:
{
Client_Registration(id);
}
case 1:
{
return PLUGIN_HANDLED;
}
}
}
else
{
switch(iKey)
{
case 0:
{
Client_Auth(id);
}
case 1:
{
return PLUGIN_HANDLED;
}
}
}
}
return PLUGIN_HANDLED;
}
stock UTIL_GetMoneyBuyItem(i)
{
if(i<4)
{
switch(i)
{
case 1: return 1000;
case 2: return 2000;
case 3: return 3000;
}
}
return abs((i-3)*5000);
}
public Show_BarrowDeduceMenu(id,isBarrow)
{
#if defined JBE_INTEGRATE
if(jbe_menu_blocked(id)) return PLUGIN_HANDLED;
jbe_informer_offset_up(id);
#endif
new iMenuStyle = get_pcvar_num(g_pMenuStyle);
#if defined JBE_INTEGRATE
new iNonActive = !jbe_is_special_allowed_p(id);
#else
new iNonActive = 0;
#endif
new b;
static szTemplate[64];
new iKeys = (1<<9);
new iLen = formatex(szMenu, charsmax(szMenu), iMenuStyle==1 ? "\y%L^n^n" : "\w%L^n^n", id, isBarrow ? "MYSQL_BANK_BORROW_MENU_TITLE" : "MYSQL_BANK_DEDUCE_MENU_TITLE",g_iPlayersData[id][PLAYER_DATA_MONEY]);
new iCurrentMoney = isBarrow ? fm_get_user_money_p(id) : 0;
for(new i = 1;i<=6;++i)
{
new iMoney = UTIL_GetMoneyBuyItem(i);
new iBool = isBarrow ? (iCurrentMoney<=iMoney) : (g_iPlayersData[id][PLAYER_DATA_MONEY]<=iMoney);
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, iNonActive || iBool)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id,"MYSQL_BANK_MENU_ITEM",iMoney);
}
new isMoneyNull = (isBarrow ? (iCurrentMoney<=0) : (g_iPlayersData[id][PLAYER_DATA_MONEY]<=0));
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, iNonActive || isMoneyNull)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id,"MYSQL_BANK_MENU_USER_MONEY");
if(GetMenuTemplate(szTemplate,charsmax(szTemplate),iMenuStyle, iNonActive || isMoneyNull)) iKeys|=1<<b;
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, ++b, id,"MYSQL_BANK_MENU_ALL_MONEY");
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n");
formatex(szMenu[iLen], charsmax(szMenu) - iLen, szTemplate, 0, id, "MYSQL_MENU_EXIT");
return show_menu(id, iKeys, szMenu, -1, isBarrow ? "Show_BarrowMenu" : "Show_DeduceMenu");
}
public Handle_BarrowMenu(id,iKey)
{
switch(iKey)
{
case 0,1,2,3,4,5:
{
new iMoney = UTIL_GetMoneyBuyItem(iKey+1);
new iCurrentMoney = fm_get_user_money_p(id);
if(iCurrentMoney<iMoney)
{
ColorChat(id, RED,"%L",id,"MYSQL_BANK_BORROW_NO_MONEY");
}
else
{
fm_set_user_money_p(id, iCurrentMoney-iMoney);
g_iPlayersData[id][PLAYER_DATA_MONEY] = g_iPlayersData[id][PLAYER_DATA_MONEY] + iMoney;
ColorChat(id, RED,"%L",id,"MYSQL_BANK_BORROWED", iMoney);
database_update(id);
}
Show_BarrowDeduceMenu(id,1);
}
case 6:
{
client_cmd(id, "messagemode ^"borrow_money^"");
}
case 7:
{
new iMoney = fm_get_user_money_p(id);
fm_set_user_money_p(id, 0);
g_iPlayersData[id][PLAYER_DATA_MONEY] = g_iPlayersData[id][PLAYER_DATA_MONEY] + iMoney;
ColorChat(id, RED,"%L",id,"MYSQL_BANK_BORROWED", iMoney);
database_update(id);
Show_BarrowDeduceMenu(id,1);
}
case 9:
{
return PLUGIN_HANDLED;
}
}
return PLUGIN_HANDLED;
}
public Handle_DeduceMenu(id,iKey)
{
switch(iKey)
{
case 0,1,2,3,4,5:
{
new iMoney = UTIL_GetMoneyBuyItem(iKey+1);
new iCurrentMoney = fm_get_user_money_p(id);
if(g_iPlayersData[id][PLAYER_DATA_MONEY]<iMoney)
{
ColorChat(id, RED,"%L",id,"MYSQL_BANK_DEDUCE_NO_MONEY");
}
else
{
fm_set_user_money_p(id, iCurrentMoney+iMoney);
g_iPlayersData[id][PLAYER_DATA_MONEY] = g_iPlayersData[id][PLAYER_DATA_MONEY] - iMoney;
ColorChat(id, RED,"%L",id,"MYSQL_BANK_DEDUCED", iMoney);
database_update(id);
}
Show_BarrowDeduceMenu(id,0);
}
case 6:
{
client_cmd(id, "messagemode ^"deduce_money^"");
}
case 7:
{
new iCurrentMoney = fm_get_user_money_p(id);
fm_set_user_money_p(id, iCurrentMoney+g_iPlayersData[id][PLAYER_DATA_MONEY]);
ColorChat(id, RED,"%L",id,"MYSQL_BANK_DEDUCED", g_iPlayersData[id][PLAYER_DATA_MONEY]);
g_iPlayersData[id][PLAYER_DATA_MONEY] = 0;
database_update(id);
}
case 9:
{
return PLUGIN_HANDLED;
}
}
return PLUGIN_HANDLED;
}
public Cmd_Barrow(id)
{
new szArgs[10];
read_args(szArgs,charsmax(szArgs));
remove_quotes(szArgs);
if(!is_str_num(szArgs))
{
ColorChat(id, RED,"%L",id,"MYSQL_BANK_BORROW_NO_NUMBER");
return PLUGIN_HANDLED;
}
new iAmount = str_to_num(szArgs);
new iMoney = fm_get_user_money_p(id);
if (iMoney < iAmount)
{
ColorChat(id, RED,"%L",id,"MYSQL_BANK_BORROW_NO_MONEY");
return PLUGIN_HANDLED;
}
fm_set_user_money_p(id, iMoney-iAmount);
g_iPlayersData[id][PLAYER_DATA_MONEY]=g_iPlayersData[id][PLAYER_DATA_MONEY]+iAmo
unt;
ColorChat(id, RED,"%L",id,"MYSQL_BANK_BORROWED", iAmount);
database_update(id);
return PLUGIN_HANDLED;
}
public Cmd_Deduce(id)
{
new szArgs[10];
read_args(szArgs,charsmax(szArgs));
remove_quotes(szArgs);
if(!is_str_num(szArgs))
{
ColorChat(id, RED,"%L",id,"MYSQL_BANK_DEDUCE_NO_NUMBER");
return PLUGIN_HANDLED;
}
new iAmount = str_to_num(szArgs);
new iMoney = fm_get_user_money_p(id);
if (g_iPlayersData[id][PLAYER_DATA_MONEY] < iAmount)
{
ColorChat(id, RED,"%L",id,"MYSQL_BANK_DEDUCE_NO_MONEY");
return PLUGIN_HANDLED;
}
fm_set_user_money_p(id, iMoney+iAmount);
g_iPlayersData[id][PLAYER_DATA_MONEY]=g_iPlayersData[id][PLAYER_DATA_MONEY]-iAmount;
ColorChat(id, RED,"%L",id,"MYSQL_BANK_DEDUCED", iAmount);
database_update(id);
return PLUGIN_HANDLED;
}
stock Client_Registration(id)
{
client_cmd(id, "messagemode bank_reg_password");
ColorChat(id, RED,"%L",id,"MYSQL_BANK_REGISTER_INFO");
ColorChat(id, RED,"%L",id,"MYSQL_BANK_REGISTER_INFO2");
}
stock Client_Auth(id)
{
client_cmd(id, "messagemode bank_auth_password");
}
public Cmd_BankRegister(id)
{
static szName[32],szSteamID[35], szArgs[512], iRegDate, iLastDate;
read_args(szArgs, 511);
remove_quotes(szArgs);
get_user_name(id, szName, charsmax(szName));
get_user_authid(id,szSteamID,charsmax(szSteamID));
iRegDate = iLastDate = get_systime();
if(!is_str_num(szArgs))
{
ColorChat(id,RED,"%L",id,"MYSQL_BANK_REGISTER_ONLY_NUMBER");
return PLUGIN_HANDLED;
}
SQL_QuoteString(Empty_Handle,szName,charsmax(szName),szName);
formatex(g_szTemp,charsmax(g_szTemp),"INSERT INTO `bank_accounts` ( `name`, `steamid`, `password`, `money`, `registration_date`, `last_date`)VALUES ('%s','%s','%s', '0', '%i', '%i');", szName, szSteamID, szArgs, iRegDate, iLastDate);
SQL_ThreadQuery(SQL_Tuple,"IgnoreHandle",g_szTemp);
g_iPlayersData[id][PLAYER_DATA_REGISTERED] = 1;
g_iPlayersData[id][PLAYER_DATA_PASSWORD] = str_to_num(szArgs);
ColorChat(id, RED,"%L",id,"MYSQL_BANK_REGISTER_SUCCESSFUL", szArgs);
Show_MainMenu(id);
return PLUGIN_HANDLED;
}
public Cmd_BankAuth(id)
{
static szArgs[34];
read_args(szArgs, charsmax(szArgs));
remove_quotes(szArgs);
bank_auth2(id,szArgs);
}
public bank_auth2(id,szArgs[])
{
static szPassword[33];
num_to_str(g_iPlayersData[id][PLAYER_DATA_PASSWORD], szPassword, charsmax(szPassword));
if (equal(szPassword, szArgs))
{
g_iPlayersData[id][PLAYER_DATA_AUTH] = true;
ColorChat(id, RED,"%L",id,"MYSQL_BANK_AUTH_INFO");
static szName[64], szSteamID[34], iLastDate;
iLastDate = get_systime();
get_user_name(id,szName,charsmax(szName));
ColorChat(0, RED,"%L",LANG_PLAYER,"MYSQL_BANK_AUTH_INFO_ALL",szName, g_iPlayersData[id][PLAYER_DATA_MONEY]);
SQL_QuoteString(Empty_Handle,szName,charsmax(szName),szName);
get_user_authid(id,szSteamID,charsmax(szSteamID));
formatex(g_szTemp,charsmax(g_szTemp),"UPDATE `bank_accounts` SET `last_date`= '%i' WHERE `bank_accounts`.`steamid` = '%s';",iLastDate, szSteamID);
SQL_ThreadQuery(SQL_Tuple,"IgnoreHandle",g_szTemp);
formatex(g_szTemp,charsmax(g_szTemp),"UPDATE `bank_accounts` SET `name`= '%s' WHERE `bank_accounts`.`steamid` = '%s';",szName, szSteamID);
SQL_ThreadQuery(SQL_Tuple,"IgnoreHandle",g_szTemp);
}
else
{
++g_iPlayersData[id][PLAYER_DATA_INVALID_PASS];
new iMaxInvalidPass = get_pcvar_num(g_pInvalid);
ColorChat(id, RED,"%L",0,"MYSQL_BANK_AUTH_INVALIDPASS", iMaxInvalidPass-g_iPlayersData[id][PLAYER_DATA_INVALID_PASS]);
if(g_iPlayersData[id][PLAYER_DATA_INVALID_PASS]>=iMaxInvalidPass)
{
server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "MYSQL_BANK_INVALID_PASSWORD");
return PLUGIN_HANDLED;
}
}
Show_MainMenu(id);
return PLUGIN_HANDLED;
}
stock GetMenuTemplate(szTemplate[], iLen, iMenuStyle ,iNonActive=0)
{
copy(szTemplate,iLen, iMenuStyle==1 ? "\y[%d] \w%L^n" : "\w%d. %L^n");
if(iNonActive)
{
replace(szTemplate,iLen,"\w","\d");
}
return !iNonActive;
}
public client_infochanged(id)
{
if (g_iPlayersData[id][PLAYER_DATA_AUTH])
{
static szNewName[64], szOldName[64];
get_user_info(id, "name", szNewName, charsmax(szNewName));
get_user_name(id, szOldName, charsmax(szOldName));
if(!equali(szOldName, szNewName))
{
static szSteamID[35];
SQL_QuoteString(0,szNewName,charsmax(szNewName),szNewName);
get_user_authid(id,szSteamID,charsmax(szSteamID));
formatex(g_szTemp,charsmax(g_szTemp),"UPDATE `bank_accounts` SET `name`= '%s' WHERE `bank_accounts`.`steamid` = '%s';",szNewName, szSteamID);
SQL_ThreadQuery(SQL_Tuple,"IgnoreHandle",g_szTemp);
}
}
}
stock log_to_error(const message[], any:...)
{
static log[256], date[32], Map[32];
vformat(log, 255, message, 2);
get_time("error_%Y%m%d.log", date, 31);
get_mapname(Map, 31);
log_to_file(date, "[%s] %s", PLUGIN, log);
}