Parent Directory | Revision Log
Revision 43 - (view) (download)
1 : | ian | 25 | /* |
2 : | ian | 43 | MP3+ v0.5 |
3 : | ian | 25 | Copyright (C) 2005-2007 Ian (Juan) Cammarata |
4 : | |||
5 : | This program is free software: you can redistribute it and/or modify | ||
6 : | it under the terms of the GNU Affero General Public License as | ||
7 : | published by the Free Software Foundation, either version 3 of the | ||
8 : | License, or (at your option) any later version. | ||
9 : | |||
10 : | This program is distributed in the hope that it will be useful, | ||
11 : | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 : | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 : | GNU Affero General Public License for more details. | ||
14 : | |||
15 : | You should have received a copy of the GNU Affero General Public License | ||
16 : | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 : | -------------------------------------------------------------------------------- | ||
18 : | http://ian.cammarata.us | ||
19 : | */ | ||
20 : | |||
21 : | ian | 1 | #include <amxmodx> |
22 : | #include <amxmisc> | ||
23 : | |||
24 : | #define PRECACHE_COUNT 2 | ||
25 : | |||
26 : | ian | 43 | new const VERSION[ ] = "0.5"; |
27 : | new const TRKCVAR[ ] = "mp3_plus_version"; | ||
28 : | new const INFO_VAR[ ] = "mp3+"; | ||
29 : | ian | 1 | |
30 : | ian | 43 | new inifile[100]; |
31 : | ian | 1 | |
32 : | public plugin_init( ) | ||
33 : | { | ||
34 : | ian | 43 | register_plugin( "mp3+", VERSION, "Ian Cammarata" ); |
35 : | register_cvar( TRKCVAR, VERSION, FCVAR_SERVER ); | ||
36 : | 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 : | ian | 1 | return PLUGIN_CONTINUE |
42 : | } | ||
43 : | |||
44 : | public plugin_precache( ) | ||
45 : | { | ||
46 : | ian | 43 | new varfile[100]; |
47 : | new len, text[100], pcfile[100]; | ||
48 : | ian | 1 | |
49 : | //Make var folder if not exists | ||
50 : | ian | 43 | get_localinfo( "amxx_datadir", varfile, 99 ); |
51 : | format( varfile, 99, "%s/var", varfile ); | ||
52 : | if( !dir_exists( varfile ) ) mkdir( varfile ); | ||
53 : | ian | 1 | |
54 : | ian | 43 | get_localinfo( "amxx_configsdir", inifile, 99 ); |
55 : | format( inifile, 99, "%s/mp3precache.ini", inifile ); | ||
56 : | format( varfile, 99, "%s/mp3precache.var", varfile ); | ||
57 : | ian | 1 | |
58 : | //Get name of last precached file | ||
59 : | if( file_exists( varfile ) ) | ||
60 : | ian | 43 | read_file( varfile, 0, pcfile, 99, len ); |
61 : | ian | 1 | |
62 : | if( file_exists( inifile ) ) | ||
63 : | { | ||
64 : | ian | 43 | new inisize = file_size( inifile, 1 ); |
65 : | ian | 1 | if( inisize ) |
66 : | { | ||
67 : | ian | 43 | new line = 0; |
68 : | ian | 1 | if( strlen( pcfile ) ) |
69 : | while( !equal( pcfile, text ) && read_file( inifile, line, text, 99, len ) ) | ||
70 : | ian | 43 | line++; |
71 : | ian | 1 | |
72 : | |||
73 : | ian | 43 | new oldline = line; |
74 : | ian | 1 | |
75 : | for( new i = 0; i <= PRECACHE_COUNT; i++) | ||
76 : | { | ||
77 : | ian | 43 | if ( line == inisize ) line = 0; |
78 : | ian | 1 | |
79 : | ian | 43 | read_file( inifile, line, pcfile, 99, len ); |
80 : | write_file( varfile, pcfile, 0 ); | ||
81 : | format( pcfile, 99, "media/%s", pcfile ); | ||
82 : | precache_generic( pcfile ); | ||
83 : | line++; | ||
84 : | if( line == oldline ) break; | ||
85 : | ian | 1 | } |
86 : | } | ||
87 : | } | ||
88 : | ian | 43 | return PLUGIN_CONTINUE; |
89 : | ian | 1 | } |
90 : | |||
91 : | public mp3( id, level, cid ) | ||
92 : | { | ||
93 : | if( !cmd_access( id, level, cid, 2 ) ) | ||
94 : | ian | 43 | return PLUGIN_HANDLED; |
95 : | ian | 1 | |
96 : | ian | 43 | new cmd[4]; |
97 : | read_argv( 1, cmd, 4 ); | ||
98 : | ian | 1 | if( equali( cmd, "stop") ) |
99 : | { | ||
100 : | ian | 43 | client_cmd( 0, "mp3 stop" ); |
101 : | client_print( 0, print_chat, "[AMX] MP3 : Stopped" ); | ||
102 : | ian | 1 | } |
103 : | if( equali( cmd, "list") ) | ||
104 : | { | ||
105 : | ian | 43 | show_motd( id, inifile, "MP3s" ); |
106 : | ian | 1 | } |
107 : | else | ||
108 : | { | ||
109 : | if( read_argc( ) != 3 ) | ||
110 : | ian | 43 | client_print( id, print_console, "Usage: amx_mp3 <play|loop|stop> [mp3]"); |
111 : | ian | 1 | else |
112 : | { | ||
113 : | ian | 43 | new title[32]; |
114 : | read_argv( 2, title, 31 ); | ||
115 : | |||
116 : | new players[32], pcount, info_val[4], exec_cmd[64], id2; | ||
117 : | 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 : | ian | 1 | } |
133 : | } | ||
134 : | ian | 43 | return PLUGIN_HANDLED; |
135 : | ian | 1 | } |
136 : | ian | 43 | |
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; | ||
159 : | } |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |