summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/packet_db.txt8
-rw-r--r--src/char_sql/Makefile.in4
-rw-r--r--src/char_sql/int_auction.c112
-rw-r--r--src/char_sql/int_auction.h4
-rw-r--r--src/char_sql/inter.c20
-rw-r--r--src/common/mmo.h19
-rw-r--r--src/map/battle.c2
-rw-r--r--src/map/battle.h2
-rw-r--r--src/map/clif.c217
-rw-r--r--src/map/clif.h5
-rw-r--r--src/map/intif.c56
-rw-r--r--src/map/intif.h3
-rw-r--r--src/map/itemdb.h17
-rw-r--r--src/map/mail.c1
-rw-r--r--src/map/map.h5
-rw-r--r--vcproj-8/char-server_sql.vcproj8
16 files changed, 428 insertions, 55 deletions
diff --git a/db/packet_db.txt b/db/packet_db.txt
index 89437a0c8..108beba7a 100644
--- a/db/packet_db.txt
+++ b/db/packet_db.txt
@@ -765,8 +765,8 @@ packet_ver: 18
0x0248,68
0x0249,3
0x024a,70
-0x024b,4
-0x024c,8
+0x024b,4,auctionregisterwindow,0
+0x024c,8,auctionsetitem,0
0x024d,14
0x024e,6
0x024f,10
@@ -797,7 +797,7 @@ packet_ver: 19
0x0251,4
//2005-08-08aSakexe
-0x024d,12
+0x024d,12,auctionregister,0
0x024e,4
//2005-08-17aSakexe
@@ -837,7 +837,7 @@ packet_ver: 19
//2005-11-07aSakexe
0x024e,6
-0x0251,34
+0x0251,34,auctionsearch,0
//2006-01-09aSakexe
0x0261,11
diff --git a/src/char_sql/Makefile.in b/src/char_sql/Makefile.in
index 8a422dcf7..ddc160e3f 100644
--- a/src/char_sql/Makefile.in
+++ b/src/char_sql/Makefile.in
@@ -14,8 +14,8 @@ COMMON_SQL_OBJ = ../common/obj_sql/sql.o
COMMON_H = ../common/sql.h
CHAR_OBJ = obj_sql/char.o obj_sql/inter.o obj_sql/int_party.o obj_sql/int_guild.o \
- obj_sql/int_storage.o obj_sql/int_pet.o obj_sql/int_homun.o obj_sql/int_mail.o
-CHAR_H = char.h inter.h int_party.h int_guild.h int_storage.h int_pet.h int_homun.h int_mail.h
+ obj_sql/int_storage.o obj_sql/int_pet.o obj_sql/int_homun.o obj_sql/int_mail.o obj_sql/int_auction.o
+CHAR_H = char.h inter.h int_party.h int_guild.h int_storage.h int_pet.h int_homun.h int_mail.h int_auction.h
HAVE_MYSQL=@HAVE_MYSQL@
ifeq ($(HAVE_MYSQL),yes)
diff --git a/src/char_sql/int_auction.c b/src/char_sql/int_auction.c
index 5d2a7fa9e..463115b10 100644
--- a/src/char_sql/int_auction.c
+++ b/src/char_sql/int_auction.c
@@ -17,6 +17,10 @@
#include <string.h>
#include <stdlib.h>
+// 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);
@@ -29,7 +33,7 @@ time_t calc_times(void)
return mktime(localtime(&temp));
}
-void inter_auction_save(struct auction_data *auction)
+void auction_save(struct auction_data *auction)
{
int j;
StringBuf buf;
@@ -39,8 +43,8 @@ void inter_auction_save(struct auction_data *auction)
return;
StringBuf_Init(&buf);
- StringBuf_Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%d', `nameid` = '%d', `refine` = '%d', `attribute` = '%d'",
- auction_db, auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, auction->timestamp, auction->item.nameid, auction->item.refine, auction->item.attribute);
+ StringBuf_Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%d', `nameid` = '%d', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'",
+ auction_db, auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ", `card%d` = '%d'", j, auction->item.card[j]);
StringBuf_Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id);
@@ -49,6 +53,7 @@ void inter_auction_save(struct auction_data *auction)
if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
@@ -61,6 +66,7 @@ void inter_auction_save(struct auction_data *auction)
static bool auction_create(struct auction_data *auction)
{
int j;
+
StringBuf buf;
SqlStmt* stmt;
@@ -68,11 +74,11 @@ static bool auction_create(struct auction_data *auction)
return false;
StringBuf_Init(&buf);
- StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`refine`,`attribute`");
+ StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`", auction_db);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
- StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%d','%d','%d','%d'",
- auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, auction->timestamp, auction->item.nameid, auction->item.refine, auction->item.attribute);
+ StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%d','%d',?,'%d','%d','%d'",
+ auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",'%d'", auction->item.card[j]);
StringBuf_AppendStr(&buf, ")");
@@ -80,19 +86,26 @@ static bool auction_create(struct auction_data *auction)
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
- || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH)) )
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
+ || SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
auction->auction_id = 0;
}
else
{
+ struct auction_data *auction_;
+
auction->item.amount = 1;
auction->item.identify = 1;
auction->auction_id = (unsigned int)SqlStmt_LastInsertId(stmt);
auction->auction_end_timer = add_timer( gettick() + ((auction->timestamp - (unsigned int)calc_times) * 1000) , auction_end_timer, auction->auction_id, 0);
- idb_put(auction_db_, auction->auction_id, auction);
+
+ CREATE(auction_, struct auction_data, 1);
+ memcpy(auction_, auction, sizeof(struct auction_data));
+ idb_put(auction_db_, auction_->auction_id, auction_);
}
SqlStmt_Free(stmt);
@@ -169,7 +182,6 @@ void auction_delete(struct auction_data *auction)
if( auction->auction_end_timer != -1 )
delete_timer(auction->auction_end_timer, auction_end_timer);
- aFree(auction);
idb_remove(auction_db_, auction_id);
}
@@ -184,10 +196,10 @@ void inter_auctions_fromsql(void)
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `auction_id`,`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,"
- "`price`,`buynow`,`hours`,`timestamp`,`nameid`,`refine`,`attribute`");
+ "`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`");
for( i = 0; i < MAX_SLOTS; i++ )
StringBuf_Printf(&buf, ",`card%d`", i);
- StringBuf_Printf(&buf, " FROM `%s` ORDER BY `id` DESC", auction_db);
+ StringBuf_Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", auction_db);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
@@ -209,15 +221,18 @@ void inter_auctions_fromsql(void)
item = &auction->item;
Sql_GetData(sql_handle, 9, &data, NULL); item->nameid = atoi(data);
- Sql_GetData(sql_handle,10, &data, NULL); item->refine = atoi(data);
- Sql_GetData(sql_handle,11, &data, NULL); item->attribute = atoi(data);
+ Sql_GetData(sql_handle,10, &data, NULL); safestrncpy(auction->item_name, data, ITEM_NAME_LENGTH);
+ Sql_GetData(sql_handle,11, &data, NULL); auction->type = atoi(data);
+
+ Sql_GetData(sql_handle,12, &data, NULL); item->refine = atoi(data);
+ Sql_GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data);
item->identify = 1;
item->amount = 1;
for( i = 0; i < MAX_SLOTS; i++ )
{
- Sql_GetData(sql_handle, 12 + i, &data, NULL);
+ Sql_GetData(sql_handle, 14 + i, &data, NULL);
item->card[i] = atoi(data);
}
@@ -233,6 +248,75 @@ void inter_auctions_fromsql(void)
Sql_FreeResult(sql_handle);
}
+static void mapif_Auction_sendlist(int fd, int account_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;
+ memcpy(WFIFOP(fd,8), buf, len - 8);
+ WFIFOSET(fd,len);
+}
+
+static void mapif_parse_Auction_requestlist(int fd)
+{
+ char searchtext[NAME_LENGTH];
+ int account_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)];
+ DBIterator* iter;
+ DBKey key;
+ struct auction_data *auction;
+ short i = 0;
+
+ memcpy(searchtext, RFIFOP(fd,14), 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) )
+ {
+ 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 && auction->price > price) ||
+ (type == 5 && strstr(auction->item_name, searchtext)) )
+ continue;
+
+ memcpy(WBUFP(buf, i * len), auction, len);
+ i++;
+ }
+ iter->destroy(iter);
+
+ mapif_Auction_sendlist(fd, account_id, i, buf);
+}
+
+static void mapif_parse_Auction_register(int fd)
+{
+ int account_id = RFIFOL(fd,4);
+ struct auction_data auction;
+
+ memcpy(&auction, RFIFOP(fd,8), sizeof(struct auction_data));
+ auction_create(&auction);
+}
+
+/*==========================================
+ * Packets From Map Server
+ *------------------------------------------*/
+int inter_auction_parse_frommap(int fd)
+{
+ switch(RFIFOW(fd,0))
+ {
+ case 0x3050: mapif_parse_Auction_requestlist(fd); break;
+ case 0x3051: mapif_parse_Auction_register(fd); break;
+ default:
+ return 0;
+ }
+ return 1;
+}
+
int inter_auction_sql_init(void)
{
auction_db_ = idb_alloc(DB_OPT_RELEASE_DATA);
diff --git a/src/char_sql/int_auction.h b/src/char_sql/int_auction.h
index 061f0855d..f7826726c 100644
--- a/src/char_sql/int_auction.h
+++ b/src/char_sql/int_auction.h
@@ -4,5 +4,9 @@
#ifndef _INT_AUCTION_SQL_H_
#define _INT_AUCTION_SQL_H_
+int inter_auction_parse_frommap(int fd);
+
+int inter_auction_sql_init(void);
+void inter_auction_sql_final(void);
#endif /* _INT_AUCTION_SQL_H_ */
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index 9cf89ae54..451ffb6b7 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -16,6 +16,7 @@
#include "int_pet.h"
#include "int_homun.h"
#include "int_mail.h"
+#include "int_auction.h"
#include <stdio.h>
#include <string.h>
@@ -47,19 +48,6 @@ static struct accreg *accreg_pt;
unsigned int party_share_level = 10;
char main_chat_nick[16] = "Main";
-// sending packet list
-// NOTE: This variable ain't used at all! And it's confusing.. where do I add that the length of packet 0x2b07 is 10? x.x [Skotlex]
-int inter_send_packet_length[] = {
- -1,-1,27,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3800-
- -1, 7, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, // 3810-
- 35,-1,11,15, 34,29, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, // 3820-
- 10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, // 3830-
- 9, 9,-1, 0, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, // 3840-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3850-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3860-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3870-
- 11,-1, 7, 3, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3880-
-};
// recv. packet list
int inter_recv_packet_length[] = {
-1,-1, 7,-1, -1,13,36, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3000-
@@ -67,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-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050-
+ -1,-1, 0, 0, 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-
@@ -398,6 +386,7 @@ int inter_init_sql(const char *file)
inter_homunculus_sql_init(); // albator
inter_accreg_sql_init();
inter_mail_sql_init();
+ inter_auction_sql_init();
sql_ping_init();
#endif //TXT_SQL_CONVERT
@@ -449,6 +438,8 @@ void inter_final(void)
inter_party_sql_final();
inter_pet_sql_final();
inter_homunculus_sql_final(); //[orn]
+ inter_mail_sql_final();
+ inter_auction_sql_final();
if (accreg_pt) aFree(accreg_pt);
return;
@@ -865,6 +856,7 @@ int inter_parse_frommap(int fd)
|| inter_pet_parse_frommap(fd)
|| inter_homunculus_parse_frommap(fd)
|| inter_mail_parse_frommap(fd)
+ || inter_auction_parse_frommap(fd)
)
break;
else
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 2ffcc33c8..6b6dfca7d 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -107,6 +107,22 @@
#define MAIL_TITLE_LENGTH 40
#define MAIL_BODY_LENGTH 200
+enum item_types {
+ IT_HEALING = 0,
+ IT_UNKNOWN, //1
+ IT_USABLE, //2
+ IT_ETC, //3
+ IT_WEAPON, //4
+ IT_ARMOR, //5
+ IT_CARD, //6
+ IT_PETEGG, //7
+ IT_PETARMOR,//8
+ IT_UNKNOWN2,//9
+ IT_AMMO, //10
+ IT_DELAYCONSUME,//11
+ IT_MAX
+};
+
struct item {
int id;
short nameid;
@@ -277,6 +293,9 @@ struct auction_data {
char buyer_name[NAME_LENGTH];
struct item item;
+ // This data is required for searching, as itemdb is not read by char server
+ char item_name[ITEM_NAME_LENGTH];
+ short type;
unsigned short hours;
unsigned int price, buynow;
diff --git a/src/map/battle.c b/src/map/battle.c
index fc88611dd..3c467ff2e 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -3652,6 +3652,8 @@ static const struct _battle_data {
{ "idle_no_autoloot", &battle_config.idle_no_autoloot, 0, 0, INT_MAX, },
{ "max_guild_alliance", &battle_config.max_guild_alliance, 3, 1, 3, },
{ "ksprotection", &battle_config.ksprotection, 5000, 0, INT_MAX, },
+ { "auction_feeperhour", &battle_config.auction_feeperhour, 12000, 0, INT_MAX, },
+ { "auction_maximumprice", &battle_config.auction_maximumprice, 500000000, 0, MAX_ZENY, },
};
diff --git a/src/map/battle.h b/src/map/battle.h
index 738f1c388..042b83cda 100644
--- a/src/map/battle.h
+++ b/src/map/battle.h
@@ -444,6 +444,8 @@ extern struct Battle_Config
int idle_no_autoloot;
int max_guild_alliance;
int ksprotection;
+ int auction_feeperhour;
+ int auction_maximumprice;
} battle_config;
void do_init_battle(void);
diff --git a/src/map/clif.c b/src/map/clif.c
index c815fd7b3..3088b040b 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -11711,6 +11711,218 @@ void clif_parse_Mail_send(int fd, struct map_session_data *sd)
sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
}
+/*==========================================
+ * AUCTION SYSTEM
+ * By Zephyrus
+ *==========================================*/
+void clif_Auction_results(struct map_session_data *sd, short count, unsigned char *buf)
+{
+ int i, fd = sd->fd, len = sizeof(struct auction_data);
+ struct auction_data auction;
+ struct item_data *item;
+ int k;
+
+ WFIFOHEAD(fd,20);
+ WFIFOW(fd,0) = 0x252;
+ WFIFOW(fd,2) = 12 + (count * 83);
+ WFIFOL(fd,4) = 1; // ??
+ WFIFOL(fd,8) = count;
+
+ for( i = 0; i < count; i++ )
+ {
+ memcpy(&auction, RBUFP(buf,i * len), len);
+ k = 12 + (i * 83);
+
+ WFIFOL(fd,k) = auction.auction_id;
+ safestrncpy(WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
+
+ if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
+ WFIFOW(fd,28+k) = item->view_id;
+ else
+ WFIFOW(fd,28+k) = auction.item.nameid;
+
+ WFIFOW(fd,30+k) = auction.type;
+ WFIFOW(fd,32+k) = 0; // ??
+ WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
+ WFIFOB(fd,36+k) = auction.item.identify;
+ WFIFOB(fd,37+k) = auction.item.attribute;
+ WFIFOB(fd,38+k) = auction.item.refine;
+ WFIFOW(fd,39+k) = auction.item.card[0];
+ WFIFOW(fd,41+k) = auction.item.card[1];
+ WFIFOW(fd,43+k) = auction.item.card[2];
+ WFIFOW(fd,45+k) = auction.item.card[3];
+ WFIFOL(fd,47+k) = auction.price;
+ WFIFOL(fd,51+k) = auction.buynow;
+ safestrncpy(WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
+ WFIFOL(fd,79+k) = auction.timestamp;
+ }
+ WFIFOSET(fd, 12 + (count * 83));
+}
+
+static void clif_Auction_setitem(int fd, int index, bool fail)
+{
+ WFIFOHEAD(fd,packet_len(0x256));
+ WFIFOW(fd,0) = 0x256;
+ WFIFOW(fd,2) = index;
+ WFIFOB(fd,4) = fail;
+ WFIFOSET(fd,packet_len(0x256));
+}
+
+void clif_parse_Auction_registerwindow(int fd, struct map_session_data *sd)
+{
+ // RFIFOW(fd,2):
+ // = 0 means player opened the register window
+ // = 1 means player press the Cancel button, in that window.
+ // But... if player just enter the register window and press X to close, no packet is send.
+ sd->auction.amount = 0;
+}
+
+void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
+{
+ int idx = RFIFOW(fd,2) - 2;
+ int amount = RFIFOL(fd,4); // Allways 1
+ struct item_data *item;
+
+ if( sd->auction.amount > 0 )
+ sd->auction.amount = 0;
+
+ if( idx < 0 || idx > MAX_INVENTORY )
+ {
+ ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
+ return;
+ }
+
+ if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
+ { // By client, amount is allways set to 1. Maybe this is a future implementation.
+ ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
+ return;
+ }
+
+ if( (item = itemdb_search(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) )
+ { // Consumible or pets are not allowed
+ clif_Auction_setitem(sd->fd, idx, true);
+ return;
+ }
+
+ if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify )
+ { // Quest Item or something else
+ clif_Auction_setitem(sd->fd, idx, true);
+ return;
+ }
+
+ sd->auction.index = idx;
+ sd->auction.amount = amount;
+ clif_Auction_setitem(fd, idx, false);
+}
+
+// 0 = You have failed to bid into the auction
+// 1 = You have successfully bid in the auction
+// 2 = The auction has been canceled
+// 3 = An auction with at least one bidder cannot be canceled
+// 4 = You cannot register more than 5 items in an auction at a time
+// 5 = You do not have enough Zeny to pay the Auction Fee
+// 6 = You have won the auction
+// 7 = You have failed to win the auction
+// 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)
+{
+ WFIFOHEAD(fd,3);
+ WFIFOW(fd,0) = 0x250;
+ WFIFOB(fd,2) = flag;
+ WFIFOSET(fd,3);
+}
+
+void clif_parse_Auction_register(int fd, struct map_session_data *sd)
+{
+ struct auction_data auction;
+ struct item_data *item;
+
+ auction.price = RFIFOL(fd,2);
+ auction.buynow = RFIFOL(fd,6);
+ auction.hours = RFIFOW(fd,10);
+
+ // Invalid Situations...
+ if( sd->auction.amount < 1 )
+ {
+ ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
+ return;
+ }
+
+ if( auction.price >= auction.buynow )
+ {
+ ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
+ return;
+ }
+
+ if( auction.hours < 1 || auction.hours > 48 )
+ {
+ ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
+ return;
+ }
+
+ // Auction checks...
+ if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
+ {
+ clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
+ return;
+ }
+
+ if( auction.buynow > battle_config.auction_maximumprice )
+ { // Zeny Limits
+ auction.buynow = battle_config.auction_maximumprice;
+ if( auction.price >= auction.buynow )
+ auction.price = auction.buynow - 1;
+ }
+
+ auction.seller_id = sd->status.char_id;
+ safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
+ auction.buyer_id = 0;
+ memset(&auction.buyer_name, '\0', NAME_LENGTH);
+
+ if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
+ {
+ clif_Auction_message(fd, 2); // The auction has been canceled
+ return;
+ }
+
+ if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
+ { // Just in case
+ clif_Auction_message(fd, 2); // The auction has been canceled
+ 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);
+}
+
+/*------------------------------------------
+ * Auction Search
+ * S 0251 <search type>.w <search price>.l <search text>.24B <01>.w
+ *------------------------------------------*/
+void clif_parse_Auction_search(int fd, struct map_session_data* sd)
+{
+ char search_text[NAME_LENGTH];
+ short type = RFIFOW(fd,2);
+ 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);
+}
+
#endif
/*==========================================
@@ -12241,6 +12453,11 @@ static int packetdb_readdb(void)
{clif_parse_Mail_setattach,"mailsetattach"},
{clif_parse_Mail_winopen,"mailwinopen"},
{clif_parse_Mail_send,"mailsend"},
+ // AUCTION SYSTEM
+ {clif_parse_Auction_search,"auctionsearch"},
+ {clif_parse_Auction_setitem,"auctionsetitem"},
+ {clif_parse_Auction_registerwindow,"auctionregisterwindow"},
+ {clif_parse_Auction_register,"auctionregister"},
#endif
{clif_parse_cashshop_buy,"cashshopbuy"},
{clif_parse_ViewPlayerEquip,"viewplayerequip"},
diff --git a/src/map/clif.h b/src/map/clif.h
index d8714554d..aed08946b 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -123,7 +123,7 @@ int clif_scriptinput(struct map_session_data*,int); //self
int clif_scriptinputstr(struct map_session_data *sd,int npcid); // self
int clif_cutin(struct map_session_data* sd, const char* image, int type); //self
int clif_viewpoint(struct map_session_data*,int,int,int,int,int,int); //self
-int clif_additem(struct map_session_data*,int,int,int); //self
+int clif_additem(struct map_session_data *sd, int n, int amount, int fail); // self
int clif_delitem(struct map_session_data*,int,int); //self
int clif_updatestatus(struct map_session_data*,int); //self
int clif_changestatus(struct block_list*,int,int); //area
@@ -301,7 +301,6 @@ int clif_guild_allianceinfo(struct map_session_data *sd);
int clif_guild_memberlist(struct map_session_data *sd);
int clif_guild_skillinfo(struct map_session_data *sd);
int clif_guild_send_onlineinfo(struct map_session_data *sd); //[LuzZza]
-int clif_guild_masterormember(struct map_session_data *sd);
int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag);
int clif_guild_invite(struct map_session_data *sd,struct guild *g);
int clif_guild_inviteack(struct map_session_data *sd,int flag);
@@ -409,6 +408,8 @@ void clif_Mail_send(int fd, bool fail);
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);
#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 b15987018..fe73d46bb 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -1671,6 +1671,57 @@ static void intif_parse_Mail_new(int fd)
clif_Mail_new(sd->fd, mail_id, sender_name, title);
}
+/*==========================================
+ * AUCTION SYSTEM
+ * By Zephyrus
+ *==========================================*/
+int intif_Auction_requestlist(int account_id, short type, int price, const char* searchtext)
+{
+ int len = NAME_LENGTH + 14;
+
+ if( CheckForCharServer() )
+ return 0;
+
+ WFIFOHEAD(inter_fd,len);
+ WFIFOW(inter_fd,0) = 0x3050;
+ WFIFOW(inter_fd,2) = len;
+ WFIFOL(inter_fd,4) = account_id;
+ WFIFOW(inter_fd,8) = type;
+ WFIFOL(inter_fd,10) = price;
+ memcpy(WFIFOP(inter_fd,14), searchtext, NAME_LENGTH);
+ WFIFOSET(inter_fd,len);
+
+ return 0;
+}
+
+static void intif_parse_Auction_results(int fd)
+{
+ struct map_session_data *sd = map_id2sd(RFIFOL(fd,4));
+ short count = (RFIFOW(fd,2) - 8) / sizeof(struct auction_data);
+
+ if( sd == NULL )
+ return;
+
+ clif_Auction_results(sd, count, (char *)RFIFOP(fd,8));
+}
+
+int intif_Auction_register(int account_id, struct auction_data *auction)
+{
+ int len = sizeof(struct auction_data) + 8;
+
+ if( CheckForCharServer() )
+ return 0;
+
+ 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));
+ WFIFOSET(inter_fd,len);
+
+ return 0;
+}
+
#endif
//-----------------------------------------------------------------
@@ -1741,16 +1792,17 @@ int intif_parse(int fd)
case 0x3841: intif_parse_GuildCastleDataSave(fd); break;
case 0x3842: intif_parse_GuildCastleAllDataLoad(fd); break;
case 0x3843: intif_parse_GuildMasterChanged(fd); break;
-// Mail System
#ifndef TXT_ONLY
+// Mail System
case 0x3848: intif_parse_Mail_inboxreceived(fd); break;
case 0x3849: intif_parse_Mail_new(fd); break;
case 0x384a: intif_parse_Mail_getattach(fd); break;
case 0x384b: intif_parse_Mail_delete(fd); break;
case 0x384c: intif_parse_Mail_return(fd); break;
case 0x384d: intif_parse_Mail_send(fd); break;
+// Auction System
+ case 0x3850: intif_parse_Auction_results(fd); break;
#endif
-// End of Mail System
case 0x3880: intif_parse_CreatePet(fd); break;
case 0x3881: intif_parse_RecvPetData(fd); break;
case 0x3882: intif_parse_SavePetOk(fd); break;
diff --git a/src/map/intif.h b/src/map/intif.h
index 4adfc0a6b..d2e3ca4f8 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -82,6 +82,9 @@ int intif_Mail_getattach(int char_id, int mail_id);
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);
#endif
int CheckForCharServer(void);
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index 865ceaf9d..6be49f3e9 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -17,23 +17,6 @@
#define ITEMID_TRAP 1065
-
-enum item_types {
- IT_HEALING = 0,
- IT_UNKNOWN, //1
- IT_USABLE, //2
- IT_ETC, //3
- IT_WEAPON, //4
- IT_ARMOR, //5
- IT_CARD, //6
- IT_PETEGG, //7
- IT_PETARMOR,//8
- IT_UNKNOWN2,//9
- IT_AMMO, //10
- IT_DELAYCONSUME,//11
- IT_MAX
-};
-
//The only item group required by the code to be known. See const.txt for the full list.
#define IG_FINDINGORE 6
#define IG_POTION 37
diff --git a/src/map/mail.c b/src/map/mail.c
index b2a4697e5..0f03ddd5c 100644
--- a/src/map/mail.c
+++ b/src/map/mail.c
@@ -28,6 +28,7 @@ void mail_clear(struct map_session_data *sd)
sd->mail.index = 0;
sd->mail.amount = 0;
sd->mail.zeny = 0;
+ sd->auction.amount = 0;
return;
}
diff --git a/src/map/map.h b/src/map/map.h
index 687b89731..8ded26f9d 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -784,6 +784,11 @@ struct map_session_data {
int cashPoints, kafraPoints;
+ // Auction System [Zephyrus]
+ struct {
+ int index, amount;
+ } auction;
+
// Mail System [Zephyrus]
struct {
short nameid;
diff --git a/vcproj-8/char-server_sql.vcproj b/vcproj-8/char-server_sql.vcproj
index c8c15893e..6a77ad245 100644
--- a/vcproj-8/char-server_sql.vcproj
+++ b/vcproj-8/char-server_sql.vcproj
@@ -346,6 +346,14 @@
>
</File>
<File
+ RelativePath="..\src\char_sql\int_auction.c"
+ >
+ </File>
+ <File
+ RelativePath="..\src\char_sql\int_auction.h"
+ >
+ </File>
+ <File
RelativePath="..\src\char_sql\int_guild.c"
>
</File>