HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <regex>
  3.  
  4. #define VERSION 0.1.3
  5.  
  6. #define MAX_SIZE 1024
  7. #define MAX_MAPS 64
  8. #define MAX_GROUP 24
  9. #define MAX_GROUPS 16
  10. #define STR_L 64
  11. #define STR_M 32
  12. #define STR_S 16
  13. #define TASK_ID 15658734
  14.  
  15. #define MAP(%1) g_maps_str[g_maps[%1]]
  16.  
  17. new g_shedule[MAX_GROUPS][4];
  18. new g_shedule_size;
  19.  
  20. new g_maps_str[MAX_SIZE];
  21. new g_maps[MAX_MAPS];
  22. new g_maps_len, g_maps_cnt;
  23.  
  24. new g_actual[MAX_GROUPS], g_actual_info[2];
  25. new g_ut_midnight;
  26.  
  27. public plugin_natives()
  28. {
  29. register_library("maps_shedule");
  30. register_native("mapsh_maps", "_mapsh_maps", 0);
  31. }
  32.  
  33. public plugin_init()
  34. {
  35. register_clcmd("amx_mapsh", "cmd_mapsh", -1, "");
  36. }
  37.  
  38. public plugin_cfg()
  39. {
  40. load_shedule();
  41. update_shedule();
  42. }
  43.  
  44. public plugin_end()
  45. {
  46. remove_task(TASK_ID);
  47. }
  48.  
  49. public update_shedule(){
  50. choose_groups(g_actual, g_actual_info);
  51. set_task(float(g_actual_info[1]) + 0.5, "update_shedule", TASK_ID, "", 0, "a", 1);
  52. }
  53.  
  54. public cmd_mapsh(id, level, cid)
  55. {
  56. new arg1[STR_S];
  57. new bool:all = true;
  58. read_argv(1, arg1, STR_S - 1);
  59. new tsec;
  60.  
  61. if(arg1[0])
  62. {
  63. if(equal(arg1, "now"))
  64. {
  65. tsec = sec_from_midnight();
  66. }
  67. else if(equal(arg1, "at"))
  68. {
  69. new arg2[STR_S];
  70. read_argv(2, arg2, STR_S - 1);
  71. new match, err[128], str[STR_S];
  72. new Regex:m = regex_match(arg2, "(\d{1,2}:\d{1,2}):?(\d{1,2})?", match, err, 127);
  73.  
  74. if(match < 1){
  75. client_print(id, print_console, "Hibas betoltes.");
  76. return PLUGIN_HANDLED;
  77. }else if (match == 2){
  78. regex_substr(m, 1, str, STR_S - 1);
  79. tsec = parse_time(str, "%H:%M", 0);
  80. }else if (match == 3){
  81. regex_substr(m, 0, str, STR_S - 1);
  82. tsec = parse_time(str, "%H:%M:%S", 0);
  83. }
  84.  
  85. new timestr[STR_M];
  86. format_time(timestr, STR_M - 1, "%H:%M:%S", tsec + g_ut_midnight);
  87. client_print(id, print_console, "# Elerheto mapok %s:", timestr);
  88. regex_free(m);
  89. }
  90. else if(equal(arg1, "id")){
  91. new arg2[STR_S];
  92. read_argv(2, arg2, STR_S - 1);
  93. if(!is_str_num(arg2)){
  94. client_print(id, print_console, "Hibas betoltes.");
  95. return PLUGIN_HANDLED;
  96. }
  97. else {
  98. new group_id = str_to_num(arg2);
  99. if( group_id >= 0 && group_id <= g_shedule_size) {
  100. print_group(id, group_id);
  101. }
  102. else {
  103. client_print(id, print_console, "Hibas id.");
  104. return PLUGIN_HANDLED;
  105. }
  106. }
  107. }
  108. all = false;
  109. }
  110.  
  111. new tleft_str[16];
  112.  
  113. if(!all){
  114. new tm[MAX_GROUPS], opt[2];
  115. choose_groups(tm, opt, tsec);
  116. for(new i = 0; i < opt[0]; i++){
  117. print_group(id, tm[i]);
  118. }
  119. sec_to_str(opt[1], tleft_str);
  120. }
  121. else {
  122. for(new i = 0; i <= g_shedule_size; i++){
  123. print_group(id, i);
  124. }
  125. sec_to_str(g_actual_info[1], tleft_str);
  126. }
  127.  
  128. client_print(id, print_console, "A kovetkezo frissitesig: %s", tleft_str);
  129. return PLUGIN_HANDLED;
  130. }
  131.  
  132. print_group(id, group_id){
  133. new t_str1[16], t_str2[16], t_str3[16], str[STR_L];
  134.  
  135. new t1 = g_shedule[group_id][0],
  136. t2 = g_shedule[group_id][1],
  137. duration = t2 == t1 ? 86400 : t2 - t1;
  138.  
  139. format_time(t_str1, 16, "%H:%M:%S", t1 + g_ut_midnight);
  140. format_time(t_str2, 16, "%H:%M:%S", t2 + g_ut_midnight);
  141. sec_to_str(duration, t_str3);
  142.  
  143. new maps = g_shedule[group_id][3] - g_shedule[group_id][2];
  144.  
  145. format(str, STR_L, "#%02d %02d %s - %s ( %s )", group_id, maps, t_str1, t_str2, t_str3);
  146. client_print(id, print_console, str);
  147.  
  148. for(new i = 0; i < maps; i++){
  149. format(str, STR_L, "%3d. %s", i, MAP(g_shedule[group_id][2] + i));
  150. client_print(id, print_console, str);
  151. }
  152. client_print(id, print_console, "");
  153. }
  154.  
  155. public _mapsh_maps(plugin, params)
  156. {
  157. new count = get_param_byref(3);
  158. new rand = get_param(4);
  159. new limit = get_param(5);
  160. new tsec = get_param(6);
  161. new current = get_param(7);
  162.  
  163. if(tsec < 0)
  164. tsec = sec_from_midnight();
  165.  
  166. new groups[MAX_GROUPS], info[2];
  167. new all_maps_ids[MAX_MAPS], maps_cnt;
  168. new group_id, group_sz;
  169. new maps_ids[MAX_MAPS], map_id;
  170.  
  171. choose_groups(groups, info, tsec);
  172.  
  173. for(new i = 0; i < info[0]; i++){
  174. group_id = groups[i];
  175. group_sz = g_shedule[group_id][3] - g_shedule[group_id][2];
  176.  
  177. for(new j = 0; j < group_sz; j++)
  178. all_maps_ids[maps_cnt + j] = g_shedule[group_id][2] + j;
  179.  
  180. maps_cnt += group_sz;
  181. }
  182.  
  183. if(current == -1){
  184. new current_map[STR_M];
  185. get_mapname(current_map, STR_M - 1);
  186. current = get_current_map_id(current_map);
  187. current = find(all_maps_ids, maps_cnt, current);
  188. if( current != -1 && maps_cnt <= limit)
  189. maps_cnt--;
  190. } else current = -1;
  191.  
  192. if(limit != -1)
  193. maps_cnt = maps_cnt < limit ? maps_cnt : limit;
  194.  
  195. for(new j = 0; j < maps_cnt; j++){
  196. if(rand){
  197. do map_id = all_maps_ids[random(maps_cnt + 1)];
  198. while(find(maps_ids, j, map_id) != -1)
  199. }
  200. else map_id = all_maps_ids[j];
  201.  
  202. if(map_id == current){
  203. if(rand)
  204. j--;
  205. continue;
  206. }
  207. else maps_ids[j] = map_id;
  208. }
  209.  
  210. new buff[MAX_SIZE];
  211. new maps[MAX_MAPS];
  212. new buff_sz, map_len;
  213.  
  214. for(new i = 0; i < maps_cnt; i++){
  215. map_len = strlen(MAP(maps_ids[i]));
  216. maps[i] = buff_sz;
  217. copy(buff[buff_sz], MAX_SIZE, MAP(maps_ids[i]));
  218. buff_sz += map_len + 1;
  219. }
  220.  
  221. set_array(1, buff, buff_sz);
  222. set_array(2, maps, maps_cnt);
  223.  
  224. if(count != -1)
  225. set_param_byref(3, maps_cnt);
  226.  
  227. return info[1];
  228. }
  229.  
  230. choose_groups(groups[MAX_GROUPS], info[2], tsec = 0)
  231. {
  232. new t, t1, t2, tleft, diff, sz;
  233. t = tsec ? tsec : sec_from_midnight();
  234. tleft = diff = 86400;
  235.  
  236. for(new i = 0; i <= g_shedule_size; i++){
  237. t1 = g_shedule[i][0] < 86400 ? g_shedule[i][0] : g_shedule[i][0] % 86400;
  238. t2 = g_shedule[i][1] < 86400 ? g_shedule[i][1] : g_shedule[i][1] % 86400;
  239.  
  240. if(t2 <= t1){
  241. t2 += 86400;
  242. if(t < t1 && t < t2)
  243. t1 = 0;
  244. }
  245.  
  246. diff = t1 - t;
  247.  
  248. if(t >= t1 && t < t2){
  249. groups[sz++] = i;
  250. diff = t2 - t;
  251. }
  252.  
  253. diff = diff < 0 ? diff + 86400 : diff;
  254. if(diff < tleft)
  255. tleft = diff;
  256. }
  257.  
  258. info[0] = sz;
  259. info[1] = tleft;
  260. }
  261.  
  262. load_shedule()
  263. {
  264. g_shedule_size = -1;
  265. new path[STR_L];
  266. get_localinfo("amxx_configsdir", path, sizeof(path) - 1);
  267. format(path, sizeof(path) - 1, "%s/maps_shedule.ini", path);
  268.  
  269. if(!file_exists(path))
  270. return;
  271.  
  272. new f = fopen(path, "r");
  273. if(!f){
  274. log_amx("I/O Error. Fajlt nem lehet megnyitni: %s", path);
  275. return;
  276. }
  277.  
  278. new str[STR_L];
  279.  
  280. while(!feof(f)){
  281. fgets(f, str, STR_L - 1);
  282. if(str[0] == ';' || strlen(str) < 4)
  283. continue;
  284.  
  285. if(str[0] == '['){
  286. if(++g_shedule_size == MAX_GROUPS)
  287. return;
  288.  
  289. str[0] = ' ';
  290. replace(str, STR_L, "]", " ");
  291. trim(str);
  292.  
  293. new l[32], r[32];
  294. strtok(str, l, 32, r, 32, '-' );
  295.  
  296. g_shedule[g_shedule_size][0] = parse_time(l, "%H:%M:%S", 0);
  297. g_shedule[g_shedule_size][1] = parse_time(r, "%H:%M:%S", 0);
  298.  
  299. continue;
  300. }
  301.  
  302. trim(str);
  303. if(is_map_valid(str)){
  304. if(g_shedule_size < 0){
  305. log_amx("Hiba: kovetkezo ^"%s^"", str);
  306. continue;
  307. }
  308.  
  309. g_maps[g_maps_cnt++] = g_maps_len;
  310. if( g_maps_len >= MAX_SIZE){
  311. log_amx("Figyelmeztetes: Tul sok mapot tartalmaz.");
  312. break;
  313. }
  314. copy(g_maps_str[g_maps_len], MAX_SIZE, str);
  315. g_maps_len += strlen(str) + 1;
  316.  
  317. if(g_shedule[g_shedule_size][3] == 0){
  318. g_shedule[g_shedule_size][2] = g_shedule[g_shedule_size][3] = g_maps_cnt - 1;
  319. }
  320. g_shedule[g_shedule_size][3] += 1;
  321. }
  322. else {
  323. log_amx("Figyelmeztetes: ^"%s^" map nem talalhato.", str);
  324. }
  325. }
  326. }
  327.  
  328. find(arr[MAX_MAPS], sz, n, start = 0){
  329. for(new i = start; i < sz; i++){
  330. if(arr[i] == n)
  331. return i;
  332. }
  333. return -1;
  334. }
  335.  
  336. sec_from_midnight()
  337. {
  338. g_ut_midnight = parse_time("00:00:00", "%H:%M:%S");
  339. return time() - g_ut_midnight;
  340. }
  341.  
  342. sec_to_str(tsec, dest[16])
  343. {
  344. tsec = tsec < 0 ? tsec + 86400 : tsec;
  345. new h = tsec / 3600,
  346. m = (tsec % 3600) / 60,
  347. s = (tsec % 3600) % 60;
  348.  
  349. format(dest, 16, "%02d:%02d:%02d", h, m, s);
  350. }
  351.  
  352. get_current_map_id(map[STR_M]){
  353. for(new i = 0; i < g_maps_cnt; i++){
  354. if(equali(MAP(i), map))
  355. return i;
  356. }
  357. return -1;
  358. }