Guest User

Untitled

a guest
Jun 17th, 2015
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. // ---------------------------------------------------------------------------------------------------------
  2.  
  3. #include <a_samp>
  4.  
  5. // ---------------------------------------------------------------------------------------------------------
  6.  
  7. #define MAX_RCON_LENGHT 32 // What is the max lenght for a new RCON password?
  8. #define MAX_RCON_WARNINGS 5 // How many times a player can input a wrong RCON password before he gets punished?
  9. #define MAX_WRONG_INPUTS 3 // How many wrong RCON password inputs are needed for a new password?
  10. #define PUNISHMENT 1 // How should a player, who exceeded the MAX_RCON_WARNINGS limit, should be punished? 1 - ban, 2 - kick.
  11.  
  12. // ---------------------------------------------------------------------------------------------------------
  13.  
  14. static const rcon_characters [63] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  15.  
  16.  
  17. new rcon_whiteList[] =
  18. {
  19. // "your_name",
  20. // "another_name", .... and so.
  21. };
  22.  
  23. static
  24. playerWarnings [MAX_PLAYERS char],
  25. wrongInputs
  26. ;
  27.  
  28. // ---------------------------------------------------------------------------------------------------------
  29.  
  30. public OnPlayerConnect (playerid)
  31. playerWarnings {playerid} = 0;
  32.  
  33. public OnPlayerCommandText (playerid, cmdtext[])
  34. {
  35. if (!strcmp (cmdtext, "/rcon_password", true))
  36. {
  37. new playerName [MAX_PLAYER_NAME];
  38.  
  39. GetPlayerName (playerid, playerName, MAX_PLAYER_NAME);
  40.  
  41. for (new i; i <= sizeof (rcon_whiteList); i++)
  42. {
  43. if (!strcmp (playerName, rcon_whiteList[i], true))
  44. {
  45. new
  46. currentRCON [64 + 1],
  47. message [128]
  48. ;
  49.  
  50. GetServerVarAsString("rcon_password", currentRCON, 64);
  51.  
  52. format (message, 128, "[ {ff0000}* {ffffff}] Current RCON is: %s", currentRCON);
  53. SendClientMessage (playerid, 0xFFFFFFFF, message);
  54.  
  55. break;
  56. }
  57.  
  58. else
  59. return SendClientMessage (playerid, 0xFFFFFFFF, "[ {ff0000}* {ffffff}] You can't use this command.");
  60. }
  61. }
  62.  
  63. return (true);
  64. }
  65.  
  66. public OnRconLoginAttempt (ip [], password [], success)
  67. {
  68. if (!success)
  69. {
  70. static playerIP [16 + 1];
  71.  
  72. for (new i, j = GetPlayerPoolSize(); i <= j; i++)
  73. {
  74. GetPlayerIp (i, playerIP, 16);
  75.  
  76. if (!strcmp (playerIP, ip, true))
  77. {
  78. playerWarnings {i} ++;
  79. wrongInputs ++;
  80.  
  81. if (playerWarnings {i} == MAX_RCON_WARNINGS)
  82. {
  83. PunishPlayer (i);
  84.  
  85. break;
  86. }
  87.  
  88. if (wrongInputs == MAX_WRONG_INPUTS)
  89. {
  90. ChangeRCONPassword ();
  91. wrongInputs = 0;
  92.  
  93. break;
  94. }
  95.  
  96. break;
  97. }
  98. }
  99. }
  100.  
  101. return (true);
  102. }
  103.  
  104. // ---------------------------------------------------------------------------------------------------------
  105.  
  106. ChangeRCONPassword ()
  107. {
  108. static newRCON [64], message [128];
  109.  
  110. for (new i; i <= MAX_RCON_LENGHT; i++)
  111. newRCON[i] = rcon_characters [random (0-62) + 62];
  112.  
  113. for (new i, j = GetPlayerPoolSize (); i <= j; i++)
  114. {
  115. if (!IsPlayerAdmin (i)) continue;
  116.  
  117. format (message, 128, "[ {ff0000}* {ffffff}] The RCON password has changed: {ff0000}%s", newRCON);
  118. SendClientMessage (i, 0xFFFFFFFF, message);
  119.  
  120. return (true);
  121. }
  122.  
  123. format (message, 128, "rcon_password %s", newRCON);
  124. SendRconCommand (message);
  125.  
  126. printf ("[ * ] The RCON password has changed: %s", newRCON);
  127.  
  128. return (true);
  129. }
  130.  
  131. PunishPlayer (playerid)
  132. {
  133. new playerName [MAX_PLAYER_NAME], message [110 + 1];
  134.  
  135. GetPlayerName (playerid, playerName, MAX_PLAYER_NAME);
  136.  
  137. #if PUNISHMENT == 1
  138.  
  139. format (message, 110, "[ {ff0000}* {ffffff}] %s has been banned for several invalid RCON login tries.", playerName);
  140. SendClientMessageToAll (0xFFFFFFFF, message);
  141.  
  142. BanEx (playerid, "Exceeded warnings for RCON login tries");
  143.  
  144. #else
  145.  
  146. format (message, 110, "[ {ff0000}* {ffffff}] %s has been kicked for several invalid RCON login tries.", playerName);
  147. SendClientMessageToAll (0xFFFFFFFF, message);
  148.  
  149. Kick (playerid);
  150.  
  151. #endif
  152. }
Advertisement
Add Comment
Please, Sign In to add comment