diff options
Diffstat (limited to 'src/char_sql/int_homun.c')
-rw-r--r-- | src/char_sql/int_homun.c | 146 |
1 files changed, 7 insertions, 139 deletions
diff --git a/src/char_sql/int_homun.c b/src/char_sql/int_homun.c index 77753f04a..5f620409e 100644 --- a/src/char_sql/int_homun.c +++ b/src/char_sql/int_homun.c @@ -293,132 +293,6 @@ static void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, c } /*========================================== - * Mercenary's System - *------------------------------------------*/ -bool mapif_mercenary_save(struct s_mercenary* merc) -{ - bool flag = true; - - if( merc->mercenary_id == 0 ) - { // Create new DB entry - if( SQL_ERROR == Sql_Query(sql_handle, - "INSERT INTO `mercenary` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')", - merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) ) - { - Sql_ShowDebug(sql_handle); - flag = false; - } - else - merc->mercenary_id = (int)Sql_LastInsertId(sql_handle); - } - else if( SQL_ERROR == Sql_Query(sql_handle, - "UPDATE `mercenary` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'", - 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); - flag = false; - } - - return flag; -} - -bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc) -{ - char* data; - - memset(merc, 0, sizeof(struct s_mercenary)); - 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 `mercenary` WHERE `mer_id` = '%d' AND `char_id` = '%d'", merc_id, char_id) ) - { - Sql_ShowDebug(sql_handle); - return false; - } - - if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) - { - Sql_FreeResult(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); - if( save_log ) - ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id); - - return true; -} - -bool mapif_mercenary_delete(int merc_id) -{ - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `mercenary` WHERE `mer_id` = '%d'", merc_id) ) - { - Sql_ShowDebug(sql_handle); - return false; - } - - return true; -} - -static void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag) -{ - int size = sizeof(struct s_mercenary) + 5; - - WFIFOHEAD(fd,size); - WFIFOW(fd,0) = 0x3870; - WFIFOW(fd,2) = size; - WFIFOB(fd,4) = flag; - memcpy(WFIFOP(fd,5),merc,sizeof(struct s_mercenary)); - WFIFOSET(fd,size); -} - -static void mapif_parse_mercenary_create(int fd, struct s_mercenary* merc) -{ - 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) -{ - struct s_mercenary merc; - 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) -{ - WFIFOHEAD(fd,3); - WFIFOW(fd,0) = 0x3871; - WFIFOB(fd,2) = flag; - WFIFOSET(fd,3); -} - -static void mapif_parse_mercenary_delete(int fd, int merc_id) -{ - bool result = mapif_mercenary_delete(merc_id); - mapif_mercenary_deleted(fd, result); -} - -static void mapif_mercenary_saved(int fd, unsigned char flag) -{ - WFIFOHEAD(fd,3); - WFIFOW(fd,0) = 0x3872; - WFIFOB(fd,2) = flag; - WFIFOSET(fd,3); -} - -static void mapif_parse_mercenary_save(int fd, struct s_mercenary* merc) -{ - bool result = mapif_mercenary_save(merc); - mapif_mercenary_saved(fd, result); -} - -/*========================================== * Inter Packets *------------------------------------------*/ int inter_homunculus_parse_frommap(int fd) @@ -427,19 +301,13 @@ int inter_homunculus_parse_frommap(int fd) switch( cmd ) { - // Homunculus Packets - case 0x3090: mapif_parse_homunculus_create(fd, (int)RFIFOW(fd,2), (int)RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,8)); break; - case 0x3091: mapif_parse_homunculus_load (fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break; - case 0x3092: mapif_parse_homunculus_save (fd, (int)RFIFOW(fd,2), (int)RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,8)); break; - case 0x3093: mapif_parse_homunculus_delete(fd, (int)RFIFOL(fd,2)); break; - case 0x3094: mapif_parse_homunculus_rename(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6), (char*)RFIFOP(fd,10)); break; - // Mercenary Packets - 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; + case 0x3090: mapif_parse_homunculus_create(fd, (int)RFIFOW(fd,2), (int)RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,8)); break; + case 0x3091: mapif_parse_homunculus_load (fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break; + case 0x3092: mapif_parse_homunculus_save (fd, (int)RFIFOW(fd,2), (int)RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,8)); break; + case 0x3093: mapif_parse_homunculus_delete(fd, (int)RFIFOL(fd,2)); break; + case 0x3094: mapif_parse_homunculus_rename(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6), (char*)RFIFOP(fd,10)); break; + default: + return 0; } return 1; } |