jlalt

GetConsoleVarAs

Aug 6th, 2016
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.62 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. #pragma dynamic 18000
  12.  
  13. // CallBack
  14.  
  15. public OnGameModeInit()
  16. {
  17.    CheckFilterScripts();
  18.    CheckPlugins();
  19.    CallLocalFunction("OnGameModeInitEx", "", "");
  20. }
  21.  
  22. // defines
  23.  
  24. #define MAX_PLUGINSZ 15
  25. #define MAX_FILTERSCRIPTSZ 20
  26.  
  27. #if defined _ALS_OnGameModeInit
  28.   #undef OnGameModeInit
  29. #endif
  30.  
  31. #define _ALS_OnGameModeInit
  32.  
  33. #define GetConsoleVarAsString GetConsoleVarAsStringEx
  34.  
  35. #define UPDATEEVERY 3 // <- seconds to re do varlist
  36.  
  37. new LastTimeUsed, GlobalHandle[3700], Pluginsz[MAX_PLUGINSZ][40], FSS[MAX_FILTERSCRIPTSZ][40];
  38.  
  39. #define OnGameModeInit OnGameModeInitEx
  40. forward OnGameModeInitEx();
  41.  
  42. // Functions
  43.  
  44. CheckPlugins()
  45. {
  46.    new File:F = fileOpen("server.cfg", io_Read);
  47.    new buf[780];
  48.    while(fileRead(F, buf))
  49.    {
  50.       if(strfind(buf, "Plugins", true, 0) != -1)
  51.       {
  52.           new where = FindChar(buf, ' ', 0);
  53.           while(where != -1)
  54.           {
  55.              new plugin[40], oldarea = where;
  56.              where = FindChar(buf, ' ', where+1);
  57.              if(where != -1)
  58.              {
  59.                 strmid(plugin, buf, oldarea+1, where);
  60.                 InsertPlugin(plugin);
  61.              }
  62.              if(where == -1 && strlen(buf) > oldarea+2)
  63.              {
  64.                 strmid(plugin, buf, oldarea+1, strlen(buf)-2);
  65.                 InsertPlugin(plugin);
  66.              }
  67.           }
  68.           break;
  69.       }
  70.    }
  71.    fileClose(F);
  72. }
  73.  
  74. CheckFilterScripts()
  75. {
  76.    new File:F = fileOpen("server.cfg", io_Read);
  77.    new buf[780];
  78.    while(fileRead(F, buf))
  79.    {
  80.       if(strfind(buf, "filterscripts", true, 0) != -1)
  81.       {
  82.           new where = FindChar(buf, ' ', 0);
  83.           while(where != -1)
  84.           {
  85.              new Filter[40], oldarea = where;
  86.              where = FindChar(buf, ' ', where+1);
  87.              if(where != -1)
  88.              {
  89.                 strmid(Filter, buf, oldarea+1, where);
  90.                 InsertFS(Filter);
  91.              }
  92.              if(where == -1 && strlen(buf) > oldarea+2)
  93.              {
  94.                 strmid(Filter, buf, oldarea+1, strlen(buf)-2);
  95.                 InsertFS(Filter);
  96.              }
  97.           }
  98.           break;
  99.       }
  100.    }
  101.    fileClose(F);
  102. }
  103.  
  104. InsertFS(FSZ[])
  105. {
  106.    for(new i = 0; i < MAX_FILTERSCRIPTSZ; i++)
  107.    {
  108.       if(!strlen(FSS[i]))
  109.       {
  110.          strcat(FSS[i], FSZ);
  111.          break;
  112.       }
  113.    }
  114. }
  115.  
  116. InsertPlugin(Pluginz[])
  117. {
  118.    for(new i = 0; i < MAX_PLUGINSZ; i++)
  119.    {
  120.       if(!strlen(Pluginsz[i]))
  121.       {
  122.          if(strfind(Pluginz, ".dll", true, 0) != -1)
  123.          {
  124.             new len = strlen(Pluginz);
  125.             strdel(Pluginz, len-4, len);
  126.             strins(Pluginz, " ", strlen(Pluginz), 40);
  127.          }
  128.          if(strfind(Pluginz, ".so", true, 0) != -1)
  129.          {
  130.             new len = strlen(Pluginz);
  131.             strdel(Pluginz, len-3, len);
  132.             strins(Pluginz, " ", strlen(Pluginz), 40);
  133.          }
  134.          
  135.          strcat(Pluginsz[i], Pluginz);
  136.          break;
  137.       }
  138.    }
  139. }
  140.  
  141. stock GetConsoleVarAsStringEx(const var[], handle[], len = sizeof handle)
  142. {
  143.    if(strfind(var, "plugins", true, 0) != -1)
  144.    {
  145.       for(new i = 0; i < MAX_PLUGINSZ; i++)
  146.       {
  147.          if(strlen(Pluginsz[i]))
  148.          {
  149.             strcat(handle, Pluginsz[i], len);
  150.          }
  151.       }
  152.       return 1;
  153.    }
  154.    
  155.    if(strfind(var, "filterscripts", true, 0) != -1)
  156.    {
  157.       for(new i = 0; i < MAX_FILTERSCRIPTSZ; i++)
  158.       {
  159.          if(strlen(FSS[i]))
  160.          {
  161.             strcat(handle, FSS[i], len);
  162.          }
  163.       }
  164.       return 1;
  165.    }
  166.    
  167.    new Handle[3700];
  168.    strcat(Handle, GetServerLog());
  169.    new where = strfind(Handle, var, true, 0);
  170.    if(where != -1)
  171.    {
  172.       strdel(Handle, 0, FindChar(Handle, '=', where)+2);
  173.       printf(Handle);
  174.       strdel(Handle, FindChar(Handle, ' ', FindChar(Handle, '\"', 1)), strlen(Handle));
  175.       if(FindChar(Handle,'\"', 0) != -1)
  176.       {
  177.          strdel(Handle, 0, 1);
  178.          new leng = strlen(Handle);
  179.          strdel(Handle, leng-1, leng);
  180.       }
  181.       format(handle, len, Handle);
  182.    }
  183.    else
  184.    {
  185.       Handle = "null";
  186.    }
  187.    return 1;
  188. }
  189.  
  190. stock Float:GetConsoleVarAsFloat(const var[])
  191. {
  192.    new Handle[3700];
  193.    strcat(Handle, GetServerLog());
  194.    new where = strfind(Handle, var, true, 0);
  195.    if(where != -1)
  196.    {
  197.       strdel(Handle, 0, FindChar(Handle, '=', where)+2);
  198.       strdel(Handle, FindChar(Handle, ' ', 0), strlen(Handle));
  199.       if(FindChar(Handle,'\"', 0) != -1)
  200.       {
  201.          strdel(Handle, 0, 1);
  202.          new leng = strlen(Handle);
  203.          strdel(Handle, leng-1, leng);
  204.       }
  205.    }
  206.    else
  207.    {
  208.       Handle = "0";
  209.    }
  210.    return floatstr(Handle);
  211. }
  212.  
  213. FindChar(const str[], charlel, pos)
  214. {
  215.    new len = strlen(str);
  216.    for(new i = pos; i < len; i++)
  217.    {
  218.       if(str[i] == charlel)
  219.       {
  220.          return i;
  221.       }
  222.    }
  223.    return -1;
  224. }
  225.  
  226. stock GetServerLog()
  227. {
  228.    if(!LastTimeUsed || (gettime()-LastTimeUsed) > UPDATEEVERY)
  229.    {
  230.       SendRconCommand("varlist");
  231.       LastTimeUsed = gettime();
  232.       new File:handle = fileOpen("server_log.txt", io_Read);
  233.       if(handle)
  234.       {
  235.           fileSeek(handle, -3700, seek_End);
  236.           new buf[350];
  237.           GlobalHandle = "\0";
  238.           while(fileRead(handle, buf))
  239.           {
  240.              strcat(GlobalHandle, buf);
  241.           }
  242.  
  243.           new where = strfind(GlobalHandle,"Console Variables:", true, where)+1;
  244.  
  245.           if(strfind(GlobalHandle,"Console Variables:", true, where) == -1)
  246.           {
  247.               strdel(GlobalHandle, 0, where-1);
  248.           }
  249.  
  250.           while(strfind(GlobalHandle,"Console Variables:", true, where) != -1)
  251.           {
  252.              where = strfind(GlobalHandle,"Console Variables:", true, where)+1;
  253.              strdel(GlobalHandle, 0, where-1);
  254.           }
  255.           fileClose(handle);
  256.       }
  257.       else
  258.       {
  259.          GlobalHandle = "null";
  260.       }
  261.       return GlobalHandle;
  262.    }
  263.    else
  264.    {
  265.       return GlobalHandle;
  266.    }
  267. }
Advertisement
Add Comment
Please, Sign In to add comment