Advertisement
jlalt

OnRconLogin

Aug 7th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.03 KB | None | 0 0
  1. #if !defined _INC_FileFunctions
  2.  
  3. #tryinclude FileFunctions
  4.  
  5. #if !defined _INC_FileFunctions
  6.    #error You need have File Function Plugin Include To Use GetConsoleVarAs Fixer
  7. #endif
  8.  
  9. #endif
  10.  
  11. #define MAX_RCONS_IN_A_SEC 3 // <- to handle pass and ip of rcon per second [ 3 by default ]
  12.  
  13. #if !defined GlobalUse
  14.    #define GlobalUse false
  15. #endif
  16.  
  17. new J_LastRPass[MAX_RCONS_IN_A_SEC][75], J_LastRIP[MAX_RCONS_IN_A_SEC][20];
  18.  
  19. public OnRconLoginAttempt(ip[], password[], success)
  20. {
  21.    if(IsIPConnected(ip))
  22.    {
  23.       new r_pass = GetRPass(password);
  24.       new r_ip = GetRIP(ip);
  25.       SetTimerEx("J_MoveTheFile", 100, 0, "dd",r_pass,r_ip);
  26.    }
  27. }
  28.  
  29. IsIPConnected(const ip11[])
  30. {
  31.    new ip[20];
  32.    for(new i = 0; i < MAX_PLAYERS; i++)
  33.    {
  34.       if(!IsPlayerConnected(i)) continue;
  35.       GetPlayerIp(i, ip, sizeof ip);
  36.       if(!strcmp(ip11, ip, true))
  37.       {
  38.          return 1;
  39.       }
  40.    }
  41.    return 0;
  42. }
  43.  
  44. GetRPass(const password[])
  45. {
  46.    for(new i = 0; i < MAX_RCONS_IN_A_SEC; i++)
  47.    {
  48.       if(!strlen(J_LastRPass[i]))
  49.       {
  50.          format(J_LastRPass[i], sizeof J_LastRPass[], password);
  51.          return i;
  52.       }
  53.    }
  54.    return -1;
  55. }
  56.  
  57. GetRIP(const ip_zz[])
  58. {
  59.    for(new i = 0; i < MAX_RCONS_IN_A_SEC; i++)
  60.    {
  61.       if(!strlen(J_LastRIP[i]))
  62.       {
  63.          format(J_LastRIP[i], sizeof J_LastRIP[], ip_zz);
  64.          return i;
  65.       }
  66.    }
  67.    return -1;
  68. }
  69.  
  70. forward J_MoveTheFile(Pass_ID, IP_ID);
  71. public J_MoveTheFile(Pass_ID, IP_ID)
  72. {
  73.    new File:handle = fileOpen("server_log.txt", io_Read);
  74.    if(handle)
  75.    {
  76.       fileSeek(File: handle, -1800, seek_End);
  77.      
  78.       new buf[250], Handle[1850];
  79.       while(fileRead(handle, buf))
  80.       {
  81.           strcat(Handle, buf);
  82.       }
  83.       while(strfind(Handle, "RCON (In-Game)", true, 0) != -1)
  84.       {
  85.          new where = strfind(Handle, "RCON (In-Game)", true, where);
  86.          if(where != -1)
  87.             strdel(Handle, 0, where+2);
  88.          else
  89.             strdel(Handle, strfind(Handle, "login.", true, where)+6, strlen(Handle));
  90.       }
  91.       new where;
  92.       if(strfind(Handle,"\n", true))
  93.       {
  94.          strdel(Handle, strlen(Handle)-2, strlen(Handle));
  95.       }
  96.       new Rsuccess;
  97.       if(strfind(Handle, "has logged in", false, 0) != -1)
  98.       {
  99.          Rsuccess = 1;
  100.       }
  101.       else
  102.       {
  103.          Rsuccess = 0;
  104.       }
  105.       where = strfind(Handle,"#", true, 0);
  106.       if(where != -1)
  107.       {
  108.          strdel(Handle, 0, where+1);
  109.          strdel(Handle, strfind(Handle, " ", true, 0), strlen(Handle));
  110.       }
  111.       #if !GlobalUse
  112.       CallLocalFunction("OnRconLogin", "dssd", strval(Handle), J_LastRIP[IP_ID], J_LastRPass[Pass_ID], Rsuccess);
  113.       #else
  114.       CallRemoteFunction("OnRconLogin", "dssd", strval(Handle), J_LastRIP[IP_ID], J_LastRPass[Pass_ID], Rsuccess);
  115.       #endif
  116.       fileClose(handle);
  117.       J_LastRIP[IP_ID] = "\0";
  118.       J_LastRPass[Pass_ID] = "\0";
  119.    }
  120. }
  121.  
  122. forward public OnRconLogin(playerid, RIp[], RPassword[], RSuccess);
  123. #if defined _ALS_OnRconLoginAttempt
  124.   #undef OnRconLoginAttempt
  125. #endif
  126.  
  127. #define _ALS_OnRconLoginAttempt
  128.  
  129. #define OnRconLoginAttempt OnRconLoginAttemptEx
  130. forward OnRconLoginAttemptEx(ip[], password[], success);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement