10.06.2013, 18:10
hello guys
Please how to make cmd /unban
Please how to make cmd /unban
pawn Код:
stock tempBanPlayer ( playerid, adminid, hours = defaultTempBanHours, reason[] = defaultTempBanReason )
{
new File: banFile = fopen( tempBanFile, io_append );
if ( !banFile ) return 0;
new unbanTime = gettime() + hours*3600, banStr[160], plName[24], admName[24];
GetPlayerName( playerid, plName, 24 );
GetPlayerName( adminid, admName, 24 );
format( banStr, 160, "%s:%d:%s\r\n", plName, unbanTime, reason );
fwritebin( banFile, banStr );
fclose(banFile);
format( banStr, 160, " * You're banned for %d hour (s) by %s . Reason:% s", hours, admName, reason );
SendClientMessage( playerid, 0xFF0000AA, banStr );
printf( " * %s (id:%d) was temp banned for %d hour(s) by %s (id:%d). Reason: %s",
plName, playerid, hours, admName, adminid, reason );
SetTimerEx("kickp", 1000, false, "i", playerid);
return 1;
}
stock isPlayerTempBanned ( playerid, & unbanTime, reason[] )
{
if ( !fexist(tempBanFile) ) return 0;
new File: banFile = fopen( tempBanFile, io_read );
if ( !banFile ) return 0;
new plName[24], plNameLen;
GetPlayerName( playerid, plName, 24 );
plNameLen = strlen(plName);
for ( new banStr[160]; fread( banFile, banStr ) > 0; )
{
if ( banStr[plNameLen] == ':' && strcmp( banStr, plName, true, plNameLen ) == 0 )
{
unbanTime = iparam( banStr, ':', 1 );
sparam( reason, 128, banStr, ':', 2, 1 );
if ( reason[0] == 0 ) format( reason, 128, "%s", defaultTempBanReason );
fclose(banFile);
return 1;
}
}
fclose(banFile);
return 0;
}
forward tempBansCleaning();
public tempBansCleaning()
{
if ( !fexist(tempBanFile) ) return;
new File: banFile = fopen( tempBanFile, io_read ), File: tmpFile = ftemp();
if ( !banFile || !tmpFile )
{
fclose(banFile);
fclose(tmpFile);
return;
}
for ( new buffer[160]; fread( banFile, buffer ) > 0; ) fwritebin( tmpFile, buffer );
fclose(banFile);
fseek( tmpFile, 0, seek_start );
banFile = fopen( tempBanFile, io_write );
if ( !banFile )
{
fclose(tmpFile);
return;
}
new curTime = gettime(), banStr[160], cleanedCount;
while ( fread( tmpFile, banStr ) > 0 )
{
if ( iparam( banStr, ':', 1 ) - curTime > 0 ) fwritebin( banFile, banStr );
else cleanedCount++;
}
fclose(banFile);
fclose(tmpFile);
printf( " * Temp bans file `" tempBanFile "` cleaning: %d expired bans removed", cleanedCount );
}
stock sparam
(
dest[], maxSize = sizeof(dest),
const source[], delimiter = ' ',
substrIndex = 0, withRest = 0
)
{
dest[0] = 0; // clear the destination string
for ( new cur, pre, i = -1; ; cur++ ) // go over each character in the string source
{
if ( source[cur] == 0 )
{
if ( ++i == substrIndex )
strmid( dest, source, pre, ( withRest ? strlen(source) : cur ), maxSize );
goto sparam_end;
}
if ( source[cur] == delimiter )
{
if ( ++i == substrIndex )
{
strmid( dest, source, pre, ( withRest ? strlen(source) : cur ), maxSize );
goto sparam_end;
}
pre = cur + 1;
}
}
sparam_end:
return;
}
stock iparam ( const source[], delimiter = ' ', substrIndex = 0 )
{
new dest[12], cur, pre, i = -1;
for ( ; ; cur++ )
{
if ( source[cur] == 0 )
{
if ( ++i == substrIndex )
strmid( dest, source, pre, cur, 12 );
goto iparam_end;
}
if ( source[cur] == delimiter )
{
if ( ++i == substrIndex )
{
strmid( dest, source, pre, cur, 12 );
goto iparam_end;
}
pre = cur + 1;
}
}
iparam_end:
return strval(dest);
}
public OnFilterScriptInit() { tempBansCleaningTimer = SetTimer( "tempBansCleaning", tempBansCleaningInterval*60000, 1 ); }
public OnFilterScriptExit() { KillTimer(tempBansCleaningTimer); }
public OnPlayerConnect ( playerid )
{
static unbanTime, curTime, reason[128];
curTime = gettime();
if ( isPlayerTempBanned( playerid, unbanTime, reason ) && (unbanTime - curTime) > 0 )
{
new banMessage[160],
unbanSeconds = unbanTime - curTime,
unbanMinutes = unbanSeconds / 60,
unbanHours = unbanMinutes / 60;
unbanMinutes -= unbanHours*60;
unbanSeconds -= unbanHours*3600 + unbanMinutes*60;
format( banMessage, 160, " * Your nickname is banned due to : %s", reason );
SendClientMessage( playerid, 0xFF0000AA, banMessage );
format( banMessage, 80, " *Until Unban left %d hour(s) , %d min., %d seconds.", unbanHours, unbanMinutes, unbanSeconds );
SendClientMessage( playerid, 0xFF0000AA, banMessage );
SetTimerEx("kickp", 1000, false, "i", playerid);
}
return 1;
}
public OnPlayerCommandText ( playerid, cmdtext[] )
{
if ( IsPlayerAdmin(playerid) && strcmp( cmdtext, "/tempban", true, 8 ) == 0 )
{
if ( cmdtext[8] != ' ' || cmdtext[9] == 0 )
{
SendClientMessage( playerid, 0xFFFFFFAA, " * Syntax: / tempban [ID Team] [number of hours] [Reason] " );
return 1;
}
new id = iparam( cmdtext, ' ', 1 );
if ( ( id == 0 && cmdtext[9] != '0' ) || !IsPlayerConnected(id) )
{
SendClientMessage( playerid, 0xFFFFFFAA, " *The player with the ID can not be found" );
return 1;
}
new hours = iparam( cmdtext, ' ', 2 ), reason[128];
sparam( reason, 128, cmdtext, ' ', 3, 1 );
if ( hours <= 0 ) hours = defaultTempBanHours;
if ( reason[0] == 0 ) reason = defaultTempBanReason;
if ( tempBanPlayer( id, playerid, hours, reason ) )
{
new reportStr[160];
GetPlayerName( id, reportStr, 24 );
format( reportStr, 160, " * %s (id:%d) is banned for %d hour(s): %s ", reportStr, id, hours, reason );
SendClientMessage( playerid, 0xFF0000AA, reportStr );
}
else
SendClientMessage( playerid, 0xFFFFFFAA, "* Error writing to the file when you add a new temporary ban ");
return 1;
}
return 0;
}