Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #define DB_SERVER "127.0.0.1"
- #define DB_USER "root"
- #define DB_DB "samp"
- #define DB_PASS ""
- #define DIALOG_REGISTER (1001)
- #define DIALOG_LOGIN (1002)
- #define DIALOG_TYPE_AGE (1003)
- #define DIALOG_DM (1004)
- #define DIALOG_RK (1005)
- #define DIALOG_DONE (1006)
- enum
- playerEnum
- {
- pName[24],
- pPassword[17],
- pLevel,
- pAge,
- pWarns,
- pAnswer,
- bool:pLogged
- }
- new
- pInfo[MAX_PLAYERS][playerEnum],
- dbHandle,
- gQuery[357];
- public OnGameModeInit()
- {
- dbHandle = mysql_connect(DB_SERVER,DB_USER,DB_DB,DB_PASS);
- mysql_function_query(dbHandle,"CREATE TABLE IF NOT EXISTS accounts (Username VARCHAR(27),Password VARCHAR(20),Level int,Age int",false,"","");
- }
- public OnPlayerConnect(playerid)
- {
- GetPlayerName(playerid,pInfo[playerid][pName],24);
- format(gQuery,357,"SELECT * FROM accounts WHERE Username='%s'",pInfo[playerid][pName]);
- mysql_function_query(dbHandle,gQuery,false,"checkPlayer","d",playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(GetPVarInt(playerid,"OnlyReg") == 1)
- {
- format(gQuery,357,"INSERT INTO accounts (Username,Password,Age) VALUES(%s,%s,%d)",pInfo[playerid][pName],pInfo[playerid][pPassword],pInfo[playerid][pAge]);
- mysql_function_query(dbHandle,gQuery,false,"","");
- }
- return 1;
- }
- public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
- {
- if(dialogid == DIALOG_LOGIN)
- {
- if(!strlen(inputtext) || strlen(inputtext) < 5 || strlen(inputtext) > 15 || strfind(inputtext,"%",true) != -1) return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login to our server!","Welcome Back, please enter your's password","Login","Cancel");
- if(!strcmp(inputtext,pInfo[playerid][pPassword],true))
- {
- SpawnPlayer(playerid);
- SendClientMessage(playerid,-1,"[Success]: you successuflly logged in!");
- } else {
- pInfo[playerid][pWarns] ++;
- if(pInfo[playerid][pWarns] >= 3) Kick(playerid);
- ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login to our server!","Incorrect Password!","Login","Cancel");
- }
- }
- if(dialogid == DIALOG_REGISTER)
- {
- if(!strlen(inputtext) || strlen(inputtext) < 5 || strlen(inputtext) > 15 || strfind(inputtext,"%",true) != -1) return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Register to our server!","Welcome, please input any password","Register","Cancel");
- SetPVarInt(playerid,"OnlyReg",1);
- format(pInfo[playerid][pPassword],17,"%s",inputtext);
- ShowPlayerDialog(playerid,DIALOG_TYPE_AGE,DIALOG_STYLE_INPUT,"Please enter your age?","Please enter your age..","Continue","Cancel");
- }
- if(dialogid == DIALOG_TYPE_AGE)
- {
- if(!strlen(inputtext) || strlen(inputtext) < 18 || strlen(inputtext) > 35) return ShowPlayerDialog(playerid,DIALOG_TYPE_AGE,DIALOG_STYLE_INPUT,"Please enter your age?","Please enter your age..","Continue","Cancel");
- pInfo[playerid][pAge] = strval(inputtext);
- ShowPlayerDialog(playerid,DIALOG_DM,DIALOG_STYLE_LIST,"What is DM?","Kill some one for fun\nGrand thaft auto\nKick players","Continue","Cancel");
- }
- if(dialogid == DIALOG_DM)
- {
- if(listitem == 2 || listitem == 3) pInfo[playerid][pAnswer] ++;
- ShowPlayerDialog(playerid,DIALOG_RK,DIALOG_STYLE_LIST,"What is RK?","Curse players\nKill someone, before this someone kill you\nShoot players","Done!","Cancel");
- if(listitem == 1 || listitem == 3) pInfo[playerid][pAnswer] ++;
- new localString[128];
- format(localString,128,"Nice, you registerd, but you faild in: %d/2 Answers!",pInfo[playerid][pAnswer]);
- if(pInfo[playerid][pAnswer] > 0) ShowPlayerDialog(playerid,DIALOG_DONE,DIALOG_STYLE_MSGBOX,"Nice you registerd!",localString,"Play","Cancel");
- else if(pInfo[playerid][pAnswer] <= 0) ShowPlayerDialog(playerid,DIALOG_DONE,DIALOG_STYLE_MSGBOX,"Nice you registerd!","Play Now","Play","Cancel");
- }
- if(dialogid == DIALOG_DONE) return pInfo[playerid][pLogged] = true;
- return 1;
- }
- forward checkPlayer(playerid);
- public checkPlayer(playerid)
- {
- new
- rows,
- fields;
- cache_get_data(rows,fields);
- if(rows != 1)
- {
- cache_get_field_content(0,"Password",pInfo[playerid][pPassword],17,dbHandle);
- pInfo[playerid][pLevel] = cache_get_field_content_int(0,"Level",dbHandle);
- pInfo[playerid][pAge] = cache_get_field_content_int(0,"Age",dbHandle);
- ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login to our server!","Welcome Back, please enter your's password","Login","Cancel");
- } else {
- ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Register to our server!","Welcome, please input any password","Register","Cancel");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement