diff options
Diffstat (limited to 'src/char/int_homun.c')
-rw-r--r-- | src/char/int_homun.c | 146 |
1 files changed, 28 insertions, 118 deletions
diff --git a/src/char/int_homun.c b/src/char/int_homun.c index 90643699c..52418a1fa 100644 --- a/src/char/int_homun.c +++ b/src/char/int_homun.c @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team - * Copyright (C) Athena Dev Teams + * Copyright (C) 2012-2020 Hercules Dev Team + * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,78 +37,18 @@ #include <stdio.h> #include <stdlib.h> -struct inter_homunculus_interface inter_homunculus_s; +static struct inter_homunculus_interface inter_homunculus_s; struct inter_homunculus_interface *inter_homunculus; -int inter_homunculus_sql_init(void) +static int inter_homunculus_sql_init(void) { return 0; } -void inter_homunculus_sql_final(void) +static void inter_homunculus_sql_final(void) { return; } -void mapif_homunculus_created(int fd, int account_id, const struct s_homunculus *sh, unsigned char flag) -{ - nullpo_retv(sh); - WFIFOHEAD(fd, sizeof(struct s_homunculus)+9); - WFIFOW(fd,0) = 0x3890; - WFIFOW(fd,2) = sizeof(struct s_homunculus)+9; - WFIFOL(fd,4) = account_id; - WFIFOB(fd,8)= flag; - memcpy(WFIFOP(fd,9),sh,sizeof(struct s_homunculus)); - WFIFOSET(fd, WFIFOW(fd,2)); -} - -void mapif_homunculus_deleted(int fd, int flag) -{ - WFIFOHEAD(fd, 3); - WFIFOW(fd, 0) = 0x3893; - WFIFOB(fd,2) = flag; //Flag 1 = success - WFIFOSET(fd, 3); -} - -void mapif_homunculus_loaded(int fd, int account_id, struct s_homunculus *hd) -{ - WFIFOHEAD(fd, sizeof(struct s_homunculus)+9); - WFIFOW(fd,0) = 0x3891; - WFIFOW(fd,2) = sizeof(struct s_homunculus)+9; - WFIFOL(fd,4) = account_id; - if( hd != NULL ) - { - WFIFOB(fd,8) = 1; // success - memcpy(WFIFOP(fd,9), hd, sizeof(struct s_homunculus)); - } - else - { - WFIFOB(fd,8) = 0; // not found. - memset(WFIFOP(fd,9), 0, sizeof(struct s_homunculus)); - } - WFIFOSET(fd, sizeof(struct s_homunculus)+9); -} - -void mapif_homunculus_saved(int fd, int account_id, bool flag) -{ - WFIFOHEAD(fd, 7); - WFIFOW(fd,0) = 0x3892; - WFIFOL(fd,2) = account_id; - WFIFOB(fd,6) = flag; // 1:success, 0:failure - WFIFOSET(fd, 7); -} - -void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char flag, const char *name) -{ - nullpo_retv(name); - WFIFOHEAD(fd, NAME_LENGTH+12); - WFIFOW(fd, 0) = 0x3894; - WFIFOL(fd, 2) = account_id; - WFIFOL(fd, 6) = char_id; - WFIFOB(fd,10) = flag; - safestrncpy(WFIFOP(fd,11), name, NAME_LENGTH); - WFIFOSET(fd, NAME_LENGTH+12); -} - /** * Creates a new homunculus with the given data. * @@ -119,7 +59,7 @@ void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char * @param[in,out] hd The new homunculus' data. * @retval false in case of errors. */ -bool mapif_homunculus_create(struct s_homunculus *hd) +static bool inter_homunculus_create(struct s_homunculus *hd) { char esc_name[NAME_LENGTH*2+1]; @@ -129,10 +69,10 @@ bool mapif_homunculus_create(struct s_homunculus *hd) SQL->EscapeStringLen(inter->sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH)); if (SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` " - "(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`) " - "VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", + "(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`, `autofeed`) " + "VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, - hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize)) { + hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->autofeed)) { Sql_ShowDebug(inter->sql_handle); return false; } @@ -146,7 +86,7 @@ bool mapif_homunculus_create(struct s_homunculus *hd) * @param hd The homunculus' data. * @retval false in case of errors. */ -bool mapif_homunculus_save(const struct s_homunculus *hd) +static bool inter_homunculus_save(const struct s_homunculus *hd) { bool flag = true; char esc_name[NAME_LENGTH*2+1]; @@ -156,9 +96,9 @@ bool mapif_homunculus_save(const struct s_homunculus *hd) SQL->EscapeStringLen(inter->sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH)); - if (SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'", + if (SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d', `autofeed`='%d' WHERE `homun_id`='%d'", homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, - hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id)) { + hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->autofeed, hd->hom_id)) { Sql_ShowDebug(inter->sql_handle); flag = false; } else { @@ -171,9 +111,9 @@ bool mapif_homunculus_save(const struct s_homunculus *hd) } else { for (i = 0; i < MAX_HOMUNSKILL; ++i) { if (hd->hskill[i].id > 0 && hd->hskill[i].lv != 0) { - SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, &hd->hskill[i].id, 0); - SQL->StmtBindParam(stmt, 1, SQLDT_USHORT, &hd->hskill[i].lv, 0); - if (SQL_ERROR == SQL->StmtExecute(stmt)) { + if (SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_USHORT, &hd->hskill[i].id, sizeof hd->hskill[i].id) + || SQL_ERROR == SQL->StmtBindParam(stmt, 1, SQLDT_UCHAR, &hd->hskill[i].lv, sizeof hd->hskill[i].lv) + || SQL_ERROR == SQL->StmtExecute(stmt)) { SqlStmt_ShowDebug(stmt); flag = false; break; @@ -188,7 +128,7 @@ bool mapif_homunculus_save(const struct s_homunculus *hd) } // Load an homunculus -bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) +static bool inter_homunculus_load(int homun_id, struct s_homunculus *hd) { char* data; size_t len; @@ -196,7 +136,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) nullpo_ret(hd); memset(hd, 0, sizeof(*hd)); - if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%d'", homunculus_db, homun_id) ) + if (SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize`, `autofeed` FROM `%s` WHERE `homun_id`='%d'", homunculus_db, homun_id)) { Sql_ShowDebug(inter->sql_handle); return false; @@ -236,6 +176,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) SQL->GetData(inter->sql_handle, 19, &data, NULL); hd->skillpts = atoi(data); SQL->GetData(inter->sql_handle, 20, &data, NULL); hd->rename_flag = atoi(data); SQL->GetData(inter->sql_handle, 21, &data, NULL); hd->vaporize = atoi(data); + SQL->GetData(inter->sql_handle, 22, &data, NULL); hd->autofeed = atoi(data); SQL->FreeResult(inter->sql_handle); hd->intimacy = cap_value(hd->intimacy, 0, 100000); @@ -262,13 +203,13 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd) } SQL->FreeResult(inter->sql_handle); - if( save_log ) + if (chr->show_save_log) ShowInfo("Homunculus loaded (%d - %s).\n", hd->hom_id, hd->name); return true; } -bool mapif_homunculus_delete(int homun_id) +static bool inter_homunculus_delete(int homun_id) { if (SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%d'", homunculus_db, homun_id) || SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%d'", skill_homunculus_db, homun_id) @@ -279,7 +220,7 @@ bool mapif_homunculus_delete(int homun_id) return true; } -bool mapif_homunculus_rename(const char *name) +static bool inter_homunculus_rename(const char *name) { int i; @@ -301,47 +242,10 @@ bool mapif_homunculus_rename(const char *name) return true; } - -void mapif_parse_homunculus_create(int fd, int len, int account_id, const struct s_homunculus *phd) -{ - struct s_homunculus shd; - bool result; - - memcpy(&shd, phd, sizeof(shd)); - - result = mapif->homunculus_create(&shd); - mapif->homunculus_created(fd, account_id, &shd, result); -} - -void mapif_parse_homunculus_delete(int fd, int homun_id) -{ - bool result = mapif->homunculus_delete(homun_id); - mapif->homunculus_deleted(fd, result); -} - -void mapif_parse_homunculus_load(int fd, int account_id, int homun_id) -{ - struct s_homunculus hd; - bool result = mapif->homunculus_load(homun_id, &hd); - mapif->homunculus_loaded(fd, account_id, ( result ? &hd : NULL )); -} - -void mapif_parse_homunculus_save(int fd, int len, int account_id, const struct s_homunculus *phd) -{ - bool result = mapif->homunculus_save(phd); - mapif->homunculus_saved(fd, account_id, result); -} - -void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, const char *name) -{ - bool result = mapif->homunculus_rename(name); - mapif->homunculus_renamed(fd, account_id, char_id, result, name); -} - /*========================================== * Inter Packets *------------------------------------------*/ -int inter_homunculus_parse_frommap(int fd) +static int inter_homunculus_parse_frommap(int fd) { unsigned short cmd = RFIFOW(fd,0); @@ -364,4 +268,10 @@ void inter_homunculus_defaults(void) inter_homunculus->sql_init = inter_homunculus_sql_init; inter_homunculus->sql_final = inter_homunculus_sql_final; inter_homunculus->parse_frommap = inter_homunculus_parse_frommap; + + inter_homunculus->create = inter_homunculus_create; + inter_homunculus->save = inter_homunculus_save; + inter_homunculus->load = inter_homunculus_load; + inter_homunculus->delete = inter_homunculus_delete; + inter_homunculus->rename = inter_homunculus_rename; } |