Guest
Public paste!

ShadowMcFartPants

By: a guest | Sep 20th, 2009 | Syntax: C++ | Size: 11.93 KB | Hits: 620 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. /*
  2.         ShadowMcFartPant's Account System!
  3.         Credits:-
  4.         YSF - Encrypt
  5.         Spilot - Some Minor Warnings
  6.         Creator of PEN:LS
  7.         ShadowMcFartPant's - Scripting
  8. */
  9.        
  10. #include <a_samp>
  11.  
  12.  
  13.  
  14. #define FILTERSCRIPT
  15.  
  16. #define COLOR_GREY 0xBEBEBEAA
  17. #define COLOR_WHITE 0xFFFFFFAA
  18. #define COLOR_GREEN 0x33AA33AA
  19. #define COLOR_GRAD5 0xE3E3E3FF
  20. #define COLOR_GRAD1 0xB4B5B7FF
  21. #define COLOR_YELLOW 0xFFFF00AA
  22.  
  23. forward ShowStats(playerid,targetid);
  24. forward OnPlayerUpdate(playerid);
  25. forward Encrypt(string[]);
  26. forward OnPlayerLogin(playerid,const string[]);
  27. forward GetPlayerID(string[]);
  28. forward IsStringAName(string[]);
  29.  
  30. enum pInfo
  31. {
  32.         pPassword[128],
  33.         pKills,
  34.         pDeaths,
  35.         pCash,
  36.         pAdmin
  37. };
  38.  
  39. new PlayerInfo[MAX_PLAYERS][pInfo];
  40. new gPlayerLogged[MAX_PLAYERS];
  41. new gPlayerAccount[MAX_PLAYERS];
  42.  
  43. public OnFilterScriptInit()
  44. {
  45.         print("ShadowMcFartPant's First Ever Account System");
  46.         print("Fully Loaded and ready too goo.");
  47.         return 1;
  48. }
  49.  
  50. public OnFilterScriptExit()
  51. {
  52.         print("ShadowMcFartPant's First ever Account System");
  53.         print("Fully Un-Loaded and ready too not goo ? ");
  54.         return 1;
  55. }
  56.  
  57. public OnPlayerConnect(playerid)
  58. {
  59.         PlayerInfo[playerid][pKills] = 0;
  60.         PlayerInfo[playerid][pAdmin] = 0;
  61.         PlayerInfo[playerid][pDeaths] = 0;
  62.         new pName[MAX_PLAYER_NAME];
  63.         new cnt[128];
  64.         GetPlayerName(playerid,pName,sizeof(pName));
  65.         format(cnt,sizeof(cnt),"%s.cer",pName);
  66.         if(fexist(cnt))
  67.         {
  68.             gPlayerAccount[playerid] = 1;
  69.             SendClientMessage(playerid, COLOR_YELLOW, "You have already registerd an account, please /login with your unique password");
  70.             return 1;
  71.         }
  72.         else
  73.         {
  74.             gPlayerAccount[playerid] = 0;
  75.             SendClientMessage(playerid, COLOR_YELLOW, "You have never played here before, please register an account with /register password");
  76.         }
  77.  
  78.         return 1;
  79. }
  80.  
  81. public OnPlayerDisconnect(playerid, reason)
  82. {
  83.     OnPlayerUpdate(playerid);
  84.     gPlayerLogged[playerid] = 0;
  85.         return 1;
  86. }
  87.  
  88. public OnPlayerDeath(playerid, killerid, reason)
  89. {
  90.         new Kills = PlayerInfo[playerid][pKills];
  91.         SetPlayerScore(playerid, Kills);
  92.         new Float:Health;
  93.         GetPlayerHealth(playerid, Health);
  94.         if(Health == 0.0)
  95.         {
  96.             PlayerInfo[playerid][pDeaths] += 1;
  97.         }
  98.         PlayerInfo[killerid][pKills] = PlayerInfo[killerid][pKills] + 1;
  99.  
  100.         return 1;
  101. }
  102.  
  103. public OnPlayerCommandText(playerid, cmdtext[])
  104. {
  105.         new giveplayer[MAX_PLAYER_NAME];
  106.         new sendername[MAX_PLAYER_NAME];
  107.         new string[256];
  108. //----------------------------------------------------------------------------
  109.                 new cmd[256];
  110.                 new idx;
  111.                 cmd = strtok(cmdtext, idx);
  112.                 new tmp[256];
  113.                 new pName[MAX_PLAYER_NAME];
  114.                 if (strcmp(cmd, "/login", true) == 0)
  115.                 {
  116.                     if(IsPlayerConnected(playerid))
  117.                     {
  118.                         new tmppass[64];
  119.                         if(gPlayerLogged[playerid] == 1)
  120.                         {
  121.                             SendClientMessage(playerid, COLOR_GREY, "You have already logged in.");
  122.                             return 1;
  123.                                 }
  124.                         tmp = strtok(cmdtext, idx);
  125.                                 if(!strlen(tmp))
  126.                                 {
  127.                                 SendClientMessage(playerid, COLOR_GREY, "ERROR: /login [password]");
  128.                                     return 1;
  129.                                 }
  130.  
  131.                                 strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
  132.                                 Encrypt(tmppass);
  133.                                 OnPlayerLogin(playerid,tmppass);
  134.                         }
  135.                         return 1;
  136.         }
  137.                 if (strcmp(cmd, "/register", true) == 0)
  138.         {
  139.             new string[256];
  140.             tmp = strtok(cmdtext, idx);
  141.             if(!strlen(tmp))
  142.             {
  143.                 SendClientMessage(playerid, COLOR_GREY, "ERROR: /register [password]");
  144.                 return 1;
  145.                 }
  146.                 if (gPlayerAccount[playerid] == 1)
  147.                 {
  148.                     SendClientMessage(playerid, COLOR_GREY, "Sorry but that name has been previously registerd");
  149.                     return 1;
  150.                 }
  151.                 strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
  152.                 Encrypt(PlayerInfo[playerid][pPassword]);
  153.                 GetPlayerName(playerid, pName, sizeof(pName));
  154.                 format(string, sizeof(string), "%s.cer", pName);
  155.                 new File: file = fopen(string, io_read);
  156.                 if (file)
  157.                 {
  158.                     SendClientMessage(playerid, COLOR_GREY, "Sorry but that name has been previously registerd");
  159.                         fclose(file);
  160.                         return 1;
  161.                 }
  162.                 new File:hFile;
  163.                 hFile = fopen(string, io_append);
  164.                 new var[32];// var
  165.                 format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
  166.                 format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
  167.         format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
  168.         PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
  169.         format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  170.         format(var, 32, "pAdmin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
  171.                 fclose(hFile);
  172.                 SendClientMessage(playerid, COLOR_WHITE, "Succesfully Registered!");
  173.                 SendClientMessage(playerid, COLOR_WHITE, "Next time you connect, remember too /login [password]");
  174.                 OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
  175.                 return 1;
  176.         }
  177.                 if (strcmp(cmd, "/mystats", true) == 0)
  178.         {
  179.             if(IsPlayerConnected(playerid))
  180.             {
  181.                         if (gPlayerLogged[playerid] != 0)
  182.                         {
  183.                                 ShowStats(playerid,playerid);
  184.                         }
  185.                         else
  186.                         {
  187.                                 SendClientMessage(playerid, COLOR_GRAD1, "You are not logged in!");
  188.                         }
  189.                 }
  190.                 return 1;
  191.         }
  192.                 if(strcmp(cmd, "/Promoteplayer", true) == 0)
  193.         {
  194.                 tmp = strtok(cmdtext, idx);
  195.                 if(!strlen(tmp))
  196.                 {
  197.                     SendClientMessage(playerid, COLOR_WHITE, "ERROR: /promoteplayer [playerid] [level]");
  198.                     return 1;
  199.                         }
  200.                         new reg1;
  201.                         new level;
  202.                         if(IsStringAName(tmp))
  203.                         {
  204.                             reg1 = GetPlayerID(tmp);
  205.                         }
  206.                         else
  207.                         {
  208.                             reg1 = strval(tmp);
  209.                         }
  210.                         tmp = strtok(cmdtext, idx);
  211.                         level = strval(tmp);
  212.                         if ((IsPlayerAdmin(playerid)) || PlayerInfo[playerid][pAdmin] >= 5)
  213.                         {
  214.                             GetPlayerName(reg1, giveplayer, sizeof(giveplayer));
  215.                             GetPlayerName(playerid, sendername, sizeof(sendername));
  216.                             PlayerInfo[reg1][pAdmin] = level;
  217.                                 format(string, sizeof(string), "You have been Promoted to level %d By %s", level, sendername);
  218.                                 SendClientMessage(reg1, COLOR_WHITE, string);
  219.                                 format(string, sizeof(string), "You have Promoted %s to level %d",giveplayer,level);
  220.                                 SendClientMessage(playerid,COLOR_WHITE,string);
  221.                         }
  222.                         else
  223.                         {
  224.                             SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use that command.");
  225.                         }
  226.                         return 1;
  227.         }
  228.  
  229.                 return 0;
  230. }
  231.  
  232. public OnPlayerLogin(playerid,const string[])
  233. {
  234.         new pName1[MAX_PLAYER_NAME];
  235.         new pName2[MAX_PLAYER_NAME];
  236.         new String1[64];
  237.         new String2[128];
  238.         GetPlayerName(playerid, pName1, sizeof(pName1));
  239.         format(String1, sizeof(String1), "%s.cer", pName1);
  240.         new File: UserFile = fopen(String1, io_read);
  241.  
  242.         if (UserFile)
  243.         {
  244.                 new valtmp[128];
  245.                 fread(UserFile, valtmp);strmid(PlayerInfo[playerid][pPassword], valtmp, 0, strlen(valtmp)-1, 255);
  246.  
  247.                 if ((strcmp(PlayerInfo[playerid][pPassword], string, true, strlen(valtmp)-1) == 0))
  248.                 {
  249.                         new key[128],val[128];
  250.                         new Data[128];
  251.                         while(fread(UserFile,Data,sizeof(Data)))
  252.                         {
  253.                                 key = ini_GetKey(Data);
  254.                 if( strcmp( key , "Kills" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pKills] = strval( val ); }
  255.                 if( strcmp( key , "Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pDeaths] = strval( val ); }
  256.                 if( strcmp( key , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pCash] = strval( val ); }
  257.                 if( strcmp( key , "pAdmin" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pAdmin] = strval( val ); }
  258.                 GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
  259.                         }
  260.                         fclose(UserFile);
  261.                         gPlayerLogged[playerid] = 1;
  262.                         gPlayerAccount[playerid] = 1;
  263.                     new kills = PlayerInfo[playerid][pKills];
  264.             SetPlayerScore(playerid, kills);
  265.                         GetPlayerName(playerid, pName2, sizeof(pName2));
  266.                         format(String2, sizeof(String2), "Welcome %s You have logged in successfully.",pName2);
  267.                         SendClientMessage(playerid, COLOR_WHITE,String2);
  268.                 }
  269.                 else
  270.                 {
  271.                         SendClientMessage(playerid, COLOR_GREY, "Incorrect Password, 2 Attempts Remaining.");
  272.                         fclose(UserFile);
  273.                 }
  274.         }
  275.         return 1;
  276. }
  277.  
  278.  
  279.  
  280. public OnPlayerUpdate(playerid)
  281. {
  282.         if(IsPlayerConnected(playerid))
  283.         {
  284.                 if(gPlayerLogged[playerid])
  285.                 {
  286.                         new string3[32];
  287.                         new pname3[MAX_PLAYER_NAME];
  288.                         GetPlayerName(playerid, pname3, sizeof(pname3));
  289.                         format(string3, sizeof(string3), "%s.cer", pname3);
  290.                         new File: pFile = fopen(string3, io_write);
  291.                         if (pFile)
  292.                         {
  293.                                 new var[32];
  294.                                 format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(pFile, var);
  295.                                 fclose(pFile);
  296.                                 new File: hFile = fopen(string3, io_append);
  297.                                 PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
  298.                                 format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
  299.                                 format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
  300.                                 format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
  301.                                 format(var, 32, "pAdmin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
  302.                                 fclose(hFile);
  303.                         }
  304.                 }
  305.         }
  306.         return 1;
  307. }
  308.  
  309. public ShowStats(playerid,targetid)
  310. {
  311.     if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
  312.         {
  313.                 new Cash = GetPlayerMoney(targetid);
  314.                 new Deaths = PlayerInfo[targetid][pDeaths];
  315.                 new Kills = PlayerInfo[targetid][pKills];
  316.                 new pName[MAX_PLAYER_NAME];
  317.                 GetPlayerName(targetid, pName, sizeof(pName));
  318.                 new Float:pX,Float:pY,Float:pZ;
  319.                 GetPlayerPos(targetid, pX,pY,pZ);
  320.                 new CoordString[256];
  321.                 SendClientMessage(playerid, COLOR_GREEN,"----------------------------------------");
  322.                 format(CoordString, sizeof(CoordString),"** %s Stats **",pName);
  323.                 SendClientMessage(playerid, COLOR_WHITE,CoordString);
  324.                 format(CoordString, sizeof(CoordString),"Admin Level:[%d]",pAdmin);
  325.                 SendClientMessage(playerid, COLOR_GRAD5,CoordString);
  326.                 format(CoordString, sizeof(CoordString),"Kills:[%d] |-| Deaths:[%d] |-| Cash[£%d]",Kills,Deaths,Cash);
  327.                 SendClientMessage(playerid, COLOR_GRAD5,CoordString);
  328.                 SendClientMessage(playerid, COLOR_GREEN,"----------------------------------------");
  329.         }
  330. }
  331.  
  332. public Encrypt(string[])
  333. {
  334.         for(new x=0; x < strlen(string); x++)
  335.           {
  336.                   string[x] += (3^x) * (x % 15);
  337.                   if(string[x] > (0xff))
  338.                   {
  339.                           string[x] -= 64;
  340.                   }
  341.           }
  342.         return 1;
  343. }
  344.  
  345. stock ini_GetKey( line[] )
  346. {
  347.         new keyRes[128];
  348.         keyRes[0] = 0;
  349.     if ( strfind( line , "=" , true ) == -1 ) return keyRes;
  350.     strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
  351.     return keyRes;
  352. }
  353.  
  354. stock ini_GetValue( line[] )
  355. {
  356.         new valRes[128];
  357.         valRes[0]=0;
  358.         if ( strfind( line , "=" , true ) == -1 ) return valRes;
  359.         strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
  360.         return valRes;
  361. }
  362.  
  363.  
  364. strtok(const string[], &index)
  365. {
  366.         new length = strlen(string);
  367.         while ((index < length) && (string[index] <= ' '))
  368.         {
  369.                 index++;
  370.         }
  371.  
  372.         new offset = index;
  373.         new result[20];
  374.         while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  375.         {
  376.                 result[index - offset] = string[index];
  377.                 index++;
  378.         }
  379.         result[index - offset] = EOS;
  380.         return result;
  381. }
  382.  
  383. public IsStringAName(string[])
  384. {
  385.         for(new i = 0; i <= MAX_PLAYERS; i++)
  386.         {
  387.                 if(IsPlayerConnected(i) == 1)
  388.                 {
  389.                         new testname[MAX_PLAYER_NAME];
  390.                         GetPlayerName(i, testname, sizeof(testname));
  391.                         //printf("IsS:testname = %s : string = %s",testname,string);
  392.                         if(strcmp(testname, string, true, strlen(string)) == 0)
  393.                         {
  394.                                 //printf("TRUE IsS:testname = %s : string = %s",testname,string);
  395.                                 return 1;
  396.                         }
  397.                 }
  398.         }
  399.         return 0;
  400. }
  401.  
  402. public GetPlayerID(string[])
  403. {
  404.         for(new i = 0; i <= MAX_PLAYERS; i++)
  405.         {
  406.                 if(IsPlayerConnected(i) == 1)
  407.                 {
  408.                         new testname[MAX_PLAYER_NAME];
  409.                         GetPlayerName(i, testname, sizeof(testname));
  410.                         //printf("GetP:testname = %s : string = %s",testname,string);
  411.                         if(strcmp(testname, string, true, strlen(string)) == 0)
  412.                         {
  413.                                 //printf("TRUE GetP:testname = %s : string = %s playerid %d",testname,string, i);
  414.                                 return i;
  415.                         }
  416.                 }
  417.         }
  418.         return INVALID_PLAYER_ID;
  419. }