From 6fdaac4a75fc6a7adbe697e248c8eebcb4d72dd1 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Tue, 11 Jun 2024 21:50:16 +0200 Subject: [PATCH] Added pincode state tracking (#8412) Fixes #6595 Thanks to @Danil0v3s --- src/char/char.hpp | 1 + src/char/char_clif.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/char/char.hpp b/src/char/char.hpp index 0a17ac8cd8..6dcee5ea88 100644 --- a/src/char/char.hpp +++ b/src/char/char.hpp @@ -266,6 +266,7 @@ struct char_session_data { uint32 pincode_seed; time_t pincode_change; uint16 pincode_try; + bool pincode_correct; // Addon system unsigned int char_moves[MAX_CHARS]; // character moves left uint8 isvip; diff --git a/src/char/char_clif.cpp b/src/char/char_clif.cpp index 1ae2d56fa3..88de93c0b3 100644 --- a/src/char/char_clif.cpp +++ b/src/char/char_clif.cpp @@ -182,6 +182,7 @@ int chclif_parse_pincode_check( int fd, struct char_session_data* sd ){ } if( char_pincode_compare( fd, sd, pin ) ){ + sd->pincode_correct = true; chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); } return 1; @@ -322,6 +323,7 @@ int chclif_parse_pincode_setnew( int fd, struct char_session_data* sd ){ if( pincode_allowed(newpin) ){ chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin ); strncpy( sd->pincode, newpin, sizeof( newpin ) ); + sd->pincode_correct = true; chclif_pincode_sendstate( fd, sd, PINCODE_PASSED ); }else{ @@ -757,6 +759,7 @@ int chclif_parse_reqtoconnect(int fd, struct char_session_data* sd,uint32 ipl){ sd->login_id2 = login_id2; sd->sex = sex; sd->auth = false; // not authed yet + sd->pincode_correct = false; // not entered pincode correctly yet // send back account_id WFIFOHEAD(fd,4); @@ -1569,6 +1572,44 @@ int chclif_parse(int fd) { unsigned short cmd; cmd = RFIFOW(fd,0); + +#if PACKETVER_SUPPORTS_PINCODE + // If the pincode system is enabled + if( charserv_config.pincode_config.pincode_enabled ){ + switch( cmd ){ + // Connect of player + case 0x65: + // Client keep-alive packet (every 12 seconds) + case 0x187: + // Checks the entered pin + case 0x8b8: + // Request for PIN window + case 0x8c5: + // Request character list + case 0x9a1: + // Connect of map-server + case 0x2af8: + break; + + // Before processing any other packets, do a few checks + default: + // If the pincode was entered correctly + if( sd->pincode_correct ){ + break; + } + + // If no pincode is set (yet) + if( strlen( sd->pincode ) <= 0 ){ + break; + } + + // The pincode was not entered correctly, yet the player (=bot) tried to send a different packet => Goodbye! + set_eof( fd ); + return 0; + } + } +#endif + switch( cmd ) { case 0x65: next=chclif_parse_reqtoconnect(fd,sd,ipl); break; // char select