diff options
Diffstat (limited to 'src/char/int_mercenary.c')
-rw-r--r-- | src/char/int_mercenary.c | 130 |
1 files changed, 73 insertions, 57 deletions
diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c index 1dffb656c..0e91b6785 100644 --- a/src/char/int_mercenary.c +++ b/src/char/int_mercenary.c @@ -12,6 +12,7 @@ #include "char.h" #include "inter.h" +#include "mapif.h" #include "../common/malloc.h" #include "../common/mmo.h" #include "../common/showmsg.h" @@ -20,53 +21,55 @@ #include "../common/strlib.h" #include "../common/utils.h" -bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status) +struct inter_mercenary_interface inter_mercenary_s; + +bool inter_mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status) { char* data; - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) { - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(inter->sql_handle); return false; } - if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(inter->sql_handle) ) { - SQL->FreeResult(sql_handle); + SQL->FreeResult(inter->sql_handle); return false; } - SQL->GetData(sql_handle, 0, &data, NULL); status->mer_id = atoi(data); - SQL->GetData(sql_handle, 1, &data, NULL); status->arch_calls = atoi(data); - SQL->GetData(sql_handle, 2, &data, NULL); status->arch_faith = atoi(data); - SQL->GetData(sql_handle, 3, &data, NULL); status->spear_calls = atoi(data); - SQL->GetData(sql_handle, 4, &data, NULL); status->spear_faith = atoi(data); - SQL->GetData(sql_handle, 5, &data, NULL); status->sword_calls = atoi(data); - SQL->GetData(sql_handle, 6, &data, NULL); status->sword_faith = atoi(data); - SQL->FreeResult(sql_handle); + SQL->GetData(inter->sql_handle, 0, &data, NULL); status->mer_id = atoi(data); + SQL->GetData(inter->sql_handle, 1, &data, NULL); status->arch_calls = atoi(data); + SQL->GetData(inter->sql_handle, 2, &data, NULL); status->arch_faith = atoi(data); + SQL->GetData(inter->sql_handle, 3, &data, NULL); status->spear_calls = atoi(data); + SQL->GetData(inter->sql_handle, 4, &data, NULL); status->spear_faith = atoi(data); + SQL->GetData(inter->sql_handle, 5, &data, NULL); status->sword_calls = atoi(data); + SQL->GetData(inter->sql_handle, 6, &data, NULL); status->sword_faith = atoi(data); + SQL->FreeResult(inter->sql_handle); return true; } -bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status) +bool inter_mercenary_owner_tosql(int char_id, struct mmo_charstatus *status) { - if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", + if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", mercenary_owner_db, char_id, status->mer_id, status->arch_calls, status->arch_faith, status->spear_calls, status->spear_faith, status->sword_calls, status->sword_faith) ) { - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(inter->sql_handle); return false; } return true; } -bool mercenary_owner_delete(int char_id) +bool inter_mercenary_owner_delete(int char_id) { - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) ) + Sql_ShowDebug(inter->sql_handle); - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_db, char_id) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", mercenary_db, char_id) ) + Sql_ShowDebug(inter->sql_handle); return true; } @@ -77,21 +80,21 @@ bool mapif_mercenary_save(struct s_mercenary* merc) if( merc->mercenary_id == 0 ) { // Create new DB entry - if( SQL_ERROR == SQL->Query(sql_handle, + if( SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')", mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) ) { - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(inter->sql_handle); flag = false; } else - merc->mercenary_id = (int)SQL->LastInsertId(sql_handle); + merc->mercenary_id = (int)SQL->LastInsertId(inter->sql_handle); } - else if( SQL_ERROR == SQL->Query(sql_handle, + else if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'", mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) ) { // Update DB entry - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(inter->sql_handle); flag = false; } @@ -106,24 +109,24 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) merc->mercenary_id = merc_id; merc->char_id = char_id; - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", mercenary_db, merc_id, char_id) ) + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", mercenary_db, merc_id, char_id) ) { - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(inter->sql_handle); return false; } - if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(inter->sql_handle) ) { - SQL->FreeResult(sql_handle); + SQL->FreeResult(inter->sql_handle); return false; } - SQL->GetData(sql_handle, 0, &data, NULL); merc->class_ = atoi(data); - SQL->GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data); - SQL->GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data); - SQL->GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data); - SQL->GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data); - SQL->FreeResult(sql_handle); + SQL->GetData(inter->sql_handle, 0, &data, NULL); merc->class_ = atoi(data); + SQL->GetData(inter->sql_handle, 1, &data, NULL); merc->hp = atoi(data); + SQL->GetData(inter->sql_handle, 2, &data, NULL); merc->sp = atoi(data); + SQL->GetData(inter->sql_handle, 3, &data, NULL); merc->kill_count = atoi(data); + SQL->GetData(inter->sql_handle, 4, &data, NULL); merc->life_time = atoi(data); + SQL->FreeResult(inter->sql_handle); if( save_log ) ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id); @@ -132,16 +135,16 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) bool mapif_mercenary_delete(int merc_id) { - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `mer_id` = '%d'", mercenary_db, merc_id) ) + if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `mer_id` = '%d'", mercenary_db, merc_id) ) { - Sql_ShowDebug(sql_handle); + Sql_ShowDebug(inter->sql_handle); return false; } return true; } -static void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag) +void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag) { int size = sizeof(struct s_mercenary) + 5; @@ -153,20 +156,20 @@ static void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char WFIFOSET(fd,size); } -static void mapif_parse_mercenary_create(int fd, struct s_mercenary* merc) +void mapif_parse_mercenary_create(int fd, struct s_mercenary* merc) { - bool result = mapif_mercenary_save(merc); - mapif_mercenary_send(fd, merc, result); + bool result = mapif->mercenary_save(merc); + mapif->mercenary_send(fd, merc, result); } -static void mapif_parse_mercenary_load(int fd, int merc_id, int char_id) +void mapif_parse_mercenary_load(int fd, int merc_id, int char_id) { struct s_mercenary merc; - bool result = mapif_mercenary_load(merc_id, char_id, &merc); - mapif_mercenary_send(fd, &merc, result); + bool result = mapif->mercenary_load(merc_id, char_id, &merc); + mapif->mercenary_send(fd, &merc, result); } -static void mapif_mercenary_deleted(int fd, unsigned char flag) +void mapif_mercenary_deleted(int fd, unsigned char flag) { WFIFOHEAD(fd,3); WFIFOW(fd,0) = 0x3871; @@ -174,13 +177,13 @@ static void mapif_mercenary_deleted(int fd, unsigned char flag) WFIFOSET(fd,3); } -static void mapif_parse_mercenary_delete(int fd, int merc_id) +void mapif_parse_mercenary_delete(int fd, int merc_id) { - bool result = mapif_mercenary_delete(merc_id); - mapif_mercenary_deleted(fd, result); + bool result = mapif->mercenary_delete(merc_id); + mapif->mercenary_deleted(fd, result); } -static void mapif_mercenary_saved(int fd, unsigned char flag) +void mapif_mercenary_saved(int fd, unsigned char flag) { WFIFOHEAD(fd,3); WFIFOW(fd,0) = 0x3872; @@ -188,10 +191,10 @@ static void mapif_mercenary_saved(int fd, unsigned char flag) WFIFOSET(fd,3); } -static void mapif_parse_mercenary_save(int fd, struct s_mercenary* merc) +void mapif_parse_mercenary_save(int fd, struct s_mercenary* merc) { - bool result = mapif_mercenary_save(merc); - mapif_mercenary_saved(fd, result); + bool result = mapif->mercenary_save(merc); + mapif->mercenary_saved(fd, result); } int inter_mercenary_sql_init(void) @@ -212,12 +215,25 @@ int inter_mercenary_parse_frommap(int fd) switch( cmd ) { - case 0x3070: mapif_parse_mercenary_create(fd, (struct s_mercenary*)RFIFOP(fd,4)); break; - case 0x3071: mapif_parse_mercenary_load(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break; - case 0x3072: mapif_parse_mercenary_delete(fd, (int)RFIFOL(fd,2)); break; - case 0x3073: mapif_parse_mercenary_save(fd, (struct s_mercenary*)RFIFOP(fd,4)); break; + case 0x3070: mapif->parse_mercenary_create(fd, (struct s_mercenary*)RFIFOP(fd,4)); break; + case 0x3071: mapif->parse_mercenary_load(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break; + case 0x3072: mapif->parse_mercenary_delete(fd, (int)RFIFOL(fd,2)); break; + case 0x3073: mapif->parse_mercenary_save(fd, (struct s_mercenary*)RFIFOP(fd,4)); break; default: return 0; } return 1; } + +void inter_mercenary_defaults(void) +{ + inter_mercenary = &inter_mercenary_s; + + inter_mercenary->owner_fromsql = inter_mercenary_owner_fromsql; + inter_mercenary->owner_tosql = inter_mercenary_owner_tosql; + inter_mercenary->owner_delete = inter_mercenary_owner_delete; + + inter_mercenary->sql_init = inter_mercenary_sql_init; + inter_mercenary->sql_final = inter_mercenary_sql_final; + inter_mercenary->parse_frommap = inter_mercenary_parse_frommap; +} |