08.01.2015, 11:38
Hey
I need help for account system.
This is the code:
This is mysql_log:
When I compile all is right, but when I connect to the server the code isn't work, just open the registration dialog.
I type the password all is right but in database it's not created the table.
The prise if anyone help me: REP +
Sorry for my bad english.
I need help for account system.
This is the code:
pawn Код:
#define mysql_host "127.0.0.1"
#define mysql_user "root"
#define mysql_password "r00t"
#define mysql_database "samp"
//--Dialogs
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
//-----Enums
enum pInfo {
pID, pLogged, pPassword, pLanguage, pMoney, pXP, pTotalXP, pLevel,
pVIPLevel, pAdminLevel, pKills, pDeaths, pMuted, pMuteTime, pMuteReason, pFreezed,
pFreezeTime, pFreezeReason, pJailed, pJailTime, pJailReason, pBanned, pBanTime, pBanReason,
pWarns, pWarnReason1, pWarnReason2, pWarnReason3, pWarnReason4, pWarnReason5
}
enum sInfo {
}
//-----News
new mysql_handle, PlayerIP[MAX_PLAYERS][16], LAttempts[MAX_PLAYERS];
new PlayerInfo[MAX_PLAYERS][pInfo];
new ServerInfo[MAX_PLAYERS][sInfo];
main() {
}
//-----The GameMode
public OnGameModeInit() {
SetGameModeText("BGEdition 0.1");
mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
mysql_handle = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
if(mysql_errno(mysql_handle) != 0) print("[ERROR]: Could not connect to database!");
return 1;
}
public OnGameModeExit() {
mysql_close(mysql_handle);
return 1;
}
public OnPlayerConnect(playerid) {
new Query[300], Rows, Fields, string[300];
GetPlayerIp(playerid, PlayerIP[playerid], 16);
mysql_format(mysql_handle, Query, sizeof(Query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", GetPName(playerid));
if(Rows) {
cache_get_field_content(0, "Password", PlayerInfo[playerid][pPassword], mysql_handle, 129);
PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}5 {FFFFFF}attempts to type corect password.", GetPName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
} else {
format(string, sizeof(string), "{FFFFFF}Welcome {2098AE}%s {FFFFFF}!\nType password below into the input to register!\nThe password must to be 5 to 30 characters long!", GetPName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, 3, "{FFFF00}Registering:", string, "Register", "Cacnel");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason) {
new IsLogged[5] = "No";
PlayerInfo[playerid][pLogged] = strval(IsLogged);
OnPlayerSave(playerid);
return 1;
}
public OnPlayerLoad(playerid) {
cache_get_field_content(0, "Logged", PlayerInfo[playerid][pLogged]);
cache_get_field_content(0, "Language", PlayerInfo[playerid][pLanguage]);
PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "Money");
PlayerInfo[playerid][pXP] = cache_get_field_content_int(0, "XP");
PlayerInfo[playerid][pTotalXP] = cache_get_field_content_int(0, "Total XP");
PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0, "Level");
PlayerInfo[playerid][pVIPLevel] = cache_get_field_content_int(0, "VIP Level");
PlayerInfo[playerid][pAdminLevel] = cache_get_field_content_int(0, "Admin Level");
PlayerInfo[playerid][pKills] = cache_get_field_content_int(0, "Kills");
PlayerInfo[playerid][pDeaths] = cache_get_field_content_int(0, "Deaths");
cache_get_field_content(0, "Muted", PlayerInfo[playerid][pMuted]);
cache_get_field_content(0, "Mute TimeStamp", PlayerInfo[playerid][pMuteTime]);
cache_get_field_content(0, "Mute Reason", PlayerInfo[playerid][pMuteReason]);
cache_get_field_content(0, "Freezed", PlayerInfo[playerid][pFreezed]);
cache_get_field_content(0, "Freeze TimeStamp", PlayerInfo[playerid][pFreezeTime]);
cache_get_field_content(0, "Freeze Reason", PlayerInfo[playerid][pFreezeReason]);
cache_get_field_content(0, "Jailed", PlayerInfo[playerid][pJailed]);
cache_get_field_content(0, "Jail TimeStamp", PlayerInfo[playerid][pJailTime]);
cache_get_field_content(0, "Jail Reason", PlayerInfo[playerid][pJailReason]);
cache_get_field_content(0, "Banned", PlayerInfo[playerid][pBanned]);
cache_get_field_content(0, "Ban TimeStamp", PlayerInfo[playerid][pBanTime]);
cache_get_field_content(0, "Ban Reason", PlayerInfo[playerid][pBanReason]);
PlayerInfo[playerid][pWarns] = cache_get_field_content_int(0, "Warns");
cache_get_field_content(0, "Warn Reason 1", PlayerInfo[playerid][pWarnReason1]);
cache_get_field_content(0, "Warn Reason 2", PlayerInfo[playerid][pWarnReason2]);
cache_get_field_content(0, "Warn Reason 3", PlayerInfo[playerid][pWarnReason3]);
cache_get_field_content(0, "Warn Reason 4", PlayerInfo[playerid][pWarnReason4]);
cache_get_field_content(0, "Warn Reason 5", PlayerInfo[playerid][pWarnReason5]);
GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
SendClientMessage(playerid, COLOR_GREEN, "[SERVER]: You are successfully logged in. Have fun!");
LAttempts[playerid] = 0;
return 1;
}
public OnPlayerSave(playerid) {
new Query[500], string[500];
format(string, sizeof(string), "UPDATE `players` SET `Language` = %s, `Money` = %d, `XP` = %d, `Total XP` = %d, `Level` = %d, `VIP Level` = %d, `Admin Level` = %d, `Kills` = %d, `Deaths` = %d");
strcat(string, "`Muted` = %s, `Mute TimeStamp` = %s, `Mute Reason` = %s, `Freezed` = %s, `Freeze TimeStamp` = %s, `Freeze Reason` = %s, `Jailed` = %s, `Jail TimeStamp` = %s, `Jail Reason` = %s");
strcat(string, "`Banned` = %s, `Ban TimeStamp` = %s, `Ban Reason` = %s, `Warns` = %d, `Warn Reason 1` = %s, `Warn Reason 2` = %s, `Warn Reason 3` = %s, `Warn Reason 4` = %s, `Warn Reason 5` = %s");
mysql_format(mysql_handle, Query, sizeof(Query), string,
PlayerInfo[playerid][pLanguage], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pXP], PlayerInfo[playerid][pTotalXP], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pVIPLevel], PlayerInfo[playerid][pAdminLevel], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths],
PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pMuteTime], PlayerInfo[playerid][pMuteReason], PlayerInfo[playerid][pFreezed], PlayerInfo[playerid][pFreezeTime], PlayerInfo[playerid][pFreezeReason], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pJailTime], PlayerInfo[playerid][pJailReason],
PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pBanTime], PlayerInfo[playerid][pBanReason], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pWarnReason1], PlayerInfo[playerid][pWarnReason2], PlayerInfo[playerid][pWarnReason3], PlayerInfo[playerid][pWarnReason4], PlayerInfo[playerid][pWarnReason5]);
return 1;
}
public OnPlayerSpawn(playerid) {
return 1;
}
public OnPlayerDeath(playerid, killerid, reason) {
return 1;
}
//-----Commands
public OnPlayerText(playerid, text[]) {
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[]) {
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate) {
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if(dialogid == DIALOG_LOGIN) {
if(response) {
new Query[300], string[300];
if(Hash(inputtext) == PlayerInfo[playerid][pPassword]) {
mysql_format(mysql_handle, Query, sizeof(Query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", GetPName(playerid));
mysql_tquery(mysql_handle, Query, "OnPlayerLoad", "i", playerid);
} else {
LAttempts[playerid] += 1;
if(LAttempts[playerid] == 1) {
format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}4 {FFFFFF}attempts to type corect password.", GetPName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
} else if(LAttempts[playerid] == 2) {
format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}3 {FFFFFF}attempts to type corect password.", GetPName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
} else if(LAttempts[playerid] == 3) {
format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}2 {FFFFFF}attempts to type corect password.", GetPName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
} else if(LAttempts[playerid] == 4) {
format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nThis is your {FF0000}final {FFFFFF}attempt to type corect password.", GetPName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
} else if(LAttempts[playerid] == 5) {
Kick(playerid);
}
}
} else {
Kick(playerid);
}
}
if(dialogid == DIALOG_REGISTER) {
if(response) {
new Query[300], string[300];
if(strlen(inputtext) > 5 && strlen(inputtext) < 30) {
mysql_format(mysql_handle, Query, sizeof(Query), "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES (`%e`, `%s`, `%s`)", GetPName(playerid), Hash(inputtext), PlayerIP[playerid]);
SendClientMessage(playerid, COLOR_GREEN, "[SERVER]: You are successfully registered. Have fun!");
PlayerInfo[playerid][pID] = cache_insert_id();
} else {
SendClientMessage(playerid, COLOR_ORANGE, "[WARNING]: Your password needs to be 5 to 30 characters long.");
format(string, sizeof(string), "{FFFFFF}Welcome {2098AE}%s {FFFFFF}!\nType password below into the input to register!\nThe password must to be 5 to 30 characters long!", GetPName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, 3, "{FFFF00}Registering:", string, "Register", "Cacnel");
}
} else {
Kick(playerid);
}
}
return 1;
}
Код:
[21:32:53] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "samp", password: "****", port: 3306, autoreconnect: true, pool_size: 2 [21:32:53] [DEBUG] CMySQLHandle::Create - creating new connection.. [21:32:53] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called [21:32:53] [DEBUG] CMySQLHandle::Create - connection created (id: 1) [21:32:53] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [21:32:53] [DEBUG] CMySQLConnection::Connect - connection was successful [21:32:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [21:32:53] [DEBUG] mysql_errno - connection: 1 [21:32:53] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [21:32:53] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [21:32:53] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [21:32:53] [DEBUG] CMySQLConnection::Connect - connection was successful [21:32:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [21:32:53] [DEBUG] CMySQLConnection::Connect - connection was successful [21:32:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [21:32:53] [DEBUG] CMySQLConnection::Connect - connection was successful [21:32:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [21:33:13] [DEBUG] mysql_format - connection: 1, len: 300, format: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1" [21:33:17] [DEBUG] mysql_format - connection: 1, len: 300, format: "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES (`%e`, `%s`, `%s`)" [21:33:17] [DEBUG] cache_insert_id - connection: 1 [21:33:17] [WARNING] cache_insert_id - no active cache [21:33:26] [DEBUG] mysql_format - connection: 1, len: 500, format: "UPDATE `players` SET `Language` = , `Money` = , `XP` = , `Total XP` = , `Level` = , `VIP Level` = , `Admin Level` = , `Kills` = ..." [21:33:30] [DEBUG] mysql_close - connection: 1 [21:33:30] [DEBUG] CMySQLConnection::Disconnect - connection was closed [21:33:30] [DEBUG] CMySQLConnection::Disconnect - connection was closed [21:33:30] [DEBUG] CMySQLConnection::Disconnect - connection was closed [21:33:30] [DEBUG] CMySQLHandle::~CMySQLHandle - deconstructor called
I type the password all is right but in database it's not created the table.
The prise if anyone help me: REP +
Sorry for my bad english.