|
@@ -409,6 +409,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
int diff = 0;
|
|
int diff = 0;
|
|
char save_status[128]; //For displaying save information. [Skotlex]
|
|
char save_status[128]; //For displaying save information. [Skotlex]
|
|
struct mmo_charstatus *cp;
|
|
struct mmo_charstatus *cp;
|
|
|
|
+ int errors = 0; //If there are any errors while saving, "cp" will not be updated at the end.
|
|
StringBuf buf;
|
|
StringBuf buf;
|
|
|
|
|
|
if (char_id!=p->char_id) return 0;
|
|
if (char_id!=p->char_id) return 0;
|
|
@@ -425,22 +426,28 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
//map inventory data
|
|
//map inventory data
|
|
if( memcmp(p->inventory, cp->inventory, sizeof(p->inventory)) )
|
|
if( memcmp(p->inventory, cp->inventory, sizeof(p->inventory)) )
|
|
{
|
|
{
|
|
- memitemdata_to_sql(p->inventory, MAX_INVENTORY, p->char_id, TABLE_INVENTORY);
|
|
|
|
- strcat(save_status, " inventory");
|
|
|
|
|
|
+ if (!memitemdata_to_sql(p->inventory, MAX_INVENTORY, p->char_id, TABLE_INVENTORY))
|
|
|
|
+ strcat(save_status, " inventory");
|
|
|
|
+ else
|
|
|
|
+ errors++;
|
|
}
|
|
}
|
|
|
|
|
|
//map cart data
|
|
//map cart data
|
|
if( memcmp(p->cart, cp->cart, sizeof(p->cart)) )
|
|
if( memcmp(p->cart, cp->cart, sizeof(p->cart)) )
|
|
{
|
|
{
|
|
- memitemdata_to_sql(p->cart, MAX_CART, p->char_id, TABLE_CART);
|
|
|
|
- strcat(save_status, " cart");
|
|
|
|
|
|
+ if (!memitemdata_to_sql(p->cart, MAX_CART, p->char_id, TABLE_CART))
|
|
|
|
+ strcat(save_status, " cart");
|
|
|
|
+ else
|
|
|
|
+ errors++;
|
|
}
|
|
}
|
|
|
|
|
|
//map storage data
|
|
//map storage data
|
|
if( memcmp(p->storage.items, cp->storage.items, sizeof(p->storage.items)) )
|
|
if( memcmp(p->storage.items, cp->storage.items, sizeof(p->storage.items)) )
|
|
{
|
|
{
|
|
- memitemdata_to_sql(p->storage.items, MAX_STORAGE, p->account_id, TABLE_STORAGE);
|
|
|
|
- strcat(save_status, " storage");
|
|
|
|
|
|
+ if (!memitemdata_to_sql(p->storage.items, MAX_STORAGE, p->account_id, TABLE_STORAGE))
|
|
|
|
+ strcat(save_status, " storage");
|
|
|
|
+ else
|
|
|
|
+ errors++;
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef TXT_SQL_CONVERT
|
|
#ifdef TXT_SQL_CONVERT
|
|
@@ -452,9 +459,9 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
char_db, p->char_id, p->account_id, p->slot, esc_name) )
|
|
char_db, p->char_id, p->account_id, p->slot, esc_name) )
|
|
{
|
|
{
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
- }
|
|
|
|
-
|
|
|
|
- strcat(save_status, " creation");
|
|
|
|
|
|
+ errors++;
|
|
|
|
+ } else
|
|
|
|
+ strcat(save_status, " creation");
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -499,8 +506,9 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
p->account_id, p->char_id) )
|
|
p->account_id, p->char_id) )
|
|
{
|
|
{
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
- }
|
|
|
|
- strcat(save_status, " status");
|
|
|
|
|
|
+ errors++;
|
|
|
|
+ } else
|
|
|
|
+ strcat(save_status, " status");
|
|
}
|
|
}
|
|
|
|
|
|
//Values that will seldom change (to speed up saving)
|
|
//Values that will seldom change (to speed up saving)
|
|
@@ -525,9 +533,9 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
p->account_id, p->char_id) )
|
|
p->account_id, p->char_id) )
|
|
{
|
|
{
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
- }
|
|
|
|
-
|
|
|
|
- strcat(save_status, " status2");
|
|
|
|
|
|
+ errors++;
|
|
|
|
+ } else
|
|
|
|
+ strcat(save_status, " status2");
|
|
}
|
|
}
|
|
|
|
|
|
/* Mercenary Owner */
|
|
/* Mercenary Owner */
|
|
@@ -536,8 +544,10 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
(p->spear_calls != cp->spear_calls) || (p->spear_faith != cp->spear_faith) ||
|
|
(p->spear_calls != cp->spear_calls) || (p->spear_faith != cp->spear_faith) ||
|
|
(p->sword_calls != cp->sword_calls) || (p->sword_faith != cp->sword_faith) )
|
|
(p->sword_calls != cp->sword_calls) || (p->sword_faith != cp->sword_faith) )
|
|
{
|
|
{
|
|
- mercenary_owner_tosql(char_id, p);
|
|
|
|
- strcat(save_status, " mercenary");
|
|
|
|
|
|
+ if (mercenary_owner_tosql(char_id, p))
|
|
|
|
+ strcat(save_status, " mercenary");
|
|
|
|
+ else
|
|
|
|
+ errors++;
|
|
}
|
|
}
|
|
|
|
|
|
//memo points
|
|
//memo points
|
|
@@ -547,7 +557,10 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
|
|
|
|
//`memo` (`memo_id`,`char_id`,`map`,`x`,`y`)
|
|
//`memo` (`memo_id`,`char_id`,`map`,`x`,`y`)
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, p->char_id) )
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, p->char_id) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
|
|
|
|
//insert here.
|
|
//insert here.
|
|
StringBuf_Clear(&buf);
|
|
StringBuf_Clear(&buf);
|
|
@@ -566,9 +579,11 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
if( count )
|
|
if( count )
|
|
{
|
|
{
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
strcat(save_status, " memo");
|
|
strcat(save_status, " memo");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -583,7 +598,10 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
{
|
|
{
|
|
//`skill` (`char_id`, `id`, `lv`)
|
|
//`skill` (`char_id`, `id`, `lv`)
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, p->char_id) )
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, p->char_id) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
|
|
|
|
StringBuf_Clear(&buf);
|
|
StringBuf_Clear(&buf);
|
|
StringBuf_Printf(&buf, "INSERT INTO `%s`(`char_id`,`id`,`lv`) VALUES ", skill_db);
|
|
StringBuf_Printf(&buf, "INSERT INTO `%s`(`char_id`,`id`,`lv`) VALUES ", skill_db);
|
|
@@ -601,7 +619,10 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
if( count )
|
|
if( count )
|
|
{
|
|
{
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
strcat(save_status, " skills");
|
|
strcat(save_status, " skills");
|
|
@@ -619,7 +640,10 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
if(diff == 1)
|
|
if(diff == 1)
|
|
{ //Save friends
|
|
{ //Save friends
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", friend_db, char_id) )
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", friend_db, char_id) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
|
|
|
|
StringBuf_Clear(&buf);
|
|
StringBuf_Clear(&buf);
|
|
StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `friend_account`, `friend_id`) VALUES ", friend_db);
|
|
StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `friend_account`, `friend_id`) VALUES ", friend_db);
|
|
@@ -636,12 +660,12 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
if( count )
|
|
if( count )
|
|
{
|
|
{
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
- else
|
|
|
|
- strcat(save_status, " friends");
|
|
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else //Friend list cleared.
|
|
|
|
- strcat(save_status, " friends");
|
|
|
|
|
|
+ strcat(save_status, " friends");
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef HOTKEY_SAVING
|
|
#ifdef HOTKEY_SAVING
|
|
@@ -660,8 +684,10 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
}
|
|
}
|
|
if(diff) {
|
|
if(diff) {
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
- else
|
|
|
|
|
|
+ errors++;
|
|
|
|
+ } else
|
|
strcat(save_status, " hotkeys");
|
|
strcat(save_status, " hotkeys");
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
@@ -669,7 +695,8 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
|
|
if (save_status[0]!='\0' && save_log)
|
|
if (save_status[0]!='\0' && save_log)
|
|
ShowInfo("Saved char %d - %s:%s.\n", char_id, p->name, save_status);
|
|
ShowInfo("Saved char %d - %s:%s.\n", char_id, p->name, save_status);
|
|
#ifndef TXT_SQL_CONVERT
|
|
#ifndef TXT_SQL_CONVERT
|
|
- memcpy(cp, p, sizeof(struct mmo_charstatus));
|
|
|
|
|
|
+ if (!errors)
|
|
|
|
+ memcpy(cp, p, sizeof(struct mmo_charstatus));
|
|
#else
|
|
#else
|
|
aFree(cp);
|
|
aFree(cp);
|
|
#endif
|
|
#endif
|
|
@@ -688,6 +715,7 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
|
|
struct item item; // temp storage variable
|
|
struct item item; // temp storage variable
|
|
bool* flag; // bit array for inventory matching
|
|
bool* flag; // bit array for inventory matching
|
|
bool found;
|
|
bool found;
|
|
|
|
+ int errors = 0;
|
|
|
|
|
|
switch (tableswitch) {
|
|
switch (tableswitch) {
|
|
case TABLE_INVENTORY: tablename = inventory_db; selectoption = "char_id"; break;
|
|
case TABLE_INVENTORY: tablename = inventory_db; selectoption = "char_id"; break;
|
|
@@ -770,7 +798,10 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
|
|
StringBuf_Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id);
|
|
StringBuf_Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id);
|
|
|
|
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
found = flag[i] = true; //Item dealt with,
|
|
found = flag[i] = true; //Item dealt with,
|
|
@@ -780,7 +811,10 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
|
|
if( !found )
|
|
if( !found )
|
|
{// Item not present in inventory, remove it.
|
|
{// Item not present in inventory, remove it.
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `id`='%d'", tablename, item.id) )
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `id`='%d'", tablename, item.id) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
SqlStmt_Free(stmt);
|
|
SqlStmt_Free(stmt);
|
|
@@ -812,12 +846,15 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
|
|
}
|
|
}
|
|
|
|
|
|
if( found && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
if( found && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
|
|
|
|
+ {
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
+ errors++;
|
|
|
|
+ }
|
|
|
|
|
|
StringBuf_Destroy(&buf);
|
|
StringBuf_Destroy(&buf);
|
|
aFree(flag);
|
|
aFree(flag);
|
|
|
|
|
|
- return 0;
|
|
|
|
|
|
+ return errors;
|
|
}
|
|
}
|
|
|
|
|
|
int mmo_char_tobuf(uint8* buf, struct mmo_charstatus* p);
|
|
int mmo_char_tobuf(uint8* buf, struct mmo_charstatus* p);
|