summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-03-08 20:11:28 +0000
committerzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-03-08 20:11:28 +0000
commit603dc60466a7067ecb68384185cb1c20aaea7366 (patch)
treeb8e75ab3e5b7fe481571738ad7454262607d403f /src
parent1f4883d1f4fb65260691692879a795992fdbcf88 (diff)
downloadhercules-603dc60466a7067ecb68384185cb1c20aaea7366.tar.gz
hercules-603dc60466a7067ecb68384185cb1c20aaea7366.tar.bz2
hercules-603dc60466a7067ecb68384185cb1c20aaea7366.tar.xz
hercules-603dc60466a7067ecb68384185cb1c20aaea7366.zip
- Auction System implementation completed.
- As mail system, this will need a "mapflag" or something to only allow auctions on some maps. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12325 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/char_sql/int_auction.c203
-rw-r--r--src/char_sql/int_mail.c21
-rw-r--r--src/char_sql/int_mail.h1
-rw-r--r--src/char_sql/inter.c2
-rw-r--r--src/common/mmo.h2
-rw-r--r--src/map/clif.c39
-rw-r--r--src/map/clif.h3
-rw-r--r--src/map/intif.c70
-rw-r--r--src/map/intif.h3
-rw-r--r--src/map/script.c15
10 files changed, 242 insertions, 117 deletions
diff --git a/src/char_sql/int_auction.c b/src/char_sql/int_auction.c
index e40098556..ddc9e567f 100644
--- a/src/char_sql/int_auction.c
+++ b/src/char_sql/int_auction.c
@@ -19,8 +19,6 @@
// This is set to limit the search result
// On iRO, no one uses auctions, so there is no way to know
-#define MAX_SEARCH_RESULTS 30
-
static DBMap* auction_db_ = NULL; // int auction_id -> struct auction_data*
void auction_delete(struct auction_data *auction);
@@ -135,56 +133,30 @@ unsigned int auction_create(struct auction_data *auction)
return auction->auction_id;
}
+static void mapif_Auction_message(int char_id, unsigned char result)
+{
+ unsigned char buf[74];
+
+ WBUFW(buf,0) = 0x3854;
+ WBUFL(buf,2) = char_id;
+ WBUFL(buf,6) = result;
+ mapif_sendall(buf,7);
+}
+
static int auction_end_timer(int tid, unsigned int tick, int id, int data)
{
struct auction_data *auction;
if( (auction = (struct auction_data *)idb_get(auction_db_, id)) != NULL )
{
- struct mail_message msg;
- memset(&msg, 0, sizeof(struct mail_message));
-
- msg.send_id = 0;
- safestrncpy(msg.send_name, "Auction Manager", NAME_LENGTH);
- safestrncpy(msg.title, "Auction", MAIL_TITLE_LENGTH);
- msg.timestamp = (int)calc_times();
-
if( auction->buyer_id )
- { // Send item to Buyer's Mail (custom messages)
- msg.dest_id = auction->buyer_id;
- safestrncpy(msg.dest_name, auction->buyer_name, NAME_LENGTH);
- safestrncpy(msg.body, "Thanks, you won the auction!.", MAIL_BODY_LENGTH);
+ {
+ mail_sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Thanks, you won the auction!.", 0, &auction->item);
+ mapif_Auction_message(auction->buyer_id, 6); // You have won the auction
+ mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your auction!.", auction->price, NULL);
}
else
- { // Return item to Seller's Mail (custom messages)
- msg.dest_id = auction->seller_id;
- safestrncpy(msg.dest_name, auction->seller_name, NAME_LENGTH);
- safestrncpy(msg.body, "Sorry, No one buy your item...", MAIL_BODY_LENGTH);
- }
-
- memcpy(&msg.item, &auction->item, sizeof(struct item));
-
- mail_savemessage(&msg);
- mapif_Mail_new(&msg);
-
- if( auction->buyer_id )
- { // Send Money to Seller
- memset(&msg, 0, sizeof(struct mail_message));
-
- msg.send_id = 0;
- 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();
- msg.zeny = auction->price;
-
- // Custom Messages, need more info
- safestrncpy(msg.title, "Auction", MAIL_TITLE_LENGTH);
- safestrncpy(msg.body, "Here is the money from your Auction.", MAIL_BODY_LENGTH);
-
- mail_savemessage(&msg);
- mapif_Mail_new(&msg);
- }
-
+ mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Sorry, No one buy your item...", 0, &auction->item);
+
ShowInfo("Auction End: id %u.\n", auction->auction_id);
auction->auction_end_timer = -1;
@@ -270,15 +242,17 @@ void inter_auctions_fromsql(void)
Sql_FreeResult(sql_handle);
}
-static void mapif_Auction_sendlist(int fd, int char_id, short count, unsigned char *buf)
+static void mapif_Auction_sendlist(int fd, int char_id, short count, short pages, unsigned char *buf)
{
- int len = (sizeof(struct auction_data) * count) + 8;
+ int len = (sizeof(struct auction_data) * count) + 12;
WFIFOHEAD(fd, len);
WFIFOW(fd,0) = 0x3850;
WFIFOW(fd,2) = len;
WFIFOL(fd,4) = char_id;
- memcpy(WFIFOP(fd,8), buf, len - 8);
+ WFIFOW(fd,8) = count;
+ WFIFOW(fd,10) = pages;
+ memcpy(WFIFOP(fd,12), buf, len - 12);
WFIFOSET(fd,len);
}
@@ -286,18 +260,18 @@ static void mapif_parse_Auction_requestlist(int fd)
{
char searchtext[NAME_LENGTH];
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)];
+ int price = RFIFOL(fd,10);
+ short type = RFIFOW(fd,8), page = max(1,RFIFOW(fd,14));
+ unsigned char buf[5 * sizeof(struct auction_data)];
DBIterator* iter;
DBKey key;
struct auction_data *auction;
- short i = 0;
+ short i = 0, j = 0, pages = 1;
- memcpy(searchtext, RFIFOP(fd,14), NAME_LENGTH);
+ memcpy(searchtext, RFIFOP(fd,16), NAME_LENGTH);
iter = auction_db_->iterator(auction_db_);
- for( auction = iter->first(iter,&key); iter->exists(iter) && i < MAX_SEARCH_RESULTS; auction = iter->next(iter,&key) )
+ for( auction = iter->first(iter,&key); iter->exists(iter); auction = iter->next(iter,&key) )
{
if( (type == 0 && auction->type != IT_ARMOR && auction->type != IT_PETARMOR) ||
(type == 1 && auction->type != IT_WEAPON) ||
@@ -309,12 +283,16 @@ static void mapif_parse_Auction_requestlist(int fd)
(type == 7 && auction->buyer_id != char_id) )
continue;
- memcpy(WBUFP(buf, i * len), auction, len);
i++;
+ if( i > 5 ) { pages++; i = 0; }
+ if( page != pages ) continue;
+
+ memcpy(WBUFP(buf, j * len), auction, len);
+ j++;
}
iter->destroy(iter);
- mapif_Auction_sendlist(fd, char_id, i, buf);
+ mapif_Auction_sendlist(fd, char_id, j, pages, buf);
}
static void mapif_Auction_register(int fd, struct auction_data *auction)
@@ -345,7 +323,7 @@ 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;
+ WFIFOL(fd,2) = char_id;
WFIFOB(fd,6) = result;
WFIFOSET(fd,7);
}
@@ -354,7 +332,6 @@ 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 )
{
@@ -374,20 +351,9 @@ static void mapif_parse_Auction_cancel(int fd)
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);
-
+ mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction canceled.", 0, &auction->item);
auction_delete(auction);
+
mapif_Auction_cancel(fd, char_id, 0); // The auction has been canceled
}
@@ -395,7 +361,7 @@ 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;
+ WFIFOL(fd,2) = char_id;
WFIFOB(fd,6) = result;
WFIFOSET(fd,7);
}
@@ -404,45 +370,87 @@ 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
+ mapif_Auction_close(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
+ mapif_Auction_close(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);
-
+ mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction closed.", auction->price, NULL);
// 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
+ 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
+ auction_delete(auction);
+
+ mapif_Auction_close(fd, char_id, 0); // You have ended the auction
+}
+
+static 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);
+}
+
+static 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(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( auction_count(char_id, true) > 4 )
+ {
+ 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 )
+ {
+ 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
+ mail_sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "You has placed a higher bid.", auction->price, NULL);
+ }
+
+ auction->buyer_id = char_id;
+ safestrncpy(auction->buyer_name, (char*)RFIFOP(fd,16), NAME_LENGTH);
+
+ 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
+
+ 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
+ mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your Auction!.", auction->buynow, NULL);
+
+ auction_delete(auction);
+ return;
+ }
+
+ auction->price = bid;
+ auction_save(auction);
+
+ mapif_Auction_bid(fd, char_id, 0, 1); // You have successfully bid in the auction
}
/*==========================================
@@ -456,6 +464,7 @@ int inter_auction_parse_frommap(int fd)
case 0x3051: mapif_parse_Auction_register(fd); break;
case 0x3052: mapif_parse_Auction_cancel(fd); break;
case 0x3053: mapif_parse_Auction_close(fd); break;
+ case 0x3055: mapif_parse_Auction_bid(fd); break;
default:
return 0;
}
diff --git a/src/char_sql/int_mail.c b/src/char_sql/int_mail.c
index 9ef9f9fd3..9ae4e1ccd 100644
--- a/src/char_sql/int_mail.c
+++ b/src/char_sql/int_mail.c
@@ -429,6 +429,27 @@ static void mapif_parse_Mail_send(int fd)
mapif_Mail_send(fd, &msg);
}
+void mail_sendmail(int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item)
+{
+ struct mail_message msg;
+ memset(&msg, 0, sizeof(struct mail_message));
+
+ msg.send_id = send_id;
+ safestrncpy(msg.send_name, send_name, NAME_LENGTH);
+ msg.dest_id = dest_id;
+ safestrncpy(msg.dest_name, dest_name, NAME_LENGTH);
+ safestrncpy(msg.title, title, MAIL_TITLE_LENGTH);
+ safestrncpy(msg.body, body, MAIL_BODY_LENGTH);
+ msg.zeny = zeny;
+ if( item != NULL )
+ memcpy(&msg.item, item, sizeof(struct item));
+
+ msg.timestamp = (int)calc_times();
+
+ mail_savemessage(&msg);
+ mapif_Mail_new(&msg);
+}
+
/*==========================================
* Packets From Map Server
*------------------------------------------*/
diff --git a/src/char_sql/int_mail.h b/src/char_sql/int_mail.h
index 8496f61fb..77db51e5b 100644
--- a/src/char_sql/int_mail.h
+++ b/src/char_sql/int_mail.h
@@ -5,6 +5,7 @@
#define _INT_MAIL_SQL_H_
int inter_mail_parse_frommap(int fd);
+void mail_sendmail(int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item);
int inter_mail_sql_init(void);
void inter_mail_sql_final(void);
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index 2271fe586..089e93740 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,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus]
+ -1,-1,10,10, 0,-1, 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/common/mmo.h b/src/common/mmo.h
index 6b6dfca7d..0d3ef44a6 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -298,7 +298,7 @@ struct auction_data {
short type;
unsigned short hours;
- unsigned int price, buynow;
+ int price, buynow;
unsigned int timestamp; // auction's end time
int auction_end_timer;
};
diff --git a/src/map/clif.c b/src/map/clif.c
index 2e0591c99..c4b0134a9 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -11716,7 +11716,7 @@ void clif_parse_Mail_send(int fd, struct map_session_data *sd)
* AUCTION SYSTEM
* By Zephyrus
*==========================================*/
-void clif_Auction_results(struct map_session_data *sd, short count, unsigned char *buf)
+void clif_Auction_results(struct map_session_data *sd, short count, short pages, unsigned char *buf)
{
int i, fd = sd->fd, len = sizeof(struct auction_data);
struct auction_data auction;
@@ -11726,7 +11726,7 @@ void clif_Auction_results(struct map_session_data *sd, short count, unsigned cha
WFIFOHEAD(fd,20);
WFIFOW(fd,0) = 0x252;
WFIFOW(fd,2) = 12 + (count * 83);
- WFIFOL(fd,4) = 1; // ??
+ WFIFOL(fd,4) = pages;
WFIFOL(fd,8) = count;
for( i = 0; i < count; i++ )
@@ -11915,7 +11915,7 @@ void clif_parse_Auction_register(int fd, struct map_session_data *sd)
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);
+ pc_delitem(sd, sd->auction.index, sd->auction.amount, 1);
sd->auction.amount = 0;
pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
}
@@ -11935,32 +11935,45 @@ void clif_parse_Auction_close(int fd, struct map_session_data *sd)
intif_Auction_close(sd->status.char_id, auction_id);
}
+void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
+{
+ unsigned int auction_id = RFIFOL(fd,2);
+ int bid = RFIFOL(fd,6);
+
+ if( bid <= 0 )
+ clif_Auction_message(fd, 0); // You have failed to bid into the auction
+ else if( bid > sd->status.zeny )
+ clif_Auction_message(fd, 8); // You do not have enough zeny
+ else
+ {
+ pc_payzeny(sd, bid);
+ intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
+ }
+}
+
/*------------------------------------------
* Auction Search
- * S 0251 <search type>.w <search price>.l <search text>.24B <01>.w
+ * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.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)
{
char search_text[NAME_LENGTH];
- short type = RFIFOW(fd,2);
+ short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
int price = RFIFOL(fd,4);
clif_parse_Auction_cancelreg(fd, sd);
safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
- intif_Auction_requestlist(sd->status.char_id, type, price, search_text);
+ intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
}
void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
{
short type = RFIFOW(fd,2) + 6;
- char search_text[NAME_LENGTH];
-
clif_parse_Auction_cancelreg(fd, sd);
- memset(&search_text, '\0', NAME_LENGTH);
- intif_Auction_requestlist(sd->status.char_id, type, 0, search_text);
+ intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
}
#endif
@@ -12023,6 +12036,9 @@ void clif_Auction_openwindow(struct map_session_data *sd)
{
int fd = sd->fd;
+ if( sd->state.storage_flag || sd->vender_id || sd->state.trading )
+ return;
+
WFIFOHEAD(fd,12);
WFIFOW(fd,0) = 0x25f;
WFIFOL(fd,2) = 0;
@@ -12499,6 +12515,9 @@ static int packetdb_readdb(void)
{clif_parse_Auction_setitem,"auctionsetitem"},
{clif_parse_Auction_cancelreg,"auctioncancelreg"},
{clif_parse_Auction_register,"auctionregister"},
+ {clif_parse_Auction_cancel,"auctioncancel"},
+ {clif_parse_Auction_close,"auctionclose"},
+ {clif_parse_Auction_bid,"auctionbid"},
#endif
{clif_parse_cashshop_buy,"cashshopbuy"},
{clif_parse_ViewPlayerEquip,"viewplayerequip"},
diff --git a/src/map/clif.h b/src/map/clif.h
index 9be840d72..58c088dad 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -409,9 +409,10 @@ void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title);
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_results(struct map_session_data *sd, short count, short pages, unsigned char *buf);
void clif_Auction_message(int fd, unsigned char flag);
void clif_Auction_close(int fd, unsigned char flag);
+void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd);
#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 ff18aecba..684353395 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,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus]
+ -1,-1, 7, 7, 7,11, 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,9 +1675,9 @@ static void intif_parse_Mail_new(int fd)
* AUCTION SYSTEM
* By Zephyrus
*==========================================*/
-int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext)
+int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext, short page)
{
- int len = NAME_LENGTH + 14;
+ int len = NAME_LENGTH + 16;
if( CheckForCharServer() )
return 0;
@@ -1688,7 +1688,8 @@ int intif_Auction_requestlist(int char_id, short type, int price, const char* se
WFIFOL(inter_fd,4) = char_id;
WFIFOW(inter_fd,8) = type;
WFIFOL(inter_fd,10) = price;
- memcpy(WFIFOP(inter_fd,14), searchtext, NAME_LENGTH);
+ WFIFOW(inter_fd,14) = page;
+ memcpy(WFIFOP(inter_fd,16), searchtext, NAME_LENGTH);
WFIFOSET(inter_fd,len);
return 0;
@@ -1697,12 +1698,12 @@ int intif_Auction_requestlist(int char_id, short type, int price, const char* se
static void intif_parse_Auction_results(int fd)
{
struct map_session_data *sd = map_charid2sd(RFIFOL(fd,4));
- short count = (RFIFOW(fd,2) - 8) / sizeof(struct auction_data);
+ short count = RFIFOW(fd,8), pages = RFIFOW(fd,10);
if( sd == NULL )
return;
- clif_Auction_results(sd, count, (char *)RFIFOP(fd,8));
+ clif_Auction_results(sd, count, pages, (char *)RFIFOP(fd,12));
}
int intif_Auction_register(struct auction_data *auction)
@@ -1800,6 +1801,61 @@ static void intif_parse_Auction_close(int fd)
return;
clif_Auction_close(sd->fd, result);
+ if( result == 0 )
+ {
+ clif_parse_Auction_cancelreg(fd, sd);
+ intif_Auction_requestlist(sd->status.char_id, 6, 0, "", 1);
+ }
+}
+
+int intif_Auction_bid(int char_id, const char* name, unsigned int auction_id, int bid)
+{
+ int len = 16 + NAME_LENGTH;
+
+ if( CheckForCharServer() )
+ return 0;
+
+ WFIFOHEAD(inter_fd,len);
+ WFIFOW(inter_fd,0) = 0x3055;
+ WFIFOW(inter_fd,2) = len;
+ WFIFOL(inter_fd,4) = char_id;
+ WFIFOL(inter_fd,8) = auction_id;
+ WFIFOL(inter_fd,12) = bid;
+ memcpy(WFIFOP(inter_fd,16), name, NAME_LENGTH);
+ WFIFOSET(inter_fd,len);
+
+ return 0;
+}
+
+static void intif_parse_Auction_bid(int fd)
+{
+ struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
+ int bid = RFIFOL(fd,6);
+ unsigned char result = RFIFOB(fd,10);
+
+ if( sd == NULL )
+ return;
+
+ clif_Auction_message(sd->fd, result);
+ if( bid > 0 )
+ pc_getzeny(sd, bid);
+ if( result == 1 )
+ { // To update the list, display your buy list
+ clif_parse_Auction_cancelreg(fd, sd);
+ intif_Auction_requestlist(sd->status.char_id, 7, 0, "", 1);
+ }
+}
+
+// Used to send 'You have won the auction' and 'You failed to won the auction' messages
+static void intif_parse_Auction_message(int fd)
+{
+ struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
+ unsigned char result = RFIFOB(fd,6);
+
+ if( sd == NULL )
+ return;
+
+ clif_Auction_message(sd->fd, result);
}
#endif
@@ -1885,6 +1941,8 @@ int intif_parse(int fd)
case 0x3851: intif_parse_Auction_register(fd); break;
case 0x3852: intif_parse_Auction_cancel(fd); break;
case 0x3853: intif_parse_Auction_close(fd); break;
+ case 0x3854: intif_parse_Auction_message(fd); break;
+ case 0x3855: intif_parse_Auction_bid(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 743057fb4..a713be7ea 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -84,10 +84,11 @@ 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 char_id, short type, int price, const char* searchtext);
+int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext, short page);
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);
+int intif_Auction_bid(int char_id, const char* name, unsigned int auction_id, int bid);
#endif
int CheckForCharServer(void);
diff --git a/src/map/script.c b/src/map/script.c
index ee5bbbdc5..36c29e8d5 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -13016,6 +13016,20 @@ BUILDIN_FUNC(openmail)
return 0;
}
+BUILDIN_FUNC(openauction)
+{
+ TBL_PC* sd;
+
+ sd = script_rid2sd(st);
+ if( sd == NULL )
+ return 0;
+
+#ifndef TXT_ONLY
+ clif_Auction_openwindow(sd);
+#endif
+ return 0;
+}
+
/// Modifies flags of cells in the specified area.
///
/// setcell "<map name>",<x1>,<y1>,<x2>,<y2>,<type>,<flag>;
@@ -13386,6 +13400,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(checkvending,"*"),
BUILDIN_DEF(checkchatting,"*"),
BUILDIN_DEF(openmail,""),
+ BUILDIN_DEF(openauction,""),
BUILDIN_DEF(setcell,"siiiiii"),
{NULL,NULL,NULL},
};