HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2.   Fordította: BBk - Death of Legend
  3. */
  4.  
  5. #include <amxmodx>
  6. #include <amxmisc>
  7.  
  8. #if !defined charsmax
  9. #define charsmax(%1) sizeof(%1)-1
  10. #endif
  11.  
  12. #define MAX_MEDIA 30
  13.  
  14. new g_mediaID
  15. new g_media_player[1536]
  16. new g_media_names[MAX_MEDIA][32]
  17. new g_media_urls[MAX_MEDIA][512]
  18. new g_menuposition[33]
  19. new g_currentmediaplaying[33]
  20.  
  21.  
  22. enum INFO { NAME, AUTHOR, VERSION }
  23.  
  24. new const PLUGIN[INFO:3][] =
  25. {
  26. "Adv. Media Player", "cheap_suit", "3.1"
  27. }
  28.  
  29. public plugin_init()
  30. {
  31. register_plugin(PLUGIN[NAME],PLUGIN[VERSION],"cheap_suit")
  32. register_cvar(PLUGIN[NAME], PLUGIN[VERSION], FCVAR_SPONLY|FCVAR_SERVER)
  33. register_menucmd(register_menuid("media_list"), 1023, "action_medialist")
  34.  
  35. register_clcmd("say", "cmd_say")
  36. register_clcmd("say_team", "cmd_say")
  37. register_concmd("amx_addmedia", "cmd_addmedia", ADMIN_CFG, "-
  38.  
  39. utmutato: <media name> <media url> | Figyelem! Pontosan irja be!")
  40. register_concmd("amx_setmedia", "cmd_setmedia", ADMIN_BAN, "-
  41.  
  42. utmutato: <@all|playerID> <media ID> | beallitott media lejatszo(k)")
  43. register_concmd("amx_reloadmedia", "cmd_reloadmedia", ADMIN_CFG, "- az
  44.  
  45. amp_medialist.ini fajl ujratoltes")
  46. register_concmd("amx_listmedia", "cmd_listmedia", 0, "- az
  47.  
  48. adminok szamara mutassa az osszes elerheto zeneszamot")
  49. register_concmd("amx_listeners", "cmd_showlisteners", 0, "-
  50.  
  51. megjeleniti az aktualis media lejatszot")
  52.  
  53. initialize()
  54. }
  55.  
  56. public client_putinserver(id)
  57. {
  58. g_currentmediaplaying[id] = -1
  59. set_task(20.0, "task_inform", id)
  60. }
  61.  
  62. public task_inform(id) if(is_user_connected(id))
  63. client_print(id, print_chat, "* A szerveren %s fut. Tracklista megtekintesehez,
  64.  
  65. lejatszasahoz ird be: /listen | /music | /media", PLUGIN[NAME])
  66.  
  67. public task_info(id) if(is_user_connected(id))
  68. client_print(id, print_chat, "* Most a %s szol. A zene leallitasahoz ird be: /stop",
  69.  
  70. g_media_names[g_currentmediaplaying[id]])
  71.  
  72. public cmd_reloadmedia(id, level, cid)
  73. {
  74. if(!cmd_access(id, level, cid, 1))
  75. return PLUGIN_HANDLED_MAIN
  76.  
  77. initialize()
  78. console_print(id, "* Az amp_medialist.ini fajl ujratoltve.")
  79.  
  80. return PLUGIN_HANDLED_MAIN
  81. }
  82.  
  83. public cmd_listmedia(id)
  84. {
  85. console_print(id, "* Elerheto Media:")
  86. for(new i = 0; i < g_mediaID; i++)
  87. console_print(id, "#%d %s", i, g_media_names[i])
  88.  
  89. return PLUGIN_HANDLED_MAIN
  90. }
  91.  
  92. public cmd_showlisteners(id)
  93. {
  94.  
  95. console_print(id, "* Jelenleg ezt a szamot hallod:")
  96. new players[32], num, i, index, mediaid
  97. get_players(players, num, "hc")
  98.  
  99. for(i = 0; i < num; i++)
  100. {
  101. index = players[i]
  102. mediaid = g_currentmediaplaying[index]
  103.  
  104. if(mediaid == -1)
  105. continue
  106.  
  107. static name[32]
  108. get_user_name(index, name, charsmax(name))
  109. console_print(id, "%s #%d. %s", name, mediaid, g_media_names[mediaid])
  110. }
  111. return PLUGIN_HANDLED_MAIN
  112. }
  113.  
  114. public cmd_addmedia(id, level, cid)
  115. {
  116. if(!cmd_access(id, level, cid, 3))
  117. return PLUGIN_HANDLED_MAIN
  118.  
  119. new medianame[32], mediaurl[256]
  120. read_argv(1, medianame, charsmax(medianame))
  121. read_argv(2, mediaurl, charsmax(mediaurl))
  122.  
  123. copy(g_media_names[g_mediaID], charsmax(g_media_names[]), medianame)
  124. copy(g_media_urls[g_mediaID++], charsmax(g_media_urls[]), mediaurl)
  125.  
  126. new configs_dir[128], file[128]
  127. get_localinfo("amxx_configsdir", configs_dir, charsmax(configs_dir))
  128.  
  129. formatex(file, charsmax(file), "%s/%s", configs_dir, "amp_medialist.ini")
  130. if(file_exists(file))
  131. {
  132. new text[512]
  133. formatex(text, charsmax(text), "^n^"%s^" ^"%s^"", medianame, mediaurl)
  134. write_file(file, text)
  135.  
  136. console_print(id, "* Hozzaadva %s az amp_medialist.ini-hez.", medianame)
  137. }
  138. return PLUGIN_HANDLED_MAIN
  139. }
  140.  
  141. public cmd_setmedia(id, level, cid)
  142. {
  143. if(!cmd_access(id, level, cid, 3))
  144. return PLUGIN_HANDLED_MAIN
  145.  
  146. new player[32], medianumber[11]
  147. read_argv(1, player, charsmax(player))
  148. read_argv(2, medianumber, charsmax(medianumber))
  149.  
  150. new mediaid = str_to_num(medianumber)
  151.  
  152. if(mediaid > g_mediaID)
  153. {
  154. console_print(id, "* Nem talalhato hangfajl.")
  155. return PLUGIN_HANDLED_MAIN
  156. }
  157.  
  158. if(equali(player, "@all"))
  159. {
  160. new players[32], num, i
  161. get_players(players, num, "hc")
  162.  
  163. for(i = 0; i < num; i++)
  164. play_media(players[i], mediaid)
  165. }
  166. else
  167. {
  168. new index = cmd_target(id, player, 2)
  169. if(index)
  170. {
  171. new name[32]
  172. get_user_name(index, name, charsmax(name))
  173.  
  174. play_media(index, mediaid)
  175. client_print(id, print_console, "* A %s szol a %s -tol.",
  176.  
  177. g_media_names[mediaid], name)
  178. }
  179. }
  180. return PLUGIN_HANDLED_MAIN
  181. }
  182.  
  183. public cmd_say(id)
  184. {
  185. static say_args[64]
  186. read_args(say_args, charsmax(say_args))
  187. remove_quotes(say_args)
  188.  
  189. if(say_args[0] != '/')
  190. return PLUGIN_CONTINUE
  191.  
  192. if(equali(say_args, "/playmusic") || equali(say_args, "/music") || equali(say_args,
  193.  
  194. "/playmedia") || equali(say_args, "/listen"))
  195. {
  196. display_medialist(id, g_menuposition[id] = 0)
  197. return PLUGIN_HANDLED_MAIN
  198. }
  199.  
  200. else if(equali(say_args, "/stopmusic") || equali(say_args, "/stop") || equali(say_args,
  201.  
  202. "/stopmedia"))
  203. {
  204. g_currentmediaplaying[id] = -1
  205.  
  206. static motd[1024], len
  207. len = formatex(motd, charsmax(motd), "<html><head><style
  208.  
  209. type=^"text/css^">pre{color:#FFB000;}body{background:#000000;margin-left:8px;margin-top:0px;}</s
  210.  
  211. tyle></head><pre><body>")
  212. len += formatex(motd[len], charsmax(motd) - len, "<center>Zene leallitva. Ezt
  213.  
  214. hozta neked: %s.^n", PLUGIN[NAME])
  215. len += formatex(motd[len], charsmax(motd) - len, "<center>Ez a plugin az
  216.  
  217. amxmodx.org-rol szarmazik.^n")
  218. len += formatex(motd[len], charsmax(motd) - len, "</body></pre></html>^n")
  219.  
  220. show_motd(id, motd, PLUGIN[NAME])
  221.  
  222. return PLUGIN_HANDLED_MAIN
  223. }
  224.  
  225. else if(equali(say_args, "/playagain") || equali(say_args, "/reload") ||
  226.  
  227. equali(say_args, "/replay"))
  228. {
  229. if(g_currentmediaplaying[id] == -1)
  230. client_print(id, print_chat, "* Nehany hangfaljt On nem hallhat.")
  231. else
  232. play_media(id, g_currentmediaplaying[id])
  233.  
  234. return PLUGIN_HANDLED_MAIN
  235. }
  236. return PLUGIN_CONTINUE
  237. }
  238.  
  239. display_medialist(id, pos)
  240. {
  241. if(pos < 0)
  242. return
  243.  
  244. new maxtotal = g_mediaID
  245.  
  246. new start = pos * 8
  247. if(start >= maxtotal)
  248. start = pos = g_menuposition[id]
  249.  
  250. new menubody[512]
  251. new len = format(menubody, charsmax(menubody), "Valasszon egy szamot:^n^n")
  252.  
  253. new end = start + 8
  254. new keys = MENU_KEY_0
  255.  
  256. if(end > maxtotal)
  257. end = maxtotal
  258.  
  259. new b = 0
  260. for(new a = start; a < end; ++a)
  261. {
  262. keys |= (1<<b)
  263. len += formatex(menubody[len], charsmax(menubody), "%d. %s^n", ++b,
  264.  
  265. g_media_names[a])
  266. }
  267.  
  268. if(end != maxtotal)
  269. {
  270. formatex(menubody[len], charsmax(menubody), "^n9. %s...^n0. %s", "Tobb", pos ?
  271.  
  272. "Vissza" : "Kilepes")
  273. keys |= MENU_KEY_9
  274. }
  275. else
  276. formatex(menubody[len], charsmax(menubody), "^n0. %s", pos ? "Vissza" :
  277.  
  278. "Kilepes")
  279.  
  280. show_menu(id, keys, menubody, -1, "media_list")
  281. }
  282.  
  283. public action_medialist(id, key)
  284. {
  285. switch(key)
  286. {
  287. case 8: display_medialist(id, ++g_menuposition[id])
  288. case 9: display_medialist(id, --g_menuposition[id])
  289. default:play_media(id, (g_menuposition[id] * 8 + key))
  290. }
  291. return PLUGIN_HANDLED
  292. }
  293.  
  294. play_media(id, media_id)
  295. {
  296. if(!file_exists(g_media_player))
  297. return
  298.  
  299. g_currentmediaplaying[id] = media_id
  300.  
  301. new player[sizeof(g_media_player)], motd[sizeof(g_media_player)], line, length
  302. while(read_file(g_media_player, line++, player, charsmax(player), length))
  303. add(motd, charsmax(motd), player)
  304.  
  305. replace_all(motd, charsmax(motd), "[MEDIA_NAME]", g_media_names[media_id])
  306. replace_all(motd, charsmax(motd), "[MEDIA_URL]", g_media_urls[media_id])
  307.  
  308. show_motd(id, motd, PLUGIN[NAME])
  309.  
  310. set_task(5.0, "task_info", id)
  311. }
  312.  
  313. initialize()
  314. {
  315. new configs_dir[128], file[128], file_text[2048], len = 0; g_mediaID = 0
  316. get_localinfo("amxx_configsdir", configs_dir, charsmax(configs_dir))
  317.  
  318. formatex(file, charsmax(file), "%s/%s", configs_dir, "amp_medialist.ini")
  319. if(!file_exists(file))
  320. {
  321. len = format(file_text, charsmax(file_text), "; %s Media Lista^n", PLUGIN[NAME])
  322. len += format(file_text[len], charsmax(file_text) - len, "; Formatum: ^"Hang
  323.  
  324. Neve^" ^"Hang URL^"^n")
  325. len += format(file_text[len], charsmax(file_text) - len, "; eg. ^"Papa Roach -
  326.  
  327. Last Resort^" ^"http://www.mysite.com/lastresort.mp3^n^"")
  328. write_file(file, file_text)
  329. }
  330.  
  331.  
  332. formatex(g_media_player, charsmax(g_media_player), "%s/%s", configs_dir,
  333.  
  334. "amp_player.html"); len = 0
  335. if(!file_exists(g_media_player))
  336. {
  337. len = formatex(file_text, charsmax(file_text), "<html><head><style
  338.  
  339. type=^"text/css^">pre{color:#FFB000;}body{background:#000000;margin-left:8px;margin-top:0px;}</s
  340.  
  341. tyle></head><pre><body>")
  342. len += formatex(file_text[len], charsmax(file_text) - len,
  343.  
  344. "<center><b>Hang:</b>[MEDIA_NAME]^n")
  345. len += formatex(file_text[len], charsmax(file_text) - len, "<center>Uzenet: A
  346.  
  347. zeneszam betoltese hosszu ideig eltarthat.^n")
  348. len += formatex(file_text[len], charsmax(file_text) - len, "<center>Bezarhatod a
  349.  
  350. MOTD-t, a zene folyamatosan szolni fog.^n")
  351. len += formatex(file_text[len], charsmax(file_text) - len, "<center><OBJECT
  352.  
  353. ID=^"MediaPlayer1^" width=400 height=144^n")
  354. len += formatex(file_text[len], charsmax(file_text) - len,
  355.  
  356. "classid=^"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95^"^n")
  357. len += formatex(file_text[len], charsmax(file_text) - len,
  358.  
  359. "CODEBASE=^"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,
  360.  
  361. 715^"^n")
  362. len += formatex(file_text[len], charsmax(file_text) - len, "standby=^"Microsoft®
  363.  
  364. Windows® Media Player componensek betoltese...^"^n")
  365. len += formatex(file_text[len], charsmax(file_text) - len,
  366.  
  367. "type=^"application/x-oleobject^">^n")
  368. len += formatex(file_text[len], charsmax(file_text) - len, "<PARAM
  369.  
  370. NAME=^"AutoStart^" ERTEK=^"Igaz^">^n")
  371. len += formatex(file_text[len], charsmax(file_text) - len, "<PARAM
  372.  
  373. NAME=^"FileName^" ERTEK=^"[MEDIA_URL]^">^n")
  374. len += formatex(file_text[len], charsmax(file_text) - len, "<PARAM
  375.  
  376. NAME=^"ShowControls^" ERTEK=^"Igaz^">^n")
  377. len += formatex(file_text[len], charsmax(file_text) - len, "<PARAM
  378.  
  379. NAME=^"ShowStatusBar^" ERTEK=^"Hamis^">^n")
  380. len += formatex(file_text[len], charsmax(file_text) - len, "<PARAM
  381.  
  382. NAME=^"AutoRewind^" ERTEK=^"Igaz^">^n")
  383. len += formatex(file_text[len], charsmax(file_text) - len, "<EMBED
  384.  
  385. type=^"application/x-mplayer2^"
  386.  
  387. pluginspage=^"http://www.microsoft.com/Windows/MediaPlayer/^"^n")
  388. len += formatex(file_text[len], charsmax(file_text) - len,
  389.  
  390. "SRC=^"[MEDIA_URL]^"^n")
  391. len += formatex(file_text[len], charsmax(file_text) - len,
  392.  
  393. "name=^"MediaPlayer1^"^n")
  394. len += formatex(file_text[len], charsmax(file_text) - len, "autostart=1^n")
  395. len += formatex(file_text[len], charsmax(file_text) - len, "showcontrols=1^n")
  396. len += formatex(file_text[len], charsmax(file_text) - len,
  397.  
  398. "autorewind=^"Igaz^"^n")
  399. len += formatex(file_text[len], charsmax(file_text) - len,
  400.  
  401. "showstatusbar=^"Hamis^">^n")
  402. len += formatex(file_text[len], charsmax(file_text) - len,
  403.  
  404. "</EMBED></OBJECT></body></pre></html>^n")
  405.  
  406. write_file(g_media_player, file_text)
  407. }
  408.  
  409. new text[1024], line, length
  410. while(read_file(file, line++, text, charsmax(text), length))
  411. {
  412. trim(text)
  413. if(!length || text[0] == ';')
  414. continue
  415.  
  416. if(g_mediaID >= MAX_MEDIA)
  417. break
  418.  
  419. static left[32], right[512]
  420. strbreak(text, left, charsmax(left), right, charsmax(right))
  421.  
  422. replace_all(left, charsmax(left), "^"", "")
  423. replace_all(right, charsmax(right), "^"", "")
  424. replace_all(right, charsmax(right), " ", "%20")
  425.  
  426. copy(g_media_names[g_mediaID], charsmax(g_media_names[]), left)
  427. copy(g_media_urls[g_mediaID++], charsmax(g_media_urls[]), right)
  428. }
  429. }