[Half-Life AMXX] / mp3_plus.sma Repository:
ViewVC logotype

Diff of /mp3_plus.sma

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

mp3.sma revision 25, Tue Nov 20 22:36:56 2007 UTC mp3_plus.sma revision 43, Mon Mar 3 06:00:27 2008 UTC
# Line 1  Line 1 
1  /*  /*
2  MP3+ v0.4  MP3+ v0.5
3  Copyright (C) 2005-2007 Ian (Juan) Cammarata  Copyright (C) 2005-2007 Ian (Juan) Cammarata
4    
5  This program is free software: you can redistribute it and/or modify  This program is free software: you can redistribute it and/or modify
# Line 23  Line 23 
23    
24  #define PRECACHE_COUNT 2  #define PRECACHE_COUNT 2
25    
26  #define VERSION "0.4"  new const VERSION[ ] = "0.5";
27    new const TRKCVAR[ ] = "mp3_plus_version";
28    new const INFO_VAR[ ] = "mp3+";
29    
30  new inifile[100]  new inifile[100];
31    
32  public plugin_init( )  public plugin_init( )
33  {  {
34          register_plugin( "mp3+", VERSION, "Ian Cammarata" )          register_plugin( "mp3+", VERSION, "Ian Cammarata" );
35          register_cvar( "mp3+_version", VERSION, FCVAR_SERVER )          register_cvar( TRKCVAR, VERSION, FCVAR_SERVER );
36          register_concmd( "amx_mp3", "mp3", ADMIN_SLAY, "<play|loop|stop|list> [mp3] - Play mp3 on all clients." )          set_cvar_string( TRKCVAR, VERSION );
37    
38            register_concmd( "amx_mp3", "mp3", ADMIN_SLAY, "<play|loop|stop|list> [mp3] - Play mp3 on all clients." );
39            register_clcmd( "say mp3_stop", "mp3_stop" );
40            register_clcmd( "say mp3_disable", "mp3_disable" );
41          return PLUGIN_CONTINUE          return PLUGIN_CONTINUE
42  }  }
43    
44  public plugin_precache( )  public plugin_precache( )
45  {  {
46          new varfile[100]          new varfile[100];
47          new len, text[100], pcfile[100]          new len, text[100], pcfile[100];
48    
49          //Make var folder if not exists          //Make var folder if not exists
50          get_localinfo( "amxx_datadir", varfile, 99 )          get_localinfo( "amxx_datadir", varfile, 99 );
51          format( varfile, 99, "%s/var", varfile )          format( varfile, 99, "%s/var", varfile );
52          if( !dir_exists( varfile ) ) mkdir( varfile )          if( !dir_exists( varfile ) ) mkdir( varfile );
53    
54          get_localinfo( "amxx_configsdir", inifile, 99 )          get_localinfo( "amxx_configsdir", inifile, 99 );
55          format( inifile, 99, "%s/mp3precache.ini", inifile )          format( inifile, 99, "%s/mp3precache.ini", inifile );
56          format( varfile, 99, "%s/mp3precache.var", varfile )          format( varfile, 99, "%s/mp3precache.var", varfile );
57    
58          //Get name of last precached file          //Get name of last precached file
59          if( file_exists( varfile ) )          if( file_exists( varfile ) )
60                  read_file( varfile, 0, pcfile, 99, len )                  read_file( varfile, 0, pcfile, 99, len );
61    
62          if( file_exists( inifile ) )          if( file_exists( inifile ) )
63          {          {
64                  new inisize = file_size( inifile, 1 )                  new inisize = file_size( inifile, 1 );
65                  if( inisize )                  if( inisize )
66                  {                  {
67                          new line = 0                          new line = 0;
68                          if( strlen( pcfile ) )                          if( strlen( pcfile ) )
69                                  while( !equal( pcfile, text ) && read_file( inifile, line, text, 99, len ) )                                  while( !equal( pcfile, text ) && read_file( inifile, line, text, 99, len ) )
70                                          line++                                          line++;
71    
72    
73                          new oldline = line                          new oldline = line;
74    
75                          for( new i = 0; i <= PRECACHE_COUNT; i++)                          for( new i = 0; i <= PRECACHE_COUNT; i++)
76                          {                          {
77                                  if ( line == inisize ) line = 0                                  if ( line == inisize ) line = 0;
78    
79                                  read_file( inifile, line, pcfile, 99, len )                                  read_file( inifile, line, pcfile, 99, len );
80                                  write_file( varfile, pcfile, 0 )                                  write_file( varfile, pcfile, 0 );
81                                  format( pcfile, 99, "media/%s", pcfile )                                  format( pcfile, 99, "media/%s", pcfile );
82                                  precache_generic( pcfile )                                  precache_generic( pcfile );
83                                  line++                                  line++;
84                                  if( line == oldline ) break                                  if( line == oldline ) break;
85                          }                          }
86                  }                  }
87          }          }
88          return PLUGIN_CONTINUE          return PLUGIN_CONTINUE;
89  }  }
90    
91  public mp3( id, level, cid )  public mp3( id, level, cid )
92  {  {
93          if( !cmd_access( id, level, cid, 2 ) )          if( !cmd_access( id, level, cid, 2 ) )
94                  return PLUGIN_HANDLED                  return PLUGIN_HANDLED;
95    
96          new cmd[4]          new cmd[4];
97          read_argv( 1, cmd, 4 )          read_argv( 1, cmd, 4 );
98          if( equali( cmd, "stop") )          if( equali( cmd, "stop") )
99          {          {
100                  client_cmd( 0, "mp3 stop" )                  client_cmd( 0, "mp3 stop" );
101                  client_print( 0, print_chat, "[AMX] MP3 : Stopped" )                  client_print( 0, print_chat, "[AMX] MP3 : Stopped" );
102          }          }
103          if( equali( cmd, "list") )          if( equali( cmd, "list") )
104          {          {
105                  show_motd( id, inifile, "MP3s" )                  show_motd( id, inifile, "MP3s" );
106          }          }
107          else          else
108          {          {
109                  if( read_argc( ) != 3 )                  if( read_argc( ) != 3 )
110                          client_print( id, print_console, "Usage: amx_mp3 <play|loop|stop> [mp3]")                          client_print( id, print_console, "Usage: amx_mp3 <play|loop|stop> [mp3]");
111                  else                  else
112                  {                  {
113                          new title[32]                          new title[32];
114                          read_argv(2,title,32)                          read_argv( 2, title, 31 );
115                          client_cmd(0,"mp3 %s media/%s",cmd,title)  
116                          strtoupper(cmd)                          new players[32], pcount, info_val[4], exec_cmd[64], id2;
117                          client_print(0,print_chat,"[AMX] : %s MP3 %s - To stop type, ^"mp3 stop^" in console.",cmd,title)                          get_players( players, pcount, "ch" );
118    
119                            formatex( exec_cmd, 63, "mp3 %s media/%s", cmd, title );
120                            strtoupper( cmd );
121    
122                            for( new i = 0; i < pcount; i++ )
123                            {
124                                    id2 = players[i];
125                                    get_user_info( id2, INFO_VAR, info_val, 3 );
126                                    if( strcmp( info_val, "off" ) )
127                                    {
128                                            client_cmd( id2, exec_cmd );
129                                            client_print( id2, print_chat, "[AMX] : %s MP3 %s - To stop type, ^"mp3_stop^".", cmd, title );
130                                    }
131                            }
132                    }
133            }
134            return PLUGIN_HANDLED;
135                  }                  }
136    
137    public mp3_stop( id )
138    {
139            client_cmd( id, "mp3 stop" );
140            client_print( id, print_chat, "MP3 Stopped. To disable MP3's permanently, type ^"mp3_disable^" or exec ^"setinfo mp3+ off^"" );
141            return PLUGIN_HANDLED;
142    }
143    
144    public mp3_disable( id )
145    {
146            new info_val[4];
147            get_user_info( id, INFO_VAR, info_val, 3 );
148            if( strcmp( info_val, "off" ) )
149            {
150                    client_print( id, print_chat, "MP3's Disabled. To enable again, type ^"mp3_disable^" or exec ^"setinfo mp3+ on^"" );
151                    set_user_info( id, INFO_VAR, "off" );
152            }
153            else
154            {
155                    client_print( id, print_chat, "MP3's Enabled." );
156                    set_user_info( id, INFO_VAR, "on" );
157          }          }
158          return PLUGIN_HANDLED          return PLUGIN_HANDLED;
159  }  }

Legend:
Removed from v.25  
changed lines
  Added in v.43

Contact
ViewVC Help
Powered by ViewVC 1.0.4