|
@@ -627,6 +627,117 @@ char storage_guild_storageopen(struct map_session_data* sd)
|
|
|
return GSTORAGE_OPEN;
|
|
|
}
|
|
|
|
|
|
+void storage_guild_log( struct map_session_data* sd, struct item* item, int16 amount ){
|
|
|
+ int i;
|
|
|
+ SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
|
|
|
+ StringBuf buf;
|
|
|
+ StringBuf_Init(&buf);
|
|
|
+
|
|
|
+ StringBuf_Printf(&buf, "INSERT INTO `%s` (`time`, `guild_id`, `char_id`, `name`, `nameid`, `amount`, `identify`, `refine`, `attribute`, `unique_id`, `bound`", guild_storage_log_table);
|
|
|
+ for (i = 0; i < MAX_SLOTS; ++i)
|
|
|
+ StringBuf_Printf(&buf, ", `card%d`", i);
|
|
|
+ for (i = 0; i < MAX_ITEM_RDM_OPT; ++i) {
|
|
|
+ StringBuf_Printf(&buf, ", `option_id%d`", i);
|
|
|
+ StringBuf_Printf(&buf, ", `option_val%d`", i);
|
|
|
+ StringBuf_Printf(&buf, ", `option_parm%d`", i);
|
|
|
+ }
|
|
|
+ StringBuf_Printf(&buf, ") VALUES(NOW(),'%u','%u', '%s', '%d', '%d','%d','%d','%d','%" PRIu64 "','%d'",
|
|
|
+ sd->status.guild_id, sd->status.char_id, sd->status.name, item->nameid, amount, item->identify, item->refine,item->attribute, item->unique_id, item->bound);
|
|
|
+
|
|
|
+ for (i = 0; i < MAX_SLOTS; i++)
|
|
|
+ StringBuf_Printf(&buf, ",'%d'", item->card[i]);
|
|
|
+ for (i = 0; i < MAX_ITEM_RDM_OPT; i++)
|
|
|
+ StringBuf_Printf(&buf, ",'%d','%d','%d'", item->option[i].id, item->option[i].value, item->option[i].param);
|
|
|
+ StringBuf_Printf(&buf, ")");
|
|
|
+
|
|
|
+ if (SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) || SQL_SUCCESS != SqlStmt_Execute(stmt))
|
|
|
+ SqlStmt_ShowDebug(stmt);
|
|
|
+
|
|
|
+ SqlStmt_Free(stmt);
|
|
|
+ StringBuf_Destroy(&buf);
|
|
|
+}
|
|
|
+
|
|
|
+enum e_guild_storage_log storage_guild_log_read_sub( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, uint32 max ){
|
|
|
+ StringBuf buf;
|
|
|
+ int j;
|
|
|
+
|
|
|
+ StringBuf_Init(&buf);
|
|
|
+
|
|
|
+ StringBuf_AppendStr(&buf, "SELECT `id`, `time`, `name`, `amount`");
|
|
|
+ StringBuf_AppendStr(&buf, " , `nameid`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`");
|
|
|
+ for (j = 0; j < MAX_SLOTS; ++j)
|
|
|
+ StringBuf_Printf(&buf, ", `card%d`", j);
|
|
|
+ for (j = 0; j < MAX_ITEM_RDM_OPT; ++j) {
|
|
|
+ StringBuf_Printf(&buf, ", `option_id%d`", j);
|
|
|
+ StringBuf_Printf(&buf, ", `option_val%d`", j);
|
|
|
+ StringBuf_Printf(&buf, ", `option_parm%d`", j);
|
|
|
+ }
|
|
|
+ StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%u'", guild_storage_log_table, sd->status.guild_id );
|
|
|
+ StringBuf_Printf(&buf, " ORDER BY `time` DESC LIMIT %u", max);
|
|
|
+
|
|
|
+ SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
|
|
|
+ if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
|
|
|
+ SQL_ERROR == SqlStmt_Execute(stmt) )
|
|
|
+ {
|
|
|
+ SqlStmt_ShowDebug(stmt);
|
|
|
+ SqlStmt_Free(stmt);
|
|
|
+ StringBuf_Destroy(&buf);
|
|
|
+
|
|
|
+ return GUILDSTORAGE_LOG_FAILED;
|
|
|
+ }
|
|
|
+
|
|
|
+ struct guild_log_entry entry;
|
|
|
+
|
|
|
+ // General data
|
|
|
+ SqlStmt_BindColumn(stmt, 0, SQLDT_UINT, &entry.id, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 1, SQLDT_STRING, &entry.time, sizeof(entry.time), NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 2, SQLDT_STRING, &entry.name, sizeof(entry.name), NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 3, SQLDT_SHORT, &entry.amount, 0, NULL, NULL);
|
|
|
+
|
|
|
+ // Item data
|
|
|
+ SqlStmt_BindColumn(stmt, 4, SQLDT_USHORT, &entry.item.nameid, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 5, SQLDT_CHAR, &entry.item.identify, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 6, SQLDT_CHAR, &entry.item.refine, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 7, SQLDT_CHAR, &entry.item.attribute, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 8, SQLDT_UINT, &entry.item.expire_time, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 9, SQLDT_UINT, &entry.item.bound, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 10, SQLDT_UINT64, &entry.item.unique_id, 0, NULL, NULL);
|
|
|
+ for( j = 0; j < MAX_SLOTS; ++j )
|
|
|
+ SqlStmt_BindColumn(stmt, 11+j, SQLDT_USHORT, &entry.item.card[j], 0, NULL, NULL);
|
|
|
+ for( j = 0; j < MAX_ITEM_RDM_OPT; ++j ) {
|
|
|
+ SqlStmt_BindColumn(stmt, 11+MAX_SLOTS+j*3, SQLDT_SHORT, &entry.item.option[j].id, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 11+MAX_SLOTS+j*3+1, SQLDT_SHORT, &entry.item.option[j].value, 0, NULL, NULL);
|
|
|
+ SqlStmt_BindColumn(stmt, 11+MAX_SLOTS+j*3+2, SQLDT_CHAR, &entry.item.option[j].param, 0, NULL, NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.reserve(max);
|
|
|
+
|
|
|
+ while( SQL_SUCCESS == SqlStmt_NextRow(stmt) ){
|
|
|
+ log.push_back( entry );
|
|
|
+ }
|
|
|
+
|
|
|
+ Sql_FreeResult(mmysql_handle);
|
|
|
+ StringBuf_Destroy(&buf);
|
|
|
+ SqlStmt_Free(stmt);
|
|
|
+
|
|
|
+ if( log.empty() ){
|
|
|
+ return GUILDSTORAGE_LOG_EMPTY;
|
|
|
+ }
|
|
|
+
|
|
|
+ return GUILDSTORAGE_LOG_FINAL_SUCCESS;
|
|
|
+}
|
|
|
+
|
|
|
+enum e_guild_storage_log storage_guild_log_read( struct map_session_data* sd ){
|
|
|
+ std::vector<struct guild_log_entry> log;
|
|
|
+
|
|
|
+ // ( 65535(maximum packet size) - 8(header) ) / 83 (entry size) = 789 (-1 for safety)
|
|
|
+ enum e_guild_storage_log ret = storage_guild_log_read_sub( sd, log, 788 );
|
|
|
+
|
|
|
+ clif_guild_storage_log( sd, log, ret );
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Attempt to add an item in guild storage, then refresh it
|
|
|
* @param sd : player attempting to open the guild_storage
|
|
@@ -671,6 +782,9 @@ bool storage_guild_additem(struct map_session_data* sd, struct s_storage* stor,
|
|
|
stor->u.items_guild[i].amount += amount;
|
|
|
clif_storageitemadded(sd,&stor->u.items_guild[i],i,amount);
|
|
|
stor->dirty = true;
|
|
|
+
|
|
|
+ storage_guild_log( sd, &stor->u.items_guild[i], amount );
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -687,6 +801,9 @@ bool storage_guild_additem(struct map_session_data* sd, struct s_storage* stor,
|
|
|
clif_storageitemadded(sd,&stor->u.items_guild[i],i,amount);
|
|
|
clif_updatestorageamount(sd, stor->amount, stor->max_amount);
|
|
|
stor->dirty = true;
|
|
|
+
|
|
|
+ storage_guild_log( sd, &stor->u.items_guild[i], amount );
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -752,6 +869,9 @@ bool storage_guild_delitem(struct map_session_data* sd, struct s_storage* stor,
|
|
|
if(!stor->u.items_guild[n].nameid || stor->u.items_guild[n].amount < amount)
|
|
|
return false;
|
|
|
|
|
|
+ // Log before removing it
|
|
|
+ storage_guild_log( sd, &stor->u.items_guild[n], -amount );
|
|
|
+
|
|
|
stor->u.items_guild[n].amount -= amount;
|
|
|
|
|
|
if(!stor->u.items_guild[n].amount) {
|