diff options
Diffstat (limited to 'src/char_sql')
-rw-r--r-- | src/char_sql/Makefile.in | 4 | ||||
-rw-r--r-- | src/char_sql/int_auction.c | 112 | ||||
-rw-r--r-- | src/char_sql/int_auction.h | 4 | ||||
-rw-r--r-- | src/char_sql/inter.c | 20 |
4 files changed, 110 insertions, 30 deletions
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 |