diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-04-15 12:56:09 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-04-15 12:56:46 +0300 |
commit | 555eb0850d0e46aa25de88c15d2f00fbe62385f5 (patch) | |
tree | 305a9ab595692591f4f1be8e633ba2861975c8cc | |
parent | 293793b7027029efc87c8b657a0c45d26e0840c5 (diff) | |
download | evol-hercules-555eb0850d0e46aa25de88c15d2f00fbe62385f5.tar.gz evol-hercules-555eb0850d0e46aa25de88c15d2f00fbe62385f5.tar.bz2 evol-hercules-555eb0850d0e46aa25de88c15d2f00fbe62385f5.tar.xz evol-hercules-555eb0850d0e46aa25de88c15d2f00fbe62385f5.zip |
Add support for change password packet.
Change server version to 6.
-rw-r--r-- | src/char/char.c | 32 | ||||
-rw-r--r-- | src/char/char.h | 4 | ||||
-rw-r--r-- | src/char/init.c | 3 | ||||
-rw-r--r-- | src/login/init.c | 1 | ||||
-rw-r--r-- | src/login/parse.c | 35 | ||||
-rw-r--r-- | src/login/parse.h | 1 | ||||
-rw-r--r-- | src/login/send.c | 11 | ||||
-rw-r--r-- | src/login/send.h | 1 |
8 files changed, 87 insertions, 1 deletions
diff --git a/src/char/char.c b/src/char/char.c index f971617..dccc7ac 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -157,3 +157,35 @@ void echar_parse_char_ping(int *fdPtr) } hookStop(); } + +void echar_parse_change_paassword(int fd) +{ + if (chr->login_fd < 0) + return; + struct char_session_data* sd = (struct char_session_data*)session[fd]->session_data; + if (!sd) + return; + WFIFOHEAD(chr->login_fd, 54); + WFIFOW(chr->login_fd, 0) = 0x5000; + WFIFOL(chr->login_fd, 2) = sd->account_id; + memcpy (WFIFOP (chr->login_fd, 6), RFIFOP (fd, 2), 24); + memcpy (WFIFOP (chr->login_fd, 30), RFIFOP (fd, 26), 24); + WFIFOSET(chr->login_fd, 54); +} + +void echar_parse_login_password_change_ack(int charFd) +{ + struct char_session_data* sd = NULL; + const int accountId = RFIFOL(charFd, 2); + const int status = RFIFOB(charFd, 6); + + int fd = -1; + ARR_FIND( 0, sockt->fd_max, fd, session[fd] && (sd = (struct char_session_data*)session[fd]->session_data) && sd->auth && sd->account_id == accountId ); + if (fd < sockt->fd_max && fd >= 0) + { + WFIFOHEAD(fd, 3); + WFIFOW(fd, 0) = 0x62; + WFIFOB(fd, 2) = status; + WFIFOSET(fd, 3); + } +} diff --git a/src/char/char.h b/src/char/char.h index eb90bce..b013f44 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -12,4 +12,8 @@ void echar_creation_failed(int *fdPtr, int *result); void echar_parse_char_ping(int *fdPtr); +void echar_parse_change_paassword(int fd); + +void echar_parse_login_password_change_ack(int charFd); + #endif // EVOL_CHAR_CHAR diff --git a/src/char/init.c b/src/char/init.c index 262a463..6c8e34d 100644 --- a/src/char/init.c +++ b/src/char/init.c @@ -60,6 +60,9 @@ HPExport void plugin_init (void) loginif = GET_SYMBOL("loginif"); mapif = GET_SYMBOL("mapif"); + addPacket(0x0061, 50, echar_parse_change_paassword, hpParse_Char); + addPacket(0x5001, 7, echar_parse_login_password_change_ack, hpParse_FromLogin); + addHookPre("chr->parse_char_login_map_server", echar_parse_char_login_map_server); addHookPre("chr->parse_char_create_new_char", echar_parse_char_create_new_char); //addHookPre("chr->parse_char_ping", echar_parse_char_ping); diff --git a/src/login/init.c b/src/login/init.c index 18ac7e0..06e747b 100644 --- a/src/login/init.c +++ b/src/login/init.c @@ -35,6 +35,7 @@ HPExport void plugin_init (void) addPacket(0x7530, 22, login_parse_version, hpParse_Login); addPacket(0x027c, 95, elogin_parse_client_login2, hpParse_Login); + addPacket(0x5000, 54, elogin_parse_change_paassword, hpParse_FromChar); addHookPre("login->parse_client_login", elogin_parse_client_login_pre); addHookPre("login->parse_request_connection", elogin_parse_request_connection); addHookPre("login->check_password", elogin_check_password); diff --git a/src/login/parse.c b/src/login/parse.c index f2e2592..53fa28f 100644 --- a/src/login/parse.c +++ b/src/login/parse.c @@ -16,6 +16,7 @@ #include "common/ip.h" #include "login/config.h" +#include "login/md5calc.h" #include "login/parse.h" #include "login/send.h" @@ -173,3 +174,37 @@ void elogin_parse_ping(int *fd, struct login_session_data* sd) } hookStop(); } + +void elogin_parse_change_paassword(int fd) +{ + char actual_pass[24], new_pass[24]; + int status = 0; + struct mmo_account acc; + const int accountId = RFIFOL (fd, 2); + + memcpy (actual_pass, RFIFOP (fd, 6), 24); + actual_pass[23] = '\0'; + memcpy (new_pass, RFIFOP (fd, 30), 24); + new_pass[23] = '\0'; + + if (!login->accounts->load_num(login->accounts, &acc, accountId)) + { + // account not found + send_char_password_change_ack(fd, accountId, 0); + return; + } + + if (!strcmp(actual_pass, acc.pass) || pass_ok(actual_pass, acc.pass)) + { + // changed ok + status = 1; + safestrncpy(acc.pass, new_pass, sizeof(acc.pass)); + login->accounts->save(login->accounts, &acc); + } + else + { + // wrong password + status = 2; + } + send_char_password_change_ack(fd, accountId, status); +} diff --git a/src/login/parse.h b/src/login/parse.h index 31d0d0c..b5c2418 100644 --- a/src/login/parse.h +++ b/src/login/parse.h @@ -9,5 +9,6 @@ int elogin_parse_client_login_pre(int *fd, struct login_session_data* sd, const void elogin_parse_client_login2(int fd); void elogin_parse_request_connection(int *fd, struct login_session_data* sd, const char *const ip); void elogin_parse_ping(int *fd, struct login_session_data* sd); +void elogin_parse_change_paassword(int fd); #endif // EVOL_LOGIN_PARSE diff --git a/src/login/send.c b/src/login/send.c index abb85da..420028c 100644 --- a/src/login/send.c +++ b/src/login/send.c @@ -21,7 +21,7 @@ void send_server_version(int fd) WFIFOW(fd, 0) = 0x7531; WFIFOW(fd, 2) = 4 + 8; WFIFOL(fd, 4) = 0; // unused - WFIFOL(fd, 8) = 5; // server version + WFIFOL(fd, 8) = 6; // server version WFIFOSET(fd, WFIFOW(fd,2)); } @@ -36,3 +36,12 @@ void send_update_host(int fd) memcpy(WFIFOP (fd, 4), update_server, sz); WFIFOSET(fd, sz + 4); } + +void send_char_password_change_ack(int fd, int accoundId, char status) +{ + WFIFOHEAD(fd, 7); + WFIFOW(fd, 0) = 0x5001; + WFIFOL(fd, 2) = accoundId; + WFIFOB(fd, 6) = status; + WFIFOSET(fd, 7); +} diff --git a/src/login/send.h b/src/login/send.h index 1c7ec27..5fdb6c4 100644 --- a/src/login/send.h +++ b/src/login/send.h @@ -6,5 +6,6 @@ void send_server_version(); void send_update_host(int fd); +void send_char_password_change_ack(int fd, int accoundId, char status); #endif // EVOL_LOGIN_SEND |