Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //################################################//
- #if defined MySQLRegLog
- @ Register & Login System
- @ Released: 28/07/2019/
- @ Author: Itz.Yansi42O / MySQL
- #endif
- //################################################//
- #include "a_samp"
- #include "a_mysql"
- #include "YSI\y_timers"
- //################################################//
- #undef MAX_PLAYERS
- const MAX_PLAYERS = 200;
- #define func:%0(%1) forward%0(%1); public%0(%1)
- //################################################//
- #define MYSQL_HOST "localhost"
- #define MYSQL_USER "root"
- #define MYSQL_PW ""
- #define MYSQL_DB "reglog_db"
- new MySQL:SQL, yQuery[500], yString[500];
- //################################################//
- #define srwboja "{E76004}"
- #define BELA "{FFFFFF}"
- #define Info(%0,%1) \
- SendClientMessageEx(%0, 0xE76004FF, "[MySQL RegLog]: "BELA""%1)
- stock SendClientMessageEx(playerid, colour, const fmat[], va_args<>) {
- new str[145];
- va_format(str, sizeof (str), fmat, va_start<3>);
- return SendClientMessage(playerid, colour, str);
- }
- //################################################//
- enum PLAYER_ENUM {
- pName[24],
- pSQLID,
- pLozinka[24],
- pDrzava,
- pEmail[128],
- pGodine,
- pSpol,
- pNovac,
- pSkin,
- pLevel
- }
- new PI[MAX_PLAYERS][PLAYER_ENUM];
- enum {
- dialog_REGISTER,
- dialog_DRZAVA,
- dialog_EMAIL,
- dialog_SPOL,
- dialog_GODINE,
- dialog_LOGIN
- }
- //################################################//
- main() {
- print("Mod je uspesno ucitan !");
- }
- func: OnGameModeInit() {
- SQL = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PW, MYSQL_DB);
- if (mysql_errno() != 0) {
- print(" * MYSQL ERROR: Nije se moguce konektovati na databazu.");
- return 0;
- }
- else print(" * MYSQL INFO: Konekcija na databazu je uspijesna.");
- SetGameModeText("@ VP > v1.0 > Yansi");
- EnableStuntBonusForAll(0);
- DisableInteriorEnterExits();
- mysql_tquery(SQL, "CREATE TABLE IF NOT EXISTS `users` (\
- `ID` int(11) NOT NULL,\
- `Name` varchar(24) NOT NULL DEFAULT 'none',\
- `Lozinka` varchar(24) NOT NULL DEFAULT 'none',\
- `Email` varchar(128) NOT NULL DEFAULT 'none',\
- `Drzava` int(11) NOT NULL DEFAULT 0,\
- `Godine` int(11) NOT NULL DEFAULT 0,\
- `Skin` int(11) NOT NULL DEFAULT 19,\
- `Level` int(11) NOT NULL DEFAULT 3,\
- `Novac` int(11) NOT NULL DEFAULT 150000,\
- `Spol` int(11) NOT NULL DEFAULT 0\
- )");
- return 1;
- }
- //################################################//
- func: OnPlayerConnect(playerid) {
- yQuery[0] = (EOS);
- mysql_format(SQL, yQuery, sizeof(yQuery), "SELECT * FROM `users` WHERE `Name` = '%e' LIMIT 1", GetName(playerid));
- mysql_pquery(SQL, yQuery, "CheckPlayerAccount", "d", "");
- TogglePlayerSpectating(playerid, false);
- return 1;
- }
- //################################################//
- func: CheckPlayerAccount(playerid) {
- switch(cache_num_rows()) {
- case 0: {
- //camera position move to spawn..
- InterpolateCameraPos(playerid, 537.2963, -995.1501, 124.7903, 1373.3412, -2283.9702, 65.2952, 10000, 30000);
- InterpolateCameraLookAt(playerid, 538.1735, -995.6352, 124.6076, 1374.3429, -2283.9468, 64.7175, 10000, 30000);
- yString[0] = (EOS);
- format(yString, sizeof(yString), \
- ""srwboja"> "BELA"Dobrodosao '%s' na 'Ime Servera'!\n\
- "srwboja"____________________________________\n\
- "srwboja"> "BELA"Vas nalog nije pronadjen u bazi!\n\
- "srwboja"> "BELA"Da biste nastavili igru potrebno je da se registrujete!\n\
- "srwboja"> "BELA"Da bi se registrovali potrebno je da uneste lozinku!\n\
- "srwboja"____________________________________\n\
- "BELA"> "srwboja"Ime Servera "BELA" - "srwboja"SINCE 2019", GetName(playerid));
- ShowPlayerDialog(playerid, dialog_REGISTER, DIALOG_STYLE_INPUT,
- ""srwboja"VP - "BELA"Registracija", yString,
- ""srwboja"UNESI", "KICK");
- }
- case 1: {
- //camera position move to spawn..
- InterpolateCameraPos(playerid, 537.2963, -995.1501, 124.7903, 1373.3412, -2283.9702, 65.2952, 10000, 30000);
- InterpolateCameraLookAt(playerid, 538.1735, -995.6352, 124.6076, 1374.3429, -2283.9468, 64.7175, 10000, 30000);
- //login dialog
- format(yString, sizeof(yString), ""srwboja"> "BELA"Dobrodosao %s na 'Ime Servera'\n"srwboja"___________________________________________________________________ \
- \n> "BELA"Vas account je pronadjen u nasoj bazi podataka..\n"srwboja"> "BELA"Molimo ulogujte se, unesite tacnu sifru ispod\n \
- "srwboja"___________________________________________________________________",
- GetName(playerid));
- ShowPlayerDialog(playerid, dialog_LOGIN, DIALOG_STYLE_PASSWORD, ""srwboja"VP - "BELA"Prijavljivanje", yString, ""srwboja"UNESI", "IZLAZ");
- }
- }
- return 1;
- }
- //################################################//
- stock GetName(playerid) {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- //################################################//
- func: CheckSQLID(playerid) {
- PI[playerid][pSQLID] = cache_insert_id();
- printf("(MYSQl REGISTER): Novi account kreiran ! Ime: %s | ID: %d", GetName(playerid), playerid);
- return 1;
- }
- //################################################//
- func: OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- if(dialogid == dialog_REGISTER) {
- if(!response)
- return Kick(playerid);
- yString[0] = (EOS);
- format(PI[playerid][pName], 24, GetName(playerid));
- format(PI[playerid][pLozinka], 128, inputtext);
- yQuery[0] = (EOS);
- mysql_format(SQL, yQuery, sizeof(yQuery), "INSERT INTO `users` (Name, Lozinka) VALUES ('%e', '%e')", GetName(playerid), inputtext);
- mysql_tquery(SQL, yQuery, "CheckSQLID", "");
- ShowPlayerDialog(playerid, dialog_DRZAVA, DIALOG_STYLE_LIST,
- ""srwboja"VP - "BELA"Drzava",
- ""srwboja"[1]. "BELA"Srbija\n"srwboja"[2]. "BELA"Hrvatska\n"srwboja"[3]. "BELA"BiH\n"srwboja"[4]. "BELA"Crna Gora\n"srwboja"[5]. "BELA"Ostalo\n",
- ""srwboja"ODABERI", "KICK");
- }
- if(dialogid == dialog_EMAIL) {
- if(!response)
- return Kick(playerid);
- if(!IsValidEmail(inputtext))
- return Kick(playerid);
- yString[0] = (EOS);
- yQuery[0] = (EOS);
- format(PI[playerid][pEmail], 128, inputtext);
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Email` = '%s' WHERE `ID` = '%d'", PI[playerid][pEmail], PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- Info(playerid, "Vasa e-mail adresa: %s", inputtext);
- yString[0] = (EOS);
- ShowPlayerDialog(playerid, dialog_SPOL, DIALOG_STYLE_MSGBOX, ""srwboja"VP - "BELA"Spol",
- ""srwboja"> "BELA"Odaberite kog ste spola, musko lili zensko?",
- ""srwboja"MUSKO", "ZENSKO");
- }
- if(dialogid == dialog_SPOL) {
- if(!response) {
- Info(playerid, "Uredu, vi ste zenskog spola !");
- PI[playerid][pSpol] = 2, PI[playerid][pSkin] = 12;
- yQuery[0] = (EOS);
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Spol` = 2, `Skin` = 12 WHERE `ID` = %d", PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- SetPlayerSkin(playerid, PI[playerid][pSkin]);
- GivePlayerMoney(playerid, PI[playerid][pNovac]);
- SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
- SpawnPlayer(playerid);
- }
- Info(playerid, "Uredu, vi ste muskog spola !");
- PI[playerid][pSpol] = 1, PI[playerid][pSkin] = 19;
- yQuery[0] = (EOS);
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Spol` = 1, `Skin` = 29 WHERE `ID` = %d", PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- SetPlayerSkin(playerid, PI[playerid][pSkin]);
- GivePlayerMoney(playerid, PI[playerid][pNovac]);
- SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
- SpawnPlayer(playerid);
- return 1;
- }
- if(dialogid == dialog_DRZAVA) {
- if(!response)
- return Kick(playerid);
- yQuery[0] = (EOS);
- switch(listitem) {
- case 0: {
- Info(playerid, "Vi ste poreklom iz Srbije !");
- PI[playerid][pDrzava] = 1;
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '1' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
- \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
- "srwboja"__________________________________________________");
- ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
- ""srwboja"VP - "BELA"Godine", yString,
- ""srwboja"UNESI", "KICK");
- }
- case 1: {
- Info(playerid, "Vi ste poreklom iz Hrvatske !");
- PI[playerid][pDrzava] = 2;
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '2' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
- \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
- "srwboja"__________________________________________________");
- ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
- ""srwboja"VP - "BELA"Godine", yString,
- ""srwboja"UNESI", "KICK");
- }
- case 2: {
- Info(playerid, "Vi ste poreklom iz Bosne i Hercegovine !");
- PI[playerid][pDrzava] = 3;
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '3' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
- \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
- "srwboja"__________________________________________________");
- ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
- ""srwboja"VP - "BELA"Godine", yString,
- ""srwboja"UNESI", "KICK");
- }
- case 3: {
- Info(playerid, "Vi ste poreklom iz Crne Gore !");
- PI[playerid][pDrzava] = 4;
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '4' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
- \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
- "srwboja"__________________________________________________");
- ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
- ""srwboja"VP - "BELA"Godine", yString,
- ""srwboja"UNESI", "KICK");
- }
- case 4: {
- Info(playerid, "Vi ste poreklom iz neke druge drzave !");
- PI[playerid][pDrzava] = 5;
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '5' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
- \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
- "srwboja"__________________________________________________");
- ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
- ""srwboja"VP - "BELA"Godine", yString,
- ""srwboja"UNESI", "KICK");
- }
- }
- return 1;
- }
- if(dialogid == dialog_GODINE) {
- if(!response)
- return Kick(playerid);
- PI[playerid][pGodine] = strval(inputtext);
- yQuery[0] = (EOS), yString[0] = (EOS);
- mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Godine` = '%d' WHERE `ID` = '%d'", PI[playerid][pGodine], PI[playerid][pSQLID]);
- mysql_tquery(SQL, yQuery);
- format(yString, sizeof(yString), ""srwboja"> "BELA"Unesite Vasu vazecu e-mail adresu !\n"srwboja"_______________________________________________ \
- \n> "BELA"Zbog bezbednosti Vaseg accounta, molimo vas unesite e-mail..\n"srwboja"___________________________________________________________________",
- GetName(playerid));
- ShowPlayerDialog(playerid, dialog_EMAIL, DIALOG_STYLE_INPUT, ""srwboja"VP - "BELA"E-Mail", yString, ""srwboja"UNESI", "KICK");
- return 1;
- }
- //login
- if(dialogid == dialog_LOGIN) {
- if(!response)
- return Kick(playerid);
- yQuery[0] = (EOS);
- mysql_format(SQL, yQuery, sizeof(yQuery), "SELECT * FROM `users` WHERE `Name` = '%e' AND `Lozinka` = '%e' LIMIT 1", GetName(playerid), inputtext);
- mysql_pquery(SQL, yQuery, "OnPlayerLogin", "d", playerid);
- }
- return 1;
- }
- //################################################//
- IsValidEmail(const email[])
- {
- new at_pos = strfind(email, "@", true);
- if(at_pos >= 1)
- {
- new offset = (at_pos + 1), dot_pos = strfind(email, ".", true, offset);
- if(dot_pos > offset)
- {
- return 1;
- }
- }
- return 0;
- }
- //################################################//
- func: OnPlayerLogin(playerid) {
- yString[0] = (EOS);
- switch(cache_num_rows()) {
- case 0: {
- format(yString, sizeof(yString), ""srwboja"> "BELA"Dobrodosao %s na 'Ime Servera'\n"srwboja"___________________________________________________________________ \
- \n> "BELA"Vas account je pronadjen u nasoj bazi podataka..\n"srwboja"> "BELA"Molimo ulogujte se, unesite tacnu sifru ispod\n \
- "srwboja"___________________________________________________________________",
- GetName(playerid));
- ShowPlayerDialog(playerid, dialog_LOGIN, DIALOG_STYLE_PASSWORD, ""srwboja"VP - "BELA"Prijavljivanje", yString, ""srwboja"UNESI", "IZLAZ");
- SendClientMessage(playerid, 0xFF0000FF, "(greska): "BELA"Pogresna lozinka !");
- }
- case 1: {
- cache_get_value_name(0, "Name", PI[playerid][pName]);
- cache_get_value_name(0, "Lozinka", PI[playerid][pLozinka]);
- cache_get_value_name(0, "Email", PI[playerid][pEmail]);
- cache_get_value_name_int(0, "Drzava", PI[playerid][pDrzava]);
- cache_get_value_name_int(0, "Godine", PI[playerid][pGodine]);
- cache_get_value_name_int(0, "Spol", PI[playerid][pSpol]);
- cache_get_value_name_int(0, "Skin", PI[playerid][pSkin]);
- cache_get_value_name_int(0, "Novac", PI[playerid][pNovac]);
- cache_get_value_name_int(0, "Level", PI[playerid][pLevel]);
- cache_get_value_name_int(0, "ID", PI[playerid][pSQLID]);
- for(new i = 0; i < 40; i++) { SendClientMessage(playerid, -1, " "); }
- Info(playerid, "%s, uspesno ste se ulogovali na 'Ime Servera' OGC !", GetName(playerid));
- ResetPlayerMoney(playerid), GivePlayerMoney(playerid, PI[playerid][pNovac]);
- SetPlayerScore(playerid, PI[playerid][pLevel]);
- SetPlayerSkin(playerid, PI[playerid][pSkin]);
- TogglePlayerSpectating(playerid, false);
- SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
- SpawnPlayer(playerid);
- }
- }
- return 1;
- }
- //################################################//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement