Advertisement
Guest User

Register System by iRaiDeN/JizzyB'

a guest
May 4th, 2014
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.73 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4. #define     DB_SERVER       "127.0.0.1"
  5. #define     DB_USER         "root"
  6. #define     DB_DB           "samp"
  7. #define     DB_PASS         ""
  8.  
  9. #define     DIALOG_REGISTER     (1001)
  10. #define     DIALOG_LOGIN        (1002)
  11. #define     DIALOG_TYPE_AGE     (1003)
  12. #define     DIALOG_DM           (1004)
  13. #define     DIALOG_RK           (1005)
  14. #define     DIALOG_DONE         (1006)
  15.  
  16. enum
  17.     playerEnum
  18. {
  19.     pName[24],
  20.     pPassword[17],
  21.     pLevel,
  22.     pAge,
  23.     pWarns,
  24.     pAnswer,
  25.     bool:pLogged
  26. }
  27.  
  28. new
  29.     pInfo[MAX_PLAYERS][playerEnum],
  30.     dbHandle,
  31.     gQuery[357];
  32.    
  33. public OnGameModeInit()
  34. {
  35.     dbHandle = mysql_connect(DB_SERVER,DB_USER,DB_DB,DB_PASS);
  36.     mysql_function_query(dbHandle,"CREATE TABLE IF NOT EXISTS accounts (Username VARCHAR(27),Password VARCHAR(20),Level int,Age int",false,"","");
  37. }
  38.  
  39. public OnPlayerConnect(playerid)
  40. {
  41.     GetPlayerName(playerid,pInfo[playerid][pName],24);
  42.     format(gQuery,357,"SELECT * FROM accounts WHERE Username='%s'",pInfo[playerid][pName]);
  43.     mysql_function_query(dbHandle,gQuery,false,"checkPlayer","d",playerid);
  44.     return 1;
  45. }
  46.  
  47. public OnPlayerDisconnect(playerid, reason)
  48. {
  49.     if(GetPVarInt(playerid,"OnlyReg") == 1)
  50.     {
  51.         format(gQuery,357,"INSERT INTO accounts (Username,Password,Age) VALUES(%s,%s,%d)",pInfo[playerid][pName],pInfo[playerid][pPassword],pInfo[playerid][pAge]);
  52.         mysql_function_query(dbHandle,gQuery,false,"","");
  53.     }
  54.     return 1;
  55. }
  56.  
  57. public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
  58. {
  59.     if(dialogid == DIALOG_LOGIN)
  60.     {
  61.         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");
  62.         if(!strcmp(inputtext,pInfo[playerid][pPassword],true))
  63.         {
  64.             SpawnPlayer(playerid);
  65.             SendClientMessage(playerid,-1,"[Success]: you successuflly logged in!");
  66.         } else {
  67.             pInfo[playerid][pWarns] ++;
  68.             if(pInfo[playerid][pWarns] >= 3) Kick(playerid);
  69.             ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login to our server!","Incorrect Password!","Login","Cancel");
  70.         }
  71.     }
  72.     if(dialogid == DIALOG_REGISTER)
  73.     {
  74.         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");
  75.         SetPVarInt(playerid,"OnlyReg",1);
  76.         format(pInfo[playerid][pPassword],17,"%s",inputtext);
  77.         ShowPlayerDialog(playerid,DIALOG_TYPE_AGE,DIALOG_STYLE_INPUT,"Please enter your age?","Please enter your age..","Continue","Cancel");
  78.     }
  79.     if(dialogid == DIALOG_TYPE_AGE)
  80.     {
  81.         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");
  82.         pInfo[playerid][pAge] = strval(inputtext);
  83.         ShowPlayerDialog(playerid,DIALOG_DM,DIALOG_STYLE_LIST,"What is DM?","Kill some one for fun\nGrand thaft auto\nKick players","Continue","Cancel");
  84.     }
  85.     if(dialogid == DIALOG_DM)
  86.     {
  87.         if(listitem == 2 || listitem == 3) pInfo[playerid][pAnswer] ++;
  88.         ShowPlayerDialog(playerid,DIALOG_RK,DIALOG_STYLE_LIST,"What is RK?","Curse players\nKill someone, before this someone kill you\nShoot players","Done!","Cancel");
  89.         if(listitem == 1 || listitem == 3) pInfo[playerid][pAnswer] ++;
  90.         new localString[128];
  91.         format(localString,128,"Nice, you registerd, but you faild in: %d/2 Answers!",pInfo[playerid][pAnswer]);
  92.         if(pInfo[playerid][pAnswer] > 0) ShowPlayerDialog(playerid,DIALOG_DONE,DIALOG_STYLE_MSGBOX,"Nice you registerd!",localString,"Play","Cancel");
  93.         else if(pInfo[playerid][pAnswer] <= 0) ShowPlayerDialog(playerid,DIALOG_DONE,DIALOG_STYLE_MSGBOX,"Nice you registerd!","Play Now","Play","Cancel");
  94.     }
  95.     if(dialogid == DIALOG_DONE) return pInfo[playerid][pLogged] = true;
  96.     return 1;
  97. }
  98.  
  99. forward checkPlayer(playerid);
  100. public checkPlayer(playerid)
  101. {
  102.     new
  103.         rows,
  104.         fields;
  105.     cache_get_data(rows,fields);
  106.     if(rows != 1)
  107.     {
  108.         cache_get_field_content(0,"Password",pInfo[playerid][pPassword],17,dbHandle);
  109.         pInfo[playerid][pLevel] = cache_get_field_content_int(0,"Level",dbHandle);
  110.         pInfo[playerid][pAge] = cache_get_field_content_int(0,"Age",dbHandle);
  111.         ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login to our server!","Welcome Back, please enter your's password","Login","Cancel");
  112.     } else {
  113.         ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Register to our server!","Welcome, please input any password","Register","Cancel");
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement