Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • zandronum/zandronum-stable
1 result
Show changes
Commits on Source (9)
......@@ -78,6 +78,10 @@
static void serverban_KickBannedPlayers( void );
static LONG serverban_ExtractBanLength( FString fSearchString, const char *pszPattern );
static time_t serverban_CreateBanDate( LONG lAmount, ULONG ulUnitSize, time_t tNow );
static void serverban_ExecuteGetIPCmd( FCommandLine &argv, bool isIndexCmd );
static void serverban_ExecuteBanCmd( FCommandLine &argv, bool isIndexCmd );
static void serverban_ExecuteAddOrDelBanCmd( IPList &list, FCommandLine &argv, bool isDelCmd );
static void serverban_ListAddresses( const IPList &list );
//--------------------------------------------------------------------------------------------------------------------------------------------------
//-- CVARS -----------------------------------------------------------------------------------------------------------------------------------------
......@@ -146,5 +150,5 @@
//*****************************************************************************
//
bool SERVERBAN_IsIPBanned( const IPStringArray &szAddress )
bool SERVERBAN_IsIPBanned( const IPStringArray &Address )
{
......@@ -150,6 +154,6 @@
{
// Is this address is banned on the master server?
if ( sv_enforcemasterbanlist && g_MasterServerBans.isIPInList( szAddress ) && !g_MasterServerBanExemptions.isIPInList( szAddress ))
// Is this address banned on the master server?
if ( SERVERBAN_IsIPMasterBanned( Address ))
return true;
// If not, let the server decide.
......@@ -153,10 +157,27 @@
return true;
// If not, let the server decide.
return ( sv_enforcebans && g_ServerBans.isIPInList( szAddress ) && !g_ServerBanExemptions.isIPInList( szAddress ));
return ( sv_enforcebans && g_ServerBans.isIPInList( Address ) && !g_ServerBanExemptions.isIPInList( Address ));
}
//*****************************************************************************
//
bool SERVERBAN_IsIPBanned( const NETADDRESS_s &Address )
{
IPStringArray convertedAddress;
convertedAddress.SetFrom( Address );
return SERVERBAN_IsIPBanned( convertedAddress );
}
//*****************************************************************************
//
bool SERVERBAN_IsIPMasterBanned( const IPStringArray &Address )
{
return ( sv_enforcemasterbanlist && g_MasterServerBans.isIPInList( Address ) && !g_MasterServerBanExemptions.isIPInList( Address ));
}
//*****************************************************************************
//
bool SERVERBAN_IsIPMasterBanned( const NETADDRESS_s &Address )
{
......@@ -157,11 +178,9 @@
}
//*****************************************************************************
//
bool SERVERBAN_IsIPMasterBanned( const NETADDRESS_s &Address )
{
return sv_enforcemasterbanlist
&& g_MasterServerBans.isIPInList( Address )
&& g_MasterServerBanExemptions.isIPInList( Address ) == false;
}
IPStringArray convertedAddress;
convertedAddress.SetFrom( Address );
......@@ -167,14 +186,5 @@
//*****************************************************************************
//
bool SERVERBAN_IsIPBanned( const NETADDRESS_s &Address )
{
// Is this address is banned on the master server?
if ( SERVERBAN_IsIPMasterBanned( Address ))
return true;
// If not, let the server decide.
return ( sv_enforcebans && g_ServerBans.isIPInList( Address ) && !g_ServerBanExemptions.isIPInList( Address ));
return SERVERBAN_IsIPMasterBanned( convertedAddress );
}
//*****************************************************************************
......@@ -388,13 +398,6 @@
//*****************************************************************************
//
IPList *SERVERBAN_GetBanExemptionList( void )
{
return &g_ServerBanExemptions;
}
//*****************************************************************************
//
void SERVERBAN_BanPlayer( ULONG ulPlayer, const char *pszBanLength, const char *pszBanReason )
{
// Make sure the target is valid and applicable.
......@@ -404,4 +407,15 @@
return;
}
SERVERBAN_BanAddress( SERVER_GetClient( ulPlayer )->Address.ToString( ), pszBanLength, pszBanReason );
}
//*****************************************************************************
//
void SERVERBAN_BanAddress( const char *address, const char *length, const char *reason )
{
// [AK] Added sanity checks to ensure the address and ban length are valid.
if (( address == nullptr ) || ( length == nullptr ))
return;
// [RC] Read the ban length.
......@@ -407,4 +421,7 @@
// [RC] Read the ban length.
time_t tExpiration = SERVERBAN_ParseBanLength( pszBanLength );
if ( tExpiration == -1 )
const time_t expiration = SERVERBAN_ParseBanLength( length );
NETADDRESS_s convertedAddress;
std::string message;
if ( convertedAddress.LoadFromString( address ) == false )
{
......@@ -410,5 +427,10 @@
{
Printf("Error: couldn't read that length. Try something like " TEXTCOLOR_RED "6day" TEXTCOLOR_NORMAL " or " TEXTCOLOR_RED "\"5 hours\"" TEXTCOLOR_NORMAL ".\n");
Printf( "Error: couldn't read that address. Make sure it's formatted correctly.\n" );
return;
}
else if ( expiration == -1 )
{
Printf( "Error: couldn't read that length. Try something like " TEXTCOLOR_RED "6day" TEXTCOLOR_NORMAL " or " TEXTCOLOR_RED "\"5 hours\"" TEXTCOLOR_NORMAL ".\n" );
return;
}
......@@ -412,7 +434,13 @@
return;
}
// Removes the color codes from the player name, for the ban record.
FString playerName = players[ulPlayer].userinfo.GetName();
V_RemoveColorCodes( playerName );
// [AK] Get the index of the player who has this address.
const int player = SERVER_FindClientByAddress( convertedAddress );
// Add the ban.
if ( player != -1 )
{
// Removes the color codes from the player name, for the ban record.
FString playerName = players[player].userinfo.GetName( );
V_RemoveColorCodes( playerName );
......@@ -418,7 +446,8 @@
// Add the ban and kick the player.
std::string message;
g_ServerBans.addEntry( SERVER_GetClient( ulPlayer )->Address.ToString(), playerName, pszBanReason, message, tExpiration );
Printf( "addban: %s", message.c_str() );
SERVER_KickPlayer( ulPlayer, pszBanReason ? pszBanReason : "" ); // [RC] serverban_KickBannedPlayers would cover this, but we want the messages to be distinct so there's no confusion.
g_ServerBans.addEntry( address, playerName.GetChars( ), reason, message, expiration );
}
else
{
g_ServerBans.addEntry( address, nullptr, reason, message, expiration );
}
......@@ -424,5 +453,13 @@
// Kick any other players using the newly-banned address.
Printf( "addban: %s", message.c_str( ));
// Kick the player.
// [RC] serverban_KickBannedPlayers would cover this, but we want the
// messages to be distinct so there's no confusion.
if ( player != -1 )
SERVER_KickPlayer( player, reason != nullptr ? reason : "" );
// Kick any players using the newly-banned address.
serverban_KickBannedPlayers( );
}
......@@ -495,7 +532,11 @@
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------
//-- CCMDS -----------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------
//*****************************************************************************
//
// [AK] Helper function for executing the "getIP" and "getIP_idx" CCMDs.
//
static void serverban_ExecuteGetIPCmd( FCommandLine &argv, bool isIndexCmd )
{
int playerIndex = MAXPLAYERS;
......@@ -501,7 +542,5 @@
CCMD( getIP )
{
// Only the server can look this up.
if ( NETWORK_GetState( ) != NETSTATE_SERVER )
// [AK] This function may not be used by ConsoleCommand.
if ( ACS_IsCalledFromConsoleCommand( ))
return;
......@@ -506,31 +545,8 @@
return;
if ( argv.argc( ) < 2 )
{
Printf( "Usage: getIP <playername> \nDescription: Returns the player's IP address.\n" );
return;
}
// Look up the player.
ULONG ulIdx = SERVER_GetPlayerIndexFromName( argv[1], true, false );
if ( SERVER_IsValidClient( ulIdx ))
Printf( "%s's IP is: %s\n", players[ulIdx].userinfo.GetName(), SERVER_GetClient( ulIdx )->Address.ToString() );
else
{
if ( SERVER_GetPlayerIndexFromName( argv[1], true, true ) != MAXPLAYERS )
Printf( "%s" TEXTCOLOR_NORMAL " is a bot.\n", argv[1] );
else
Printf( "Unknown player: %s" TEXTCOLOR_NORMAL "\n",argv[1] );
}
}
//*****************************************************************************
//
CCMD( getIP_idx )
{
// Only the server can look this up.
if ( NETWORK_GetState( ) != NETSTATE_SERVER )
return;
if ( argv.argc( ) < 2 )
{
......@@ -531,10 +547,17 @@
// Only the server can look this up.
if ( NETWORK_GetState( ) != NETSTATE_SERVER )
return;
if ( argv.argc( ) < 2 )
{
Printf( "Usage: getIP_idx <player index>\nDescription: Returns the player's IP, via his index. You can get the list of players' indexes via the ccmd playerinfo.\n" );
FString message;
message.Format( "Usage: %s <player %s>\nDescription: Returns the player's IP address", argv[0], isIndexCmd ? "index" : "name" );
// [AK] Add extra information for the index version of the command.
if ( isIndexCmd )
message.AppendFormat( ", via their index. You can get the list of players' indexes via the \"playerinfo\" CCMD" );
Printf( "%s.\n", message.GetChars( ));
return;
}
......@@ -538,19 +561,10 @@
return;
}
int playerIndex;
if ( argv.SafeGetNumber( 1, playerIndex ) == false )
return;
// Make sure the target is valid.
if (( playerIndex >= MAXPLAYERS ) || ( !playeringame[playerIndex] ))
return;
if ( players[playerIndex].bIsBot )
Printf( "%s is a bot.\n", players[playerIndex].userinfo.GetName() );
else
Printf( "%s's IP is: %s\n", players[playerIndex].userinfo.GetName(), SERVER_GetClient( playerIndex )->Address.ToString() );
// Look up the player, and make sure they're valid.
if ( argv.GetPlayerFromArg( playerIndex, 1, isIndexCmd, true ))
Printf( "%s's IP is: %s\n", players[playerIndex].userinfo.GetName( ), SERVER_GetClient( playerIndex )->Address.ToString( ));
}
//*****************************************************************************
//
......@@ -553,6 +567,8 @@
}
//*****************************************************************************
//
CCMD( ban_idx )
// [AK] Helper function for executing the "ban" and "ban_idx" CCMDs.
//
static void serverban_ExecuteBanCmd( FCommandLine &argv, bool isIndexCmd )
{
......@@ -558,31 +574,5 @@
{
// [AK] This function may not be used by ConsoleCommand.
if ( ACS_IsCalledFromConsoleCommand( ))
return;
// Only the server can ban players!
if ( NETWORK_GetState( ) != NETSTATE_SERVER )
return;
if ( argv.argc( ) < 3 )
{
Printf( "Usage: ban_idx <player index> <duration> [reason]\nDescriptions: Bans the player, via his index, for the given duration (\"perm\" for a permanent ban).\n To see the list of players' indexes, try the ccmd playerinfo.\n" );
return;
}
int playerIndex;
if ( argv.SafeGetNumber( 1, playerIndex ) == false )
return;
SERVERBAN_BanPlayer( playerIndex, argv[2], (argv.argc( ) >= 4) ? argv[3] : NULL );
}
//*****************************************************************************
//
CCMD( ban )
{
ULONG ulIdx;
int playerIndex = MAXPLAYERS;
// [AK] This function may not be used by ConsoleCommand.
if ( ACS_IsCalledFromConsoleCommand( ))
......@@ -594,7 +584,42 @@
if ( argv.argc( ) < 3 )
{
Printf( "Usage: ban <playername> <duration> [reason]\nDescription: Bans the player for the given duration (\"perm\" for a permanent ban).\n" );
FString message;
message.Format( "Usage: %s <player %s> <duration> [reason]\nDescription: Bans the player", argv[0], isIndexCmd ? "index" : "name" );
if ( isIndexCmd )
message += ", via their index,";
message += " for the given duration (\"perm\" for a permanent ban).";
if ( isIndexCmd )
message += " To see the list of players' indexes, try the \"playerinfo\" CCMD.";
Printf( "%s\n", message.GetChars( ));
return;
}
// Look up the player, and make sure they're valid.
if ( argv.GetPlayerFromArg( playerIndex, 1, isIndexCmd, true ))
SERVERBAN_BanPlayer( playerIndex, argv[2], ( argv.argc( ) >= 4 ) ? argv[3] : nullptr );
}
//*****************************************************************************
//
// [AK] Helper function for executing the "delban", "addbanexemption" and "delbanexemption" CCMDs.
// Note that the "addban" CCMD works differently, so this can't be used for it.
//
static void serverban_ExecuteAddOrDelBanCmd( IPList &list, FCommandLine &argv, bool isDelCmd )
{
std::string message;
// [AK] This function may not be used by ConsoleCommand.
if ( ACS_IsCalledFromConsoleCommand( ))
return;
if ( argv.argc( ) < 2 )
{
Printf( "Usage: %s <IP address>%s\n", argv[0], isDelCmd ? "" : " [comment]" );
return;
}
......@@ -598,6 +623,11 @@
return;
}
// Get the index.
ulIdx = SERVER_GetPlayerIndexFromName( argv[1], true, false );
if ( isDelCmd )
list.removeEntry( argv[1], message );
else
list.addEntry( argv[1], nullptr, ( argv.argc( ) >= 3 ) ? argv[2] : nullptr, message, 0 );
Printf( "%s: %s", argv[0], message.c_str( ));
}
......@@ -603,6 +633,15 @@
// Found him?
if ( ulIdx != MAXPLAYERS )
{
char szString[256];
//*****************************************************************************
//
// [AK] Helper function for listing addresses via CCMDs (e.g. "viewbanlist").
//
static void serverban_ListAddresses( const IPList &list )
{
for ( unsigned int i = 0; i < list.size( ); i++ )
Printf( "%s", list.getEntryAsString( i ).c_str( ));
}
//--------------------------------------------------------------------------------------------------------------------------------------------------
//-- CCMDS -----------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------
......@@ -608,15 +647,28 @@
// Ban via the index.
sprintf( szString, "ban_idx %lu \"%s\" \"%s\"", ulIdx, argv[2], (argv.argc( ) >= 4) ? argv[3] : "" );
SERVER_AddCommand( szString );
}
else
{
if ( SERVER_GetPlayerIndexFromName( argv[1], true, true ) != MAXPLAYERS )
Printf( "%s" TEXTCOLOR_NORMAL " is a bot.\n", argv[1] );
else
Printf( "Unknown player: %s" TEXTCOLOR_NORMAL "\n",argv[1] );
}
CCMD( getIP )
{
serverban_ExecuteGetIPCmd( argv, false );
}
//*****************************************************************************
//
CCMD( getIP_idx )
{
serverban_ExecuteGetIPCmd( argv, true );
}
//*****************************************************************************
//
CCMD( ban )
{
serverban_ExecuteBanCmd( argv, false );
}
//*****************************************************************************
//
CCMD( ban_idx )
{
serverban_ExecuteBanCmd( argv, true );
}
//*****************************************************************************
......@@ -633,22 +685,10 @@
return;
}
time_t tExpiration = SERVERBAN_ParseBanLength( argv[2] );
if ( tExpiration == -1 )
{
Printf("Error: couldn't read that length. Try something like " TEXTCOLOR_RED "6day" TEXTCOLOR_NORMAL " or " TEXTCOLOR_RED "\"5 hours\"" TEXTCOLOR_NORMAL ".\n");
return;
}
std::string message;
g_ServerBans.addEntry( argv[1], NULL, (argv.argc( ) >= 4) ? argv[3] : NULL, message, tExpiration );
Printf( "addban: %s", message.c_str() );
// Kick any players using the newly-banned address.
serverban_KickBannedPlayers( );
SERVERBAN_BanAddress( argv[1], argv[2], ( argv.argc( ) >= 4 ) ? argv[3] : nullptr );
}
//*****************************************************************************
//
CCMD( delban )
{
......@@ -649,25 +689,13 @@
}
//*****************************************************************************
//
CCMD( delban )
{
// [AK] This function may not be used by ConsoleCommand.
if ( ACS_IsCalledFromConsoleCommand( ))
return;
if ( argv.argc( ) < 2 )
{
Printf( "Usage: delban <IP address>\n" );
return;
}
std::string message;
g_ServerBans.removeEntry( argv[1], message );
Printf( "delban: %s", message.c_str() );
serverban_ExecuteAddOrDelBanCmd( g_ServerBans, argv, true );
}
//*****************************************************************************
//
CCMD( addbanexemption )
{
......@@ -668,25 +696,13 @@
}
//*****************************************************************************
//
CCMD( addbanexemption )
{
// [AK] This function may not be used by ConsoleCommand.
if ( ACS_IsCalledFromConsoleCommand( ))
return;
if ( argv.argc( ) < 2 )
{
Printf( "Usage: addbanexemption <IP address> [comment]\n" );
return;
}
std::string message;
g_ServerBanExemptions.addEntry( argv[1], NULL, (argv.argc( ) >= 3) ? argv[2] : NULL, message, 0 );
Printf( "addbanexemption: %s", message.c_str() );
serverban_ExecuteAddOrDelBanCmd( g_ServerBanExemptions, argv, false );
}
//*****************************************************************************
//
CCMD( delbanexemption )
{
......@@ -687,25 +703,13 @@
}
//*****************************************************************************
//
CCMD( delbanexemption )
{
// [AK] This function may not be used by ConsoleCommand.
if ( ACS_IsCalledFromConsoleCommand( ))
return;
if ( argv.argc( ) < 2 )
{
Printf( "Usage: delbanexemption <IP address>\n" );
return;
}
std::string message;
g_ServerBanExemptions.removeEntry( argv[1], message );
Printf( "delbanexemption: %s", message.c_str() );
serverban_ExecuteAddOrDelBanCmd( g_ServerBanExemptions, argv, true );
}
//*****************************************************************************
//
CCMD( viewbanlist )
{
......@@ -706,14 +710,13 @@
}
//*****************************************************************************
//
CCMD( viewbanlist )
{
for ( ULONG ulIdx = 0; ulIdx < g_ServerBans.size(); ulIdx++ )
Printf( "%s", g_ServerBans.getEntryAsString(ulIdx).c_str( ));
serverban_ListAddresses( g_ServerBans );
}
//*****************************************************************************
//
CCMD( viewbanexemptionlist )
{
......@@ -714,14 +717,13 @@
}
//*****************************************************************************
//
CCMD( viewbanexemptionlist )
{
for ( ULONG ulIdx = 0; ulIdx < g_ServerBanExemptions.size(); ulIdx++ )
Printf( "%s", g_ServerBanExemptions.getEntryAsString(ulIdx).c_str( ));
serverban_ListAddresses( g_ServerBanExemptions );
}
//*****************************************************************************
//
CCMD( viewmasterbanlist )
{
......@@ -722,14 +724,13 @@
}
//*****************************************************************************
//
CCMD( viewmasterbanlist )
{
for ( ULONG ulIdx = 0; ulIdx < g_MasterServerBans.size(); ulIdx++ )
Printf( "%s", g_MasterServerBans.getEntryAsString(ulIdx).c_str( ));
serverban_ListAddresses( g_MasterServerBans );
}
//*****************************************************************************
//
CCMD( viewmasterexemptionbanlist )
{
......@@ -730,11 +731,10 @@
}
//*****************************************************************************
//
CCMD( viewmasterexemptionbanlist )
{
for ( ULONG ulIdx = 0; ulIdx < g_MasterServerBanExemptions.size(); ulIdx++ )
Printf( "%s", g_MasterServerBanExemptions.getEntryAsString(ulIdx).c_str( ));
serverban_ListAddresses( g_MasterServerBanExemptions );
}
//*****************************************************************************
......
......@@ -58,5 +58,5 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------
void SERVERBAN_Tick( void );
bool SERVERBAN_IsIPBanned( const IPStringArray &szAddress );
bool SERVERBAN_IsIPBanned( const IPStringArray &Address );
bool SERVERBAN_IsIPBanned( const NETADDRESS_s &Address );
......@@ -62,7 +62,8 @@
bool SERVERBAN_IsIPBanned( const NETADDRESS_s &Address );
bool SERVERBAN_IsIPMasterBanned( const IPStringArray &Address );
bool SERVERBAN_IsIPMasterBanned( const NETADDRESS_s &Address );
void SERVERBAN_ClearBans( void );
void SERVERBAN_ReadMasterServerBans( BYTESTREAM_s *pByteStream );
void SERVERBAN_ReadMasterServerBanlistPart( BYTESTREAM_s *pByteStream );
time_t SERVERBAN_ParseBanLength( const char *szLengthString );
IPList *SERVERBAN_GetBanList( void );
......@@ -63,8 +64,7 @@
bool SERVERBAN_IsIPMasterBanned( const NETADDRESS_s &Address );
void SERVERBAN_ClearBans( void );
void SERVERBAN_ReadMasterServerBans( BYTESTREAM_s *pByteStream );
void SERVERBAN_ReadMasterServerBanlistPart( BYTESTREAM_s *pByteStream );
time_t SERVERBAN_ParseBanLength( const char *szLengthString );
IPList *SERVERBAN_GetBanList( void );
IPList *SERVERBAN_GetBanExemptionList( void );
void SERVERBAN_BanPlayer( ULONG ulPlayer, const char *pszBanLength, const char *pszBanReason );
......@@ -70,4 +70,5 @@
void SERVERBAN_BanPlayer( ULONG ulPlayer, const char *pszBanLength, const char *pszBanReason );
void SERVERBAN_BanAddress( const char *address, const char *length, const char *reason );
//--------------------------------------------------------------------------------------------------------------------------------------------------
//-- EXTERNAL CONSOLE VARIABLES --------------------------------------------------------------------------------------------------------------------
......
......@@ -1419,7 +1419,7 @@
// Clear out the ban list, and then add all the bans in the ban list.
SERVERBAN_ClearBans( );
// Now, add the maps in the listbox to the map rotation list.
// Now, add the bans in the listbox to the ban list.
lCount = SendDlgItemMessage( hDlg, IDC_BANLIST, LB_GETCOUNT, 0, 0 );
if ( lCount != LB_ERR )
{
......@@ -1423,12 +1423,5 @@
lCount = SendDlgItemMessage( hDlg, IDC_BANLIST, LB_GETCOUNT, 0, 0 );
if ( lCount != LB_ERR )
{
char *pszIP;
char szIP[32];
char *pszComment;
char szComment[224];
char szDate[128];
char *pszBuffer;
for ( lIdx = 0; lIdx < lCount; lIdx++ )
{
......@@ -1433,4 +1426,5 @@
for ( lIdx = 0; lIdx < lCount; lIdx++ )
{
SendDlgItemMessage( hDlg, IDC_BANLIST, LB_GETTEXT, lIdx, (LPARAM) (LPCTSTR)szBuffer );
char banString[256];
SendDlgItemMessage( hDlg, IDC_BANLIST, LB_GETTEXT, lIdx, (LPARAM) (LPCTSTR)banString );
......@@ -1436,15 +1430,6 @@
pszIP = szIP;
*pszIP = 0;
szDate[0] = 0;
pszComment = szComment;
*pszComment = 0;
pszBuffer = szBuffer;
while ( *pszBuffer != 0 && *pszBuffer != ':' && *pszBuffer != '/' && *pszBuffer != '<' )
{
*pszIP = *pszBuffer;
pszBuffer++;
pszIP++;
*pszIP = 0;
}
unsigned int index = 0;
time_t expiration = 0;
FString ipAddress;
FString comment;
......@@ -1450,4 +1435,7 @@
//======================================================================================================
// [AK] Read the IP address first.
while (( banString[index] != 0 ) && ( banString[index] != ':' ) && ( banString[index] != '/' ) && ( banString[index] != '<' ))
ipAddress += banString[index++];
// [RC] Read the expiration date.
// This is a very klunky temporary solution that I've already fixed it in my redo of the server dialogs.
......@@ -1452,4 +1440,9 @@
// [RC] Read the expiration date.
// This is a very klunky temporary solution that I've already fixed it in my redo of the server dialogs.
//======================================================================================================
if ( banString[index] == '<' )
{
index++;
const long month = strtol( banString + index, nullptr, 10 );
index += 3;
......@@ -1455,6 +1448,10 @@
time_t tExpiration = NULL;
if ( *pszBuffer == '<' )
{
int iMonth = 0, iDay = 0, iYear = 0, iHour = 0, iMinute = 0;
const long day = strtol( banString + index, nullptr, 10 );
index += 3;
const long year = strtol( banString + index, nullptr, 10 );
index += 5;
const long hour = strtol( banString + index, nullptr, 10 );
index += 3;
......@@ -1460,14 +1457,5 @@
pszBuffer++;
iMonth = strtol( pszBuffer, NULL, 10 );
pszBuffer += 3;
iDay = strtol( pszBuffer, NULL, 10 );
pszBuffer += 3;
iYear = strtol( pszBuffer, NULL, 10 );
pszBuffer += 5;
iHour = strtol( pszBuffer, NULL, 10 );
pszBuffer += 3;
iMinute = strtol( pszBuffer, NULL, 10 );
pszBuffer += 2;
const long minute = strtol( banString + index, nullptr, 10 );
index += 2;
// If fewer than 5 elements (the %ds) were read, the user probably edited the file incorrectly.
......@@ -1473,3 +1461,3 @@
// If fewer than 5 elements (the %ds) were read, the user probably edited the file incorrectly.
if ( *pszBuffer != '>' )
if ( banString[index] != '>' )
{
......@@ -1475,4 +1463,4 @@
{
Printf("parseNextLine: WARNING! Failure to read the ban expiration date!" );
return NULL;
Printf( "WARNING: failure to read the ban expiration date for entry \"%s\"!\n", banString );
continue;
}
......@@ -1478,4 +1466,5 @@
}
pszBuffer++;
index++;
// Create the time structure, based on the current time.
......@@ -1481,6 +1470,7 @@
// Create the time structure, based on the current time.
time_t tNow;
time( &tNow );
struct tm *pTimeInfo = localtime( &tNow );
time_t now;
time( &now );
struct tm *timeInfo = localtime( &now );
// Edit the values, and stitch them into a new time.
......@@ -1485,5 +1475,5 @@
// Edit the values, and stitch them into a new time.
pTimeInfo->tm_mon = iMonth - 1;
pTimeInfo->tm_mday = iDay;
timeInfo->tm_mon = month - 1;
timeInfo->tm_mday = day;
......@@ -1489,4 +1479,4 @@
if ( iYear < 100 )
pTimeInfo->tm_year = iYear + 2000;
if ( year < 100 )
timeInfo->tm_year = year + 2000;
else
......@@ -1492,3 +1482,3 @@
else
pTimeInfo->tm_year = iYear - 1900;
timeInfo->tm_year = year - 1900;
......@@ -1494,9 +1484,9 @@
pTimeInfo->tm_hour = iHour;
pTimeInfo->tm_min = iMinute;
pTimeInfo->tm_sec = 0;
tExpiration = mktime( pTimeInfo );
timeInfo->tm_hour = hour;
timeInfo->tm_min = minute;
timeInfo->tm_sec = 0;
expiration = mktime( timeInfo );
}
// Don't include the comment denotion character in the comment string.
......@@ -1500,6 +1490,6 @@
}
// Don't include the comment denotion character in the comment string.
while ( *pszBuffer == ':' || *pszBuffer == '/' )
pszBuffer++;
while (( banString[index] == ':' ) || ( banString[index] == '/' ))
index++;
......@@ -1505,9 +1495,4 @@
while ( *pszBuffer != 0 )
{
*pszComment = *pszBuffer;
pszBuffer++;
pszComment++;
*pszComment = 0;
}
while ( banString[index] != 0 )
comment += banString[index++];
......@@ -1513,6 +1498,6 @@
std::string Message;
SERVERBAN_GetBanList( )->addEntry( szIP, "", szComment, Message, tExpiration );
std::string message;
SERVERBAN_GetBanList( )->addEntry( ipAddress.GetChars( ), "", comment.GetChars( ), message, expiration );
}
}
}
......