Advertisement
Lordz

OPRL.inc

Feb 1st, 2014
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.84 KB | None | 0 0
  1. /*______________________________________________________________________________
  2.  
  3.                         OPRL.inc - OnPlayerRconLogin
  4.                                 By Lordz.
  5.  
  6.     "OPRL" AKA "OnPlayerRconLogin" is an include which procies a callback called
  7.     OnPlayerRconLogin which gets called when a player logins as RCON. This is
  8.     called only when a player ID logs in, not if an IP does.
  9.  
  10.  
  11.  
  12.       This Source Code Form is subject to the
  13.       terms of the Mozilla Public License, v.
  14.       2.0. If a copy of the MPL was not
  15.       distributed with this file, You can
  16.       obtain one at
  17.       http://mozilla.org/MPL/2.0/.
  18.  
  19. Author : Lordz™ AKA Lordzy.
  20.  
  21. NOTES:
  22. 1)You may have thought why "OPRL_USE_TIMER" define has been kept. OnPlayerUpdate
  23. don't get called if you're not in game. RCON logins can also be done in apps
  24. like RakSAMP which MAY or MAY NOT call OnPlayerUpdate. But as a timer gets -
  25. called, such a define is used. Uncomment "OPRL_USE_TIMER" to use OnPlayerUpdate.
  26.  
  27. 2) Why not "OnRconLoginAttempt"? Because, it may retrieve multiple users who are
  28.    logged in with the same IP address. So, a timer or OnPlayerUpdate is better!
  29.  
  30.  
  31. Callbacks:
  32. OnPlayerRconLogin(playerid);
  33.  
  34. ______________________________________________________________________________*/
  35.  
  36. #if defined _OnPlayerRconLogin_included
  37.     #endinput
  38. #endif
  39.  
  40. #define _OnPlayerRconLogin_included
  41.  
  42.  
  43.  
  44. //Comment this define in case if you want to avoid timer and use OnPlayerUpdate.
  45. #define OPRL_USE_TIMER
  46.  
  47. static
  48.     #if defined OPRL_USE_TIMER
  49.     OPRL_LTimer,
  50.     #endif
  51.     bool:OPRL_IsPlayerAdmin[MAX_PLAYERS];
  52.  
  53.  
  54. #if defined FILTERSCRIPT
  55. public OnFilterScriptInit() {
  56.     for(new i; i< GetMaxPlayers(); i++) {
  57.         if(IsPlayerAdmin(i)) OPRL_IsPlayerAdmin[i] = true;
  58.         else OPRL_IsPlayerAdmin[i] = false;
  59.     }
  60.     #if defined OPRL_USE_TIMER
  61.         OPRL_LTimer = SetTimer("OPRL_OnUpdate", 600, 1);
  62.     #endif
  63.     #if defined OPRL_OnFilterScriptInit
  64.         OPRL_OnFilterScriptInit();
  65.     #endif
  66.     return 1;
  67. }
  68.  
  69. #if defined OPRL_USE_TIMER
  70. public OnFilterScriptExit() {
  71.     KillTimer(OPRL_LTimer);
  72.     #if defined OPRL_OnFilterScriptExit
  73.         OPRL_OnFilterScriptExit();
  74.     #endif
  75.     return 1;
  76. }
  77. #endif
  78.  
  79. #else
  80.  
  81. public OnGameModeInit() {
  82.     for(new i; i< GetMaxPlayers(); i++) {
  83.         if(IsPlayerAdmin(i)) OPRL_IsPlayerAdmin[i] = true;
  84.         else OPRL_IsPlayerAdmin[i] = false;
  85.     }
  86.     #if defined OPRL_USE_TIMER
  87.         SetTimer("OPRL_OnUpdate", 600, 1);
  88.     #endif
  89.     #if defined ORPL_OnGameModeInit
  90.         OPRL_OnGameModeInit();
  91.     #endif
  92.     return 1;
  93. }
  94.  
  95. #if defined OPRL_USE_TIMER
  96. public OnGameModeExit() {
  97.     KillTimer(OPRL_LTimer);
  98.     #if defined OPRL_OnGameModeExit
  99.         OPRL_OnGameModeExit();
  100.     #endif
  101.     return 1;
  102. }
  103. #endif
  104.  
  105.  
  106. #endif
  107.  
  108. #if defined FILTERSCRIPT
  109.  
  110.     #if defined _ALS_OnFilterScriptInit
  111.         #undef OnFilterScriptInit
  112.     #else
  113.         #define _ALS_OnFilterScriptInit
  114.     #endif
  115.  
  116.     #define OnFilterScriptInit OPRL_OnFilterScriptInit
  117.  
  118.     #if defined OPRL_OnFilterScriptInit
  119.     forward OPRL_OnFilterScriptInit();
  120.     #endif
  121.    
  122.     #if defined OPRL_USE_TIMER
  123.    
  124.         #if defined _ALS_OnFilterScriptExit
  125.             #undef OnFilterScriptExit
  126.         #else
  127.             #define _ALS_OnFilterScriptExit
  128.         #endif
  129.    
  130.         #define OnFilterScriptExit OPRL_OnFilterScriptExit
  131.    
  132.         #if defined OPRL_OnFilterScriptExit
  133.         forward OPRL_OnFilterScriptExit();
  134.         #endif
  135.     #endif
  136.    
  137.  
  138. #else
  139.  
  140.     #if defined _ALS_OnGameModeInit
  141.         #undef OnGameModeInit
  142.     #else
  143.         #define _ALS_OnGameModeInit
  144.     #endif
  145.    
  146.     #define OnGameModeInit OPRL_OnGameModeInit
  147.  
  148.     #if defined OPRL_OnGameModeInit
  149.     forward OPRL_OnGameModeInit();
  150.     #endif
  151.    
  152.     #if defined OPRL_USE_TIMER
  153.         #if defined _ALS_OnGameModeExit
  154.             #undef OnGameModeExit
  155.         #else
  156.             #define _ALS_OnGameModeExit
  157.         #endif
  158.        
  159.         #define OnGameModeExit OPRL_OnGameModeExit
  160.        
  161.         #if defined OPRL_OnGameModeExit
  162.         forward OPRL_OnGameModeExit();
  163.         #endif
  164.     #endif
  165. #endif
  166.  
  167.  
  168. static stock OPRL_CheckRCONAdmin(playerid) {
  169.     if(IsPlayerAdmin(playerid) && OPRL_IsPlayerAdmin[playerid] == false) {
  170.         OPRL_IsPlayerAdmin[playerid] = true;
  171.         CallLocalFunction("OnPlayerRconLogin", "i", playerid);
  172.     }
  173.     else if(!IsPlayerAdmin(playerid) && OPRL_IsPlayerAdmin[playerid] == true) {
  174.         OPRL_IsPlayerAdmin[playerid] = false;
  175.     }
  176.     return 1;
  177. }
  178. #if defined OPRL_USE_TIMER
  179. forward OPRL_OnUpdate();
  180.  
  181. public OPRL_OnUpdate() {
  182.     for(new i; i< GetMaxPlayers(); i++) {
  183.         if(!IsPlayerConnected(i)) continue;
  184.         OPRL_CheckRCONAdmin(i);
  185.     }
  186.     return 1;
  187. }
  188.  
  189. #else
  190.  
  191. public OnPlayerUpdate(playerid) {
  192.     OPRL_CheckRCONAdmin(playerid);
  193.     #if defined OPRL_OnPlayerUpdate
  194.         OPRL_OnPlayerUpdate(playerid);
  195.     #endif
  196.     return 1;
  197. }
  198.  
  199.     #if defined _ALS_OnPlayerUpdate
  200.         #undef OnPlayerUpdate
  201.     #else
  202.         #define _ALS_OnPlayerUpdate
  203.     #endif
  204.    
  205.     #define OnPlayerUpdate OPRL_OnPlayerUpdate
  206.  
  207.     #if defined OPRL_OnPlayerUpdate
  208.     forward OPRL_OnPlayerUpdate(playerid);
  209.     #endif
  210. #endif
  211.  
  212.  
  213. forward OnPlayerRconLogin(playerid);
  214.  
  215. /* Copyright(c) 2014 - "OPRL.inc" */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement