summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/char/char.c2
-rw-r--r--src/char/int_auction.c112
-rw-r--r--src/char/int_auction.h19
-rw-r--r--src/char/inter.c6
-rw-r--r--src/char/mapif.c23
-rw-r--r--src/char/mapif.h11
6 files changed, 118 insertions, 55 deletions
diff --git a/src/char/char.c b/src/char/char.c
index b4dd60e6d..d789de027 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -16,6 +16,7 @@
#include <time.h>
#include "HPMchar.h"
+#include "int_auction.h"
#include "int_elemental.h"
#include "int_guild.h"
#include "int_homun.h"
@@ -6004,6 +6005,7 @@ void char_load_defaults(void)
char_defaults();
loginif_defaults();
mapif_defaults();
+ inter_auction_defaults();
}
void char_defaults(void)
diff --git a/src/char/int_auction.c b/src/char/int_auction.c
index cab986101..4ae4b8bc9 100644
--- a/src/char/int_auction.c
+++ b/src/char/int_auction.c
@@ -23,10 +23,9 @@
#include "../common/strlib.h"
#include "../common/timer.h"
-static DBMap* auction_db_ = NULL; // int auction_id -> struct auction_data*
+struct inter_auction_interface inter_auction_s;
-void inter_auction_delete(struct auction_data *auction);
-static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data);
+static DBMap* auction_db_ = NULL; // int auction_id -> struct auction_data*
static int inter_auction_count(int char_id, bool buy)
{
@@ -115,7 +114,7 @@ unsigned int inter_auction_create(struct auction_data *auction)
auction->item.expire_time = 0;
auction->auction_id = (unsigned int)SQL->StmtLastInsertId(stmt);
- auction->auction_end_timer = timer->add( timer->gettick() + tick , inter_auction_end_timer, auction->auction_id, 0);
+ auction->auction_end_timer = timer->add( timer->gettick() + tick , inter_auction->end_timer, auction->auction_id, 0);
ShowInfo("New Auction %u | time left %"PRId64" ms | By %s.\n", auction->auction_id, tick, auction->seller_name);
CREATE(auction_, struct auction_data, 1);
@@ -129,7 +128,7 @@ unsigned int inter_auction_create(struct auction_data *auction)
return auction->auction_id;
}
-static void mapif_Auction_message(int char_id, unsigned char result)
+void mapif_auction_message(int char_id, unsigned char result)
{
unsigned char buf[74];
@@ -146,7 +145,7 @@ static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data) {
if( auction->buyer_id )
{
inter_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
+ mapif->auction_message(auction->buyer_id, 6); // You have won the auction
inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your auction!.", auction->price, NULL);
}
else
@@ -155,7 +154,7 @@ static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data) {
ShowInfo("Auction End: id %u.\n", auction->auction_id);
auction->auction_end_timer = INVALID_TIMER;
- inter_auction_delete(auction);
+ inter_auction->delete_(auction);
}
return 0;
@@ -169,7 +168,7 @@ void inter_auction_delete(struct auction_data *auction)
Sql_ShowDebug(sql_handle);
if( auction->auction_end_timer != INVALID_TIMER )
- timer->delete(auction->auction_end_timer, inter_auction_end_timer);
+ timer->delete(auction->auction_end_timer, inter_auction->end_timer);
idb_remove(auction_db_, auction_id);
}
@@ -233,14 +232,14 @@ void inter_auctions_fromsql(void)
else
endtick = tick + 10000; // 10 seconds to process ended auctions
- auction->auction_end_timer = timer->add(endtick, inter_auction_end_timer, auction->auction_id, 0);
+ auction->auction_end_timer = timer->add(endtick, inter_auction->end_timer, auction->auction_id, 0);
idb_put(auction_db_, auction->auction_id, auction);
}
SQL->FreeResult(sql_handle);
}
-static void mapif_Auction_sendlist(int fd, int char_id, short count, short pages, unsigned char *buf)
+void mapif_auction_sendlist(int fd, int char_id, short count, short pages, unsigned char *buf)
{
int len = (sizeof(struct auction_data) * count) + 12;
@@ -254,7 +253,7 @@ static void mapif_Auction_sendlist(int fd, int char_id, short count, short pages
WFIFOSET(fd,len);
}
-static void mapif_parse_Auction_requestlist(int fd)
+void mapif_parse_auction_requestlist(int fd)
{
char searchtext[NAME_LENGTH];
int char_id = RFIFOL(fd,4), len = sizeof(struct auction_data);
@@ -294,10 +293,10 @@ static void mapif_parse_Auction_requestlist(int fd)
}
dbi_destroy(iter);
- mapif_Auction_sendlist(fd, char_id, j, pages, buf);
+ mapif->auction_sendlist(fd, char_id, j, pages, buf);
}
-static void mapif_Auction_register(int fd, struct auction_data *auction)
+void mapif_auction_register(int fd, struct auction_data *auction)
{
int len = sizeof(struct auction_data) + 4;
@@ -308,20 +307,20 @@ static void mapif_Auction_register(int fd, struct auction_data *auction)
WFIFOSET(fd,len);
}
-static void mapif_parse_Auction_register(int fd)
+void mapif_parse_auction_register(int fd)
{
struct auction_data auction;
if( RFIFOW(fd,2) != sizeof(struct auction_data) + 4 )
return;
memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
- if( inter_auction_count(auction.seller_id, false) < 5 )
- auction.auction_id = inter_auction_create(&auction);
+ if( inter_auction->count(auction.seller_id, false) < 5 )
+ auction.auction_id = inter_auction->create(&auction);
- mapif_Auction_register(fd, &auction);
+ mapif->auction_register(fd, &auction);
}
-static void mapif_Auction_cancel(int fd, int char_id, unsigned char result)
+void mapif_auction_cancel(int fd, int char_id, unsigned char result)
{
WFIFOHEAD(fd,7);
WFIFOW(fd,0) = 0x3852;
@@ -330,36 +329,36 @@ static void mapif_Auction_cancel(int fd, int char_id, unsigned char result)
WFIFOSET(fd,7);
}
-static void mapif_parse_Auction_cancel(int fd)
+void mapif_parse_auction_cancel(int fd)
{
int char_id = RFIFOL(fd,2), auction_id = RFIFOL(fd,6);
struct auction_data *auction;
if( (auction = (struct auction_data *)idb_get(auction_db_, auction_id)) == NULL )
{
- mapif_Auction_cancel(fd, char_id, 1); // Bid Number is Incorrect
+ 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
+ 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
+ mapif->auction_cancel(fd, char_id, 3); // An auction with at least one bidder cannot be canceled
return;
}
inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction canceled.", 0, &auction->item);
- inter_auction_delete(auction);
+ inter_auction->delete_(auction);
- mapif_Auction_cancel(fd, char_id, 0); // The auction has been canceled
+ 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)
+void mapif_auction_close(int fd, int char_id, unsigned char result)
{
WFIFOHEAD(fd,7);
WFIFOW(fd,0) = 0x3853;
@@ -368,26 +367,26 @@ static void mapif_Auction_close(int fd, int char_id, unsigned char result)
WFIFOSET(fd,7);
}
-static void mapif_parse_Auction_close(int fd)
+void mapif_parse_auction_close(int fd)
{
int char_id = RFIFOL(fd,2), auction_id = RFIFOL(fd,6);
struct auction_data *auction;
if( (auction = (struct auction_data *)idb_get(auction_db_, auction_id)) == NULL )
{
- mapif_Auction_close(fd, char_id, 2); // Bid Number is Incorrect
+ mapif->auction_close(fd, char_id, 2); // Bid Number is Incorrect
return;
}
if( auction->seller_id != char_id )
{
- mapif_Auction_close(fd, char_id, 1); // You cannot end the auction
+ mapif->auction_close(fd, char_id, 1); // You cannot end the auction
return;
}
if( auction->buyer_id == 0 )
{
- mapif_Auction_close(fd, char_id, 1); // You cannot end the auction
+ mapif->auction_close(fd, char_id, 1); // You cannot end the auction
return;
}
@@ -395,13 +394,13 @@ static void mapif_parse_Auction_close(int fd)
inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction closed.", auction->price, NULL);
// Send Item to Buyer
inter_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
- inter_auction_delete(auction);
+ mapif->auction_message(auction->buyer_id, 6); // You have won the auction
+ inter_auction->delete_(auction);
- mapif_Auction_close(fd, char_id, 0); // You have ended the 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)
+void mapif_auction_bid(int fd, int char_id, int bid, unsigned char result)
{
WFIFOHEAD(fd,11);
WFIFOW(fd,0) = 0x3855;
@@ -411,7 +410,7 @@ static void mapif_Auction_bid(int fd, int char_id, int bid, unsigned char result
WFIFOSET(fd,11);
}
-static void mapif_parse_Auction_bid(int fd)
+void mapif_parse_auction_bid(int fd)
{
int char_id = RFIFOL(fd,4), bid = RFIFOL(fd,12);
unsigned int auction_id = RFIFOL(fd,8);
@@ -419,13 +418,13 @@ static void mapif_parse_Auction_bid(int fd)
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
+ mapif->auction_bid(fd, char_id, bid, 0); // You have failed to bid in the auction
return;
}
- if( inter_auction_count(char_id, true) > 4 && bid < auction->buynow && auction->buyer_id != char_id )
+ if( inter_auction->count(char_id, true) > 4 && bid < auction->buynow && auction->buyer_id != char_id )
{
- mapif_Auction_bid(fd, char_id, bid, 9); // You cannot place more than 5 bids at a time
+ mapif->auction_bid(fd, char_id, bid, 9); // You cannot place more than 5 bids at a time
return;
}
@@ -434,7 +433,7 @@ static void mapif_parse_Auction_bid(int fd)
if( auction->buyer_id != char_id )
{
inter_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
+ mapif->auction_message(auction->buyer_id, 7); // You have failed to win the auction
}
else
inter_mail_sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "You have placed a higher bid.", auction->price, NULL);
@@ -446,19 +445,19 @@ static void mapif_parse_Auction_bid(int fd)
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
+ mapif->auction_bid(fd, char_id, bid - auction->buynow, 1); // You have successfully bid in the auction
inter_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
+ mapif->auction_message(char_id, 6); // You have won the auction
inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your auction!.", auction->buynow, NULL);
- inter_auction_delete(auction);
+ inter_auction->delete_(auction);
return;
}
- inter_auction_save(auction);
+ inter_auction->save(auction);
- mapif_Auction_bid(fd, char_id, 0, 1); // You have successfully bid in the auction
+ mapif->auction_bid(fd, char_id, 0, 1); // You have successfully bid in the auction
}
/*==========================================
@@ -468,11 +467,11 @@ 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;
- case 0x3052: mapif_parse_Auction_cancel(fd); break;
- case 0x3053: mapif_parse_Auction_close(fd); break;
- case 0x3055: mapif_parse_Auction_bid(fd); break;
+ 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;
+ case 0x3055: mapif->parse_auction_bid(fd); break;
default:
return 0;
}
@@ -482,7 +481,7 @@ int inter_auction_parse_frommap(int fd)
int inter_auction_sql_init(void)
{
auction_db_ = idb_alloc(DB_OPT_RELEASE_DATA);
- inter_auctions_fromsql();
+ inter_auction->fromsql();
return 0;
}
@@ -493,3 +492,18 @@ void inter_auction_sql_final(void)
return;
}
+
+void inter_auction_defaults(void)
+{
+ inter_auction = &inter_auction_s;
+
+ inter_auction->count = inter_auction_count;
+ inter_auction->save = inter_auction_save;
+ inter_auction->create = inter_auction_create;
+ inter_auction->end_timer = inter_auction_end_timer;
+ inter_auction->delete_ = inter_auction_delete;
+ inter_auction->fromsql = inter_auctions_fromsql;
+ inter_auction->parse_frommap = inter_auction_parse_frommap;
+ inter_auction->sql_init = inter_auction_sql_init;
+ inter_auction->sql_final = inter_auction_sql_final;
+}
diff --git a/src/char/int_auction.h b/src/char/int_auction.h
index 17fd75a58..d44ff37cb 100644
--- a/src/char/int_auction.h
+++ b/src/char/int_auction.h
@@ -4,9 +4,22 @@
#ifndef CHAR_INT_AUCTION_H
#define CHAR_INT_AUCTION_H
-int inter_auction_parse_frommap(int fd);
+#include "../common/mmo.h"
-int inter_auction_sql_init(void);
-void inter_auction_sql_final(void);
+void inter_auction_defaults(void);
+
+struct inter_auction_interface {
+ int (*count) (int char_id, bool buy);
+ void (*save) (struct auction_data *auction);
+ unsigned int (*create) (struct auction_data *auction);
+ int (*end_timer) (int tid, int64 tick, int id, intptr_t data);
+ void (*delete_) (struct auction_data *auction);
+ void (*fromsql) (void);
+ int (*parse_frommap) (int fd);
+ int (*sql_init) (void);
+ void (*sql_final) (void);
+};
+
+struct inter_auction_interface *inter_auction;
#endif /* CHAR_INT_AUCTION_H */
diff --git a/src/char/inter.c b/src/char/inter.c
index cda4c8ed8..2df4d668f 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -1034,7 +1034,7 @@ int inter_init_sql(const char *file)
inter_mercenary_sql_init();
inter_elemental_sql_init();
inter_mail_sql_init();
- inter_auction_sql_init();
+ inter_auction->sql_init();
geoip_init();
inter_msg_config_read("conf/messages.conf", false);
@@ -1054,7 +1054,7 @@ void inter_final(void)
inter_mercenary_sql_final();
inter_elemental_sql_final();
inter_mail_sql_final();
- inter_auction_sql_final();
+ inter_auction->sql_final();
geoip_final(true);
inter_do_final_msg();
@@ -1461,7 +1461,7 @@ int inter_parse_frommap(int fd)
|| inter_mercenary_parse_frommap(fd)
|| inter_elemental_parse_frommap(fd)
|| inter_mail_parse_frommap(fd)
- || inter_auction_parse_frommap(fd)
+ || inter_auction->parse_frommap(fd)
|| inter_quest_parse_frommap(fd)
)
break;
diff --git a/src/char/mapif.c b/src/char/mapif.c
index 7c807e21f..dfa8f437b 100644
--- a/src/char/mapif.c
+++ b/src/char/mapif.c
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include "char.h"
+#include "int_auction.h"
#include "../common/cbasetypes.h"
#include "../common/mmo.h"
#include "../common/random.h"
@@ -27,6 +28,17 @@ int mapif_sendall(unsigned char *buf, unsigned int len);
int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len);
int mapif_send(int fd, unsigned char *buf, unsigned int len);
void mapif_send_users_count(int users);
+void mapif_auction_message(int char_id, unsigned char result);
+void mapif_auction_sendlist(int fd, int char_id, short count, short pages, unsigned char *buf);
+void mapif_parse_auction_requestlist(int fd);
+void mapif_auction_register(int fd, struct auction_data *auction);
+void mapif_parse_auction_register(int fd);
+void mapif_auction_cancel(int fd, int char_id, unsigned char result);
+void mapif_parse_auction_cancel(int fd);
+void mapif_auction_close(int fd, int char_id, unsigned char result);
+void mapif_parse_auction_close(int fd);
+void mapif_auction_bid(int fd, int char_id, int bid, unsigned char result);
+void mapif_parse_auction_bid(int fd);
void mapif_defaults(void) {
mapif = &mapif_s;
@@ -42,4 +54,15 @@ void mapif_defaults(void) {
mapif->sendallwos = mapif_sendallwos;
mapif->send = mapif_send;
mapif->send_users_count = mapif_send_users_count;
+ mapif->auction_message = mapif_auction_message;
+ mapif->auction_sendlist = mapif_auction_sendlist;
+ mapif->parse_auction_requestlist = mapif_parse_auction_requestlist;
+ mapif->auction_register = mapif_auction_register;
+ mapif->parse_auction_register = mapif_parse_auction_register;
+ mapif->auction_cancel = mapif_auction_cancel;
+ mapif->parse_auction_cancel = mapif_parse_auction_cancel;
+ mapif->auction_close = mapif_auction_close;
+ mapif->parse_auction_close = mapif_parse_auction_close;
+ mapif->auction_bid = mapif_auction_bid;
+ mapif->parse_auction_bid = mapif_parse_auction_bid;
}
diff --git a/src/char/mapif.h b/src/char/mapif.h
index 089fb751b..6ba6e5924 100644
--- a/src/char/mapif.h
+++ b/src/char/mapif.h
@@ -20,6 +20,17 @@ struct mapif_interface {
int (*sendallwos) (int sfd, unsigned char *buf, unsigned int len);
int (*send) (int fd, unsigned char *buf, unsigned int len);
void (*send_users_count) (int users);
+ void (*auction_message) (int char_id, unsigned char result);
+ void (*auction_sendlist) (int fd, int char_id, short count, short pages, unsigned char *buf);
+ void (*parse_auction_requestlist) (int fd);
+ void (*auction_register) (int fd, struct auction_data *auction);
+ void (*parse_auction_register) (int fd);
+ void (*auction_cancel) (int fd, int char_id, unsigned char result);
+ void (*parse_auction_cancel) (int fd);
+ void (*auction_close) (int fd, int char_id, unsigned char result);
+ void (*parse_auction_close) (int fd);
+ void (*auction_bid) (int fd, int char_id, int bid, unsigned char result);
+ void (*parse_auction_bid) (int fd);
} mapif_s;
struct mapif_interface *mapif;