15.05.2013, 15:25
Eae povinho do meu pulmгo, eu to seguindo o tutorial do BlueX, mais a database ta com um erro, ela ou o acesso a ele, a parte do phpmyadmin, eu uso xamp, ligo o Apache, MySQL, entro no phpmyadmin e crio a database, mais nгo vai na hora do registro, pois o CheckAccount nгo й executado por nгo conseguir ler a database ( creio eu ).
Nenhum erro de compilaзгo, warning.
[12:21:36] Loaded 3 plugins.
Log:
GM completo:
Server.cfg
ATENЗГO: Nгo venha a esse tуpico falando mal sobre o MySQL, sу pesso que possam me ajudar a resolver esse erro para prosseguir com meu projeto.
Nenhum erro de compilaзгo, warning.
[12:21:36] Loaded 3 plugins.
Log:
Код:
[12:15:06] >> mysql_connect(localhost, root, contas, ******) on port 3306 [12:15:06] CMySQLHandler::CMySQLHandler() - constructor called. [12:15:06] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "contas" | Username: "root" [12:15:06] CMySQLHandler::Connect() - Connection was successful. [12:15:06] CMySQLHandler::Connect() - Auto-Reconnect has been enabled. [12:15:06] >> mysql_query_callback( Connection handle: 1 ) [12:15:06] Passing query CREATE TABLE IF NOT EXISTS `users` (`id` int(11) NOT NULL, AUTO_INCREMENT,`name` varchar(25) NOT NULL, `password` varchar(25) NOT NULL, `level` int(11) NOT NULL, `bank` int(11) NOT NULL, `skin` int(11) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY(`id`)) | s [12:15:06] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()
PHP код:
#include < a_samp >
#include < a_mysql >
#include < zcmd >
#include < sscanf >
#include < streamer >
#define xBranco 0xFFFFFFFF
#define MAX_SOLTS (25)
#define D_LOGIN 1
#define D_REGISTER 2
new const
mysql_host[] = "localhost",
mysql_user[] = "root",
mysql_database[] = "contas",
mysql_password[] = "";
new Query[500];
new MysqlC;
new PlayerName[25];
enum pInfo{
pLevel,
pMoney,
pBank,
pSkin,
pWarn
};
new PlayerInfo[MAX_SOLTS][pInfo];
main()
{
print("=========================================\n");
print("Servidor Iniciado.");
print("=========================================\n");
}
public OnGameModeInit()
{
MySQL_Start();
AddPlayerClass(0, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
MySQL_CheckAccount(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
MySQL_SaveAccount(playerid);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid){
case D_LOGIN:{
if(!response)
Kick(playerid);
else {
if(strlen(inputtext) < 4)
return ShowPlayerDialog(playerid,D_LOGIN,3,"login","insira a sua password para logar","logar","sair");
else
MySQL_CheckPassword(playerid,inputtext);
}
}
case D_REGISTER:{
if(!response)
Kick(playerid);
else {
if( 5 < (strlen(inputtext)) > 25)
return ShowPlayerDialog(playerid,D_REGISTER,3,"registro","insira uma password para registrar","registrar","sair");
else
MySQL_CreateAccount(playerid,inputtext);
}
}
}
return 1;
}
forward MySQL_Start();
forward r@MySQL_Start(text[]);
forward MySQL_CheckAccount(playerid);
forward r@MySQL_CheckAccount(playerid);
forward MySQL_CheckPassword(playerid,password[]);
forward r@MySQL_CheckPassword(playerid);
forward MySQL_CreateAccount(playerid,password[]);
forward r@MySQL_CreateAccount(playerid);
forward MySQL_LoadAccount(playerid);
forward r@MySQL_LoadAccount(playerid);
forward MySQL_SaveAccount(playerid);
forward r@MySQL_SaveAccount(playerid);
forward PlayerSpawn(playerid);
public MySQL_Start(){
MysqlC = mysql_connect(mysql_host,mysql_user,mysql_database,mysql_password);
if(!MysqlC)
return print("Nгo foi possivel conectar a database, verifique as definiзхes novamente.");
else {
mysql_function_query(MysqlC,
"CREATE TABLE IF NOT EXISTS `users` (\
`id` int(11) NOT NULL, AUTO_INCREMENT,\
`name` varchar(25) NOT NULL, \
`password` varchar(25) NOT NULL, \
`level` int(11) NOT NULL, \
`bank` int(11) NOT NULL, \
`skin` int(11) NOT NULL, \
`money` int(11) NOT NULL, \
PRIMARY KEY(`id`)\
)",false,"r@MySQL_Start","s","users");
}
return 1;
}
public r@MySQL_Start(text[])
return printf("Tabela %s verificada com sucesso.",text);
public MySQL_CheckAccount(playerid){
GetPlayerName(playerid,PlayerName,25);
format(Query,sizeof(Query),"SELECT * FROM `users` WHERE name='%s'",PlayerName);
mysql_function_query(MysqlC,Query,true,"r@MySQL_CheckAccount","d",playerid);
return 1;
}
public r@MySQL_CheckAccount(playerid){
new rows,fields;
cache_get_data(rows,fields,MysqlC);
if(rows){
ShowPlayerDialog(playerid,D_LOGIN,3,"login","insira a sua password para logar","logar","sair");
} else {
ShowPlayerDialog(playerid,D_REGISTER,3,"registro","insira uma password para registrar","registrar","sair");
}
return 1;
}
public MySQL_CheckPassword(playerid,password[]){
GetPlayerName(playerid,PlayerName,25);
format(Query,sizeof(Query),"SELECT * FROM `users` WHERE name='%s' AND password='%s'",PlayerName,password);
mysql_function_query(MysqlC,Query,true,"r@MySQL_CheckPassword","ds",playerid);
return 1;
}
public r@MySQL_CheckPassword(playerid){
new rows,fields;
cache_get_data(rows,fields,MysqlC);
if(rows)
MySQL_LoadAccount(playerid);
else
ShowPlayerDialog(playerid,D_LOGIN,3,"login","insira a sua password para logar","logar","sair");
return 1;
}
public MySQL_CreateAccount(playerid,password[]){
GetPlayerName(playerid,PlayerName,25);
format(Query,sizeof(Query),"INSERT INTO `users` (name,password,level,money,bank,skin) VALUES ('%s','%s','2','4500','0','240');",PlayerName,password);
mysql_function_query(MysqlC,Query,true,"r@MySQL_CreateAccount","s",playerid);
return 1;
}
public r@MySQL_CreateAccount(playerid){
SendClientMessage(playerid,-1,"Registrado com sucesso, aguarde um pouco...");
MySQL_LoadAccount(playerid);
return 1;
}
public MySQL_LoadAccount(playerid){
GetPlayerName(playerid,PlayerName,25);
format(Query,sizeof(Query),"SELECT * FROM `users` WHERE name='%s'",PlayerName);
mysql_function_query(MysqlC,Query,true,"r@MySQL_LoadAccount","d",playerid);
return 1;
}
public r@MySQL_LoadAccount(playerid){
new rows,fields;
cache_get_data(rows,fields,MysqlC);
if(rows){
cache_get_field_content(0,"level",Query,MysqlC);
PlayerInfo[playerid][pLevel] = strval(Query);
cache_get_field_content(0,"money",Query,MysqlC);
PlayerInfo[playerid][pMoney] = strval(Query);
cache_get_field_content(0,"bank",Query,MysqlC);
PlayerInfo[playerid][pBank] = strval(Query);
cache_get_field_content(0,"skin",Query,MysqlC);
PlayerInfo[playerid][pSkin] = strval(Query);
PlayerSpawn(playerid);
}
else
SendClientMessage(playerid,-1,"Houve um erro com a sua conta"),Kick(playerid);
return 1;
}
public PlayerSpawn(playerid){
SpawnPlayer(playerid);
GivePlayerMoney(playerid,PlayerInfo[playerid][pMoney]);
SetPlayerScore(playerid,PlayerInfo[playerid][pLevel]);
SetPlayerSkin(playerid,PlayerInfo[playerid][pSkin]);
SetPlayerPos(playerid, 2257.1907, -88.5199, 26.4844);
SendClientMessage(playerid,-1,"Seja bem vindo!");
return 1;
}
public MySQL_SaveAccount(playerid){
GetPlayerName(playerid,PlayerName,25);
format(Query,sizeof(Query),"UPDATE `users` SET level='%d',money='%d',bank='%d',skin='%d' WHERE name='%s'",PlayerInfo[playerid][pLevel],PlayerInfo[playerid][pMoney],PlayerInfo[playerid][pBank],PlayerInfo[playerid][pSkin],PlayerName);
mysql_function_query(MysqlC,Query,false,"r@MySQL_SaveAccount","d",playerid);
return 1;
}
public r@MySQL_SaveAccount(playerid)
return printf("Conta %d salva com sucesso.",playerid);
Код:
echo Executing Server Config... lanmode 0 rcon_password 963 maxplayers 50 port 3306 hostname Adventure gamemode0 Adventure filterscripts plugins mysql.dll sscanf.dll streamer.dll announce 0 query 1 chatlogging 0 weburl www.sa-mp.com onfoot_rate 40 incar_rate 40 weapon_rate 40 stream_distance 300.0 stream_rate 1000 maxnpc 0 logtimeformat [%H:%M:%S]