diff options
Diffstat (limited to 'src/echar')
-rw-r--r-- | src/echar/char.c | 50 | ||||
-rw-r--r-- | src/echar/char.h | 2 | ||||
-rw-r--r-- | src/echar/init.c | 1 |
3 files changed, 50 insertions, 3 deletions
diff --git a/src/echar/char.c b/src/echar/char.c index cac3daf..cbaa884 100644 --- a/src/echar/char.c +++ b/src/echar/char.c @@ -21,6 +21,8 @@ #include "plugins/HPMHooking.h" +#include "ecommon/enum/gender.h" + #include "echar/char.h" #include "echar/config.h" @@ -355,10 +357,52 @@ int echar_mmo_gender(const struct char_session_data **sd __attribute__ ((unused) switch (*sex) { case 'M': - return SEX_MALE; + return GENDER_MALE; case 'F': - return SEX_FEMALE; + return GENDER_FEMALE; default: - return 3; // FIXME: this enum has no SEX_OTHER + return GENDER_NONBINARY; + } +} + +// update sql from map to char with the new gender +// XXX: this whole hook is only to change one line; we might want to change it +// upstream in hercules +int echar_changecharsex(int *char_idPtr, int *sexPtr) +{ + int char_id = *char_idPtr; + int sex = *sexPtr; + + int account_id = 0; + char *data; + + // get character data + if (SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `account_id` FROM `char` WHERE `char_id` = '%d'", char_id)) { + Sql_ShowDebug(inter->sql_handle); + hookStop(); + return 1; + } + + if (SQL->NumRows(inter->sql_handle) != 1 || SQL_ERROR == SQL->NextRow(inter->sql_handle)) { + SQL->FreeResult(inter->sql_handle); + hookStop(); + return 1; } + + SQL->GetData(inter->sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->FreeResult(inter->sql_handle); + + if (SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `char` SET `sex` = '%c' WHERE `char_id` = '%d'", sex == SEX_MALE ? 'M' : (sex == SEX_FEMALE ? 'F' : 'U'), char_id)) { + Sql_ShowDebug(inter->sql_handle); + hookStop(); + return 1; + } + + // disconnect player if online on char-server + chr->disconnect_player(account_id); + + // notify all mapservers about this change + chr->changesex(account_id, sex); + hookStop(); + return 0; } diff --git a/src/echar/char.h b/src/echar/char.h index 9a59a44..534b075 100644 --- a/src/echar/char.h +++ b/src/echar/char.h @@ -31,4 +31,6 @@ void echat_send_login_serverexit(const int code); int echar_mmo_gender(const struct char_session_data **, const struct mmo_charstatus **, char *sex); +int echar_changecharsex(int *char_idPtr, int *sexPtr); + #endif // EVOL_CHAR_CHAR diff --git a/src/echar/init.c b/src/echar/init.c index 1c0ba48..f58802c 100644 --- a/src/echar/init.c +++ b/src/echar/init.c @@ -68,6 +68,7 @@ HPExport void plugin_init (void) // non-binary gender stuff: addHookPre(chr, mmo_gender, echar_mmo_gender); + addHookPre(chr, changecharsex, echar_changecharsex); addHookPost(chr, send_HC_ACK_CHARINFO_PER_PAGE, echar_send_HC_ACK_CHARINFO_PER_PAGE_post); addHookPost(chr, mmo_char_send_characters, echar_mmo_char_send_characters_post); |