summaryrefslogtreecommitdiff
path: root/src/char_sql
diff options
context:
space:
mode:
authorzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-03-07 05:08:12 +0000
committerzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-03-07 05:08:12 +0000
commit88d795a036a4f954df1987fe3b241964df182a65 (patch)
treed7b4e8ea7524a8936d15fb95f83c0fc8f7f1ea1d /src/char_sql
parent4641fe9f49efdb3cf5dc7ef96f3d7838c6dab473 (diff)
downloadhercules-88d795a036a4f954df1987fe3b241964df182a65.tar.gz
hercules-88d795a036a4f954df1987fe3b241964df182a65.tar.bz2
hercules-88d795a036a4f954df1987fe3b241964df182a65.tar.xz
hercules-88d795a036a4f954df1987fe3b241964df182a65.zip
- More updates to Auctions. Now you "really" can register auctions, limit to 5 per char (according to official info).
- Also added the Buy and Sell lists. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12314 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/char_sql')
-rw-r--r--src/char_sql/int_auction.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/char_sql/int_auction.c b/src/char_sql/int_auction.c
index 9ee2e0afd..a04aacaf3 100644
--- a/src/char_sql/int_auction.c
+++ b/src/char_sql/int_auction.c
@@ -33,6 +33,24 @@ time_t calc_times(void)
return mktime(localtime(&temp));
}
+static int auction_count(int char_id, bool buy)
+{
+ int i = 0;
+ struct auction_data *auction;
+ DBIterator* iter;
+ DBKey key;
+
+ iter = auction_db_->iterator(auction_db_);
+ for( auction = iter->first(iter,&key); iter->exists(iter); auction = iter->next(iter,&key) )
+ {
+ if( (buy && auction->buyer_id == char_id) || (!buy && auction->seller_id == char_id) )
+ i++;
+ }
+ iter->destroy(iter);
+
+ return i;
+}
+
void auction_save(struct auction_data *auction)
{
int j;
@@ -247,14 +265,14 @@ void inter_auctions_fromsql(void)
Sql_FreeResult(sql_handle);
}
-static void mapif_Auction_sendlist(int fd, int account_id, short count, unsigned char *buf)
+static void mapif_Auction_sendlist(int fd, int char_id, short count, unsigned char *buf)
{
int len = (sizeof(struct auction_data) * count) + 8;
WFIFOHEAD(fd, len);
WFIFOW(fd,0) = 0x3850;
WFIFOW(fd,2) = len;
- WFIFOL(fd,4) = account_id;
+ WFIFOL(fd,4) = char_id;
memcpy(WFIFOP(fd,8), buf, len - 8);
WFIFOSET(fd,len);
}
@@ -262,7 +280,7 @@ static void mapif_Auction_sendlist(int fd, int account_id, short count, unsigned
static void mapif_parse_Auction_requestlist(int fd)
{
char searchtext[NAME_LENGTH];
- int account_id = RFIFOL(fd,4), len = sizeof(struct auction_data);
+ int char_id = RFIFOL(fd,4), len = sizeof(struct auction_data);
unsigned int price = RFIFOL(fd,10);
short type = RFIFOW(fd,8);
unsigned char buf[MAX_SEARCH_RESULTS * sizeof(struct auction_data)];
@@ -281,7 +299,9 @@ static void mapif_parse_Auction_requestlist(int fd)
(type == 2 && auction->type != IT_CARD) ||
(type == 3 && auction->type != IT_ETC) ||
(type == 4 && auction->price > price) ||
- (type == 5 && strstr(auction->item_name, searchtext)) )
+ (type == 5 && strstr(auction->item_name, searchtext)) ||
+ (type == 6 && auction->seller_id != char_id) ||
+ (type == 7 && auction->buyer_id != char_id) )
continue;
memcpy(WBUFP(buf, i * len), auction, len);
@@ -289,16 +309,31 @@ static void mapif_parse_Auction_requestlist(int fd)
}
iter->destroy(iter);
- mapif_Auction_sendlist(fd, account_id, i, buf);
+ mapif_Auction_sendlist(fd, char_id, i, buf);
+}
+
+static void mapif_Auction_register(int fd, struct auction_data *auction)
+{
+ int len = sizeof(struct auction_data) + 4;
+
+ WFIFOHEAD(fd, len);
+ WFIFOW(fd,0) = 0x3851;
+ WFIFOW(fd,2) = len;
+ memcpy(WFIFOP(fd,4), auction, sizeof(struct auction_data));
+ WFIFOSET(fd,len);
}
static void mapif_parse_Auction_register(int fd)
{
- int account_id = RFIFOL(fd,4);
struct auction_data auction;
+ if( RFIFOW(fd,2) != sizeof(struct auction_data) + 4 )
+ return;
+
+ memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
+ if( auction_count(auction.seller_id, false) < 5 )
+ auction_create(&auction);
- memcpy(&auction, RFIFOP(fd,8), sizeof(struct auction_data));
- auction_create(&auction);
+ mapif_Auction_register(fd, &auction);
}
/*==========================================