|
@@ -242,11 +242,13 @@ void buyingstore_close(struct map_session_data* sd)
|
|
|
{
|
|
|
if( sd->state.buyingstore )
|
|
|
{
|
|
|
- if(
|
|
|
- !sd->state.autotrade &&
|
|
|
- Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE buyingstore_id = %d;", buyingstore_items_db, sd->buyer_id ) != SQL_SUCCESS ||
|
|
|
- Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `id` = %d;", buyingstore_db, sd->buyer_id ) != SQL_SUCCESS ){
|
|
|
+ if( !sd->state.autotrade ){
|
|
|
+ if(
|
|
|
+ Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE buyingstore_id = %d;", buyingstore_items_db, sd->buyer_id ) != SQL_SUCCESS ||
|
|
|
+ Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `id` = %d;", buyingstore_db, sd->buyer_id ) != SQL_SUCCESS
|
|
|
+ ){
|
|
|
Sql_ShowDebug(mmysql_handle);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// invalidate data
|
|
@@ -618,95 +620,94 @@ void do_init_buyingstore_autotrade( void ) {
|
|
|
if (Sql_Query(mmysql_handle,
|
|
|
"SELECT `id`, `account_id`, `char_id`, `sex`, `title`, `limit` "
|
|
|
"FROM `%s` "
|
|
|
- "WHERE `autotrade` = 1 AND (SELECT COUNT(`buyingstore_id`) FROM `%s` WHERE `buyingstore_id` = `id`) > 0;",
|
|
|
+ "WHERE `autotrade` = 1 AND `limit` > 0 AND (SELECT COUNT(`buyingstore_id`) FROM `%s` WHERE `buyingstore_id` = `id`) > 0;",
|
|
|
buyingstore_db, buyingstore_items_db ) != SQL_SUCCESS )
|
|
|
{
|
|
|
Sql_ShowDebug(mmysql_handle);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (!(autotrader_count = (uint32)Sql_NumRows(mmysql_handle))) //Nothing to do
|
|
|
- return;
|
|
|
-
|
|
|
- // Init autotraders
|
|
|
- CREATE(autotraders, struct s_autotrade *, autotrader_count);
|
|
|
+ if( (autotrader_count = (uint32)Sql_NumRows(mmysql_handle)) > 0 ){
|
|
|
+ // Init autotraders
|
|
|
+ CREATE(autotraders, struct s_autotrade *, autotrader_count);
|
|
|
|
|
|
- if (autotraders == NULL) { //This is shouldn't happen [Cydh]
|
|
|
- ShowError("Failed to initialize buyingstore autotraders!\n");
|
|
|
- Sql_FreeResult(mmysql_handle);
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (autotraders == NULL) { //This is shouldn't happen [Cydh]
|
|
|
+ ShowError("Failed to initialize buyingstore autotraders!\n");
|
|
|
+ Sql_FreeResult(mmysql_handle);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // Init each autotrader data
|
|
|
- i = 0;
|
|
|
- while (SQL_SUCCESS == Sql_NextRow(mmysql_handle) && i < autotrader_count) {
|
|
|
- size_t len;
|
|
|
- char* data;
|
|
|
+ // Init each autotrader data
|
|
|
+ i = 0;
|
|
|
+ while (SQL_SUCCESS == Sql_NextRow(mmysql_handle) && i < autotrader_count) {
|
|
|
+ size_t len;
|
|
|
+ char* data;
|
|
|
|
|
|
- CREATE(autotraders[i], struct s_autotrade, 1);
|
|
|
+ CREATE(autotraders[i], struct s_autotrade, 1);
|
|
|
|
|
|
- Sql_GetData(mmysql_handle, 0, &data, NULL); autotraders[i]->buyer_id = atoi(data);
|
|
|
- Sql_GetData(mmysql_handle, 1, &data, NULL); autotraders[i]->account_id = atoi(data);
|
|
|
- Sql_GetData(mmysql_handle, 2, &data, NULL); autotraders[i]->char_id = atoi(data);
|
|
|
- Sql_GetData(mmysql_handle, 3, &data, NULL); autotraders[i]->sex = (data[0] == 'F') ? 0 : 1;
|
|
|
- Sql_GetData(mmysql_handle, 4, &data, &len); safestrncpy(autotraders[i]->title, data, min(len + 1, MESSAGE_SIZE));
|
|
|
- Sql_GetData(mmysql_handle, 5, &data, NULL); autotraders[i]->limit = atoi(data);
|
|
|
- autotraders[i]->count = 0;
|
|
|
+ Sql_GetData(mmysql_handle, 0, &data, NULL); autotraders[i]->buyer_id = atoi(data);
|
|
|
+ Sql_GetData(mmysql_handle, 1, &data, NULL); autotraders[i]->account_id = atoi(data);
|
|
|
+ Sql_GetData(mmysql_handle, 2, &data, NULL); autotraders[i]->char_id = atoi(data);
|
|
|
+ Sql_GetData(mmysql_handle, 3, &data, NULL); autotraders[i]->sex = (data[0] == 'F') ? 0 : 1;
|
|
|
+ Sql_GetData(mmysql_handle, 4, &data, &len); safestrncpy(autotraders[i]->title, data, min(len + 1, MESSAGE_SIZE));
|
|
|
+ Sql_GetData(mmysql_handle, 5, &data, NULL); autotraders[i]->limit = atoi(data);
|
|
|
+ autotraders[i]->count = 0;
|
|
|
|
|
|
- // initialize player
|
|
|
- CREATE(autotraders[i]->sd, struct map_session_data, 1);
|
|
|
+ // initialize player
|
|
|
+ CREATE(autotraders[i]->sd, struct map_session_data, 1);
|
|
|
|
|
|
- pc_setnewpc(autotraders[i]->sd, autotraders[i]->account_id, autotraders[i]->char_id, 0, gettick(), autotraders[i]->sex, 0);
|
|
|
+ pc_setnewpc(autotraders[i]->sd, autotraders[i]->account_id, autotraders[i]->char_id, 0, gettick(), autotraders[i]->sex, 0);
|
|
|
|
|
|
- autotraders[i]->sd->state.autotrade = 1;
|
|
|
- chrif_authreq(autotraders[i]->sd, true);
|
|
|
- i++;
|
|
|
- }
|
|
|
- Sql_FreeResult(mmysql_handle);
|
|
|
-
|
|
|
- //Init items on vending list each autotrader
|
|
|
- for (i = 0; i < autotrader_count; i++){
|
|
|
- struct s_autotrade *at = NULL;
|
|
|
- uint16 j;
|
|
|
-
|
|
|
- if (autotraders[i] == NULL)
|
|
|
- continue;
|
|
|
- at = autotraders[i];
|
|
|
-
|
|
|
- if (SQL_ERROR == Sql_Query(mmysql_handle,
|
|
|
- "SELECT `item_id`, `amount`, `price` "
|
|
|
- "FROM `%s` "
|
|
|
- "WHERE `buyingstore_id` = %d "
|
|
|
- "ORDER BY `index` ASC;", buyingstore_items_db, at->buyer_id ) )
|
|
|
- {
|
|
|
- Sql_ShowDebug(mmysql_handle);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (!(at->count = (uint32)Sql_NumRows(mmysql_handle))) {
|
|
|
- map_quit(at->sd);
|
|
|
- continue;
|
|
|
+ autotraders[i]->sd->state.autotrade = 1;
|
|
|
+ chrif_authreq(autotraders[i]->sd, true);
|
|
|
+ i++;
|
|
|
}
|
|
|
-
|
|
|
- //Init the list
|
|
|
- CREATE(at->entries, struct s_autotrade_entry *,at->count);
|
|
|
+ Sql_FreeResult(mmysql_handle);
|
|
|
|
|
|
- //Add the item into list
|
|
|
- j = 0;
|
|
|
- while (SQL_SUCCESS == Sql_NextRow(mmysql_handle) && j < at->count) {
|
|
|
- char* data;
|
|
|
- CREATE(at->entries[j], struct s_autotrade_entry, 1);
|
|
|
+ //Init items on vending list each autotrader
|
|
|
+ for (i = 0; i < autotrader_count; i++){
|
|
|
+ struct s_autotrade *at = NULL;
|
|
|
+ uint16 j;
|
|
|
+
|
|
|
+ if (autotraders[i] == NULL)
|
|
|
+ continue;
|
|
|
+ at = autotraders[i];
|
|
|
+
|
|
|
+ if (SQL_ERROR == Sql_Query(mmysql_handle,
|
|
|
+ "SELECT `item_id`, `amount`, `price` "
|
|
|
+ "FROM `%s` "
|
|
|
+ "WHERE `buyingstore_id` = %d "
|
|
|
+ "ORDER BY `index` ASC;", buyingstore_items_db, at->buyer_id ) )
|
|
|
+ {
|
|
|
+ Sql_ShowDebug(mmysql_handle);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- Sql_GetData(mmysql_handle, 0, &data, NULL); at->entries[j]->item_id = atoi(data);
|
|
|
- Sql_GetData(mmysql_handle, 1, &data, NULL); at->entries[j]->amount = atoi(data);
|
|
|
- Sql_GetData(mmysql_handle, 2, &data, NULL); at->entries[j]->price = atoi(data);
|
|
|
- j++;
|
|
|
+ if (!(at->count = (uint32)Sql_NumRows(mmysql_handle))) {
|
|
|
+ map_quit(at->sd);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //Init the list
|
|
|
+ CREATE(at->entries, struct s_autotrade_entry *,at->count);
|
|
|
+
|
|
|
+ //Add the item into list
|
|
|
+ j = 0;
|
|
|
+ while (SQL_SUCCESS == Sql_NextRow(mmysql_handle) && j < at->count) {
|
|
|
+ char* data;
|
|
|
+ CREATE(at->entries[j], struct s_autotrade_entry, 1);
|
|
|
+
|
|
|
+ Sql_GetData(mmysql_handle, 0, &data, NULL); at->entries[j]->item_id = atoi(data);
|
|
|
+ Sql_GetData(mmysql_handle, 1, &data, NULL); at->entries[j]->amount = atoi(data);
|
|
|
+ Sql_GetData(mmysql_handle, 2, &data, NULL); at->entries[j]->price = atoi(data);
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ items += j;
|
|
|
+ Sql_FreeResult(mmysql_handle);
|
|
|
}
|
|
|
- items += j;
|
|
|
- Sql_FreeResult(mmysql_handle);
|
|
|
- }
|
|
|
|
|
|
- ShowStatus("Done loading '"CL_WHITE"%d"CL_RESET"' autotraders with '"CL_WHITE"%d"CL_RESET"' items.\n", autotrader_count, items);
|
|
|
+ ShowStatus("Done loading '"CL_WHITE"%d"CL_RESET"' autotraders with '"CL_WHITE"%d"CL_RESET"' items.\n", autotrader_count, items);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Everything is loaded fine, their entries will be reinserted once they are loaded
|