|
@@ -13,6 +13,7 @@
|
|
#include "../common/timer.h"
|
|
#include "../common/timer.h"
|
|
#include "../common/utils.h"
|
|
#include "../common/utils.h"
|
|
#include "../common/cli.h"
|
|
#include "../common/cli.h"
|
|
|
|
+#include "../common/random.h"
|
|
#include "int_guild.h"
|
|
#include "int_guild.h"
|
|
#include "int_homun.h"
|
|
#include "int_homun.h"
|
|
#include "int_mercenary.h"
|
|
#include "int_mercenary.h"
|
|
@@ -29,6 +30,7 @@
|
|
#include <stdarg.h>
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
|
+#include <malloc.h>
|
|
|
|
|
|
#define CHAR_MAX_MSG 300
|
|
#define CHAR_MAX_MSG 300
|
|
static char* msg_table[CHAR_MAX_MSG]; // Login Server messages_conf
|
|
static char* msg_table[CHAR_MAX_MSG]; // Login Server messages_conf
|
|
@@ -132,8 +134,8 @@ struct char_session_data {
|
|
char new_name[NAME_LENGTH];
|
|
char new_name[NAME_LENGTH];
|
|
char birthdate[10+1]; // YYYY-MM-DD
|
|
char birthdate[10+1]; // YYYY-MM-DD
|
|
// Pincode system
|
|
// Pincode system
|
|
- char pincode[4+1];
|
|
|
|
- uint16 pincode_seed;
|
|
|
|
|
|
+ char pincode[PINCODE_LENGTH+1];
|
|
|
|
+ uint32 pincode_seed;
|
|
time_t pincode_change;
|
|
time_t pincode_change;
|
|
uint16 pincode_try;
|
|
uint16 pincode_try;
|
|
// Addon system
|
|
// Addon system
|
|
@@ -168,7 +170,7 @@ void pincode_setnew( int fd, struct char_session_data* sd );
|
|
void pincode_sendstate( int fd, struct char_session_data* sd, uint16 state );
|
|
void pincode_sendstate( int fd, struct char_session_data* sd, uint16 state );
|
|
void pincode_notifyLoginPinUpdate( int account_id, char* pin );
|
|
void pincode_notifyLoginPinUpdate( int account_id, char* pin );
|
|
void pincode_notifyLoginPinError( int account_id );
|
|
void pincode_notifyLoginPinError( int account_id );
|
|
-void pincode_decrypt( unsigned long userSeed, char* pin );
|
|
|
|
|
|
+void pincode_decrypt( uint32 userSeed, char* pin );
|
|
int pincode_compare( int fd, struct char_session_data* sd, char* pin );
|
|
int pincode_compare( int fd, struct char_session_data* sd, char* pin );
|
|
|
|
|
|
// Addon system
|
|
// Addon system
|
|
@@ -4275,10 +4277,8 @@ int parse_char(int fd)
|
|
if( RFIFOREST(fd) < 10 )
|
|
if( RFIFOREST(fd) < 10 )
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
- if( RFIFOL(fd,2) != sd->account_id )
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- pincode_check( fd, sd );
|
|
|
|
|
|
+ if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
|
|
|
|
+ pincode_check( fd, sd );
|
|
|
|
|
|
RFIFOSKIP(fd,10);
|
|
RFIFOSKIP(fd,10);
|
|
break;
|
|
break;
|
|
@@ -4288,13 +4288,12 @@ int parse_char(int fd)
|
|
if( RFIFOREST(fd) < 6 )
|
|
if( RFIFOREST(fd) < 6 )
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
- if( RFIFOL(fd,2) != sd->account_id )
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- if( strlen( sd->pincode ) <= 0 ){
|
|
|
|
- pincode_sendstate( fd, sd, PINCODE_NEW );
|
|
|
|
- }else{
|
|
|
|
- pincode_sendstate( fd, sd, PINCODE_ASK );
|
|
|
|
|
|
+ if( pincode_enabled && RFIFOL(fd,2) == sd->account_id ){
|
|
|
|
+ if( strlen( sd->pincode ) <= 0 ){
|
|
|
|
+ pincode_sendstate( fd, sd, PINCODE_NEW );
|
|
|
|
+ }else{
|
|
|
|
+ pincode_sendstate( fd, sd, PINCODE_ASK );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
RFIFOSKIP(fd,6);
|
|
RFIFOSKIP(fd,6);
|
|
@@ -4305,10 +4304,8 @@ int parse_char(int fd)
|
|
if( RFIFOREST(fd) < 14 )
|
|
if( RFIFOREST(fd) < 14 )
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
- if( RFIFOL(fd,2) != sd->account_id )
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- pincode_change( fd, sd );
|
|
|
|
|
|
+ if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
|
|
|
|
+ pincode_change( fd, sd );
|
|
|
|
|
|
RFIFOSKIP(fd,14);
|
|
RFIFOSKIP(fd,14);
|
|
break;
|
|
break;
|
|
@@ -4318,10 +4315,8 @@ int parse_char(int fd)
|
|
if( RFIFOREST(fd) < 10 )
|
|
if( RFIFOREST(fd) < 10 )
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
- if( RFIFOL(fd,2) != sd->account_id )
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- pincode_setnew( fd, sd );
|
|
|
|
|
|
+ if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
|
|
|
|
+ pincode_setnew( fd, sd );
|
|
|
|
|
|
RFIFOSKIP(fd,10);
|
|
RFIFOSKIP(fd,10);
|
|
break;
|
|
break;
|
|
@@ -4520,8 +4515,11 @@ int check_connect_login_server(int tid, unsigned int tick, int id, intptr_t data
|
|
//Pincode system
|
|
//Pincode system
|
|
//------------------------------------------------
|
|
//------------------------------------------------
|
|
void pincode_check( 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((char*)pin, (char*)RFIFOP(fd, 6), 4+1);
|
|
|
|
|
|
+ char pin[PINCODE_LENGTH+1];
|
|
|
|
+
|
|
|
|
+ memset(pin,0,PINCODE_LENGTH+1);
|
|
|
|
+
|
|
|
|
+ strncpy((char*)pin, (char*)RFIFOP(fd, 6), PINCODE_LENGTH);
|
|
|
|
|
|
pincode_decrypt(sd->pincode_seed, pin );
|
|
pincode_decrypt(sd->pincode_seed, pin );
|
|
|
|
|
|
@@ -4546,27 +4544,33 @@ int pincode_compare( int fd, struct char_session_data* sd, char* pin ){
|
|
}
|
|
}
|
|
|
|
|
|
void pincode_change( int fd, struct char_session_data* sd ){
|
|
void pincode_change( int fd, struct char_session_data* sd ){
|
|
- char oldpin[5] = "\0\0\0\0";
|
|
|
|
- char newpin[5] = "\0\0\0\0";
|
|
|
|
|
|
+ char oldpin[PINCODE_LENGTH+1];
|
|
|
|
+ char newpin[PINCODE_LENGTH+1];
|
|
|
|
|
|
- strncpy(oldpin, (char*)RFIFOP(fd,6), 4+1);
|
|
|
|
|
|
+ memset(oldpin,0,PINCODE_LENGTH+1);
|
|
|
|
+ memset(newpin,0,PINCODE_LENGTH+1);
|
|
|
|
+
|
|
|
|
+ strncpy(oldpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH);
|
|
pincode_decrypt(sd->pincode_seed,oldpin);
|
|
pincode_decrypt(sd->pincode_seed,oldpin);
|
|
|
|
|
|
if( !pincode_compare( fd, sd, oldpin ) )
|
|
if( !pincode_compare( fd, sd, oldpin ) )
|
|
return;
|
|
return;
|
|
|
|
|
|
- strncpy(newpin, (char*)RFIFOP(fd,10), 4+1);
|
|
|
|
|
|
+ strncpy(newpin, (char*)RFIFOP(fd,10), PINCODE_LENGTH);
|
|
pincode_decrypt(sd->pincode_seed,newpin);
|
|
pincode_decrypt(sd->pincode_seed,newpin);
|
|
|
|
|
|
pincode_notifyLoginPinUpdate( sd->account_id, newpin );
|
|
pincode_notifyLoginPinUpdate( sd->account_id, newpin );
|
|
|
|
+ strncpy(sd->pincode, newpin, sizeof(newpin));
|
|
|
|
|
|
pincode_sendstate( fd, sd, PINCODE_PASSED );
|
|
pincode_sendstate( fd, sd, PINCODE_PASSED );
|
|
}
|
|
}
|
|
|
|
|
|
void pincode_setnew( int fd, struct char_session_data* sd ){
|
|
void pincode_setnew( int fd, struct char_session_data* sd ){
|
|
- char newpin[5] = "\0\0\0\0";
|
|
|
|
|
|
+ char newpin[PINCODE_LENGTH+1];
|
|
|
|
+
|
|
|
|
+ memset(newpin,0,PINCODE_LENGTH+1);
|
|
|
|
|
|
- strncpy( newpin, (char*)RFIFOP(fd,6), 4+1 );
|
|
|
|
|
|
+ strncpy( newpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH );
|
|
pincode_decrypt( sd->pincode_seed, newpin );
|
|
pincode_decrypt( sd->pincode_seed, newpin );
|
|
|
|
|
|
pincode_notifyLoginPinUpdate( sd->account_id, newpin );
|
|
pincode_notifyLoginPinUpdate( sd->account_id, newpin );
|
|
@@ -4587,7 +4591,7 @@ void pincode_setnew( int fd, struct char_session_data* sd ){
|
|
void pincode_sendstate( int fd, struct char_session_data* sd, uint16 state ){
|
|
void pincode_sendstate( int fd, struct char_session_data* sd, uint16 state ){
|
|
WFIFOHEAD(fd, 12);
|
|
WFIFOHEAD(fd, 12);
|
|
WFIFOW(fd, 0) = 0x8b9;
|
|
WFIFOW(fd, 0) = 0x8b9;
|
|
- WFIFOL(fd, 2) = sd->pincode_seed = rand() % 0xFFFF;
|
|
|
|
|
|
+ WFIFOL(fd, 2) = sd->pincode_seed = rnd() % 0xFFFF;
|
|
WFIFOL(fd, 6) = sd->account_id;
|
|
WFIFOL(fd, 6) = sd->account_id;
|
|
WFIFOW(fd,10) = state;
|
|
WFIFOW(fd,10) = state;
|
|
WFIFOSET(fd,12);
|
|
WFIFOSET(fd,12);
|
|
@@ -4597,7 +4601,7 @@ void pincode_notifyLoginPinUpdate( int account_id, char* pin ){
|
|
WFIFOHEAD(login_fd,11);
|
|
WFIFOHEAD(login_fd,11);
|
|
WFIFOW(login_fd,0) = 0x2738;
|
|
WFIFOW(login_fd,0) = 0x2738;
|
|
WFIFOL(login_fd,2) = account_id;
|
|
WFIFOL(login_fd,2) = account_id;
|
|
- strncpy( (char*)WFIFOP(login_fd,6), pin, 5 );
|
|
|
|
|
|
+ strncpy( (char*)WFIFOP(login_fd,6), pin, PINCODE_LENGTH+1 );
|
|
WFIFOSET(login_fd,11);
|
|
WFIFOSET(login_fd,11);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4608,10 +4612,11 @@ void pincode_notifyLoginPinError( int account_id ){
|
|
WFIFOSET(login_fd,6);
|
|
WFIFOSET(login_fd,6);
|
|
}
|
|
}
|
|
|
|
|
|
-void pincode_decrypt( unsigned long userSeed, char* pin ){
|
|
|
|
|
|
+void pincode_decrypt( uint32 userSeed, char* pin ){
|
|
int i, pos;
|
|
int i, pos;
|
|
char tab[10] = {0,1,2,3,4,5,6,7,8,9};
|
|
char tab[10] = {0,1,2,3,4,5,6,7,8,9};
|
|
- unsigned long multiplier = 0x3498, baseSeed = 0x881234;
|
|
|
|
|
|
+ char *buf;
|
|
|
|
+ uint32 multiplier = 0x3498, baseSeed = 0x881234;
|
|
|
|
|
|
for( i = 1; i < 10; i++ ){
|
|
for( i = 1; i < 10; i++ ){
|
|
userSeed = baseSeed + userSeed * multiplier;
|
|
userSeed = baseSeed + userSeed * multiplier;
|
|
@@ -4623,11 +4628,13 @@ void pincode_decrypt( unsigned long userSeed, char* pin ){
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- for( i = 0; i < 4; i++ ){
|
|
|
|
- pin[i] = tab[pin[i]- '0'];
|
|
|
|
|
|
+ buf = (char *)malloc(sizeof(pin));
|
|
|
|
+ memset(buf,0,PINCODE_LENGTH+1);
|
|
|
|
+ for( i = 0; i < PINCODE_LENGTH; i++ ){
|
|
|
|
+ sprintf(buf+i,"%d",tab[pin[i] - '0']);
|
|
}
|
|
}
|
|
-
|
|
|
|
- sprintf(pin, "%d%d%d%d", pin[0], pin[1], pin[2], pin[3]);
|
|
|
|
|
|
+ strcpy(pin,buf);
|
|
|
|
+ free(buf);
|
|
}
|
|
}
|
|
|
|
|
|
//------------------------------------------------
|
|
//------------------------------------------------
|
|
@@ -5018,6 +5025,12 @@ int char_config_read(const char* cfgName)
|
|
guild_exp_rate = atoi(w2);
|
|
guild_exp_rate = atoi(w2);
|
|
} else if (strcmpi(w1, "pincode_enabled") == 0) {
|
|
} else if (strcmpi(w1, "pincode_enabled") == 0) {
|
|
pincode_enabled = config_switch(w2);
|
|
pincode_enabled = config_switch(w2);
|
|
|
|
+ #if PACKETVER < 20110309
|
|
|
|
+ if( pincode_enabled ) {
|
|
|
|
+ ShowWarning("pincode_enabled requires PACKETVER 20110309 or higher. Disabling...\n");
|
|
|
|
+ pincode_enabled = false;
|
|
|
|
+ }
|
|
|
|
+ #endif
|
|
} else if (strcmpi(w1, "pincode_changetime") == 0) {
|
|
} else if (strcmpi(w1, "pincode_changetime") == 0) {
|
|
pincode_changetime = atoi(w2)*60*60*24;
|
|
pincode_changetime = atoi(w2)*60*60*24;
|
|
} else if (strcmpi(w1, "pincode_maxtry") == 0) {
|
|
} else if (strcmpi(w1, "pincode_maxtry") == 0) {
|