/* * activate PIN system and set first PIN */ int chclif_parse_pincode_setnew( int fd, struct char_session_data* sd ){ if( RFIFOREST(fd) < 10 ) return 0; if( charserv_config.pincode_config.pincode_enabled==0 || RFIFOL(fd,2) != sd->account_id ) return 1; else { char newpin[PINCODE_LENGTH+1]; memset(newpin,0,PINCODE_LENGTH+1); strncpy( newpin, RFIFOCP(fd,6), PINCODE_LENGTH ); RFIFOSKIP(fd,10); char_pincode_decrypt( sd->pincode_seed, 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 ); }else{ chclif_pincode_sendstate( fd, sd, PINCODE_ILLEGAL ); } } return 1; }
/* * Client request to change pincode */ int chclif_parse_pincode_change( int fd, struct char_session_data* sd ){ if( RFIFOREST(fd) < 14 ) return 0; if( charserv_config.pincode_config.pincode_enabled==0 || RFIFOL(fd,2) != sd->account_id ) return 1; else { char oldpin[PINCODE_LENGTH+1]; char newpin[PINCODE_LENGTH+1]; memset(oldpin,0,PINCODE_LENGTH+1); memset(newpin,0,PINCODE_LENGTH+1); strncpy(oldpin, RFIFOCP(fd,6), PINCODE_LENGTH); strncpy(newpin, RFIFOCP(fd,10), PINCODE_LENGTH); RFIFOSKIP(fd,14); char_pincode_decrypt(sd->pincode_seed,oldpin); 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); chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); }else{ chclif_pincode_sendstate( fd, sd, PINCODE_ILLEGAL ); } } return 1; }
/* * Client just entering charserv from login, send him pincode confirmation */ int chclif_parse_reqpincode_window(int fd, struct char_session_data* sd){ if( RFIFOREST(fd) < 6 ) return 0; if( charserv_config.pincode_config.pincode_enabled && RFIFOL(fd,2) == sd->account_id ){ if( strlen( sd->pincode ) <= 0 ){ chclif_pincode_sendstate( fd, sd, PINCODE_NEW ); }else{ chclif_pincode_sendstate( fd, sd, PINCODE_ASK ); } } RFIFOSKIP(fd,6); return 1; }
void chlogif_pincode_start(int fd, struct char_session_data* sd){ if( charserv_config.pincode_config.pincode_enabled ){ //ShowInfo("Asking to start pincode to AID: %d\n", sd->account_id); // PIN code system enabled if( sd->pincode[0] == '\0' ){ // No PIN code has been set yet if( charserv_config.pincode_config.pincode_force ){ chclif_pincode_sendstate( fd, sd, PINCODE_NEW ); }else{ chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); } }else{ if( !(charserv_config.pincode_config.pincode_changetime) || ( sd->pincode_change + charserv_config.pincode_config.pincode_changetime ) > time(NULL) ){ DBMap* online_char_db = char_get_onlinedb(); struct online_char_data* node = (struct online_char_data*)idb_get( online_char_db, sd->account_id ); if( node != NULL && node->pincode_success ){ // User has already passed the check chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); }else{ // Ask user for his PIN code chclif_pincode_sendstate( fd, sd, PINCODE_ASK ); } }else{ // User hasnt changed his PIN code too long chclif_pincode_sendstate( fd, sd, PINCODE_EXPIRED ); } } }else{ // PIN code system disabled //ShowInfo("Pincode is disabled.\n"); chclif_pincode_sendstate( fd, sd, PINCODE_OK ); } }
/* * Client as anwsered pincode questionning, checking if valid anwser */ int chclif_parse_pincode_check( int fd, struct char_session_data* sd ){ char pin[PINCODE_LENGTH+1]; if( RFIFOREST(fd) < 10 ) return 0; if( charserv_config.pincode_config.pincode_enabled==0 || RFIFOL(fd,2) != sd->account_id ) return 1; memset(pin,0,PINCODE_LENGTH+1); strncpy((char*)pin, RFIFOCP(fd, 6), PINCODE_LENGTH); RFIFOSKIP(fd,10); char_pincode_decrypt(sd->pincode_seed, pin ); if( char_pincode_compare( fd, sd, pin ) ){ chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); } return 1; }