From 10c2dc10dc13cad6b56651d885ebd548c84d0615 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Wed, 7 Oct 2015 00:15:11 +0200 Subject: [PATCH] Pincode Functionality Extension Added some options to allow or disallow certain combinations in the pincode as aegis has it. In AEGIS it is not allowed to use pincodes like 0000 or 1111 where the pincode only contains 1 character. It is also not allowed to use sequences like 1234 or 5678. In addition to the official check, which only disallows ascending sequences I also added descending ones. --- conf/char_athena.conf | 8 ++++ src/char/char.c | 6 +++ src/char/char.h | 3 ++ src/char/char_clif.c | 95 +++++++++++++++++++++++++++++++++++++++---- 4 files changed, 104 insertions(+), 8 deletions(-) diff --git a/conf/char_athena.conf b/conf/char_athena.conf index f0f9cb0f7f..f9106ee259 100644 --- a/conf/char_athena.conf +++ b/conf/char_athena.conf @@ -196,6 +196,14 @@ pincode_maxtry: 3 // Default: yes pincode_force: yes +// Are repeated numbers allowed? +// Default: no +pincode_allow_repeated: no + +// Are sequential numbers allowed? +// Default: no +pincode_allow_sequential: no + //=================================== // Addon system //=================================== diff --git a/src/char/char.c b/src/char/char.c index c99cbdea28..e588b9f3b8 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2588,6 +2588,8 @@ void char_set_defaults(){ charserv_config.pincode_config.pincode_changetime = 0; charserv_config.pincode_config.pincode_maxtry = 3; charserv_config.pincode_config.pincode_force = true; + charserv_config.pincode_config.pincode_allow_repeated = false; + charserv_config.pincode_config.pincode_allow_sequential = false; charserv_config.charmove_config.char_move_enabled = true; charserv_config.charmove_config.char_movetoused = true; @@ -2826,6 +2828,10 @@ bool char_config_read(const char* cfgName, bool normal){ charserv_config.pincode_config.pincode_maxtry = atoi(w2); } else if (strcmpi(w1, "pincode_force") == 0) { charserv_config.pincode_config.pincode_force = config_switch(w2); + } else if (strcmpi(w1, "pincode_allow_repeated") == 0) { + charserv_config.pincode_config.pincode_allow_repeated = config_switch(w2); + } else if (strcmpi(w1, "pincode_allow_sequential") == 0) { + charserv_config.pincode_config.pincode_allow_sequential = config_switch(w2); } else if (strcmpi(w1, "char_move_enabled") == 0) { charserv_config.charmove_config.char_move_enabled = config_switch(w2); } else if (strcmpi(w1, "char_movetoused") == 0) { diff --git a/src/char/char.h b/src/char/char.h index 3cb7cc441f..2b1a4c7ec2 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -78,6 +78,7 @@ enum pincode_state { PINCODE_NOTSET = 2, PINCODE_EXPIRED = 3, PINCODE_NEW = 4, + PINCODE_ILLEGAL = 5, PINCODE_PASSED = 7, PINCODE_WRONG = 8, PINCODE_MAXSTATE @@ -87,6 +88,8 @@ struct Pincode_Config { int pincode_changetime; int pincode_maxtry; bool pincode_force; + bool pincode_allow_repeated; + bool pincode_allow_sequential; }; struct CharMove_Config { bool char_move_enabled; diff --git a/src/char/char_clif.c b/src/char/char_clif.c index 7d45feb030..670618bcd0 100644 --- a/src/char/char_clif.c +++ b/src/char/char_clif.c @@ -19,6 +19,7 @@ #include +bool pincode_allowed( char* pincode ); //------------------------------------------------ //Add On system @@ -158,6 +159,76 @@ int chclif_parse_pincode_check( int fd, struct char_session_data* sd ){ return 1; } +/* + * Helper function to check if a new pincode contains illegal characters or combinations + */ +bool pincode_allowed( char* pincode ){ + int i; + char c, n, compare[PINCODE_LENGTH+1]; + + memset( compare, 0, PINCODE_LENGTH+1); + + // Sanity check for bots to prevent errors + for( i = 0; i < PINCODE_LENGTH; i++ ){ + c = pincode[i]; + + if( c < '0' || c > '9' ){ + return false; + } + } + + // Is it forbidden to use only the same character? + if( !charserv_config.pincode_config.pincode_allow_repeated ){ + c = pincode[0]; + + // Check if the first character equals the rest of the input + for( i = 0; i < PINCODE_LENGTH; i++ ){ + compare[i] = c; + } + + if( strncmp( pincode, compare, PINCODE_LENGTH + 1 ) == 0 ){ + return false; + } + } + + // Is it forbidden to use a sequential combination of numbers? + if( !charserv_config.pincode_config.pincode_allow_sequential ){ + c = pincode[0]; + + // Check if it is an ascending sequence + for( i = 0; i < PINCODE_LENGTH; i++ ){ + n = c + i; + + if( n > '9' ){ + compare[i] = '0' + ( n - '9' ) - 1; + }else{ + compare[i] = n; + } + } + + if( strncmp( pincode, compare, PINCODE_LENGTH + 1 ) == 0 ){ + return false; + } + + // Check if it is an descending sequence + for( i = 0; i < PINCODE_LENGTH; i++ ){ + n = c - i; + + if( n < '0' ){ + compare[i] = '9' - ( '0' - n ) + 1; + }else{ + compare[i] = n; + } + } + + if( strncmp( pincode, compare, PINCODE_LENGTH + 1 ) == 0 ){ + return false; + } + } + + return true; +} + /* * Client request to change pincode */ @@ -180,12 +251,16 @@ int chclif_parse_pincode_change( int fd, struct char_session_data* sd ){ if( !char_pincode_compare( fd, sd, oldpin ) ) return 1; char_pincode_decrypt(sd->pincode_seed,newpin); + + if( pincode_allowed(newpin) ){ + chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin ); + strncpy(sd->pincode, newpin, sizeof(newpin)); + ShowInfo("Pincode changed for AID: %d\n", sd->account_id); - chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin ); - strncpy(sd->pincode, newpin, sizeof(newpin)); - ShowInfo("Pincode changed for AID: %d\n", sd->account_id); - - chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); + chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); + }else{ + chclif_pincode_sendstate( fd, sd, PINCODE_ILLEGAL ); + } } return 1; } @@ -207,10 +282,14 @@ int chclif_parse_pincode_setnew( int fd, struct char_session_data* sd ){ char_pincode_decrypt( sd->pincode_seed, newpin ); - chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin ); - strncpy( sd->pincode, newpin, strlen( newpin ) ); + if( pincode_allowed(newpin) ){ + chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin ); + strncpy( sd->pincode, newpin, strlen( newpin ) ); - chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); + chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); + }else{ + chclif_pincode_sendstate( fd, sd, PINCODE_ILLEGAL ); + } } return 1; }