From cb3652004f979f2efd3ea3ad397e306165ada79b Mon Sep 17 00:00:00 2001 From: Haru Date: Mon, 2 Feb 2015 23:43:38 +0100 Subject: Fixed @changesex issues on PACKETVERs that don't support per-character sex. - Fixes bugreport:8504 http://hercules.ws/board/tracker/issue-8504-changesex/ - Existing database entries with an incorrect per-character sex will be fixed automatically when the character logs in to match the account's sex, if the PACKETVER doesn't support per-character sex. Signed-off-by: Haru --- src/map/atcommand.c | 2 +- src/map/chrif.c | 37 +++++++++++++++++++++++++++++-------- src/map/chrif.h | 2 +- src/map/script.c | 9 ++------- 4 files changed, 33 insertions(+), 17 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 560848c5b..b9b4704bc 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -6431,7 +6431,7 @@ ACMD(changesex) // to avoid any problem with equipment and invalid sex, equipment is unequipped. for( i=0; iequip_index[i] >= 0 ) pc->unequipitem(sd, sd->equip_index[i], 3); - chrif->changesex(sd); + chrif->changesex(sd, true); return true; } diff --git a/src/map/chrif.c b/src/map/chrif.c index da946f050..6ac7d5695 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -62,7 +62,7 @@ struct chrif_interface chrif_s; //2b0a: Incoming/Outgoing, socket_datasync() //2b0b: Outgoing, update charserv skillid2idx //2b0c: Outgoing, chrif_changeemail -> 'change mail address ...' -//2b0d: Incoming, chrif_changedsex -> 'Change sex of acc XY' +//2b0d: Incoming, chrif_changedsex -> 'Change sex of acc XY' (or char) //2b0e: Outgoing, chrif_char_ask_name -> 'Do some operations (change sex, ban / unban etc)' //2b0f: Incoming, chrif_char_ask_name_answer -> 'answer of the 2b0e' //2b10: Outgoing, chrif_updatefamelist -> 'Update the fame ranking lists and send them' @@ -744,10 +744,18 @@ bool chrif_changeemail(int id, const char *actual_email, const char *new_email) } /*========================================== - * S 2b0e .l .24B .w { .w .w .w .w .w .w } + * S 2b0e .l .24B .w { .12B } + * { .w .w .w .w .w .w } * Send an account modification request to the login server (via char server). - * type of operation: - * 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex (use next function for 5), 6: charban + * type of operation {additional fields}: + * 1: block { n/a } + * 2: ban { .w .w .w .w .w .w } + * 3: unblock { n/a } + * 4: unban { n/a } + * 5: changesex { n/a } -- use chrif_changesex + * 6: charban { .w .w .w .w .w .w } + * 7: charunban { n/a } + * 8: changecharsex { .b } -- use chrif_changesex *------------------------------------------*/ bool chrif_char_ask_name(int acc, const char* character_name, unsigned short operation_type, int year, int month, int day, int hour, int minute, int second) { @@ -772,14 +780,24 @@ bool chrif_char_ask_name(int acc, const char* character_name, unsigned short ope return true; } -bool chrif_changesex(struct map_session_data *sd) { +/** + * Requests a sex change (either per character or per account). + * + * @param sd The character's data. + * @param change_account Whether to change the per-account sex. + * @retval true. + */ +bool chrif_changesex(struct map_session_data *sd, bool change_account) +{ chrif_check(false); WFIFOHEAD(chrif->fd,44); WFIFOW(chrif->fd,0) = 0x2b0e; WFIFOL(chrif->fd,2) = sd->status.account_id; safestrncpy((char*)WFIFOP(chrif->fd,6), sd->status.name, NAME_LENGTH); - WFIFOW(chrif->fd,30) = 5; + WFIFOW(chrif->fd,30) = change_account ? 5 : 8; + if (!change_account) + WFIFOB(chrif->fd,32) = sd->status.sex == SEX_MALE ? SEX_FEMALE : SEX_MALE; WFIFOSET(chrif->fd,44); clif->message(sd->fd, msg_sd(sd,408)); //"Disconnecting to perform change-sex request..." @@ -795,7 +813,7 @@ bool chrif_changesex(struct map_session_data *sd) { * R 2b0f .l .24B .w .w * Processing a reply to chrif->char_ask_name() (request to modify an account). * type of operation: - * 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex, 6: charban, 7: charunban + * 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex, 6: charban, 7: charunban, 8: changecharsex * type of answer: * 0: login-server request done * 1: player not found @@ -847,8 +865,11 @@ void chrif_changedsex(int fd) { ShowNotice("chrif_changedsex %d.\n", acc); // Path to activate this response: - // Map(start) (0x2b0e) -> Char(0x2727) -> Login + // Map(start) (0x2b0e type 5) -> Char(0x2727) -> Login // Login(0x2723) [ALL] -> Char (0x2b0d)[ALL] -> Map (HERE) + // OR + // Map(start) (0x2b03 type 8) -> Char + // Char(0x2b0d)[ALL] -> Map (HERE) // Char will usually be "logged in" despite being forced to log-out in the beginning // of this process, but there's no need to perform map-server specific response // as everything should been changed through char-server [Panikon] diff --git a/src/map/chrif.h b/src/map/chrif.h index 271fc076d..c90d00ef5 100644 --- a/src/map/chrif.h +++ b/src/map/chrif.h @@ -103,7 +103,7 @@ struct chrif_interface { bool (*char_reset_offline) (void); bool (*send_users_tochar) (void); bool (*char_online) (struct map_session_data *sd); - bool (*changesex) (struct map_session_data *sd); + bool (*changesex) (struct map_session_data *sd, bool change_account); //int (*chardisconnect) (struct map_session_data *sd); // FIXME: Commented out in clif.c, function does not exist bool (*divorce) (int partner_id1, int partner_id2); diff --git a/src/map/script.c b/src/map/script.c index ed9345678..b7fdf1596 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11244,7 +11244,7 @@ BUILDIN(changesex) TBL_PC *sd = prepareChangeSex(st); if (sd == NULL) return false; - chrif->changesex(sd); + chrif->changesex(sd, true); return true; } @@ -11256,12 +11256,7 @@ BUILDIN(changecharsex) TBL_PC *sd = prepareChangeSex(st); if (sd == NULL) return false; - if (sd->status.sex == 99) - sd->status.sex = 0; - sd->status.sex = sd->status.sex ? 0 : 1; - chrif->save(sd, 0); - if (sd->fd) - clif->authfail_fd(sd->fd, 15); + chrif->changesex(sd, false); return true; } -- cgit v1.2.3-70-g09d2