--- mp3.sma 2007/11/20 22:36:56 25 +++ mp3_plus.sma 2008/03/03 06:00:27 43 @@ -1,5 +1,5 @@ /* -MP3+ v0.4 +MP3+ v0.5 Copyright (C) 2005-2007 Ian (Juan) Cammarata This program is free software: you can redistribute it and/or modify @@ -23,93 +23,137 @@ #define PRECACHE_COUNT 2 -#define VERSION "0.4" +new const VERSION[ ] = "0.5"; +new const TRKCVAR[ ] = "mp3_plus_version"; +new const INFO_VAR[ ] = "mp3+"; -new inifile[100] +new inifile[100]; public plugin_init( ) { - register_plugin( "mp3+", VERSION, "Ian Cammarata" ) - register_cvar( "mp3+_version", VERSION, FCVAR_SERVER ) - register_concmd( "amx_mp3", "mp3", ADMIN_SLAY, " [mp3] - Play mp3 on all clients." ) + register_plugin( "mp3+", VERSION, "Ian Cammarata" ); + register_cvar( TRKCVAR, VERSION, FCVAR_SERVER ); + set_cvar_string( TRKCVAR, VERSION ); + + register_concmd( "amx_mp3", "mp3", ADMIN_SLAY, " [mp3] - Play mp3 on all clients." ); + register_clcmd( "say mp3_stop", "mp3_stop" ); + register_clcmd( "say mp3_disable", "mp3_disable" ); return PLUGIN_CONTINUE } public plugin_precache( ) { - new varfile[100] - new len, text[100], pcfile[100] + new varfile[100]; + new len, text[100], pcfile[100]; //Make var folder if not exists - get_localinfo( "amxx_datadir", varfile, 99 ) - format( varfile, 99, "%s/var", varfile ) - if( !dir_exists( varfile ) ) mkdir( varfile ) + get_localinfo( "amxx_datadir", varfile, 99 ); + format( varfile, 99, "%s/var", varfile ); + if( !dir_exists( varfile ) ) mkdir( varfile ); - get_localinfo( "amxx_configsdir", inifile, 99 ) - format( inifile, 99, "%s/mp3precache.ini", inifile ) - format( varfile, 99, "%s/mp3precache.var", varfile ) + get_localinfo( "amxx_configsdir", inifile, 99 ); + format( inifile, 99, "%s/mp3precache.ini", inifile ); + format( varfile, 99, "%s/mp3precache.var", varfile ); //Get name of last precached file if( file_exists( varfile ) ) - read_file( varfile, 0, pcfile, 99, len ) + read_file( varfile, 0, pcfile, 99, len ); if( file_exists( inifile ) ) { - new inisize = file_size( inifile, 1 ) + new inisize = file_size( inifile, 1 ); if( inisize ) { - new line = 0 + new line = 0; if( strlen( pcfile ) ) while( !equal( pcfile, text ) && read_file( inifile, line, text, 99, len ) ) - line++ + line++; - new oldline = line + new oldline = line; for( new i = 0; i <= PRECACHE_COUNT; i++) { - if ( line == inisize ) line = 0 + if ( line == inisize ) line = 0; - read_file( inifile, line, pcfile, 99, len ) - write_file( varfile, pcfile, 0 ) - format( pcfile, 99, "media/%s", pcfile ) - precache_generic( pcfile ) - line++ - if( line == oldline ) break + read_file( inifile, line, pcfile, 99, len ); + write_file( varfile, pcfile, 0 ); + format( pcfile, 99, "media/%s", pcfile ); + precache_generic( pcfile ); + line++; + if( line == oldline ) break; } } } - return PLUGIN_CONTINUE + return PLUGIN_CONTINUE; } public mp3( id, level, cid ) { if( !cmd_access( id, level, cid, 2 ) ) - return PLUGIN_HANDLED + return PLUGIN_HANDLED; - new cmd[4] - read_argv( 1, cmd, 4 ) + new cmd[4]; + read_argv( 1, cmd, 4 ); if( equali( cmd, "stop") ) { - client_cmd( 0, "mp3 stop" ) - client_print( 0, print_chat, "[AMX] MP3 : Stopped" ) + client_cmd( 0, "mp3 stop" ); + client_print( 0, print_chat, "[AMX] MP3 : Stopped" ); } if( equali( cmd, "list") ) { - show_motd( id, inifile, "MP3s" ) + show_motd( id, inifile, "MP3s" ); } else { if( read_argc( ) != 3 ) - client_print( id, print_console, "Usage: amx_mp3 [mp3]") + client_print( id, print_console, "Usage: amx_mp3 [mp3]"); else { - new title[32] - read_argv(2,title,32) - client_cmd(0,"mp3 %s media/%s",cmd,title) - strtoupper(cmd) - client_print(0,print_chat,"[AMX] : %s MP3 %s - To stop type, ^"mp3 stop^" in console.",cmd,title) + new title[32]; + read_argv( 2, title, 31 ); + + new players[32], pcount, info_val[4], exec_cmd[64], id2; + get_players( players, pcount, "ch" ); + + formatex( exec_cmd, 63, "mp3 %s media/%s", cmd, title ); + strtoupper( cmd ); + + for( new i = 0; i < pcount; i++ ) + { + id2 = players[i]; + get_user_info( id2, INFO_VAR, info_val, 3 ); + if( strcmp( info_val, "off" ) ) + { + client_cmd( id2, exec_cmd ); + client_print( id2, print_chat, "[AMX] : %s MP3 %s - To stop type, ^"mp3_stop^".", cmd, title ); + } + } } } - return PLUGIN_HANDLED + return PLUGIN_HANDLED; +} + +public mp3_stop( id ) +{ + client_cmd( id, "mp3 stop" ); + client_print( id, print_chat, "MP3 Stopped. To disable MP3's permanently, type ^"mp3_disable^" or exec ^"setinfo mp3+ off^"" ); + return PLUGIN_HANDLED; +} + +public mp3_disable( id ) +{ + new info_val[4]; + get_user_info( id, INFO_VAR, info_val, 3 ); + if( strcmp( info_val, "off" ) ) + { + client_print( id, print_chat, "MP3's Disabled. To enable again, type ^"mp3_disable^" or exec ^"setinfo mp3+ on^"" ); + set_user_info( id, INFO_VAR, "off" ); + } + else + { + client_print( id, print_chat, "MP3's Enabled." ); + set_user_info( id, INFO_VAR, "on" ); + } + return PLUGIN_HANDLED; }