summaryrefslogtreecommitdiff
path: root/src/char/int_homun.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/char/int_homun.c')
-rw-r--r--src/char/int_homun.c154
1 files changed, 82 insertions, 72 deletions
diff --git a/src/char/int_homun.c b/src/char/int_homun.c
index acde9eb38..d3cc1c46c 100644
--- a/src/char/int_homun.c
+++ b/src/char/int_homun.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,6 +21,8 @@
#include "../common/strlib.h"
#include "../common/utils.h"
+struct inter_homunculus_interface inter_homunculus_s;
+
int inter_homunculus_sql_init(void)
{
return 0;
@@ -29,7 +32,7 @@ void inter_homunculus_sql_final(void)
return;
}
-static void mapif_homunculus_created(int fd, int account_id, struct s_homunculus *sh, unsigned char flag)
+void mapif_homunculus_created(int fd, int account_id, struct s_homunculus *sh, unsigned char flag)
{
WFIFOHEAD(fd, sizeof(struct s_homunculus)+9);
WFIFOW(fd,0) = 0x3890;
@@ -40,7 +43,7 @@ static void mapif_homunculus_created(int fd, int account_id, struct s_homunculus
WFIFOSET(fd, WFIFOW(fd,2));
}
-static void mapif_homunculus_deleted(int fd, int flag)
+void mapif_homunculus_deleted(int fd, int flag)
{
WFIFOHEAD(fd, 3);
WFIFOW(fd, 0) = 0x3893;
@@ -48,7 +51,7 @@ static void mapif_homunculus_deleted(int fd, int flag)
WFIFOSET(fd, 3);
}
-static void mapif_homunculus_loaded(int fd, int account_id, struct s_homunculus *hd)
+void mapif_homunculus_loaded(int fd, int account_id, struct s_homunculus *hd)
{
WFIFOHEAD(fd, sizeof(struct s_homunculus)+9);
WFIFOW(fd,0) = 0x3891;
@@ -67,7 +70,7 @@ static void mapif_homunculus_loaded(int fd, int account_id, struct s_homunculus
WFIFOSET(fd, sizeof(struct s_homunculus)+9);
}
-static void mapif_homunculus_saved(int fd, int account_id, bool flag)
+void mapif_homunculus_saved(int fd, int account_id, bool flag)
{
WFIFOHEAD(fd, 7);
WFIFOW(fd,0) = 0x3892;
@@ -76,7 +79,7 @@ static void mapif_homunculus_saved(int fd, int account_id, bool flag)
WFIFOSET(fd, 7);
}
-static void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char flag, char* name)
+void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char flag, char* name)
{
WFIFOHEAD(fd, NAME_LENGTH+12);
WFIFOW(fd, 0) = 0x3894;
@@ -92,31 +95,31 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
bool flag = true;
char esc_name[NAME_LENGTH*2+1];
- SQL->EscapeStringLen(sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH));
+ SQL->EscapeStringLen(inter->sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH));
if( hd->hom_id == 0 )
{// new homunculus
- if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` "
+ 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')",
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) )
{
- Sql_ShowDebug(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
flag = false;
}
else
{
- hd->hom_id = (int)SQL->LastInsertId(sql_handle);
+ hd->hom_id = (int)SQL->LastInsertId(inter->sql_handle);
}
}
else
{
- if( SQL_ERROR == SQL->Query(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' 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) )
{
- Sql_ShowDebug(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
flag = false;
}
else
@@ -124,7 +127,7 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
SqlStmt* stmt;
int i;
- stmt = SQL->StmtMalloc(sql_handle);
+ stmt = SQL->StmtMalloc(inter->sql_handle);
if( SQL_ERROR == SQL->StmtPrepare(stmt, "REPLACE INTO `%s` (`homun_id`, `id`, `lv`) VALUES (%d, ?, ?)", skill_homunculus_db, hd->hom_id) )
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_HOMUNSKILL; ++i )
@@ -149,8 +152,6 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
return flag;
}
-
-
// Load an homunculus
bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
{
@@ -160,61 +161,61 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
memset(hd, 0, sizeof(*hd));
- if( SQL_ERROR == SQL->Query(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`='%u'", 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` FROM `%s` WHERE `homun_id`='%u'", homunculus_db, homun_id) )
{
- Sql_ShowDebug(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
return false;
}
- if( !SQL->NumRows(sql_handle) )
+ if( !SQL->NumRows(inter->sql_handle) )
{ //No homunculus found.
- SQL->FreeResult(sql_handle);
+ SQL->FreeResult(inter->sql_handle);
return false;
}
- if( SQL_SUCCESS != SQL->NextRow(sql_handle) )
+ if( SQL_SUCCESS != SQL->NextRow(inter->sql_handle) )
{
- Sql_ShowDebug(sql_handle);
- SQL->FreeResult(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
+ SQL->FreeResult(inter->sql_handle);
return false;
}
hd->hom_id = homun_id;
- SQL->GetData(sql_handle, 1, &data, NULL); hd->char_id = atoi(data);
- SQL->GetData(sql_handle, 2, &data, NULL); hd->class_ = atoi(data);
- SQL->GetData(sql_handle, 3, &data, NULL); hd->prev_class = atoi(data);
- SQL->GetData(sql_handle, 4, &data, &len); safestrncpy(hd->name, data, sizeof(hd->name));
- SQL->GetData(sql_handle, 5, &data, NULL); hd->level = atoi(data);
- SQL->GetData(sql_handle, 6, &data, NULL); hd->exp = atoi(data);
- SQL->GetData(sql_handle, 7, &data, NULL); hd->intimacy = (unsigned int)strtoul(data, NULL, 10);
- SQL->GetData(sql_handle, 8, &data, NULL); hd->hunger = atoi(data);
- SQL->GetData(sql_handle, 9, &data, NULL); hd->str = atoi(data);
- SQL->GetData(sql_handle, 10, &data, NULL); hd->agi = atoi(data);
- SQL->GetData(sql_handle, 11, &data, NULL); hd->vit = atoi(data);
- SQL->GetData(sql_handle, 12, &data, NULL); hd->int_ = atoi(data);
- SQL->GetData(sql_handle, 13, &data, NULL); hd->dex = atoi(data);
- SQL->GetData(sql_handle, 14, &data, NULL); hd->luk = atoi(data);
- SQL->GetData(sql_handle, 15, &data, NULL); hd->hp = atoi(data);
- SQL->GetData(sql_handle, 16, &data, NULL); hd->max_hp = atoi(data);
- SQL->GetData(sql_handle, 17, &data, NULL); hd->sp = atoi(data);
- SQL->GetData(sql_handle, 18, &data, NULL); hd->max_sp = atoi(data);
- SQL->GetData(sql_handle, 19, &data, NULL); hd->skillpts = atoi(data);
- SQL->GetData(sql_handle, 20, &data, NULL); hd->rename_flag = atoi(data);
- SQL->GetData(sql_handle, 21, &data, NULL); hd->vaporize = atoi(data);
- SQL->FreeResult(sql_handle);
+ SQL->GetData(inter->sql_handle, 1, &data, NULL); hd->char_id = atoi(data);
+ SQL->GetData(inter->sql_handle, 2, &data, NULL); hd->class_ = atoi(data);
+ SQL->GetData(inter->sql_handle, 3, &data, NULL); hd->prev_class = atoi(data);
+ SQL->GetData(inter->sql_handle, 4, &data, &len); safestrncpy(hd->name, data, sizeof(hd->name));
+ SQL->GetData(inter->sql_handle, 5, &data, NULL); hd->level = atoi(data);
+ SQL->GetData(inter->sql_handle, 6, &data, NULL); hd->exp = atoi(data);
+ SQL->GetData(inter->sql_handle, 7, &data, NULL); hd->intimacy = (unsigned int)strtoul(data, NULL, 10);
+ SQL->GetData(inter->sql_handle, 8, &data, NULL); hd->hunger = atoi(data);
+ SQL->GetData(inter->sql_handle, 9, &data, NULL); hd->str = atoi(data);
+ SQL->GetData(inter->sql_handle, 10, &data, NULL); hd->agi = atoi(data);
+ SQL->GetData(inter->sql_handle, 11, &data, NULL); hd->vit = atoi(data);
+ SQL->GetData(inter->sql_handle, 12, &data, NULL); hd->int_ = atoi(data);
+ SQL->GetData(inter->sql_handle, 13, &data, NULL); hd->dex = atoi(data);
+ SQL->GetData(inter->sql_handle, 14, &data, NULL); hd->luk = atoi(data);
+ SQL->GetData(inter->sql_handle, 15, &data, NULL); hd->hp = atoi(data);
+ SQL->GetData(inter->sql_handle, 16, &data, NULL); hd->max_hp = atoi(data);
+ SQL->GetData(inter->sql_handle, 17, &data, NULL); hd->sp = atoi(data);
+ SQL->GetData(inter->sql_handle, 18, &data, NULL); hd->max_sp = atoi(data);
+ 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->FreeResult(inter->sql_handle);
hd->intimacy = cap_value(hd->intimacy, 0, 100000);
hd->hunger = cap_value(hd->hunger, 0, 100);
// Load Homunculus Skill
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id) )
+ if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id) )
{
- Sql_ShowDebug(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
return false;
}
- while( SQL_SUCCESS == SQL->NextRow(sql_handle) )
+ while( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) )
{
// id
- SQL->GetData(sql_handle, 0, &data, NULL);
+ SQL->GetData(inter->sql_handle, 0, &data, NULL);
i = atoi(data);
if( i < HM_SKILLBASE || i >= HM_SKILLBASE + MAX_HOMUNSKILL )
continue;// invalid skill id
@@ -222,10 +223,10 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
hd->hskill[i].id = (unsigned short)atoi(data);
// lv
- SQL->GetData(sql_handle, 1, &data, NULL);
+ SQL->GetData(inter->sql_handle, 1, &data, NULL);
hd->hskill[i].lv = (unsigned char)atoi(data);
}
- SQL->FreeResult(sql_handle);
+ SQL->FreeResult(inter->sql_handle);
if( save_log )
ShowInfo("Homunculus loaded (%d - %s).\n", hd->hom_id, hd->name);
@@ -235,10 +236,10 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
bool mapif_homunculus_delete(int homun_id)
{
- if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", homunculus_db, homun_id)
- || SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", skill_homunculus_db, homun_id)
+ if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", homunculus_db, homun_id)
+ || SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", skill_homunculus_db, homun_id)
) {
- Sql_ShowDebug(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
return false;
}
return true;
@@ -266,35 +267,35 @@ bool mapif_homunculus_rename(char *name)
}
-static void mapif_parse_homunculus_create(int fd, int len, int account_id, struct s_homunculus* phd)
+void mapif_parse_homunculus_create(int fd, int len, int account_id, struct s_homunculus* phd)
{
- bool result = mapif_homunculus_save(phd);
- mapif_homunculus_created(fd, account_id, phd, result);
+ bool result = mapif->homunculus_save(phd);
+ mapif->homunculus_created(fd, account_id, phd, result);
}
-static void mapif_parse_homunculus_delete(int fd, int homun_id)
+void mapif_parse_homunculus_delete(int fd, int homun_id)
{
- bool result = mapif_homunculus_delete(homun_id);
- mapif_homunculus_deleted(fd, result);
+ bool result = mapif->homunculus_delete(homun_id);
+ mapif->homunculus_deleted(fd, result);
}
-static void mapif_parse_homunculus_load(int fd, int account_id, int homun_id)
+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 ));
+ bool result = mapif->homunculus_load(homun_id, &hd);
+ mapif->homunculus_loaded(fd, account_id, ( result ? &hd : NULL ));
}
-static void mapif_parse_homunculus_save(int fd, int len, int account_id, struct s_homunculus* phd)
+void mapif_parse_homunculus_save(int fd, int len, int account_id, struct s_homunculus* phd)
{
- bool result = mapif_homunculus_save(phd);
- mapif_homunculus_saved(fd, account_id, result);
+ bool result = mapif->homunculus_save(phd);
+ mapif->homunculus_saved(fd, account_id, result);
}
-static void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, char* name)
+void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, char* name)
{
- bool result = mapif_homunculus_rename(name);
- mapif_homunculus_renamed(fd, account_id, char_id, result, name);
+ bool result = mapif->homunculus_rename(name);
+ mapif->homunculus_renamed(fd, account_id, char_id, result, name);
}
/*==========================================
@@ -306,13 +307,22 @@ int inter_homunculus_parse_frommap(int fd)
switch( cmd )
{
- 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;
+ 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;
}
+
+void inter_homunculus_defaults(void)
+{
+ inter_homunculus = &inter_homunculus_s;
+
+ inter_homunculus->sql_init = inter_homunculus_sql_init;
+ inter_homunculus->sql_final = inter_homunculus_sql_final;
+ inter_homunculus->parse_frommap = inter_homunculus_parse_frommap;
+}