diff options
-rw-r--r-- | db/packet_db.txt | 6 | ||||
-rw-r--r-- | src/char_sql/int_auction.c | 106 | ||||
-rw-r--r-- | src/char_sql/inter.c | 2 | ||||
-rw-r--r-- | src/map/clif.c | 25 | ||||
-rw-r--r-- | src/map/clif.h | 1 | ||||
-rw-r--r-- | src/map/intif.c | 58 | ||||
-rw-r--r-- | src/map/intif.h | 2 |
7 files changed, 196 insertions, 4 deletions
diff --git a/db/packet_db.txt b/db/packet_db.txt index 103795d25..95c6c8ac5 100644 --- a/db/packet_db.txt +++ b/db/packet_db.txt @@ -768,7 +768,7 @@ packet_ver: 18 0x024b,4,auctioncancelreg,0 0x024c,8,auctionsetitem,0 0x024d,14 -0x024e,6 +0x024e,6,auctioncancel,0 0x024f,10 0x0250,3 0x0251,2 @@ -828,7 +828,7 @@ packet_ver: 19 //2005-10-17aSakexe 0x007a,58 -0x025d,-1 +0x025d,6,auctionclose,0 0x025e,4 //2005-10-24aSakexe @@ -836,7 +836,7 @@ packet_ver: 19 0x0260,6 //2005-11-07aSakexe -0x024e,6 +0x024e,6,auctioncancel,0 0x0251,34,auctionsearch,0 //2006-01-09aSakexe diff --git a/src/char_sql/int_auction.c b/src/char_sql/int_auction.c index 1495afc1e..e40098556 100644 --- a/src/char_sql/int_auction.c +++ b/src/char_sql/int_auction.c @@ -341,6 +341,110 @@ static void mapif_parse_Auction_register(int fd) mapif_Auction_register(fd, &auction); } +static void mapif_Auction_cancel(int fd, int char_id, unsigned char result) +{ + WFIFOHEAD(fd,7); + WFIFOW(fd,0) = 0x3852; + WFIFOL(fd,8) = char_id; + WFIFOB(fd,6) = result; + WFIFOSET(fd,7); +} + +static void mapif_parse_Auction_cancel(int fd) +{ + int char_id = RFIFOL(fd,2), auction_id = RFIFOL(fd,6); + struct auction_data *auction; + struct mail_message msg; + + if( (auction = (struct auction_data *)idb_get(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; + } + + memset(&msg, 0, sizeof(struct mail_message)); + safestrncpy(msg.send_name, "Auction Manager", NAME_LENGTH); + msg.dest_id = auction->seller_id; + safestrncpy(msg.dest_name, auction->seller_name, NAME_LENGTH); + msg.timestamp = (int)calc_times(); + safestrncpy(msg.title, "Auction", MAIL_TITLE_LENGTH); + safestrncpy(msg.body, "Auction canceled.", MAIL_BODY_LENGTH); + + memcpy(&msg.item, &auction->item, sizeof(struct item)); + + mail_savemessage(&msg); + mapif_Mail_new(&msg); + + auction_delete(auction); + mapif_Auction_cancel(fd, char_id, 0); // The auction has been canceled +} + +static void mapif_Auction_close(int fd, int char_id, unsigned char result) +{ + WFIFOHEAD(fd,7); + WFIFOW(fd,0) = 0x3853; + WFIFOL(fd,8) = char_id; + WFIFOB(fd,6) = result; + WFIFOSET(fd,7); +} + +static void mapif_parse_Auction_close(int fd) +{ + int char_id = RFIFOL(fd,2), auction_id = RFIFOL(fd,6); + struct auction_data *auction; + struct mail_message msg; + + if( (auction = (struct auction_data *)idb_get(auction_db_, auction_id)) == NULL ) + { + mapif_Auction_cancel(fd, char_id, 2); // Bid Number is Incorrect + return; + } + + if( auction->buyer_id == 0 ) + { + mapif_Auction_cancel(fd, char_id, 1); // You cannot end the auction + return; + } + + // Send Money to Seller + memset(&msg, 0, sizeof(struct mail_message)); + safestrncpy(msg.send_name, "Auction Manager", NAME_LENGTH); + msg.dest_id = auction->seller_id; + safestrncpy(msg.dest_name, auction->seller_name, NAME_LENGTH); + msg.timestamp = (int)calc_times(); + safestrncpy(msg.title, "Auction", MAIL_TITLE_LENGTH); + safestrncpy(msg.body, "Auction closed.", MAIL_BODY_LENGTH); + msg.zeny = auction->price; // Current Bid + mail_savemessage(&msg); + mapif_Mail_new(&msg); + + // Send Item to Buyer + memset(&msg, 0, sizeof(struct mail_message)); + safestrncpy(msg.send_name, "Auction Manager", NAME_LENGTH); + msg.dest_id = auction->buyer_id; + safestrncpy(msg.dest_name, auction->buyer_name, NAME_LENGTH); + msg.timestamp = (int)calc_times(); + safestrncpy(msg.title, "Auction", MAIL_TITLE_LENGTH); + safestrncpy(msg.body, "Auction winner.", MAIL_BODY_LENGTH); + memcpy(&msg.item, &auction->item, sizeof(struct item)); + mail_savemessage(&msg); + mapif_Mail_new(&msg); + + mapif_Auction_cancel(fd, char_id, 0); // You have ended the auction +} + /*========================================== * Packets From Map Server *------------------------------------------*/ @@ -350,6 +454,8 @@ int inter_auction_parse_frommap(int fd) { case 0x3050: mapif_parse_Auction_requestlist(fd); break; case 0x3051: mapif_parse_Auction_register(fd); break; + case 0x3052: mapif_parse_Auction_cancel(fd); break; + case 0x3053: mapif_parse_Auction_close(fd); break; default: return 0; } diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c index 451ffb6b7..2271fe586 100644 --- a/src/char_sql/inter.c +++ b/src/char_sql/inter.c @@ -55,7 +55,7 @@ int inter_recv_packet_length[] = { -1, 6,-1,14, 14,19, 6,-1, 14,14, 0, 0, 0, 0, 0, 0, // 3020- -1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 14,19,186,-1, // 3030- 5, 9, 0, 0, 0, 0, 0, 0, 7, 6,10,10, 10,-1, 0, 0, // 3040- - -1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus] + -1,-1,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus] 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3070- 48,14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3080- diff --git a/src/map/clif.c b/src/map/clif.c index a71c19f44..2e0591c99 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -11834,6 +11834,17 @@ void clif_Auction_message(int fd, unsigned char flag) WFIFOSET(fd,3); } +// 0 = You have ended the auction +// 1 = You cannot end the auction +// 2 = Bid number is incorrect +void clif_Auction_close(int fd, unsigned char flag) +{ + WFIFOHEAD(fd,6); + WFIFOW(fd,0) = 0x25d; + WFIFOL(fd,2) = flag; + WFIFOSET(fd,6); +} + void clif_parse_Auction_register(int fd, struct map_session_data *sd) { struct auction_data auction; @@ -11910,6 +11921,20 @@ void clif_parse_Auction_register(int fd, struct map_session_data *sd) } } +void clif_parse_Auction_cancel(int fd, struct map_session_data *sd) +{ + unsigned int auction_id = RFIFOL(fd,2); + + intif_Auction_cancel(sd->status.char_id, auction_id); +} + +void clif_parse_Auction_close(int fd, struct map_session_data *sd) +{ + unsigned int auction_id = RFIFOL(fd,2); + + intif_Auction_close(sd->status.char_id, auction_id); +} + /*------------------------------------------ * Auction Search * S 0251 <search type>.w <search price>.l <search text>.24B <01>.w diff --git a/src/map/clif.h b/src/map/clif.h index 6e136a302..9be840d72 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -411,6 +411,7 @@ 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); +void clif_Auction_close(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 a9fba59e9..ff18aecba 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -1746,6 +1746,62 @@ static void intif_parse_Auction_register(int fd) } } +int intif_Auction_cancel(int char_id, unsigned int auction_id) +{ + if( CheckForCharServer() ) + return 0; + + WFIFOHEAD(inter_fd,10); + WFIFOW(inter_fd,0) = 0x3052; + WFIFOL(inter_fd,2) = char_id; + WFIFOL(inter_fd,6) = auction_id; + WFIFOSET(inter_fd,10); + + return 0; +} + +static void intif_parse_Auction_cancel(int fd) +{ + struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2)); + int result = RFIFOB(fd,6); + + if( sd == NULL ) + return; + + switch( result ) + { + case 0: clif_Auction_message(sd->fd, 2); break; + case 1: clif_Auction_close(sd->fd, 2); break; + case 2: clif_Auction_close(sd->fd, 1); break; + case 3: clif_Auction_message(sd->fd, 3); break; + } +} + +int intif_Auction_close(int char_id, unsigned int auction_id) +{ + if( CheckForCharServer() ) + return 0; + + WFIFOHEAD(inter_fd,10); + WFIFOW(inter_fd,0) = 0x3053; + WFIFOL(inter_fd,2) = char_id; + WFIFOL(inter_fd,6) = auction_id; + WFIFOSET(inter_fd,10); + + return 0; +} + +static void intif_parse_Auction_close(int fd) +{ + struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2)); + unsigned char result = RFIFOB(fd,6); + + if( sd == NULL ) + return; + + clif_Auction_close(sd->fd, result); +} + #endif //----------------------------------------------------------------- @@ -1827,6 +1883,8 @@ int intif_parse(int fd) // Auction System case 0x3850: intif_parse_Auction_results(fd); break; case 0x3851: intif_parse_Auction_register(fd); break; + case 0x3852: intif_parse_Auction_cancel(fd); break; + case 0x3853: intif_parse_Auction_close(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 8f3cd1d9a..743057fb4 100644 --- a/src/map/intif.h +++ b/src/map/intif.h @@ -86,6 +86,8 @@ int intif_Mail_send(int account_id, struct mail_message *msg); // AUCTION SYSTEM int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext); int intif_Auction_register(struct auction_data *auction); +int intif_Auction_cancel(int char_id, unsigned int auction_id); +int intif_Auction_close(int char_id, unsigned int auction_id); #endif int CheckForCharServer(void); |