summaryrefslogtreecommitdiff
path: root/src/char
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2014-11-16 01:42:47 +0100
committerHaru <haru@dotalux.com>2014-11-16 07:16:22 +0100
commit72c36285c7cda6b953782b2291474ef25b8763ee (patch)
treef577021ba57ef462611ea511858df9f9fabcbca3 /src/char
parentb4d2f41696de385a08e5830c785ad7fc8e691992 (diff)
downloadhercules-72c36285c7cda6b953782b2291474ef25b8763ee.tar.gz
hercules-72c36285c7cda6b953782b2291474ef25b8763ee.tar.bz2
hercules-72c36285c7cda6b953782b2291474ef25b8763ee.tar.xz
hercules-72c36285c7cda6b953782b2291474ef25b8763ee.zip
Moved pincode settings into the interface
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/char')
-rw-r--r--src/char/char.c6
-rw-r--r--src/char/pincode.c47
-rw-r--r--src/char/pincode.h28
3 files changed, 39 insertions, 42 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 8aab5bffb..d5adaa251 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -213,7 +213,7 @@ void char_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;
+ character->pincode_enable = pincode->charselect + pincode->enabled;
if(character->waiting_disconnect != INVALID_TIMER) {
timer->delete(character->waiting_disconnect, chr->waiting_disconnect);
@@ -4437,7 +4437,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl)
RFIFOSKIP(fd,3);
#if PACKETVER >= 20110309
- if( *pincode->enabled ){ // hack check
+ if( pincode->enabled ){ // hack check
struct online_char_data* character;
character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id);
if( character && character->pincode_enable == -1){
@@ -4636,7 +4636,7 @@ void char_parse_char_delete_char(int fd, struct char_session_data* sd, unsigned
int cid = RFIFOL(fd,2);
int i;
#if PACKETVER >= 20110309
- if( *pincode->enabled ){ // hack check
+ if( pincode->enabled ){ // hack check
struct online_char_data* character;
character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id);
if( character && character->pincode_enable == -1 ){
diff --git a/src/char/pincode.c b/src/char/pincode.c
index c8a76719f..a4ec89484 100644
--- a/src/char/pincode.c
+++ b/src/char/pincode.c
@@ -16,25 +16,20 @@
#include "../common/socket.h"
#include "../common/strlib.h"
-int pincode_enabled = PINCODE_OK;
-int pincode_changetime = 0;
-int pincode_maxtry = 3;
-int pincode_charselect = 0;
-unsigned int pincode_multiplier = 0x3498;
-unsigned int pincode_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(chr->online_char_db, sd->account_id);
- if( character && character->pincode_enable > *pincode->charselect ){
- character->pincode_enable = *pincode->charselect * 2;
+ 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 );
@@ -54,7 +49,7 @@ void pincode_check(int fd, struct char_session_data* sd) {
if( pincode->compare( fd, sd, pin ) ){
struct online_char_data* character;
if( (character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id)) )
- character->pincode_enable = *pincode->charselect * 2;
+ character->pincode_enable = pincode->charselect * 2;
pincode->sendstate( fd, sd, PINCODE_OK );
}
}
@@ -65,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;
@@ -135,7 +130,7 @@ void pincode_decrypt(unsigned int userSeed, char* pin) {
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];
@@ -156,7 +151,7 @@ bool pincode_config_read(char *w1, char *w2) {
while ( true ) {
if ( strcmpi(w1, "pincode_enabled") == 0 ) {
- pincode_enabled = atoi(w2);
+ pincode->enabled = atoi(w2);
#if PACKETVER < 20110309
if( pincode_enabled ) {
ShowWarning("pincode_enabled requires PACKETVER 20110309 or higher. disabling...\n");
@@ -164,15 +159,15 @@ bool pincode_config_read(char *w1, char *w2) {
}
#endif
} else if ( strcmpi(w1, "pincode_changetime") == 0 ) {
- pincode_changetime = atoi(w2)*60;
+ pincode->changetime = atoi(w2)*60;
} else if ( strcmpi(w1, "pincode_maxtry") == 0 ) {
- 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;
+ 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 ) {
- pincode_charselect = atoi(w2);
+ pincode->charselect = atoi(w2);
} else
return false;
@@ -185,13 +180,13 @@ bool pincode_config_read(char *w1, char *w2) {
void pincode_defaults(void) {
pincode = &pincode_s;
- pincode->enabled = &pincode_enabled;
- pincode->changetime = &pincode_changetime;
- pincode->maxtry = &pincode_maxtry;
- pincode->charselect = &pincode_charselect;
- pincode->multiplier = &pincode_multiplier;
- pincode->baseSeed = &pincode_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;
diff --git a/src/char/pincode.h b/src/char/pincode.h
index fa43eb9c2..f4265716a 100644
--- a/src/char/pincode.h
+++ b/src/char/pincode.h
@@ -7,24 +7,26 @@
#include "char.h"
-#define PINCODE_OK 0
-#define PINCODE_ASK 1
-#define PINCODE_NOTSET 2
-#define PINCODE_EXPIRED 3
-#define PINCODE_UNUSED 7
-#define PINCODE_WRONG 8
+enum PincodeResponseCode {
+ PINCODE_OK = 0,
+ PINCODE_ASK = 1,
+ PINCODE_NOTSET = 2,
+ PINCODE_EXPIRED = 3,
+ PINCODE_UNUSED = 7,
+ PINCODE_WRONG = 8,
+};
/**
* pincode interface
**/
struct pincode_interface {
/* vars */
- int *enabled;
- int *changetime;
- int *maxtry;
- int *charselect;
- unsigned int *multiplier;
- unsigned int *baseSeed;
+ int enabled;
+ int changetime;
+ int maxtry;
+ int charselect;
+ unsigned int multiplier;
+ unsigned int baseSeed;
/* handler */
void (*handle) (int fd, struct char_session_data* sd);
void (*decrypt) (unsigned int userSeed, char* pin);
@@ -36,7 +38,7 @@ struct pincode_interface {
int (*compare) (int fd, struct char_session_data* sd, char* pin);
void (*check) (int fd, struct char_session_data* sd);
bool (*config_read) (char *w1, char *w2);
-} pincode_s;
+};
struct pincode_interface *pincode;