summaryrefslogtreecommitdiff
path: root/src/char/pincode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/char/pincode.c')
-rw-r--r--src/char/pincode.c97
1 files changed, 46 insertions, 51 deletions
diff --git a/src/char/pincode.c b/src/char/pincode.c
index 18ad0ffc8..a3843ff53 100644
--- a/src/char/pincode.c
+++ b/src/char/pincode.c
@@ -16,24 +16,20 @@
#include "../common/socket.h"
#include "../common/strlib.h"
-int enabled = PINCODE_OK;
-int changetime = 0;
-int maxtry = 3;
-int charselect = 0;
-unsigned int multiplier = 0x3498, baseSeed = 0x881234;
+struct pincode_interface pincode_s;
void pincode_handle ( int fd, struct char_session_data* sd ) {
- struct online_char_data* character = (struct online_char_data*)idb_get(online_char_db, sd->account_id);
-
- if( character && character->pincode_enable > *pincode->charselect ){
- character->pincode_enable = *pincode->charselect * 2;
+ struct online_char_data* character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id);
+
+ if( character && character->pincode_enable > pincode->charselect ){
+ character->pincode_enable = pincode->charselect * 2;
}else{
pincode->sendstate( fd, sd, PINCODE_OK );
return;
}
-
+
if( strlen(sd->pincode) == 4 ){
- if( *pincode->changetime && time(NULL) > (sd->pincode_change+*pincode->changetime) ){ // User hasn't changed his PIN code for a long time
+ if( pincode->changetime && time(NULL) > (sd->pincode_change+pincode->changetime) ){ // User hasn't 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 );
@@ -47,13 +43,13 @@ void pincode_handle ( int fd, struct char_session_data* sd ) {
void pincode_check(int fd, struct char_session_data* sd) {
char pin[5] = "\0\0\0\0";
-
+
strncpy(pin, (char*)RFIFOP(fd, 6), 4+1);
pincode->decrypt(sd->pincode_seed, pin);
if( pincode->compare( fd, sd, pin ) ){
struct online_char_data* character;
- if( (character = (struct online_char_data*)idb_get(online_char_db, sd->account_id)) )
- character->pincode_enable = *pincode->charselect * 2;
+ if( (character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id)) )
+ character->pincode_enable = pincode->charselect * 2;
pincode->sendstate( fd, sd, PINCODE_OK );
}
}
@@ -64,7 +60,7 @@ int pincode_compare(int fd, struct char_session_data* sd, char* pin) {
return 1;
} else {
pincode->sendstate( fd, sd, PINCODE_WRONG );
- if( *pincode->maxtry && ++sd->pincode_try >= *pincode->maxtry ){
+ if( pincode->maxtry && ++sd->pincode_try >= pincode->maxtry ){
pincode->error( sd->account_id );
}
return 0;
@@ -78,7 +74,7 @@ void pincode_change(int fd, struct char_session_data* sd) {
pincode->decrypt(sd->pincode_seed,oldpin);
if( !pincode->compare( fd, sd, oldpin ) )
return;
-
+
strncpy(newpin, (char*)RFIFOP(fd,10), sizeof(newpin));
pincode->decrypt(sd->pincode_seed,newpin);
pincode->update( sd->account_id, newpin );
@@ -115,26 +111,26 @@ void pincode_sendstate(int fd, struct char_session_data* sd, uint16 state) {
}
void pincode_notifyLoginPinUpdate(int account_id, char* pin) {
- WFIFOHEAD(login_fd,11);
- WFIFOW(login_fd,0) = 0x2738;
- WFIFOL(login_fd,2) = account_id;
- strncpy( (char*)WFIFOP(login_fd,6), pin, 5 );
- WFIFOSET(login_fd,11);
+ WFIFOHEAD(chr->login_fd,11);
+ WFIFOW(chr->login_fd,0) = 0x2738;
+ WFIFOL(chr->login_fd,2) = account_id;
+ strncpy( (char*)WFIFOP(chr->login_fd,6), pin, 5 );
+ WFIFOSET(chr->login_fd,11);
}
void pincode_notifyLoginPinError(int account_id) {
- WFIFOHEAD(login_fd,6);
- WFIFOW(login_fd,0) = 0x2739;
- WFIFOL(login_fd,2) = account_id;
- WFIFOSET(login_fd,6);
+ WFIFOHEAD(chr->login_fd,6);
+ WFIFOW(chr->login_fd,0) = 0x2739;
+ WFIFOL(chr->login_fd,2) = account_id;
+ WFIFOSET(chr->login_fd,6);
}
void pincode_decrypt(unsigned int userSeed, char* pin) {
int i, pos;
char tab[10] = {0,1,2,3,4,5,6,7,8,9};
-
+
for( i = 1; i < 10; i++ ){
- userSeed = *pincode->baseSeed + userSeed * *pincode->multiplier;
+ userSeed = pincode->baseSeed + userSeed * pincode->multiplier;
pos = userSeed % (i + 1);
if( i != pos ){
tab[i] ^= tab[pos];
@@ -142,55 +138,54 @@ void pincode_decrypt(unsigned int userSeed, char* pin) {
tab[i] ^= tab[pos];
}
}
-
+
for( i = 0; i < 4; i++ ){
pin[i] = tab[pin[i] - '0'];
}
-
+
sprintf(pin, "%d%d%d%d", pin[0], pin[1], pin[2], pin[3]);
}
bool pincode_config_read(char *w1, char *w2) {
-
+
while ( true ) {
-
if ( strcmpi(w1, "pincode_enabled") == 0 ) {
- enabled = atoi(w2);
+ pincode->enabled = atoi(w2);
#if PACKETVER < 20110309
- if( enabled ) {
+ if( pincode->enabled ) {
ShowWarning("pincode_enabled requires PACKETVER 20110309 or higher. disabling...\n");
- enabled = 0;
+ pincode->enabled = 0;
}
#endif
} else if ( strcmpi(w1, "pincode_changetime") == 0 ) {
- changetime = atoi(w2)*60;
+ pincode->changetime = atoi(w2)*60;
} else if ( strcmpi(w1, "pincode_maxtry") == 0 ) {
- maxtry = atoi(w2);
- if( maxtry > 3 ) {
- ShowWarning("pincode_maxtry is too high (%d); maximum allowed: 3! capping to 3...\n",maxtry);
- maxtry = 3;
+ pincode->maxtry = atoi(w2);
+ if( pincode->maxtry > 3 ) {
+ ShowWarning("pincode_maxtry is too high (%d); maximum allowed: 3! capping to 3...\n", pincode->maxtry);
+ pincode->maxtry = 3;
}
} else if ( strcmpi(w1, "pincode_charselect") == 0 ) {
- charselect = atoi(w2);
- } else
+ pincode->charselect = atoi(w2);
+ } else {
return false;
-
+ }
break;
}
-
+
return true;
}
void pincode_defaults(void) {
pincode = &pincode_s;
-
- pincode->enabled = &enabled;
- pincode->changetime = &changetime;
- pincode->maxtry = &maxtry;
- pincode->charselect = &charselect;
- pincode->multiplier = &multiplier;
- pincode->baseSeed = &baseSeed;
-
+
+ pincode->enabled = PINCODE_OK;
+ pincode->changetime = 0;
+ pincode->maxtry = 3;
+ pincode->charselect = 0;
+ pincode->multiplier = 0x3498;
+ pincode->baseSeed = 0x881234;
+
pincode->handle = pincode_handle;
pincode->decrypt = pincode_decrypt;
pincode->error = pincode_notifyLoginPinError;