Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if !defined _INC_FileFunctions
- #tryinclude FileFunctions
- #if !defined _INC_FileFunctions
- #error You need have File Function Plugin Include To Use GetConsoleVarAs Fixer
- #endif
- #endif
- #pragma dynamic 18000
- // CallBack
- public OnGameModeInit()
- {
- CheckFilterScripts();
- CheckPlugins();
- CallLocalFunction("OnGameModeInitEx", "", "");
- }
- // defines
- #define MAX_PLUGINSZ 15
- #define MAX_FILTERSCRIPTSZ 20
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #endif
- #define _ALS_OnGameModeInit
- #define GetConsoleVarAsString GetConsoleVarAsStringEx
- #define UPDATEEVERY 3 // <- seconds to re do varlist
- new LastTimeUsed, GlobalHandle[3700], Pluginsz[MAX_PLUGINSZ][40], FSS[MAX_FILTERSCRIPTSZ][40];
- #define OnGameModeInit OnGameModeInitEx
- forward OnGameModeInitEx();
- // Functions
- CheckPlugins()
- {
- new File:F = fileOpen("server.cfg", io_Read);
- new buf[780];
- while(fileRead(F, buf))
- {
- if(strfind(buf, "Plugins", true, 0) != -1)
- {
- new where = FindChar(buf, ' ', 0);
- while(where != -1)
- {
- new plugin[40], oldarea = where;
- where = FindChar(buf, ' ', where+1);
- if(where != -1)
- {
- strmid(plugin, buf, oldarea+1, where);
- InsertPlugin(plugin);
- }
- if(where == -1 && strlen(buf) > oldarea+2)
- {
- strmid(plugin, buf, oldarea+1, strlen(buf)-2);
- InsertPlugin(plugin);
- }
- }
- break;
- }
- }
- fileClose(F);
- }
- CheckFilterScripts()
- {
- new File:F = fileOpen("server.cfg", io_Read);
- new buf[780];
- while(fileRead(F, buf))
- {
- if(strfind(buf, "filterscripts", true, 0) != -1)
- {
- new where = FindChar(buf, ' ', 0);
- while(where != -1)
- {
- new Filter[40], oldarea = where;
- where = FindChar(buf, ' ', where+1);
- if(where != -1)
- {
- strmid(Filter, buf, oldarea+1, where);
- InsertFS(Filter);
- }
- if(where == -1 && strlen(buf) > oldarea+2)
- {
- strmid(Filter, buf, oldarea+1, strlen(buf)-2);
- InsertFS(Filter);
- }
- }
- break;
- }
- }
- fileClose(F);
- }
- InsertFS(FSZ[])
- {
- for(new i = 0; i < MAX_FILTERSCRIPTSZ; i++)
- {
- if(!strlen(FSS[i]))
- {
- strcat(FSS[i], FSZ);
- break;
- }
- }
- }
- InsertPlugin(Pluginz[])
- {
- for(new i = 0; i < MAX_PLUGINSZ; i++)
- {
- if(!strlen(Pluginsz[i]))
- {
- if(strfind(Pluginz, ".dll", true, 0) != -1)
- {
- new len = strlen(Pluginz);
- strdel(Pluginz, len-4, len);
- strins(Pluginz, " ", strlen(Pluginz), 40);
- }
- if(strfind(Pluginz, ".so", true, 0) != -1)
- {
- new len = strlen(Pluginz);
- strdel(Pluginz, len-3, len);
- strins(Pluginz, " ", strlen(Pluginz), 40);
- }
- strcat(Pluginsz[i], Pluginz);
- break;
- }
- }
- }
- stock GetConsoleVarAsStringEx(const var[], handle[], len = sizeof handle)
- {
- if(strfind(var, "plugins", true, 0) != -1)
- {
- for(new i = 0; i < MAX_PLUGINSZ; i++)
- {
- if(strlen(Pluginsz[i]))
- {
- strcat(handle, Pluginsz[i], len);
- }
- }
- return 1;
- }
- if(strfind(var, "filterscripts", true, 0) != -1)
- {
- for(new i = 0; i < MAX_FILTERSCRIPTSZ; i++)
- {
- if(strlen(FSS[i]))
- {
- strcat(handle, FSS[i], len);
- }
- }
- return 1;
- }
- new Handle[3700];
- strcat(Handle, GetServerLog());
- new where = strfind(Handle, var, true, 0);
- if(where != -1)
- {
- strdel(Handle, 0, FindChar(Handle, '=', where)+2);
- printf(Handle);
- strdel(Handle, FindChar(Handle, ' ', FindChar(Handle, '\"', 1)), strlen(Handle));
- if(FindChar(Handle,'\"', 0) != -1)
- {
- strdel(Handle, 0, 1);
- new leng = strlen(Handle);
- strdel(Handle, leng-1, leng);
- }
- format(handle, len, Handle);
- }
- else
- {
- Handle = "null";
- }
- return 1;
- }
- stock Float:GetConsoleVarAsFloat(const var[])
- {
- new Handle[3700];
- strcat(Handle, GetServerLog());
- new where = strfind(Handle, var, true, 0);
- if(where != -1)
- {
- strdel(Handle, 0, FindChar(Handle, '=', where)+2);
- strdel(Handle, FindChar(Handle, ' ', 0), strlen(Handle));
- if(FindChar(Handle,'\"', 0) != -1)
- {
- strdel(Handle, 0, 1);
- new leng = strlen(Handle);
- strdel(Handle, leng-1, leng);
- }
- }
- else
- {
- Handle = "0";
- }
- return floatstr(Handle);
- }
- FindChar(const str[], charlel, pos)
- {
- new len = strlen(str);
- for(new i = pos; i < len; i++)
- {
- if(str[i] == charlel)
- {
- return i;
- }
- }
- return -1;
- }
- stock GetServerLog()
- {
- if(!LastTimeUsed || (gettime()-LastTimeUsed) > UPDATEEVERY)
- {
- SendRconCommand("varlist");
- LastTimeUsed = gettime();
- new File:handle = fileOpen("server_log.txt", io_Read);
- if(handle)
- {
- fileSeek(handle, -3700, seek_End);
- new buf[350];
- GlobalHandle = "\0";
- while(fileRead(handle, buf))
- {
- strcat(GlobalHandle, buf);
- }
- new where = strfind(GlobalHandle,"Console Variables:", true, where)+1;
- if(strfind(GlobalHandle,"Console Variables:", true, where) == -1)
- {
- strdel(GlobalHandle, 0, where-1);
- }
- while(strfind(GlobalHandle,"Console Variables:", true, where) != -1)
- {
- where = strfind(GlobalHandle,"Console Variables:", true, where)+1;
- strdel(GlobalHandle, 0, where-1);
- }
- fileClose(handle);
- }
- else
- {
- GlobalHandle = "null";
- }
- return GlobalHandle;
- }
- else
- {
- return GlobalHandle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment