Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.56 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define white 0xFFFFFFAA
  4. #define yellow 0xFFFFF00AA
  5. #define red 0xFF0000FF
  6. #define pink 0xFF66FFAA
  7. #define lightblue 0x33CCFFAA
  8. #define darkred 0x660000AA
  9. #define grey 0xAFAFAFAA
  10. #define error 0xD2691EAA
  11. #define orange 0xFF9900AA
  12. #define nicepink 0xEC13COFF
  13. #define grad1 0xB4B5B7AA
  14. #define lightgreen 0x7CFC00AA
  15.  
  16. #define MAX_FAIL_LOGINS 4
  17.  
  18. enum Info
  19. {
  20.     pPassword[128],
  21.     pScore,
  22.     pCash,
  23.     FailLogin,
  24. };
  25.  
  26. new PlayerInfo[MAX_PLAYERS][Info];
  27. new gPlayerLogged[MAX_PLAYERS];
  28. new gPlayerAccount[MAX_PLAYERS];
  29. forward OnPlayerLogin(playerid,const string[]);
  30. forward String(string[]);
  31. forward OnPlayerRegister(playerid, password[]);
  32.  
  33. #define FILTERSCRIPT
  34.  
  35. public OnFilterScriptInit()
  36. {
  37.     print("\n--------------------------------------");
  38.     print(" register /login system ");
  39.     print("--------------------------------------\n");
  40.     return 1;
  41. }
  42.  
  43. public OnFilterScriptExit()
  44. {
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerConnect(playerid)
  49. {
  50.     PlayerInfo[playerid][FailLogin] = 0;
  51.     gPlayerLogged[playerid] = 0;
  52.     if(gPlayerAccount[playerid] == 1)
  53.     {
  54.         SendClientMessage(playerid, lightgreen, "Use /login [password] to login into your account.");
  55.     }
  56.     if(gPlayerAccount[playerid] == 0)
  57.     {
  58.         SendClientMessage(playerid, lightgreen, "Use /register [password] to create a new account.");
  59.     }
  60.     return 1;
  61. }
  62.  
  63. public OnPlayerDisconnect(playerid, reason)
  64. {
  65.     return 1;
  66. }
  67.  
  68. public OnPlayerSpawn(playerid)
  69. {
  70.     return 1;
  71. }
  72.  
  73. public OnPlayerDeath(playerid, killerid, reason)
  74. {
  75.     return 1;
  76. }
  77.  
  78. public OnVehicleSpawn(vehicleid)
  79. {
  80.     return 1;
  81. }
  82.  
  83. public OnVehicleDeath(vehicleid, killerid)
  84. {
  85.     return 1;
  86. }
  87.  
  88. public OnPlayerText(playerid, text[])
  89. {
  90.     return 1;
  91. }
  92.  
  93. public OnPlayerCommandText(playerid, cmdtext[])
  94. {
  95.     new cmd[256];
  96.     new idx;
  97.     cmd = strtok(cmdtext, idx);
  98.     new tmp[256];
  99.     new playername[MAX_PLAYER_NAME];
  100.     GetPlayerName(playerid,playername,sizeof(playername));
  101.     if (strcmp(cmd, "/savestats", true) ==0 )
  102.     {
  103.         if(gPlayerLogged[playerid])
  104.         {
  105.             new string3[32];
  106.             new pname3[MAX_PLAYER_NAME];
  107.             GetPlayerName(playerid, pname3, sizeof(pname3));
  108.             format(string3, sizeof(string3), "%s.ini", pname3);
  109.             new File: pFile = fopen(string3, io_write);
  110.             if (pFile)
  111.             {
  112.                 new var[32];
  113.                 format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var);
  114.                 fclose(pFile);
  115.                 new File: hFile = fopen(string3, io_append);
  116.                 PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
  117.                 PlayerInfo[playerid][pScore] = GetPlayerScore(playerid);
  118.                 format(var, 32, "Score:%d\n",PlayerInfo[playerid][pScore]);fwrite(hFile, var);
  119.                 format(var, 32, "Cash:%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  120.                 fclose(hFile);
  121.                 SendClientMessage(playerid, lightgreen, "data saved.");
  122.                 format(string3, sizeof(string3), "cash: %d score: %d",PlayerInfo[playerid][pCash],PlayerInfo[playerid][pScore]);
  123.                 SendClientMessage(playerid, lightgreen,string3);
  124.                 PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
  125.             }
  126.         }
  127.         else return SendClientMessage(playerid, lightgreen, "ur not logged in !");
  128.         return 1;
  129.     }
  130.     if (strcmp(cmd, "/login", true) ==0 )
  131.     {
  132.         if(IsPlayerConnected(playerid))
  133.         {
  134.             new tmppass[64];
  135.             if(gPlayerLogged[playerid] == 1)
  136.             {
  137.                 SendClientMessage(playerid, lightgreen, "You are already logged in.");
  138.                 return 1;
  139.             }
  140.             tmp = strtok(cmdtext, idx);
  141.             if(!strlen(tmp))
  142.             {
  143.                 SendClientMessage(playerid, red, "USAGE: /login [password]");
  144.                 return 1;
  145.             }
  146.             strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
  147.             String(tmppass);
  148.             OnPlayerLogin(playerid,tmppass);
  149.         }
  150.         return 1;
  151.     }
  152.     if (strcmp(cmd, "/register", true)==0)
  153.     {
  154.         new string[265];
  155.         tmp = strtok(cmdtext, idx);
  156.         if(!strlen(tmp))
  157.         {
  158.             SendClientMessage(playerid, red, "USAGE: /register [password]");
  159.             return 1;
  160.         }
  161.         if (gPlayerAccount[playerid] == 1)
  162.         {
  163.             SendClientMessage(playerid, lightgreen, "This nickname is already registered.");
  164.             return 1;
  165.         }
  166.         strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
  167.         String(PlayerInfo[playerid][pPassword]);
  168.         GetPlayerName(playerid, playername, sizeof(playername));
  169.         format(string, sizeof(string), "%s.ini", playername);
  170.         new File: file = fopen(string, io_read);
  171.         if (file)
  172.         {
  173.             SendClientMessage(playerid, lightgreen, "This name is already registered.");
  174.             fclose(file);
  175.             return 1;
  176.         }
  177.         new File:hFile;
  178.         hFile = fopen(string, io_append);
  179.         new var[32];
  180.         format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
  181.         PlayerInfo[playerid][pScore] = GetPlayerScore(playerid);
  182.         format(var, 32, "Score:%d\n",PlayerInfo[playerid][pScore]);fwrite(hFile, var);
  183.         PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
  184.         format(var, 32, "Cash:%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  185.         fclose(hFile);
  186.         SendClientMessage(playerid, yellow, "Your now registered ! Next time when you come, use /login [password].");
  187.         OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
  188.         return 1;
  189.     }
  190.     return 0;
  191. }
  192. public String(string[])
  193. {
  194.     for(new x=0; x < strlen(string); x++)
  195.       {
  196.           string[x] += (3^x) * (x % 15);
  197.           if(string[x] > (0xff))
  198.           {
  199.               string[x] -= 64;
  200.           }
  201.       }
  202.     return 1;
  203. }
  204. strtok(const string[], &index)
  205. {
  206.     new length = strlen(string);
  207.     while ((index < length) && (string[index] <= ' '))
  208.     {
  209.         index++;
  210.     }
  211.  
  212.     new offset = index;
  213.     new result[20];
  214.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  215.     {
  216.         result[index - offset] = string[index];
  217.         index++;
  218.     }
  219.     result[index - offset] = EOS;
  220.     return result;
  221. }
  222. public OnPlayerRegister(playerid, password[])
  223. {
  224.     if(IsPlayerConnected(playerid))
  225.     {
  226.             new PlayerName[MAX_PLAYERS];
  227.             new string3[128];
  228.             format(string3, sizeof(string3), "%s.ini", PlayerName(playerid));
  229.             new File: hFile = fopen(string3, io_write);
  230.             if (hFile)
  231.             {
  232.                 new var[32];
  233.                 PlayerInfo[playerid][pCash] = GetPlayerCash(playerid);
  234.                 format(var, 32, "Level=%d\n",PlayerInfo[playerid][pScore]);fwrite(hFile, var);
  235.                 format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  236.                 fclose(hFile);
  237.                 SendClientMessage(playerid, lightgreen, "Registration successful.");
  238.             }
  239.     }
  240.     return 1;
  241. }
  242. stock GetPlayerCash(playerid)
  243. {
  244.     return PlayerInfo[playerid][pCash];
  245. }
  246. public OnPlayerLogin(playerid,const string[])
  247. {
  248.     new pname2[MAX_PLAYER_NAME];
  249.     new pname3[MAX_PLAYER_NAME];
  250.     new string2[64];
  251.     new string3[64];
  252.     GetPlayerName(playerid, pname2, sizeof(pname2));
  253.     format(string2, sizeof(string2), "%s.ini", pname2);
  254.     new File: UserFile = fopen(string2, io_read);
  255.     if(UserFile)
  256.     {
  257.         new valtmp[128];
  258.         fread(UserFile, valtmp);
  259.         strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);
  260.         if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0))
  261.         {
  262.             new key[128],val[128];
  263.             new Data[128];
  264.             while(fread(UserFile,Data,sizeof(Data)))
  265.             {
  266.                 key = ini_GetKey(Data);
  267.                 if( strcmp( key , "Score" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pScore] = strval( val ); }
  268.                 if( strcmp( key , "Cash" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); }
  269.             }
  270.             SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
  271.             GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
  272.             gPlayerLogged[playerid] = 1;
  273.             gPlayerAccount[playerid] = 1;
  274.             GetPlayerName(playerid, pname3, sizeof(pname3));
  275.             SendClientMessage(playerid, lightgreen, "Successfully logged in !");
  276.             format(string3, sizeof(string3), "cash: %d score: %d",PlayerInfo[playerid][pCash],PlayerInfo[playerid][pScore]);
  277.             SendClientMessage(playerid, lightgreen,string3);
  278.             PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
  279.             fclose(UserFile);
  280.         }
  281.         else
  282.         {
  283.             new strr[128];
  284.             SendClientMessage(playerid, red, "Invalid Password!");
  285.             PlayerInfo[playerid][FailLogin]++;
  286.             if(PlayerInfo[playerid][FailLogin] == MAX_FAIL_LOGINS)
  287.             {
  288.                 new name[MAX_PLAYER_NAME];
  289.                 GetPlayerName(playerid, name, sizeof(name));
  290.                 format(strr, sizeof(strr), "*** KICK: %s has been kicked by the server. (Failed Logins)",name);
  291.                 SendClientMessageToAll(pink, strr);
  292.                 print(strr);
  293.                 Kick(playerid);
  294.             }
  295.             fclose(UserFile);
  296.             format(strr,sizeof(strr),"Incorrect Password ! Failed Attempt Before Kick (%d/4)",PlayerInfo[playerid][FailLogin]);
  297.             return SendClientMessage(playerid, red, strr);
  298.         }
  299.     }
  300.     return 1;
  301. }
  302. stock ini_GetKey( line[] )
  303. {
  304.     new keyRes[128];
  305.     keyRes[0] = 0;
  306.     if ( strfind( line , "=" , true ) == -1 ) return keyRes;
  307.     strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
  308.     return keyRes;
  309. }
  310. stock ini_GetValue( line[] )
  311. {
  312.     new valRes[128];
  313.     valRes[0]=0;
  314.     if ( strfind( line , "=" , true ) == -1 ) return valRes;
  315.     strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
  316.     return valRes;
  317. }
  318. public OnPlayerUpdate(playerid)
  319. {
  320.     if(IsPlayerConnected(playerid))
  321.     {
  322.         if(gPlayerLogged[playerid])
  323.         {
  324.             new string3[32];
  325.             new pname3[MAX_PLAYER_NAME];
  326.             GetPlayerName(playerid, pname3, sizeof(pname3));
  327.             format(string3, sizeof(string3), "%s.txt", pname3);
  328.             new File: pFile = fopen(string3, io_write);
  329.             if (pFile)
  330.             {
  331.                 new var[32];
  332.                 format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var);
  333.                 fclose(pFile);
  334.                 new File: hFile = fopen(string3, io_append);
  335.                 PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
  336.                 PlayerInfo[playerid][pScore] = GetPlayerScore(playerid);
  337.                 format(var, 32, "Score:%d\n",PlayerInfo[playerid][pScore]);fwrite(hFile, var);
  338.                 format(var, 32, "Cash:%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  339.                 fclose(hFile);
  340.             }
  341.         }
  342.     }
  343.     return 1;
  344. }
  345.  
  346. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  347. {
  348.     return 1;
  349. }
  350.  
  351. public OnPlayerExitVehicle(playerid, vehicleid)
  352. {
  353.     return 1;
  354. }
  355.  
  356. public OnPlayerStateChange(playerid, newstate, oldstate)
  357. {
  358.     return 1;
  359. }
  360.  
  361. public OnPlayerEnterCheckpoint(playerid)
  362. {
  363.     return 1;
  364. }
  365.  
  366. public OnPlayerLeaveCheckpoint(playerid)
  367. {
  368.     return 1;
  369. }
  370.  
  371. public OnPlayerEnterRaceCheckpoint(playerid)
  372. {
  373.     return 1;
  374. }
  375.  
  376. public OnPlayerLeaveRaceCheckpoint(playerid)
  377. {
  378.     return 1;
  379. }
  380.  
  381. public OnRconCommand(cmd[])
  382. {
  383.     return 1;
  384. }
  385.  
  386. public OnObjectMoved(objectid)
  387. {
  388.     return 1;
  389. }
  390.  
  391. public OnPlayerObjectMoved(playerid, objectid)
  392. {
  393.     return 1;
  394. }
  395.  
  396. public OnPlayerPickUpPickup(playerid, pickupid)
  397. {
  398.     return 1;
  399. }
  400.  
  401. public OnPlayerSelectedMenuRow(playerid, row)
  402. {
  403.     return 1;
  404. }
  405.  
  406. public OnPlayerExitedMenu(playerid)
  407. {
  408.     return 1;
  409. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement