/*
MP3+ v0.5
Copyright (C) 2005-2007 Ian (Juan) Cammarata
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
--------------------------------------------------------------------------------
http://ian.cammarata.us
*/
#include
#include
#define PRECACHE_COUNT 2
new const VERSION[ ] = "0.5";
new const TRKCVAR[ ] = "mp3_plus_version";
new const INFO_VAR[ ] = "mp3+";
new inifile[100];
public plugin_init( )
{
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];
//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_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 );
if( file_exists( inifile ) )
{
new inisize = file_size( inifile, 1 );
if( inisize )
{
new line = 0;
if( strlen( pcfile ) )
while( !equal( pcfile, text ) && read_file( inifile, line, text, 99, len ) )
line++;
new oldline = line;
for( new i = 0; i <= PRECACHE_COUNT; i++)
{
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;
}
}
}
return PLUGIN_CONTINUE;
}
public mp3( id, level, cid )
{
if( !cmd_access( id, level, cid, 2 ) )
return PLUGIN_HANDLED;
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" );
}
if( equali( cmd, "list") )
{
show_motd( id, inifile, "MP3s" );
}
else
{
if( read_argc( ) != 3 )
client_print( id, print_console, "Usage: amx_mp3 [mp3]");
else
{
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;
}
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;
}