seroff

Crash Logs

Dec 16th, 2017
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. // Запускать сервер с параметром -condebug
  2.  
  3.  
  4.  
  5. #include <amxmodx>
  6.  
  7. #include <fakemeta>
  8.  
  9.  
  10.  
  11. #define PLUGIN "Crash Logs"
  12.  
  13. #define VERSION "1.1"
  14.  
  15. #define AUTHOR "Ser_UFL"
  16.  
  17.  
  18.  
  19. #define CRASHED_MAPS "addons/amxmodx/configs/Crashes/Crash.log"
  20.  
  21. #define CRASHED_MAPS_DIR "addons/amxmodx/configs/Crashes"
  22.  
  23.  
  24.  
  25. new g_ConsoleFile[16]
  26.  
  27. new bool:g_LoadingMap
  28.  
  29.  
  30.  
  31. public plugin_init()
  32.  
  33. {
  34.  
  35. register_plugin(PLUGIN, VERSION, AUTHOR)
  36.  
  37.  
  38.  
  39. register_forward(FM_ServerDeactivate, "Deactivate_Server")
  40.  
  41.  
  42.  
  43. is_linux_server() ? formatex(g_ConsoleFile, charsmax(g_ConsoleFile), "qconsole.log") : formatex(g_ConsoleFile, charsmax(g_ConsoleFile), "../qconsole.log")
  44.  
  45.  
  46.  
  47. new Time[32], this_map[32], this_map_log[64], Logs_all[64], Crash_file[64]
  48.  
  49.  
  50.  
  51. get_time("%d.%m.%Y / %X", Time, charsmax(Time))
  52.  
  53. get_mapname(this_map, charsmax(this_map))
  54.  
  55.  
  56.  
  57. formatex(Logs_all, charsmax(Logs_all), "Start: %s | %s", Time, this_map)
  58.  
  59. formatex(this_map_log, charsmax(this_map_log), "%s/%s.txt", CRASHED_MAPS_DIR, this_map)
  60.  
  61.  
  62.  
  63. new CrashDir = open_dir(CRASHED_MAPS_DIR, Crash_file, charsmax(Crash_file))
  64.  
  65.  
  66.  
  67. if (!CrashDir)
  68.  
  69. return
  70.  
  71. do
  72.  
  73. {
  74.  
  75. if (containi(Crash_file, ".txt") != -1)
  76.  
  77. {
  78.  
  79. new i_LineLen, Crashed_map_file[64], s_Line[64], Logs_all_crashes[96]
  80.  
  81.  
  82.  
  83. formatex(Crashed_map_file, charsmax(Crashed_map_file), "%s/%s", CRASHED_MAPS_DIR, Crash_file)
  84.  
  85.  
  86.  
  87. read_file(Crashed_map_file, 0, s_Line, charsmax(s_Line), i_LineLen)
  88.  
  89.  
  90.  
  91. formatex(Logs_all_crashes, charsmax(Logs_all_crashes), "%s | Deactivate: %s", s_Line, Time)
  92.  
  93.  
  94.  
  95. write_file(CRASHED_MAPS, Logs_all_crashes)
  96.  
  97. delete_file(Crash_file)
  98.  
  99. }
  100.  
  101. }
  102.  
  103. while (next_file(CrashDir, Crash_file, charsmax(Crash_file)))
  104.  
  105.  
  106.  
  107. close_dir(CrashDir)
  108.  
  109.  
  110.  
  111. write_file(this_map_log, Logs_all)
  112.  
  113.  
  114.  
  115. g_LoadingMap = true
  116.  
  117.  
  118.  
  119. set_task(1.0, "Fatal_Error")
  120.  
  121. }
  122.  
  123.  
  124.  
  125. public Deactivate_Server()
  126.  
  127. {
  128.  
  129. new map_deactivate[64]
  130.  
  131.  
  132.  
  133. get_mapname(map_deactivate, charsmax(map_deactivate))
  134.  
  135.  
  136.  
  137. format(map_deactivate, charsmax(map_deactivate), "%s/%s.txt", CRASHED_MAPS_DIR, map_deactivate)
  138.  
  139.  
  140.  
  141. delete_file(map_deactivate)
  142.  
  143.  
  144.  
  145. server_cmd("log on")
  146.  
  147. server_cmd("condebug")
  148.  
  149. server_exec()
  150.  
  151. }
  152.  
  153.  
  154.  
  155. public Fatal_Error()
  156.  
  157. {
  158.  
  159. server_cmd("condebug")
  160.  
  161. server_exec()
  162.  
  163.  
  164.  
  165. new i_LineLen, i_LineCount, s_Line[192]
  166.  
  167.  
  168.  
  169. while (read_file(g_ConsoleFile, i_LineCount++, s_Line, charsmax(s_Line), i_LineLen))
  170.  
  171. {
  172.  
  173. if (containi(s_Line, "FATAL ERROR") != -1)
  174.  
  175. {
  176.  
  177. g_LoadingMap = false
  178.  
  179.  
  180.  
  181. format(s_Line, charsmax(s_Line), "Произошла следующая ошибка: %s", s_Line)
  182.  
  183.  
  184.  
  185. write_file(CRASHED_MAPS, s_Line)
  186.  
  187. }
  188.  
  189. }
  190.  
  191.  
  192.  
  193. if (!g_LoadingMap)
  194.  
  195. set_task(0.1, "Loading_map")
  196.  
  197. else
  198.  
  199. delete_file(g_ConsoleFile)
  200.  
  201. }
  202.  
  203.  
  204.  
  205. public Loading_map()
  206.  
  207. {
  208.  
  209. new i_LineLen, i_LineCount, s_Line[192]
  210.  
  211.  
  212.  
  213. while (read_file(g_ConsoleFile, i_LineCount++, s_Line, charsmax(s_Line), i_LineLen))
  214.  
  215. {
  216.  
  217. if (containi(s_Line, "Loading map") != -1)
  218.  
  219. {
  220.  
  221. format(s_Line, charsmax(s_Line), "при загрузке карты: %s", s_Line)
  222.  
  223.  
  224.  
  225. write_file(CRASHED_MAPS, s_Line)
  226.  
  227. }
  228.  
  229. }
  230.  
  231.  
  232.  
  233. delete_file(g_ConsoleFile)
  234.  
  235. }
Advertisement
Add Comment
Please, Sign In to add comment