summaryrefslogtreecommitdiff
path: root/src/char/int_auction.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/char/int_auction.c')
-rw-r--r--src/char/int_auction.c298
1 files changed, 38 insertions, 260 deletions
diff --git a/src/char/int_auction.c b/src/char/int_auction.c
index 51acb32a6..aa01872f9 100644
--- a/src/char/int_auction.c
+++ b/src/char/int_auction.c
@@ -2,8 +2,8 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
- * Copyright (C) Athena Dev Teams
+ * Copyright (C) 2012-2020 Hercules Dev Team
+ * Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
-struct inter_auction_interface inter_auction_s;
+static struct inter_auction_interface inter_auction_s;
struct inter_auction_interface *inter_auction;
static int inter_auction_count(int char_id, bool buy)
@@ -59,7 +59,7 @@ static int inter_auction_count(int char_id, bool buy)
return i;
}
-void inter_auction_save(struct auction_data *auction)
+static void inter_auction_save(struct auction_data *auction)
{
int j;
StringBuf buf;
@@ -71,8 +71,10 @@ void inter_auction_save(struct auction_data *auction)
StrBuf->Init(&buf);
StrBuf->Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%lu', `nameid` = '%d', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'",
auction_db, auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute);
- for( j = 0; j < MAX_SLOTS; j++ )
+ for (j = 0; j < MAX_SLOTS; j++)
StrBuf->Printf(&buf, ", `card%d` = '%d'", j, auction->item.card[j]);
+ for (j = 0; j < MAX_ITEM_OPTIONS; j++)
+ StrBuf->Printf(&buf, ", `opt_idx%d` = '%d', `opt_val%d` = '%d'", j, auction->item.option[j].index, j, auction->item.option[j].value);
StrBuf->Printf(&buf, " WHERE `auction_id` = '%u'", auction->auction_id);
stmt = SQL->StmtMalloc(inter->sql_handle);
@@ -89,39 +91,41 @@ void inter_auction_save(struct auction_data *auction)
StrBuf->Destroy(&buf);
}
-unsigned int inter_auction_create(struct auction_data *auction)
+static unsigned int inter_auction_create(struct auction_data *auction)
{
int j;
StringBuf buf;
struct SqlStmt *stmt;
- if( !auction )
- return false;
+ nullpo_ret(auction);
auction->timestamp = time(NULL) + (auction->hours * 3600);
StrBuf->Init(&buf);
StrBuf->Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`", auction_db);
- for( j = 0; j < MAX_SLOTS; j++ )
+ for (j = 0; j < MAX_SLOTS; j++)
StrBuf->Printf(&buf, ",`card%d`", j);
+ for (j = 0; j < MAX_ITEM_OPTIONS; j++)
+ StrBuf->Printf(&buf, ", `opt_idx%d`, `opt_val%d`", j, j);
StrBuf->Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'",
auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.unique_id);
- for( j = 0; j < MAX_SLOTS; j++ )
+ for (j = 0; j < MAX_SLOTS; j++)
StrBuf->Printf(&buf, ",'%d'", auction->item.card[j]);
+ for (j = 0; j < MAX_ITEM_OPTIONS; j++)
+ StrBuf->Printf(&buf, ",'%d','%d'", auction->item.option[j].index, auction->item.option[j].value);
+
StrBuf->AppendStr(&buf, ")");
stmt = SQL->StmtMalloc(inter->sql_handle);
- if( SQL_SUCCESS != SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
+ if (SQL_SUCCESS != SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
- || SQL_SUCCESS != SQL->StmtExecute(stmt) )
+ || SQL_SUCCESS != SQL->StmtExecute(stmt))
{
SqlStmt_ShowDebug(stmt);
auction->auction_id = 0;
- }
- else
- {
+ } else {
struct auction_data *auction_;
int64 tick = (int64)auction->hours * 3600000;
@@ -144,17 +148,8 @@ unsigned int inter_auction_create(struct auction_data *auction)
return auction->auction_id;
}
-void mapif_auction_message(int char_id, unsigned char result)
+static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data)
{
- unsigned char buf[74];
-
- WBUFW(buf,0) = 0x3854;
- WBUFL(buf,2) = char_id;
- WBUFL(buf,6) = result;
- mapif->sendall(buf,7);
-}
-
-static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data) {
struct auction_data *auction;
if( (auction = (struct auction_data *)idb_get(inter_auction->db, id)) != NULL )
{
@@ -176,7 +171,7 @@ static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data) {
return 0;
}
-void inter_auction_delete(struct auction_data *auction)
+static void inter_auction_delete(struct auction_data *auction)
{
unsigned int auction_id;
nullpo_retv(auction);
@@ -192,7 +187,7 @@ void inter_auction_delete(struct auction_data *auction)
idb_remove(inter_auction->db, auction_id);
}
-void inter_auctions_fromsql(void)
+static void inter_auctions_fromsql(void)
{
int i;
struct auction_data *auction;
@@ -204,8 +199,10 @@ void inter_auctions_fromsql(void)
StrBuf->Init(&buf);
StrBuf->AppendStr(&buf, "SELECT `auction_id`,`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,"
"`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`");
- for( i = 0; i < MAX_SLOTS; i++ )
+ for (i = 0; i < MAX_SLOTS; i++)
StrBuf->Printf(&buf, ",`card%d`", i);
+ for (i = 0; i < MAX_ITEM_OPTIONS; i++)
+ StrBuf->Printf(&buf, ", `opt_idx%d`, `opt_val%d`", i, i);
StrBuf->Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", auction_db);
if (SQL_ERROR == SQL->QueryStr(inter->sql_handle, StrBuf->Value(&buf)))
@@ -238,14 +235,20 @@ void inter_auctions_fromsql(void)
item->identify = 1;
item->amount = 1;
item->expire_time = 0;
-
- for( i = 0; i < MAX_SLOTS; i++ )
- {
+ /* Card Slots */
+ for (i = 0; i < MAX_SLOTS; i++) {
SQL->GetData(inter->sql_handle, 15 + i, &data, NULL);
item->card[i] = atoi(data);
}
+ /* Item Options */
+ for (i = 0; i < MAX_ITEM_OPTIONS; i++) {
+ SQL->GetData(inter->sql_handle, 15 + MAX_SLOTS + i * 2, &data, NULL);
+ item->option[i].index = atoi(data);
+ SQL->GetData(inter->sql_handle, 16 + MAX_SLOTS + i * 2, &data, NULL);
+ item->option[i].value = atoi(data);
+ }
- if( auction->timestamp > now )
+ if (auction->timestamp > now)
endtick = ((int64)(auction->timestamp - now) * 1000) + tick;
else
endtick = tick + 10000; // 10 seconds to process ended auctions
@@ -257,235 +260,10 @@ void inter_auctions_fromsql(void)
SQL->FreeResult(inter->sql_handle);
}
-void mapif_auction_sendlist(int fd, int char_id, short count, short pages, unsigned char *buf)
-{
- int len = (sizeof(struct auction_data) * count) + 12;
-
- nullpo_retv(buf);
-
- WFIFOHEAD(fd, len);
- WFIFOW(fd,0) = 0x3850;
- WFIFOW(fd,2) = len;
- WFIFOL(fd,4) = char_id;
- WFIFOW(fd,8) = count;
- WFIFOW(fd,10) = pages;
- memcpy(WFIFOP(fd,12), buf, len - 12);
- WFIFOSET(fd,len);
-}
-
-void mapif_parse_auction_requestlist(int fd)
-{
- char searchtext[NAME_LENGTH];
- int char_id = RFIFOL(fd,4), len = sizeof(struct auction_data);
- int price = RFIFOL(fd,10);
- short type = RFIFOW(fd,8), page = max(1,RFIFOW(fd,14));
- unsigned char buf[5 * sizeof(struct auction_data)];
- struct DBIterator *iter = db_iterator(inter_auction->db);
- struct auction_data *auction;
- short i = 0, j = 0, pages = 1;
-
- memcpy(searchtext, RFIFOP(fd,16), NAME_LENGTH);
-
- for( auction = dbi_first(iter); dbi_exists(iter); auction = dbi_next(iter) )
- {
- if( (type == 0 && auction->type != IT_ARMOR && auction->type != IT_PETARMOR) ||
- (type == 1 && auction->type != IT_WEAPON) ||
- (type == 2 && auction->type != IT_CARD) ||
- (type == 3 && auction->type != IT_ETC) ||
- (type == 4 && !strstr(auction->item_name, searchtext)) ||
- (type == 5 && auction->price > price) ||
- (type == 6 && auction->seller_id != char_id) ||
- (type == 7 && auction->buyer_id != char_id) )
- continue;
-
- i++;
- if( i > 5 )
- { // Counting Pages of Total Results (5 Results per Page)
- pages++;
- i = 1; // First Result of This Page
- }
-
- if( page != pages )
- continue; // This is not the requested Page
-
- memcpy(WBUFP(buf, j * len), auction, len);
- j++; // Found Results
- }
- dbi_destroy(iter);
-
- mapif->auction_sendlist(fd, char_id, j, pages, buf);
-}
-
-void mapif_auction_register(int fd, struct auction_data *auction)
-{
- int len = sizeof(struct auction_data) + 4;
-
- nullpo_retv(auction);
-
- WFIFOHEAD(fd,len);
- WFIFOW(fd,0) = 0x3851;
- WFIFOW(fd,2) = len;
- memcpy(WFIFOP(fd,4), auction, sizeof(struct auction_data));
- WFIFOSET(fd,len);
-}
-
-void mapif_parse_auction_register(int fd)
-{
- struct auction_data auction;
- if( RFIFOW(fd,2) != sizeof(struct auction_data) + 4 )
- return;
-
- memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
- if( inter_auction->count(auction.seller_id, false) < 5 )
- auction.auction_id = inter_auction->create(&auction);
-
- mapif->auction_register(fd, &auction);
-}
-
-void mapif_auction_cancel(int fd, int char_id, unsigned char result)
-{
- WFIFOHEAD(fd,7);
- WFIFOW(fd,0) = 0x3852;
- WFIFOL(fd,2) = char_id;
- WFIFOB(fd,6) = result;
- WFIFOSET(fd,7);
-}
-
-void mapif_parse_auction_cancel(int fd)
-{
- int char_id = RFIFOL(fd,2), auction_id = RFIFOL(fd,6);
- struct auction_data *auction;
-
- if( (auction = (struct auction_data *)idb_get(inter_auction->db, auction_id)) == NULL )
- {
- mapif->auction_cancel(fd, char_id, 1); // Bid Number is Incorrect
- return;
- }
-
- if( auction->seller_id != char_id )
- {
- mapif->auction_cancel(fd, char_id, 2); // You cannot end the auction
- return;
- }
-
- if( auction->buyer_id > 0 )
- {
- mapif->auction_cancel(fd, char_id, 3); // An auction with at least one bidder cannot be canceled
- return;
- }
-
- inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction canceled.", 0, &auction->item);
- inter_auction->delete_(auction);
-
- mapif->auction_cancel(fd, char_id, 0); // The auction has been canceled
-}
-
-void mapif_auction_close(int fd, int char_id, unsigned char result)
-{
- WFIFOHEAD(fd,7);
- WFIFOW(fd,0) = 0x3853;
- WFIFOL(fd,2) = char_id;
- WFIFOB(fd,6) = result;
- WFIFOSET(fd,7);
-}
-
-void mapif_parse_auction_close(int fd)
-{
- int char_id = RFIFOL(fd,2), auction_id = RFIFOL(fd,6);
- struct auction_data *auction;
-
- if( (auction = (struct auction_data *)idb_get(inter_auction->db, auction_id)) == NULL )
- {
- mapif->auction_close(fd, char_id, 2); // Bid Number is Incorrect
- return;
- }
-
- if( auction->seller_id != char_id )
- {
- mapif->auction_close(fd, char_id, 1); // You cannot end the auction
- return;
- }
-
- if( auction->buyer_id == 0 )
- {
- mapif->auction_close(fd, char_id, 1); // You cannot end the auction
- return;
- }
-
- // Send Money to Seller
- inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction closed.", auction->price, NULL);
- // Send Item to Buyer
- inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Auction winner.", 0, &auction->item);
- mapif->auction_message(auction->buyer_id, 6); // You have won the auction
- inter_auction->delete_(auction);
-
- mapif->auction_close(fd, char_id, 0); // You have ended the auction
-}
-
-void mapif_auction_bid(int fd, int char_id, int bid, unsigned char result)
-{
- WFIFOHEAD(fd,11);
- WFIFOW(fd,0) = 0x3855;
- WFIFOL(fd,2) = char_id;
- WFIFOL(fd,6) = bid; // To Return Zeny
- WFIFOB(fd,10) = result;
- WFIFOSET(fd,11);
-}
-
-void mapif_parse_auction_bid(int fd)
-{
- int char_id = RFIFOL(fd,4), bid = RFIFOL(fd,12);
- unsigned int auction_id = RFIFOL(fd,8);
- struct auction_data *auction;
-
- if( (auction = (struct auction_data *)idb_get(inter_auction->db, auction_id)) == NULL || auction->price >= bid || auction->seller_id == char_id )
- {
- mapif->auction_bid(fd, char_id, bid, 0); // You have failed to bid in the auction
- return;
- }
-
- if( inter_auction->count(char_id, true) > 4 && bid < auction->buynow && auction->buyer_id != char_id )
- {
- mapif->auction_bid(fd, char_id, bid, 9); // You cannot place more than 5 bids at a time
- return;
- }
-
- if( auction->buyer_id > 0 )
- { // Send Money back to the previous Buyer
- if( auction->buyer_id != char_id )
- {
- inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Someone has placed a higher bid.", auction->price, NULL);
- mapif->auction_message(auction->buyer_id, 7); // You have failed to win the auction
- }
- else
- inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "You have placed a higher bid.", auction->price, NULL);
- }
-
- auction->buyer_id = char_id;
- safestrncpy(auction->buyer_name, RFIFOP(fd,16), NAME_LENGTH);
- auction->price = bid;
-
- if( bid >= auction->buynow )
- { // Automatic won the auction
- mapif->auction_bid(fd, char_id, bid - auction->buynow, 1); // You have successfully bid in the auction
-
- inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "You have won the auction.", 0, &auction->item);
- mapif->auction_message(char_id, 6); // You have won the auction
- inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your auction!.", auction->buynow, NULL);
-
- inter_auction->delete_(auction);
- return;
- }
-
- inter_auction->save(auction);
-
- mapif->auction_bid(fd, char_id, 0, 1); // You have successfully bid in the auction
-}
-
/*==========================================
* Packets From Map Server
*------------------------------------------*/
-int inter_auction_parse_frommap(int fd)
+static int inter_auction_parse_frommap(int fd)
{
switch(RFIFOW(fd,0))
{
@@ -500,7 +278,7 @@ int inter_auction_parse_frommap(int fd)
return 1;
}
-int inter_auction_sql_init(void)
+static int inter_auction_sql_init(void)
{
inter_auction->db = idb_alloc(DB_OPT_RELEASE_DATA);
inter_auction->fromsql();
@@ -508,7 +286,7 @@ int inter_auction_sql_init(void)
return 0;
}
-void inter_auction_sql_final(void)
+static void inter_auction_sql_final(void)
{
inter_auction->db->destroy(inter_auction->db,NULL);