pawn Код:
#include <a_samp>#include <a_mysql>#define MySQL_HOST "<censored>"#define MySQL_USER "<censored>"#define MySQL_DB "<censored>"#define MySQL_PASS "<censored>"#define Grey "{6B6868}"#define White "{FFFBFF}" // Normal Chat.#define Pink "{FFBDC0}" // OOC Chat.#define BRed "{FF0000}" // Error Messages.#define Red "{FF3F40}" // Shout.#define Orange "{FF7E40}" // Emote Commands.#define Yellow "{FFFB00}" // System Messages & Achievement#define LGreen "{40FB40}" // Server Announcements & "Success" Messages.#define Green "{40FB40}" // Group Chat.#define DGreen "{40BD4C}" // Group Announcements.#define DDGreen "{00A700}" // Items.#define SBlue "{00FBF6}" // PMs#define Blue "{5554FF}" // Skill-ups#define KBlue "{6F6DFF}" // Experience Gains.#define GBlue "{AAA7FF}" // Help Chat.#define Purple "{FF7EFF}" // Whisper Chat#undef MAX_PLAYERS#define MAX_PLAYERS 50enum PlayerInformation
{ NickName
[255],
Password
[255],
Email
[255],
RoleplayName
[255],
LoggedOn,
LogOnAttempt,
Tutorial,
Experience,
Level
}new Player
[MAX_PLAYERS
][PlayerInformation
];
public OnGameModeInit
(){ ConnectMySQL
();
return 1;
}public OnPlayerConnect
(playerid
){ new str
[128], GetName
[MAX_PLAYER_NAME
];
GetPlayerName
(playerid, GetName,
sizeof(GetName
));
if(CheckAccountExists
(GetName
) >= 1) { LoadPlayerData
(playerid
);
Player
[playerid
][LoggedOn
] = 0;
SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); format(str,
128,
""#Yellow"Welcome to Trinty Trucking! Please wait while we load your account.", GetName); SendClientMessage
(playerid,
-1, str
);
SendClientMessage
(playerid,
-1,
""#Yellow"You will need to type in your password below to continue."); SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); ShowPlayerDialog
(playerid,
0, DIALOG_STYLE_INPUT,
"Login",
""#Yellow"Welcome back to Trinty Trucking! Please wait while we load your account.\n\n You will need to type in your password below to continue.", "Login", "Help"); TogglePlayerControllable
(playerid,
0);
} if(CheckAccountExists
(GetName
) == 0) { ResetPlayerData
(playerid
);
format(Player
[playerid
][NickName
],
255,
"%s", GetName
);
Player
[playerid
][LoggedOn
] = 0;
Player
[playerid
][Tutorial
] = 0;
SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); format(str,
128,
""#Yellow"Welcome to Trinty Trucking! Please wait while we load your account into our database!", GetName); SendClientMessage
(playerid,
-1, str
);
SendClientMessage
(playerid,
-1,
""#Yellow"You will need to type in your desired password below to continue."); SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); ShowPlayerDialog
(playerid,
1, DIALOG_STYLE_INPUT,
"Registration",
""#Yellow"Welcome to Trinty Trucking! Please wait while we load your account into our database!\n\n You will need to type in your desired password below to continue.", "Continue", "Help"); TogglePlayerControllable
(playerid,
0);
} return 1;
}public OnPlayerDisconnect
(playerid, reason
){ if(Player
[playerid
][LoggedOn
] == 1) { Player
[playerid
][LoggedOn
] = 0;
LogPlayerOut
(playerid
);
} return 1;
}public OnDialogResponse
(playerid, dialogid, response, listitem, inputtext
[]){ new str
[128];
if(dialogid
== 0) { if(!response
) return Kick
(playerid
);
if(response
) { if(strlen(inputtext
) != Player
[playerid
][Password
]) { if(Player
[playerid
][LogOnAttempt
] == 3) { Kick
(playerid
);
Player
[playerid
][LogOnAttempt
] = 0;
} if(Player
[playerid
][LogOnAttempt
] == 2) { SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); SendClientMessage
(playerid,
-1,
""#BRed"I'm sorry, you have one more try before you are kicked."#Yellow" Please try again."); SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); Player
[playerid
][LogOnAttempt
] = 3;
ShowPlayerDialog
(playerid,
0, DIALOG_STYLE_INPUT,
"Login",
""#Yellow"Welcome back to Trinty Trucking "#Orange"%s!"#Yellow"Please wait while we load your account.\n\n You will need to type in your password below to continue.", "Login", "Help"); } if(Player
[playerid
][LogOnAttempt
] == 1) { SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); SendClientMessage
(playerid,
-1,
""#BRed"I'm sorry, that was still the wrong password."#Yellow" Please try again."); SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); Player
[playerid
][LogOnAttempt
] = 2;
ShowPlayerDialog
(playerid,
0, DIALOG_STYLE_INPUT,
"Login",
""#Yellow"Welcome back to Trinty Trucking "#Orange"%s!"#Yellow"Please wait while we load your account.\n\n You will need to type in your password below to continue.", "Login", "Help"); } if(Player
[playerid
][LogOnAttempt
] == 0) { SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); SendClientMessage
(playerid,
-1,
""#BRed"I'm sorry, that was the wrong password."#Yellow" Please try again."); SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); Player
[playerid
][LogOnAttempt
] = 1;
ShowPlayerDialog
(playerid,
0, DIALOG_STYLE_INPUT,
"Login",
""#Yellow"Welcome back to Trinty Trucking "#Orange"%s!"#Yellow"Please wait while we load your account.\n\n You will need to type in your password below to continue.", "Login", "Help"); } } else { SpawnPlayerEx
(playerid
);
Player
[playerid
][LoggedOn
] = 1;
TogglePlayerControllable
(playerid,
1);
SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); SendClientMessage
(playerid,
-1,
""#Yellow"Welcome back to "#Orange"Trinity Trucking"#Yellow"!"); format(str,
128,
""#Yellow"|| Player Statistics:: Nick Name: %s | Password: %s | Roleplay Name: %s | Level: %s | Experience: %s ||", Player[playerid][NickName], Player[playerid][Password], Player[playerid][RoleplayName], Player[playerid][Level], Player[playerid][Experience]); SendClientMessage
(playerid,
-1, str
);
SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); Player
[playerid
][LogOnAttempt
] = 0;
} } } if(dialogid
== 1) { if(!response
) return ShowPlayerDialog
(playerid,
1, DIALOG_STYLE_INPUT,
"Registration",
""#Yellow"Welcome to Trinty Trucking "#Orange"%s!"#Yellow"Please wait while we load your account into our database!/n/n You will need to type in your desired password below to continue.", "Register", "Help"); if(strlen(inputtext
) < 3 ||
strlen(inputtext
) >= 32) { SendClientMessage
(playerid,
-1,
""#BRed"Your password is too short or too long!"#Yellow" It must be between 3 and 32 characters."); } if(response
) { Player
[playerid
][Tutorial
] = 1;
Player
[playerid
][LoggedOn
] = 1;
format(Player
[playerid
][Password
],
255,
"%s", inputtext
);
SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); format(str,
128,
""#Yellow"Okay "#Orange"%s"#Yellow", your new password is "#Orange"%s"#Yellow"! Now we need to know your email address (if you have one).", Player[playerid][NickName], inputtext); SendClientMessage
(playerid,
-1, str
);
SendClientMessage
(playerid,
-1,
""#Yellow"*Note* We only use your email address to confirm the account is yours when you lose or forget your password."); SendClientMessage
(playerid,
-1,
""#Yellow"If you do not have an email address, type Idonot@haveanemail.com or whatever to trick the script."); SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); ShowPlayerDialog
(playerid,
2, DIALOG_STYLE_INPUT,
"Registration",
""#Yellow"Now we need your email address.\n\n*Note* We use your email address to confirm the account is yours when you lose or forget your password.\n\n If you do not have an email address, type Idonot@haveanemail.com or whatever to trick the script.", "Register", "Help"); } } if(dialogid
== 2) { if(!response
) return ShowPlayerDialog
(playerid,
2, DIALOG_STYLE_INPUT,
"Registration",
""#Yellow"Now we need your email address.\n\n*Note* We use your email address to confirm the account is yours when you lose or forget your password.\n\n If you do not have an email address, type Idonot@haveanemail.com or whatever to trick the script.", "Register", "Help"); if(response
) { if(strfind(inputtext,
"@",true
)!= -1 && strfind(inputtext,
".",true
)!= -1) { Player
[playerid
][Tutorial
] = 2;
format(Player
[playerid
][Email
],
255,
"%s", inputtext
);
SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); format(str,
128,
""#Yellow"Okay your password, "#Orange"%s"#Yellow", is now linked to the email "#Orange"%s.", Player[playerid][Password], inputtext); SendClientMessage
(playerid,
-1, str
);
SendClientMessage
(playerid,
-1,
""#Yellow"*Note* We only use your email address to confirm the account is yours when you lose or forget your password."); SendClientMessage
(playerid,
-1,
""#Yellow"Would you like to endure our server tutorial?"); SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); SpawnPlayerEx
(playerid
);
} else { SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); SendClientMessage
(playerid,
-1,
""#BRed"That is an invalid email address."#Yellow" Please give us a valid email address so if you password is lost or stolen we can recover it securely."); SendClientMessage
(playerid,
-1,
""#Grey"-----------------------------------------------------------------------------------------------------------------"); ShowPlayerDialog
(playerid,
2, DIALOG_STYLE_INPUT,
"Registration",
""#Yellow"Now we need your email address.\n\n*Note* We use your email address to confirm the account is yours when you lose or forget your password.\n\n If you do not have an email address, type Idonot@haveanemail.com or whatever to trick the script.", "Register", "Help"); } } } return 1;
}ConnectMySQL
(){ if(mysql_connect
(MySQL_HOST, MySQL_USER, MySQL_DB, MySQL_PASS
)) { mysql_debug
(1);
print("[MySQL] Connection to the MySQL Database was successful!");
} else { print("[MySQL] Could not connect to the MySQL Database.");
}}CheckMySQL
(){ if(mysql_ping
() == -1) { mysql_connect
(MySQL_HOST, MySQL_USER, MySQL_DB, MySQL_PASS
);
}}CheckAccountExists
(account
[]){ new string
[128];
format(string,
sizeof(string
),
"SELECT * FROM accounts WHERE NickName = '%s'", account
);
mysql_query
(string
);
mysql_store_result
();
new value;
value
= mysql_num_rows
();
mysql_free_result
();
return value;
}// Created by Westieexplode
(const sSource
[], aExplode
[][],
const sDelimiter
[] = " ", iVertices
= sizeof aExplode, iLength
= sizeof aExplode
[]){ new iNode, iPointer, iPrevious
= -1, iDelimiter
= strlen(sDelimiter
);
while(iNode
< iVertices
) { iPointer
= strfind(sSource, sDelimiter, false, iPointer
);
if(iPointer
== -1) { strmid(aExplode
[iNode
], sSource, iPrevious,
strlen(sSource
), iLength
);
break;
} else { strmid(aExplode
[iNode
], sSource, iPrevious, iPointer, iLength
);
} iPrevious
= (iPointer
+= iDelimiter
);
++iNode;
} return iPrevious;
}stock ResetPlayerData
(playerid
){ new GetName
[MAX_PLAYER_NAME
];
GetPlayerName
(playerid, GetName,
sizeof(GetName
));
CheckMySQL
();
new string
[128];
format(string,
sizeof(string
),
"INSERT INTO accounts (NickName,Password,Email,RoleplayName,LoggedOn,LogOnAttempt,Tutorial,Experience,Level) VALUES ('%s','%s','%s','%s','%d','%d','%d','%d','%d')", GetName, Player
[playerid
][Password
], Player
[playerid
][Email
], Player
[playerid
][RoleplayName
], Player
[playerid
][LoggedOn
], Player
[playerid
][LogOnAttempt
], Player
[playerid
][Tutorial
], Player
[playerid
][Experience
], Player
[playerid
][Level
]);
mysql_query
(string
);
return 1;
}stock LoadPlayerData
(playerid
){ new GetName
[MAX_PLAYER_NAME
];
GetPlayerName
(playerid, GetName,
sizeof(GetName
));
CheckMySQL
();
new string
[128];
format(string,
sizeof(string
),
"SELECT * FROM accounts WHERE NickName = '%s'", GetName
);
mysql_query
(string
);
mysql_store_result
();
new row
[128];
new field
[9][32];
mysql_fetch_row_format
(row,
"|");
explode
(row, field,
"|");
mysql_free_result
();
format(Player
[playerid
][Password
],
32,
"%s", field
[1]);
format(Player
[playerid
][Email
],
32,
"%s", field
[2]);
format(Player
[playerid
][RoleplayName
],
24,
"%s", field
[3]);
Player
[playerid
][LoggedOn
] = strval(field
[4]);
Player
[playerid
][LogOnAttempt
] = strval(field
[5]);
Player
[playerid
][Tutorial
] = strval(field
[6]);
Player
[playerid
][Experience
] = strval(field
[7]);
Player
[playerid
][Level
] = strval(field
[8]);
return 1;
}stock SpawnPlayerEx
(playerid
){ LoadPlayerData
(playerid
);
return 1;
}stock LogPlayerOut
(playerid
){ if(Player
[playerid
][LoggedOn
] == 1) { new GetName
[MAX_PLAYER_NAME
];
GetPlayerName
(playerid, GetName,
sizeof(GetName
));
CheckMySQL
();
new string
[256];
format(string,
sizeof(string
),
"UPDATE Accounts SET Password='%s',Email='%s',RoleplayName='%s',LoggedOn='%d',LogOnAttempt='%d',Tutorial='%d',Experience='%d',Level='%d' WHERE NickName='%s'", Player
[playerid
][Password
], Player
[playerid
][Email
], Player
[playerid
][RoleplayName
], Player
[playerid
][LoggedOn
], Player
[playerid
][LogOnAttempt
], Player
[playerid
][Tutorial
], Player
[playerid
][Experience
], Player
[playerid
][Level
], GetName
);
mysql_query
(string
);
} return 1;
}
Can someone who knows MySQL tell me why when I log out, this isn't working?
LOL I fkin fail, when player logs out I made it check if player was logged on if so it would set the logon thingy to 0 and then run a command that ALSO checks if the player is logged on... FAIL