Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- .--. .-.
- : .--' : :
- `. `. .---. : `-. .--. .-.,-.
- _`, :: .; `: .. :' '_.'`. .'
- `.__.': ._.':_;:_;`.__.':_,._;
- : :
- :_;
- spRegister by Sphex
- Creation Date: 12/04/2012 20:48
- Version: 0.1
- */
- // =-=-= [ Includes ] =-=-=
- #include <a_samp>
- #include <a_mysql>
- // =-=-= [ Defines ] =-=-=
- // General
- #define VERSION "0.1"
- #define GN GetName(playerid)
- // SQL
- #define sql_host "localhost" // change to your host
- #define sql_user "root" // change to your username
- #define sql_pass "" // change to your password
- #define sql_db "spregister" // change to your db name
- // Dialogs
- #define DIALOG_MSG 900 // change if the id already exists
- #define DIALOG_REGISTER 901 // change if the id already exists
- #define DIALOG_LOGIN 902 // change if the id already exists
- // Dialog Colors
- #define DIALOG_GOLD "{B8860A}"
- #define DIALOG_GREEN "{33AA33}"
- #define DIALOG_YELLOW "{FFFF00}"
- #define DIALOG_RED "{AA3333}"
- #define DIALOG_LIGHTBLUE "{33CCFF}"
- // =-=-= [ Vars ] =-=-=
- new str[128], query[300];
- // =-=-= [ Publics ] =-=-=
- public OnFilterScriptInit() {
- print("\n\t____________________________________");
- printf("\n\t__________ spRegister V%s _________", VERSION);
- print("\n\t____________________________________\n");
- mysql_debug(1);
- mysql_connect(sql_host, sql_user, sql_db, sql_pass);
- mysql_query("CREATE TABLE IF NOT EXISTS users(id INT NULL AUTO_INCREMENT, username VARCHAR(50), password VARCHAR(250), PRIMARY KEY(id))");
- return 1;
- }
- public OnPlayerConnect(playerid) {
- format(str, sizeof(str), "[spRegister V%s] This server uses a registration system built by Sphex.", VERSION);
- SendClientMessage(playerid, 0xFFFF00AA, str);
- format(query, sizeof(query), "SELECT id FROM users WHERE username='%s'", GN);
- mysql_query(query);
- mysql_store_result();
- if (mysql_num_rows() == 0) { // not registered
- format(str, sizeof(str), ""DIALOG_YELLOW"Welcome %s!"DIALOG_LIGHTBLUE"\nPlease type in a password to register:", GN);
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""DIALOG_GOLD"Registration", str, "Register", "Cancel");
- } else { // registered
- format(str, sizeof(str), ""DIALOG_YELLOW"Welcome %s!"DIALOG_LIGHTBLUE"\nPlease type in a password to login:", GN);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""DIALOG_GOLD"Login", str, "Login", "Cancel");
- }
- mysql_free_result();
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- if (dialogid == DIALOG_REGISTER) {
- if (!response) return Kick(playerid);
- if (!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""DIALOG_GOLD"Registration", ""DIALOG_RED"Please type in a password!\n"DIALOG_LIGHTBLUE"Please type in a password to register:", "Register", "Cancel");
- format(query, sizeof(query), "INSERT INTO users VALUES(NULL, '%s', '%d')", GN, udb_hash(inputtext));
- mysql_query(query);
- mysql_free_result();
- return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""DIALOG_GOLD"Login", ""DIALOG_GREEN"You have been successfully registered!\n"DIALOG_LIGHTBLUE"Please type in a password to login:", "Login", "Cancel");
- }
- if (dialogid == DIALOG_LOGIN) {
- if (!response) return Kick(playerid);
- if (!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""DIALOG_GOLD"Login", ""DIALOG_RED"Please type in a password!\n"DIALOG_LIGHTBLUE"Please type in a password to login:", "Login", "Cancel");
- format(query, sizeof(query), "SELECT id FROM users WHERE password='%d' AND username='%s'", udb_hash(inputtext), GN);
- mysql_query(query);
- mysql_store_result();
- if (mysql_num_rows() == 0) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""DIALOG_GOLD"Login", ""DIALOG_RED"The password you've entered is invalid!\n"DIALOG_LIGHTBLUE"Please type in a password to login:", "Login", "Cancel");
- mysql_free_result();
- return ShowPlayerDialog(playerid, DIALOG_MSG, DIALOG_STYLE_MSGBOX, ""DIALOG_GOLD"Login", ""DIALOG_GREEN"You have been successfully logged in!", "Okay", "");
- }
- return 0;
- }
- // =-=-= [ Stocks ] =-=-=
- stock GetName(playerid) {
- new pname[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pname, sizeof(pname));
- return pname;
- }
- stock udb_hash(buf[]) { //Credits to Dracoblue
- new length=strlen(buf);
- new s1 = 1;
- new s2 = 0;
- new n;
- for (n=0; n<length; n++)
- {
- s1 = (s1 + buf[n]) % 65521;
- s2 = (s2 + s1) % 65521;
- }
- return (s2 << 16) + s1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement