- 听众
- 收听
- 积分
- 132
- 主题
- 回帖
- 0
- 精华
注册时间2008-4-29
最后登录1970-1-1
该用户从未签到
|
楼主 |
发表于 2011-5-5 20:56:31
|
显示全部楼层
本来是#include < amxmodx >
#include < sockets >
new g_szMapName[ 32 ], g_szRecordsFile[ 128 ], szBuffer[ 25001 ], bool:g_bUpdatedXJ;
public plugin_init( ) {
register_plugin( "KZ Records", "2.1", "SchlumPF / xPaw" );
register_clcmd( "say", "CmdSay" );
get_mapname( g_szMapName, 31 );
strtolower( g_szMapName );
new szTemp[ 128 ];
get_localinfo( "amxx_datadir", szTemp, 127 );
format( szTemp, 127, "%s/kreedz", szTemp );
if( !dir_exists( szTemp ) )
mkdir( szTemp );
formatex( g_szRecordsFile, 127, "%s/demos.txt", szTemp );
format( szTemp, 127, "%s/demos_last_update.ini", szTemp );
if( !file_exists( szTemp ) ) {
UpdateRecords( szTemp );
return;
}
new iYear, iMonth, iDay, szDate[ 11 ];
date( iYear, iMonth, iDay );
new iFile = fopen( szTemp, "rt" );
fgets( iFile, szDate, 10 );
fclose( iFile );
if( iYear > str_to_num( szDate[ 0 ] ) || iMonth > str_to_num( szDate[ 5 ] ) || iDay > str_to_num( szDate[ 8 ] ) )
UpdateRecords( szTemp );
}
public CmdSay( const id ) {
new szCommand[ 36 ];
read_args( szCommand, 35 );
remove_quotes( szCommand );
if( !szCommand[ 0 ] || szCommand[ 0 ] != '/' || ( szCommand[ 3 ] && szCommand[ 3 ] != ' ' ) )
return;
new szMap[ 32 ];
parse( szCommand, szCommand, 3, szMap, 31 );
if( equali( szCommand[ 1 ], "wr" ) ) {
new szMessage[ 256 ], szAuthor[ 6 ][ 32 ], szTime[ 6 ][ 9 ], szExtension[ 6 ][ 8 ], iLen, iFounds;
if( szMap[ 0 ] ) {
iFounds = GetRecordData( szMap, szAuthor, szTime, szExtension );
iLen = formatex( szMessage, 255, "World Record of %s:", szMap );
} else {
iFounds = GetRecordData( g_szMapName, szAuthor, szTime, szExtension );
iLen = formatex( szMessage, 255, "World Record of %s:", g_szMapName );
}
if( iFounds > 0 ) {
for( new i; i < iFounds; i++ ) {
if( !szAuthor[ i ][ 0 ] )
break;
if( szExtension[ i ][ 0 ] ) {
if( szTime[ i ][ 0 ] == '*' )
iLen += formatex( szMessage[ iLen ], 255 - iLen, "^n [%s] No record.", szExtension[ i ] );
else
iLen += formatex( szMessage[ iLen ], 255 - iLen, "^n [%s] %s by %s", szExtension[ i ], szTime[ i ], szAuthor[ i ] );
} else {
if( szTime[ i ][ 0 ] == '*' )
iLen += formatex( szMessage[ iLen ], 255 - iLen, "^n No record." );
else
iLen += formatex( szMessage[ iLen ], 255 - iLen, "^n %s by %s", szTime[ i ], szAuthor[ i ] );
}
}
} else {
iLen += formatex( szMessage[ iLen ], 255 - iLen, "^n No record." );
}
set_hudmessage( 0, 127, 255, 0.01, 0.2, _, _, 3.5, _, _, 1 );
show_hudmessage( id, szMessage );
}
}
GetRecordData( const Map[ 32 ], Jumper[ 6 ][ 32 ], Time[ 6 ][ 9 ], Extension[ 6 ][ 8 ] ) {
new szData[ 64 ], szMap[ 32 ], szTime[ 9 ], iFounds, iLen, iMapLen = strlen( Map );
new iFile = fopen( g_szRecordsFile, "rt" );
if( !iFile )
return 0;
while( !feof( iFile ) ) {
fgets( iFile, szData, 63 );
trim( szData );
if( !szData[ 0 ] || !equali( szData, Map, iMapLen ) )
continue;
iLen = 1 + copyc( szMap, 31, szData, ' ' );
if( szMap[ iMapLen ] != '[' && iMapLen != strlen( szMap ) )
continue;
iLen += 1 + copyc( szTime, 8, szData[ iLen ], ' ' );
copy( Jumper[ iFounds ], 32, szData[ iLen ] );
if( szTime[ 2 ] != ':' )
ClimbtimeToString( str_to_float( szTime ), szTime, 8 );
copy( Time[ iFounds ], 8, szTime );
//Time[ iFounds ] = str_to_num( szTime );
if( szMap[ iMapLen ] == '[' )
copyc( Extension[ iFounds ], 8, szMap[ iMapLen + 1 ], ']' );
iFounds++;
}
fclose( iFile );
return iFounds;
}
public ReadWeb( const iSocket ) {
socket_recv( iSocket, szBuffer, 25000 );
if( szBuffer[ 0 ] ) {
if( szBuffer[ 0 ] == 'H' && szBuffer[ 1 ] == 'T' ) { // Header
new iPos;
iPos = contain( szBuffer, "^r^n^r^n" ) + 4;
iPos += contain( szBuffer[ iPos ], "^n" ) + 1;
formatex( szBuffer, charsmax( szBuffer ), szBuffer[ iPos ] );
}
new iFile = fopen( g_szRecordsFile, "at" );
fputs( iFile, szBuffer );
fclose( iFile );
if( !g_bUpdatedXJ )
g_bUpdatedXJ = true;
else
szBuffer[ 0 ] = 0; // Clean the memory.
}
socket_close( iSocket );
}
public UpdateRecords( const File[ ] ) {
new const szDownloadLinks[ 2 ][ ] = {
"http://xtreme-jumps.eu/demos_tcl.txt",
"http://cosy-climbing.net/demoz.txt"
};
if( file_exists( g_szRecordsFile ) )
delete_file( g_szRecordsFile );
if( file_exists( File ) )
delete_file( File );
new iYear, iMonth, iDay, szTemp[ 11 ];
date( iYear, iMonth, iDay );
new iFile = fopen( File, "wt" );
formatex( szTemp, 10, "%04ix%02ix%02i", iYear, iMonth, iDay );
fputs( iFile, szTemp );
fclose( iFile );
new szHost[ 96 ], szUrl[ 96 ], szSocket[ 256 ], iPos, iSocket;
for( new i; i < 2; i++ ) {
copy( szHost, 95, szDownloadLinks[ i ][ 7 ] );
iPos = contain( szHost, "/" );
if( iPos != -1 ) {
copy( szUrl, 95, szHost[ iPos + 1 ] );
szHost[ iPos ] = 0;
}
iSocket = socket_open( szHost, 80, SOCKET_TCP, iPos );
if( iPos > 0 ) {
delete_file( File ); // One server was down, lets try again on next map
continue;
}
formatex( szSocket, 255, "GET /%s HTTP/1.1^nHost: %s^r^n^r^n", szUrl, szHost );
socket_send( iSocket, szSocket, 255 );
set_task( 0.25, "ReadWeb", iSocket );
}
}
ClimbtimeToString( const Float:flClimbTime, szOutPut[ ], const iLen ) {
if( !flClimbTime ) {
copy( szOutPut, iLen, "**:**.**" );
return;
}
new iMinutes = floatround( flClimbTime / 60.0, floatround_floor );
new iSeconds = floatround( flClimbTime - iMinutes * 60, floatround_floor );
new iMiliSeconds = floatround( ( flClimbTime - ( iMinutes * 60 + iSeconds ) ) * 100, floatround_floor );
formatex( szOutPut, iLen, "%02i:%02i.%02i", iMinutes, iSeconds, iMiliSeconds );
}
这样的 做成.sma |
|