From f214021bb14aa3ab976730b32dd79d843ff8e93e Mon Sep 17 00:00:00 2001 From: malufett Date: Sat, 16 Mar 2013 10:13:03 +0800 Subject: Follow up fixed for Pin Code Feature -Fixed some warning in Windows. -Fixed 'pincode_charselect' where it doesn't work properly Signed-off-by: malufett --- src/char/char.c | 24 ++++++++-------- src/char/char.h | 3 +- src/char/pincode.c | 83 ++++++++++++++++++++---------------------------------- src/char/pincode.h | 5 ++-- src/login/login.c | 2 +- 5 files changed, 45 insertions(+), 72 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index 3436860d0..9e63a682c 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -186,6 +186,7 @@ static DBData create_online_char_data(DBKey key, va_list args) character->account_id = key.i; character->char_id = -1; character->server = -1; + character->pincode_enable = -1; character->fd = -1; character->waiting_disconnect = INVALID_TIMER; return db_ptr2data(character); @@ -203,6 +204,8 @@ void set_char_charselect(int account_id) character->char_id = -1; character->server = -1; + if(character->pincode_enable == -1) + character->pincode_enable = *pincode->charselect + *pincode->enabled; if(character->waiting_disconnect != INVALID_TIMER) { delete_timer(character->waiting_disconnect, chardb_waiting_disconnect); @@ -299,6 +302,7 @@ void set_char_offline(int char_id, int account_id) { character->char_id = -1; character->server = -1; + character->pincode_enable = -1; } //FIXME? Why Kevin free'd the online information when the char was effectively in the map-server? @@ -4167,10 +4171,8 @@ int parse_char(int fd) if( RFIFOREST(fd) < 10 ) return 0; - if( !sd->pincode_pass ) { - if( RFIFOL(fd,2) == sd->account_id ) - pincode->check( fd, sd ); - } + if( RFIFOL(fd,2) == sd->account_id ) + pincode->check( fd, sd ); RFIFOSKIP(fd,10); break; @@ -4180,7 +4182,7 @@ int parse_char(int fd) if( RFIFOREST(fd) < 6 ) return 0; if( RFIFOL(fd,2) == sd->account_id ) - pincode->state( fd, sd, PINCODE_NOTSET ); + pincode->sendstate( fd, sd, PINCODE_NOTSET ); RFIFOSKIP(fd,6); break; @@ -4189,10 +4191,8 @@ int parse_char(int fd) case 0x8be: if( RFIFOREST(fd) < 14 ) return 0; - if( !sd->pincode_pass ) { - if( RFIFOL(fd,2) == sd->account_id ) - pincode->change( fd, sd ); - } + if( RFIFOL(fd,2) == sd->account_id ) + pincode->change( fd, sd ); RFIFOSKIP(fd,14); break; @@ -4201,10 +4201,8 @@ int parse_char(int fd) case 0x8ba: if( RFIFOREST(fd) < 10 ) return 0; - if( !sd->pincode_pass ) { - if( RFIFOL(fd,2) == sd->account_id ) - pincode->new( fd, sd ); - } + if( RFIFOL(fd,2) == sd->account_id ) + pincode->setnew( fd, sd ); RFIFOSKIP(fd,10); break; diff --git a/src/char/char.h b/src/char/char.h index 934c26f45..b48ea359c 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -30,7 +30,6 @@ struct char_session_data { uint32 pincode_seed; uint16 pincode_try; uint32 pincode_change; - bool pincode_pass; char new_name[NAME_LENGTH]; char birthdate[10+1]; // YYYY-MM-DD }; @@ -41,7 +40,7 @@ struct online_char_data { int fd; int waiting_disconnect; short server; // -2: unknown server, -1: not connected, 0+: id of server - bool pincode_passed; + int pincode_enable; }; DBMap* online_char_db; // int account_id -> struct online_char_data* diff --git a/src/char/pincode.c b/src/char/pincode.c index c7d7bce4c..3acc0aa6f 100644 --- a/src/char/pincode.c +++ b/src/char/pincode.c @@ -19,75 +19,54 @@ int charselect = 0; unsigned int multiplier = 0x3498, baseSeed = 0x881234; void pincode_handle ( int fd, struct char_session_data* sd ) { - bool pass = true; + struct online_char_data* character; - if( !*pincode->charselect ) { - struct online_char_data* character; - if( (character = (struct online_char_data*)idb_get(online_char_db, sd->account_id)) != NULL ) { - if( character->pincode_passed ) - pass = false; - } - } + character = (struct online_char_data*)idb_get(online_char_db, sd->account_id); - if( *pincode->enabled && pass ) { - - sd->pincode_pass = false; - // PIN code system enabled - if( sd->pincode[0] == '\0' ){ - // No PIN code has been set yet - pincode->state( fd, sd, PINCODE_NOTSET ); - } else { - if( !pincode->changetime || !( time(NULL) > (sd->pincode_change+*pincode->changetime) ) ){ - // Ask user for his PIN code - pincode->state( fd, sd, PINCODE_ASK ); - } else { - // User hasnt changed his PIN code too long - pincode->state( fd, sd, PINCODE_EXPIRED ); - } - } - } else { - // PIN code system, disabled - pincode->state( fd, sd, PINCODE_OK ); + if( character && character->pincode_enable > *pincode->charselect ){ + character->pincode_enable = *pincode->charselect * 2; + }else{ + pincode->sendstate( fd, sd, PINCODE_OK ); + return; } -} -void pincode_pass(struct char_session_data *sd) { - struct online_char_data* character; - if( (character = (struct online_char_data*)idb_get(online_char_db, sd->account_id)) != NULL ) { - character->pincode_passed = true; - } - sd->pincode_pass = true; + if( strlen(sd->pincode) ){ + if( *pincode->changetime && time(NULL) > (sd->pincode_change+*pincode->changetime) ){ // User hasnt changed his PIN code for a long time + pincode->sendstate( fd, sd, PINCODE_EXPIRED ); + } else { // Ask user for his PIN code + pincode->sendstate( fd, sd, PINCODE_ASK ); + } + } else // No PIN code has been set yet + pincode->sendstate( fd, sd, PINCODE_NOTSET ); } + void pincode_check(int fd, struct char_session_data* sd) { - char pin[4] = "\0\0\0\0"; + char pin[5] = "\0\0\0\0"; - strncpy(pin, (char*)RFIFOP(fd, 6), 3+1); + strncpy(pin, (char*)RFIFOP(fd, 6), 4+1); pincode->decrypt(sd->pincode_seed, pin); if( pincode->compare( fd, sd, pin ) ){ - pincode->state( fd, sd, PINCODE_OK ); + pincode->sendstate( fd, sd, PINCODE_OK ); } } int pincode_compare(int fd, struct char_session_data* sd, char* pin) { if( strcmp( sd->pincode, pin ) == 0 ){ sd->pincode_try = 0; - pincode->pass(sd); return 1; } else { - pincode->state( fd, sd, PINCODE_WRONG ); - + pincode->sendstate( fd, sd, PINCODE_WRONG ); if( *pincode->maxtry && ++sd->pincode_try >= *pincode->maxtry ){ pincode->error( sd->account_id ); } - return 0; } } void pincode_change(int fd, struct char_session_data* sd) { - char oldpin[4] = "\0\0\0\0", newpin[4] = "\0\0\0\0"; + char oldpin[5] = "\0\0\0\0", newpin[5] = "\0\0\0\0"; - strncpy(oldpin, (char*)RFIFOP(fd,6), 3+1); + strncpy(oldpin, (char*)RFIFOP(fd,6), 4+1); pincode->decrypt(sd->pincode_seed,oldpin); if( !pincode->compare( fd, sd, oldpin ) ) return; @@ -96,22 +75,21 @@ void pincode_change(int fd, struct char_session_data* sd) { pincode->decrypt(sd->pincode_seed,newpin); pincode->update( sd->account_id, newpin ); - pincode->state( fd, sd, PINCODE_OK ); + pincode->sendstate( fd, sd, PINCODE_OK ); } void pincode_setnew(int fd, struct char_session_data* sd) { - char newpin[4] = "\0\0\0\0"; + char newpin[5] = "\0\0\0\0"; - strncpy(newpin, (char*)RFIFOP(fd,6), 3+1); + strncpy(newpin, (char*)RFIFOP(fd,6), 4+1); pincode->decrypt(sd->pincode_seed,newpin); pincode->update( sd->account_id, newpin ); - pincode->state( fd, sd, PINCODE_OK ); - pincode->pass(sd); + pincode->sendstate( fd, sd, PINCODE_OK ); } -// 0 = disabled / pin is correct +// 0 = pin is correct // 1 = ask for pin - client sends 0x8b8 // 2 = create new pin - client sends 0x8ba // 3 = pin must be changed - client 0x8be @@ -171,7 +149,7 @@ bool pincode_config_read(char *w1, char *w2) { if ( strcmpi(w1, "pincode_enabled") == 0 ) { enabled = atoi(w2); -#ifdef PACKETVER < 20110309 +#if PACKETVER < 20110309 if( enabled ) { ShowWarning("pincode_enabled requires PACKETVER 20110309 or higher. disabling...\n"); enabled = 0; @@ -210,11 +188,10 @@ void pincode_defaults(void) { pincode->decrypt = pincode_decrypt; pincode->error = pincode_notifyLoginPinError; pincode->update = pincode_notifyLoginPinUpdate; - pincode->state = pincode_sendstate; - pincode->new = pincode_setnew; + pincode->sendstate = pincode_sendstate; + pincode->setnew = pincode_setnew; pincode->change = pincode_change; pincode->compare = pincode_compare; - pincode->pass = pincode_pass; pincode->check = pincode_check; pincode->config_read = pincode_config_read; diff --git a/src/char/pincode.h b/src/char/pincode.h index 1856e4baa..94e0b4f5b 100644 --- a/src/char/pincode.h +++ b/src/char/pincode.h @@ -27,11 +27,10 @@ struct pincode_interface { void (*decrypt) (unsigned int userSeed, char* pin); void (*error) (int account_id); void (*update) (int account_id, char* pin); - void (*state) (int fd, struct char_session_data* sd, uint16 state); - void (*new) (int fd, struct char_session_data* sd); + void (*sendstate) (int fd, struct char_session_data* sd, uint16 state); + void (*setnew) (int fd, struct char_session_data* sd); void (*change) (int fd, struct char_session_data* sd); int (*compare) (int fd, struct char_session_data* sd, char* pin); - void (*pass) (struct char_session_data *sd); void (*check) (int fd, struct char_session_data* sd); bool (*config_read) (char *w1, char *w2); } pincode_s; diff --git a/src/login/login.c b/src/login/login.c index dfa67d932..51bc7f29c 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -559,7 +559,7 @@ int parse_fromchar(int fd) int group_id = 0; uint8 char_slots = 0; char birthdate[10+1] = ""; - char pincode[4+1] = "\0\0\0\0\0"; + char pincode[4+1] = "\0\0\0\0"; int account_id = RFIFOL(fd,2); RFIFOSKIP(fd,6); -- cgit v1.2.3-60-g2f50