Advertisement
Guest User

sdiag.inc

a guest
Nov 8th, 2019
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //SDiag by Nexius v1.1
  2.  
  3. #if defined _sdiag_included
  4.     #endinput
  5. #endif
  6. #define _sdiag_included
  7.  
  8. #include <a_samp>
  9.  
  10. #define SDIAG_VERSION       "1.1"
  11.  
  12. enum wMode
  13. {
  14.     WARNING_MODE_GM,
  15.     WARNING_MODE_FS
  16. }
  17.  
  18. static const WarningMode[wMode][] =
  19. {
  20.     "[SDiag: GM] ",
  21.     "[SDiag: FS] "
  22. };
  23.  
  24. enum wMessage
  25. {
  26.     NO_FILTERSCRIPT_DEFINE,
  27.     WRONG_MAX_PLAYERS_DEFINE,
  28.     INCLUDE_VERSION_MISMATCH,
  29.     NEGATIVE_TICK_COUNT,
  30.     NO_SCRIPTFILES_FOLDER,
  31.     WRONG_MAXNPC_VALUE,
  32.     LOW_SLEEP_VALUE,
  33.     QUERY_IS_DISABLED
  34. }
  35.  
  36. static const WarningMessage[wMessage][] =
  37. {
  38.     "One of your filterscripts doesn't have FILTERSCRIPT define",
  39.     "Your MAX_PLAYERS define isn't equal to the real number of player slots",
  40.     "The SA-MP includes version doesn't match with the server version. Please update them",
  41.     "GetTickCount is less than 0. Please restart your computer",
  42.     "Your scriptfiles folder isn't created or you don't have access to it (some scripts may not work correctly)",
  43.     "The variable 'maxnpc' exceeds the maximum number of player slots",
  44.     "The variable 'sleep' is less than the default value. Your timers may work less accurately",
  45.     "Query is disabled. Your server will not be visible in masterlist"
  46. };
  47.  
  48. static bool:sdiag_IsFilterscript;
  49.  
  50. public OnFilterScriptInit()
  51. {
  52.     sdiag_IsFilterscript = true;
  53.  
  54.     #if !defined FILTERSCRIPT
  55.         sdiag_SendWarning(NO_FILTERSCRIPT_DEFINE);
  56.     #endif
  57.  
  58.     if(MAX_PLAYERS != GetMaxPlayers()) sdiag_SendWarning(WRONG_MAX_PLAYERS_DEFINE);
  59.  
  60.     new strtmp[10];
  61.     GetServerVarAsString("version", strtmp, sizeof strtmp);
  62.     if(strfind(strtmp, "0.3.7") != -1)
  63.     {
  64.         #if !defined OnVehicleSirenStateChange
  65.             sdiag_SendWarning(INCLUDE_VERSION_MISMATCH);
  66.         #else
  67.             if(!strcmp(strtmp, "0.3.7-R2") || !strcmp(strtmp, "0.3.7-R3"))
  68.             {
  69.                 #if !defined GetConsoleVarAsInt
  70.                     sdiag_SendWarning(INCLUDE_VERSION_MISMATCH);
  71.                 #endif
  72.             }
  73.         #endif
  74.     }
  75.     else if(strfind(strtmp, "0.3.DL") != -1)
  76.     {
  77.         #if !defined GetPlayerCustomSkin
  78.             sdiag_SendWarning(INCLUDE_VERSION_MISMATCH);
  79.         #endif
  80.     }
  81.  
  82.     #if defined sdiag_OnFilterScriptInit
  83.         return sdiag_OnFilterScriptInit();
  84.     #else
  85.         return 1;
  86.     #endif
  87. }
  88.  
  89. #if defined _ALS_OnFilterScriptInit
  90.     #undef OnFilterScriptInit
  91. #else
  92.     #define _ALS_OnFilterScriptInit
  93. #endif
  94. #define OnFilterScriptInit sdiag_OnFilterScriptInit
  95. #if defined sdiag_OnFilterScriptInit
  96.     forward sdiag_OnFilterScriptInit();
  97. #endif
  98.  
  99. public OnGameModeInit()
  100. {
  101.     if(!sdiag_IsFilterscript)
  102.     {
  103.         if(GetTickCount() < 0) sdiag_SendWarning(NEGATIVE_TICK_COUNT);
  104.  
  105.         if(MAX_PLAYERS != GetMaxPlayers()) sdiag_SendWarning(WRONG_MAX_PLAYERS_DEFINE);
  106.  
  107.         new strtmp[10];
  108.         GetServerVarAsString("version", strtmp, sizeof strtmp);
  109.         if(strfind(strtmp, "0.3.7") != -1)
  110.         {
  111.             #if !defined OnVehicleSirenStateChange
  112.                 sdiag_SendWarning(INCLUDE_VERSION_MISMATCH);
  113.             #else
  114.                 if(!strcmp(strtmp, "0.3.7-R2") || !strcmp(strtmp, "0.3.7-R3"))
  115.                 {
  116.                     #if !defined GetConsoleVarAsInt
  117.                         sdiag_SendWarning(INCLUDE_VERSION_MISMATCH);
  118.                     #endif
  119.                 }
  120.             #endif
  121.         }
  122.         else if(strfind(strtmp, "0.3.DL") != -1)
  123.         {
  124.             #if !defined GetPlayerCustomSkin
  125.                 sdiag_SendWarning(INCLUDE_VERSION_MISMATCH);
  126.             #endif
  127.         }
  128.  
  129.         new File:fhandle = fopen("sdiag_testfile.txt");
  130.         if(!fhandle) sdiag_SendWarning(NO_SCRIPTFILES_FOLDER);
  131.         else
  132.         {
  133.             fclose(fhandle);
  134.             fremove("sdiag_testfile.txt");
  135.         }
  136.  
  137.         if(GetServerVarAsInt("maxnpc") > GetMaxPlayers()) sdiag_SendWarning(WRONG_MAXNPC_VALUE);
  138.  
  139.         if(GetServerVarAsInt("sleep") < 5) sdiag_SendWarning(LOW_SLEEP_VALUE);
  140.  
  141.         if(GetServerVarAsBool("query") != 1) sdiag_SendWarning(QUERY_IS_DISABLED);
  142.     }
  143.     #if defined sdiag_OnGameModeInit
  144.         return sdiag_OnGameModeInit();
  145.     #else
  146.         return 1;
  147.     #endif
  148. }
  149.  
  150. #if defined _ALS_OnGameModeInit
  151.     #undef OnGameModeInit
  152. #else
  153.     #define _ALS_OnGameModeInit
  154. #endif
  155. #define OnGameModeInit sdiag_OnGameModeInit
  156. #if defined sdiag_OnGameModeInit
  157.     forward sdiag_OnGameModeInit();
  158. #endif
  159.  
  160. static sdiag_SendWarning(wMessage:warnid)
  161. {
  162.     if(sdiag_IsFilterscript) printf("%s%s", WarningMode[WARNING_MODE_FS], WarningMessage[warnid]);
  163.     else printf("%s%s", WarningMode[WARNING_MODE_GM], WarningMessage[warnid]);
  164.     return 1;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement