summaryrefslogtreecommitdiff
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
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
-rw-r--r--db/packet_db.txt2
-rw-r--r--src/char_sql/int_auction.c51
-rw-r--r--src/map/clif.c32
-rw-r--r--src/map/clif.h1
-rw-r--r--src/map/intif.c43
-rw-r--r--src/map/intif.h4
6 files changed, 103 insertions, 30 deletions
diff --git a/db/packet_db.txt b/db/packet_db.txt
index 108beba7a..a8a33c676 100644
--- a/db/packet_db.txt
+++ b/db/packet_db.txt
@@ -824,7 +824,7 @@ packet_ver: 19
//2005-10-13aSakexe
0x007a,6
0x0251,32
-0x025c,4
+0x025c,4,auctionbuysell,0
//2005-10-17aSakexe
0x007a,58
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);
}
/*==========================================
diff --git a/src/map/clif.c b/src/map/clif.c
index a3ee81e0b..032fb275a 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -11826,7 +11826,7 @@ void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
// 8 = You do not have enough Zeny
// 9 = You cannot place more than 5 bids at a time
-static void clif_Auction_message(int fd, unsigned char flag)
+void clif_Auction_message(int fd, unsigned char flag)
{
WFIFOHEAD(fd,3);
WFIFOW(fd,0) = 0x250;
@@ -11876,6 +11876,7 @@ void clif_parse_Auction_register(int fd, struct map_session_data *sd)
auction.price = auction.buynow - 1;
}
+ auction.auction_id = 0;
auction.seller_id = sd->status.char_id;
safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
auction.buyer_id = 0;
@@ -11893,25 +11894,26 @@ void clif_parse_Auction_register(int fd, struct map_session_data *sd)
return;
}
- sd->status.zeny -= (auction.hours * battle_config.auction_feeperhour);
- clif_updatestatus(sd, SP_ZENY);
-
safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
auction.type = item->type;
memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
auction.item.amount = 1;
- auction.item.identify = 1;
-
- pc_delitem(sd, sd->auction.index, sd->auction.amount, 0);
- sd->auction.amount = 0;
auction.timestamp = (int)mail_calctimes() + (auction.hours * 3600);
- intif_Auction_register(sd->status.account_id, &auction);
+ if( !intif_Auction_register(&auction) )
+ clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
+ else
+ {
+ pc_delitem(sd, sd->auction.index, sd->auction.amount, 0);
+ sd->auction.amount = 0;
+ pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
+ }
}
/*------------------------------------------
* Auction Search
* S 0251 <search type>.w <search price>.l <search text>.24B <01>.w
+ * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
*------------------------------------------*/
void clif_parse_Auction_search(int fd, struct map_session_data* sd)
{
@@ -11920,7 +11922,16 @@ void clif_parse_Auction_search(int fd, struct map_session_data* sd)
int price = RFIFOL(fd,4);
safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
- intif_Auction_requestlist(sd->status.account_id, type, price, search_text);
+ intif_Auction_requestlist(sd->status.char_id, type, price, search_text);
+}
+
+void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
+{
+ short type = RFIFOW(fd,2) + 6;
+ char search_text[NAME_LENGTH];
+
+ memset(&search_text, '\0', NAME_LENGTH);
+ intif_Auction_requestlist(sd->status.char_id, type, 0, search_text);
}
#endif
@@ -12455,6 +12466,7 @@ static int packetdb_readdb(void)
{clif_parse_Mail_send,"mailsend"},
// AUCTION SYSTEM
{clif_parse_Auction_search,"auctionsearch"},
+ {clif_parse_Auction_buysell,"auctionbuysell"},
{clif_parse_Auction_setitem,"auctionsetitem"},
{clif_parse_Auction_registerwindow,"auctionregisterwindow"},
{clif_parse_Auction_register,"auctionregister"},
diff --git a/src/map/clif.h b/src/map/clif.h
index aed08946b..6e136a302 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -410,6 +410,7 @@ void clif_Mail_refreshinbox(struct map_session_data *sd);
void clif_Mail_getattachment(int fd, uint8 flag);
// AUCTION SYSTEM
void clif_Auction_results(struct map_session_data *sd, short count, unsigned char *buf);
+void clif_Auction_message(int fd, unsigned char flag);
#endif
void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd);
diff --git a/src/map/intif.c b/src/map/intif.c
index 0216da950..6bf6f4ef8 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -35,7 +35,7 @@ static const int packet_len_table[]={
39,-1,15,15, 14,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840
- -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus]
+ -1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus]
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3880
@@ -1675,7 +1675,7 @@ static void intif_parse_Mail_new(int fd)
* AUCTION SYSTEM
* By Zephyrus
*==========================================*/
-int intif_Auction_requestlist(int account_id, short type, int price, const char* searchtext)
+int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext)
{
int len = NAME_LENGTH + 14;
@@ -1685,7 +1685,7 @@ int intif_Auction_requestlist(int account_id, short type, int price, const char*
WFIFOHEAD(inter_fd,len);
WFIFOW(inter_fd,0) = 0x3050;
WFIFOW(inter_fd,2) = len;
- WFIFOL(inter_fd,4) = account_id;
+ WFIFOL(inter_fd,4) = char_id;
WFIFOW(inter_fd,8) = type;
WFIFOL(inter_fd,10) = price;
memcpy(WFIFOP(inter_fd,14), searchtext, NAME_LENGTH);
@@ -1696,7 +1696,7 @@ int intif_Auction_requestlist(int account_id, short type, int price, const char*
static void intif_parse_Auction_results(int fd)
{
- struct map_session_data *sd = map_id2sd(RFIFOL(fd,4));
+ struct map_session_data *sd = map_charid2sd(RFIFOL(fd,4));
short count = (RFIFOW(fd,2) - 8) / sizeof(struct auction_data);
if( sd == NULL )
@@ -1705,9 +1705,9 @@ static void intif_parse_Auction_results(int fd)
clif_Auction_results(sd, count, (char *)RFIFOP(fd,8));
}
-int intif_Auction_register(int account_id, struct auction_data *auction)
+int intif_Auction_register(struct auction_data *auction)
{
- int len = sizeof(struct auction_data) + 8;
+ int len = sizeof(struct auction_data) + 4;
if( CheckForCharServer() )
return 0;
@@ -1715,11 +1715,35 @@ int intif_Auction_register(int account_id, struct auction_data *auction)
WFIFOHEAD(inter_fd,len);
WFIFOW(inter_fd,0) = 0x3051;
WFIFOW(inter_fd,2) = len;
- WFIFOL(inter_fd,4) = account_id;
- memcpy(WFIFOP(inter_fd,8), auction, sizeof(struct auction_data));
+ memcpy(WFIFOP(inter_fd,4), auction, sizeof(struct auction_data));
WFIFOSET(inter_fd,len);
- return 0;
+ return 1;
+}
+
+static void intif_parse_Auction_register(int fd)
+{
+ struct map_session_data *sd;
+ struct auction_data auction;
+
+ if( RFIFOW(fd,2) - 4 != sizeof(struct auction_data) )
+ {
+ ShowError("intif_parse_Auction_register: data size error %d %d\n", RFIFOW(fd,2) - 4, sizeof(struct auction_data));
+ return;
+ }
+
+ memcpy(&auction, WFIFOP(fd,4), sizeof(struct auction_data));
+ if( (sd = map_charid2sd(auction.seller_id)) == NULL )
+ return;
+
+ if( auction.auction_id > 0 )
+ clif_Auction_message(sd->fd, 1); // Confirmation Packet ??
+ else
+ {
+ clif_Auction_message(sd->fd, 4);
+ pc_additem(sd, &auction.item, auction.item.amount);
+ pc_getzeny(sd, auction.hours * battle_config.auction_feeperhour);
+ }
}
#endif
@@ -1802,6 +1826,7 @@ int intif_parse(int fd)
case 0x384d: intif_parse_Mail_send(fd); break;
// Auction System
case 0x3850: intif_parse_Auction_results(fd); break;
+ case 0x3851: intif_parse_Auction_register(fd); break;
#endif
case 0x3880: intif_parse_CreatePet(fd); break;
case 0x3881: intif_parse_RecvPetData(fd); break;
diff --git a/src/map/intif.h b/src/map/intif.h
index d2e3ca4f8..8628e752b 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -83,8 +83,8 @@ int intif_Mail_delete(int char_id, int mail_id);
int intif_Mail_return(int char_id, int mail_id);
int intif_Mail_send(int account_id, struct mail_message *msg);
// AUCTION SYSTEM
-int intif_Auction_requestlist(int account_id, short type, int price, const char* searchtext);
-int intif_Auction_register(int account_id, struct auction_data *auction);
+int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext);
+int intif_Auction_register(struct auction_data *auction);
#endif
int CheckForCharServer(void);