auction removed
This commit is contained in:
@@ -1,719 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#ifdef __AUCTION__
|
||||
|
||||
#include "DBManager.h"
|
||||
#include "Peer.h"
|
||||
#include "AuctionManager.h"
|
||||
|
||||
void MyBidBoard::Boot (CPeer* peer)
|
||||
{
|
||||
peer->EncodeWORD(sizeof(DWORD) + sizeof(DWORD) + sizeof(int));
|
||||
peer->EncodeWORD(Size());
|
||||
|
||||
for (TMyBidBoard::iterator pc_it = pc_map.begin(); pc_it != pc_map.end(); pc_it++)
|
||||
{
|
||||
TItemMap* item_map = pc_it->second;
|
||||
for (TItemMap::iterator it = item_map->begin(); it != item_map->end(); it++)
|
||||
{
|
||||
peer->Encode(&(pc_it->first), sizeof(DWORD));
|
||||
peer->Encode(&(it->first), sizeof(DWORD));
|
||||
peer->Encode(&(it->second), sizeof(int));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t MyBidBoard::Size ()
|
||||
{
|
||||
size_t size = 0;
|
||||
for (TMyBidBoard::iterator it = pc_map.begin(); it != pc_map.end(); it++)
|
||||
{
|
||||
size += it->second->size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
int MyBidBoard::GetMoney (DWORD player_id, DWORD item_id)
|
||||
{
|
||||
TMyBidBoard::iterator pc_it = pc_map.find (player_id);
|
||||
if (pc_it == pc_map.end())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
TItemMap* item_map = pc_it->second;
|
||||
TItemMap::iterator it = item_map->find (item_id);
|
||||
if (it == item_map->end())
|
||||
return -1;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool MyBidBoard::Delete (DWORD player_id, DWORD item_id)
|
||||
{
|
||||
TMyBidBoard::iterator pc_it = pc_map.find (player_id);
|
||||
if (pc_it == pc_map.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TItemMap* item_map = pc_it->second;
|
||||
TItemMap::iterator it = item_map->find (item_id);
|
||||
if (it == item_map->end())
|
||||
return false;
|
||||
else
|
||||
{
|
||||
item_map->erase(it);
|
||||
}
|
||||
char szQuery[512];
|
||||
snprintf(szQuery, sizeof(szQuery), "DELETE FROM my_bid WHERE player_id = %d and item_id = %d", player_id, item_id);
|
||||
CDBManager::instance().AsyncQuery(szQuery);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MyBidBoard::Insert (DWORD player_id, DWORD item_id, int money)
|
||||
{
|
||||
TMyBidBoard::iterator pc_it = pc_map.find (player_id);
|
||||
TItemMap* item_map;
|
||||
if (pc_it == pc_map.end())
|
||||
{
|
||||
item_map = new TItemMap();
|
||||
pc_map.insert (TMyBidBoard::value_type (player_id, item_map));
|
||||
}
|
||||
else
|
||||
item_map = pc_it->second;
|
||||
|
||||
TItemMap::iterator it = item_map->find (item_id);
|
||||
if (it == item_map->end())
|
||||
{
|
||||
item_map->insert (TItemMap::value_type (item_id, money));
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second = money;
|
||||
}
|
||||
char szQuery[512];
|
||||
snprintf(szQuery, sizeof(szQuery), "REPLACE INTO my_bid VALUES (%d, %d, %d)", player_id, item_id, money);
|
||||
CDBManager::instance().AsyncQuery(szQuery);
|
||||
}
|
||||
|
||||
AuctionManager::AuctionManager()
|
||||
{
|
||||
}
|
||||
|
||||
AuctionManager::~AuctionManager()
|
||||
{
|
||||
}
|
||||
|
||||
void AuctionManager::Initialize()
|
||||
{ auction_item_cache_map.clear();
|
||||
LoadAuctionItem();
|
||||
LoadAuctionInfo();
|
||||
LoadSaleInfo();
|
||||
LoadWishInfo();
|
||||
LoadMyBidInfo();
|
||||
}
|
||||
|
||||
void AuctionManager::LoadAuctionItem()
|
||||
{
|
||||
char szQuery[512];
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"SELECT id, owner_id, count, vnum, socket0, socket1, socket2, "
|
||||
"attrtype0, attrvalue0, "
|
||||
"attrtype1, attrvalue1, "
|
||||
"attrtype2, attrvalue2, "
|
||||
"attrtype3, attrvalue3, "
|
||||
"attrtype4, attrvalue4, "
|
||||
"attrtype5, attrvalue5, "
|
||||
"attrtype6, attrvalue6 "
|
||||
"FROM item WHERE window = 'AUCTION'");
|
||||
|
||||
SQLMsg *msg = CDBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
MYSQL_RES *res = msg->Get()->pSQLResult;
|
||||
|
||||
if (!res)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int rows;
|
||||
|
||||
if ((rows = mysql_num_rows(res)) <= 0) // 데이터 없음
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(res);
|
||||
TPlayerItem item;
|
||||
|
||||
int cur = 0;
|
||||
|
||||
str_to_number(item.id, row[cur++]);
|
||||
str_to_number(item.owner, row[cur++]);
|
||||
item.window = AUCTION;
|
||||
str_to_number(item.count, row[cur++]);
|
||||
str_to_number(item.vnum, row[cur++]);
|
||||
str_to_number(item.alSockets[0], row[cur++]);
|
||||
str_to_number(item.alSockets[1], row[cur++]);
|
||||
str_to_number(item.alSockets[2], row[cur++]);
|
||||
|
||||
for (int j = 0; j < ITEM_ATTRIBUTE_MAX_NUM; j++)
|
||||
{
|
||||
str_to_number(item.aAttr[j].bType, row[cur++]);
|
||||
str_to_number(item.aAttr[j].sValue, row[cur++]);
|
||||
}
|
||||
InsertItemCache(&item, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void AuctionManager::LoadAuctionInfo()
|
||||
{
|
||||
char szQuery[512];
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"select * from auction");
|
||||
|
||||
SQLMsg *msg = CDBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
MYSQL_RES *res = msg->Get()->pSQLResult;
|
||||
|
||||
if (!res)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int rows;
|
||||
|
||||
if ((rows = mysql_num_rows(res)) <= 0) // 데이터 없음
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(res);
|
||||
TAuctionItemInfo auctionItemInfo;
|
||||
|
||||
int cur = 0;
|
||||
|
||||
str_to_number(auctionItemInfo.item_num, row[cur++]);
|
||||
str_to_number(auctionItemInfo.offer_price, row[cur++]);
|
||||
str_to_number(auctionItemInfo.price, row[cur++]);
|
||||
str_to_number(auctionItemInfo.offer_id, row[cur++]);
|
||||
thecore_memcpy (auctionItemInfo.shown_name, (char*)row[cur], strlen((char*)row[cur]) +1);
|
||||
cur++;
|
||||
str_to_number(auctionItemInfo.empire, row[cur++]);
|
||||
str_to_number(auctionItemInfo.expired_time, row[cur++]);
|
||||
str_to_number(auctionItemInfo.item_id, row[cur++]);
|
||||
str_to_number(auctionItemInfo.bidder_id, row[cur++]);
|
||||
|
||||
InsertAuctionItemInfoCache(&auctionItemInfo, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void AuctionManager::LoadSaleInfo()
|
||||
{
|
||||
char szQuery[512];
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"select * from sale");
|
||||
|
||||
SQLMsg *msg = CDBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
MYSQL_RES *res = msg->Get()->pSQLResult;
|
||||
|
||||
if (!res)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int rows;
|
||||
|
||||
if ((rows = mysql_num_rows(res)) <= 0) // 데이터 없음
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(res);
|
||||
TSaleItemInfo saleItemInfo;
|
||||
|
||||
int cur = 0;
|
||||
|
||||
str_to_number(saleItemInfo.item_num, row[cur++]);
|
||||
str_to_number(saleItemInfo.offer_price, row[cur++]);
|
||||
str_to_number(saleItemInfo.price, row[cur++]);
|
||||
str_to_number(saleItemInfo.offer_id, row[cur++]);
|
||||
thecore_memcpy (saleItemInfo.shown_name, (char*)row[cur], strlen((char*)row[cur]) +1);
|
||||
cur++;
|
||||
str_to_number(saleItemInfo.empire, row[cur++]);
|
||||
str_to_number(saleItemInfo.expired_time, row[cur++]);
|
||||
str_to_number(saleItemInfo.item_id, row[cur++]);
|
||||
str_to_number(saleItemInfo.wisher_id, row[cur++]);
|
||||
|
||||
InsertSaleItemInfoCache(&saleItemInfo, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
void AuctionManager::LoadWishInfo()
|
||||
{
|
||||
char szQuery[512];
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"select * from wish");
|
||||
|
||||
SQLMsg *msg = CDBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
MYSQL_RES *res = msg->Get()->pSQLResult;
|
||||
|
||||
if (!res)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int rows;
|
||||
|
||||
if ((rows = mysql_num_rows(res)) <= 0) // 데이터 없음
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(res);
|
||||
TWishItemInfo wishItemInfo;
|
||||
|
||||
int cur = 0;
|
||||
|
||||
str_to_number(wishItemInfo.item_num, row[cur++]);
|
||||
str_to_number(wishItemInfo.offer_price, row[cur++]);
|
||||
str_to_number(wishItemInfo.price, row[cur++]);
|
||||
str_to_number(wishItemInfo.offer_id, row[cur++]);
|
||||
thecore_memcpy (wishItemInfo.shown_name, (char*)row[cur], strlen((char*)row[cur]) +1);
|
||||
cur++;
|
||||
str_to_number(wishItemInfo.empire, row[cur++]);
|
||||
str_to_number(wishItemInfo.expired_time, row[cur++]);
|
||||
|
||||
InsertWishItemInfoCache(&wishItemInfo, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void AuctionManager::LoadMyBidInfo ()
|
||||
{
|
||||
char szQuery[512];
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"select * from my_bid");
|
||||
|
||||
SQLMsg *msg = CDBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
MYSQL_RES *res = msg->Get()->pSQLResult;
|
||||
|
||||
if (!res)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int rows;
|
||||
|
||||
if ((rows = mysql_num_rows(res)) <= 0) // 데이터 없음
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows; ++i)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(res);
|
||||
|
||||
int cur = 0;
|
||||
DWORD player_id;
|
||||
DWORD item_id;
|
||||
int money;
|
||||
|
||||
str_to_number(player_id, row[cur++]);
|
||||
str_to_number(item_id, row[cur++]);
|
||||
str_to_number(money, row[cur++]);
|
||||
|
||||
InsertMyBid (player_id, item_id, money);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
inline CItemCache* AuctionManager::GetItemCache(DWORD item_id)
|
||||
{
|
||||
TItemCacheMap::iterator it = auction_item_cache_map.find (item_id);
|
||||
if (it == auction_item_cache_map.end())
|
||||
return NULL;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void AuctionManager::Boot(CPeer* peer)
|
||||
{
|
||||
peer->EncodeWORD(sizeof(TPlayerItem));
|
||||
peer->EncodeWORD(auction_item_cache_map.size());
|
||||
|
||||
itertype(auction_item_cache_map) auction_item_cache_map_it = auction_item_cache_map.begin();
|
||||
|
||||
while (auction_item_cache_map_it != auction_item_cache_map.end())
|
||||
peer->Encode((auction_item_cache_map_it++)->second->Get(), sizeof(TPlayerItem));
|
||||
|
||||
Auction.Boot(peer);
|
||||
Sale.Boot(peer);
|
||||
Wish.Boot(peer);
|
||||
MyBid.Boot(peer);
|
||||
}
|
||||
|
||||
bool AuctionManager::InsertItemCache(CItemCache *item_cache, bool bSkipQuery)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_cache->Get(false)->id);
|
||||
if (c != NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auction_item_cache_map.insert(TItemCacheMap::value_type(item_cache->Get(true)->id, item_cache));
|
||||
item_cache->OnFlush();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AuctionManager::InsertItemCache(TPlayerItem * pNew, bool bSkipQuery)
|
||||
{
|
||||
CItemCache* c = GetItemCache (pNew->id);
|
||||
if (c != NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
c = new CItemCache();
|
||||
|
||||
c->Put(pNew, bSkipQuery);
|
||||
|
||||
auction_item_cache_map.insert(TItemCacheMap::value_type(pNew->id, c));
|
||||
c->Flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AuctionManager::DeleteItemCache(DWORD item_id)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_id);
|
||||
if (c == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
c->Delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::EnrollInAuction(CItemCache* item_cache, TAuctionItemInfo &item_info)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_info.item_id);
|
||||
if (c != NULL)
|
||||
{
|
||||
sys_err ("item id : %d is already in AuctionManager", item_info.item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
if (!Auction.InsertItemInfo (&item_info))
|
||||
{
|
||||
sys_err ("item id : %d is already in AuctionBoard", item_info.item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
item_cache->Get()->window = AUCTION;
|
||||
item_cache->Get()->pos = 9999999;
|
||||
|
||||
InsertItemCache (item_cache);
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::EnrollInSale(CItemCache* item_cache, TSaleItemInfo &item_info)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_info.item_id);
|
||||
if (c != NULL)
|
||||
{
|
||||
sys_err ("item id : %d is already in AuctionManager", item_info.item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
if (!Wish.GetItemInfoCache (WishBoard::Key (item_info.item_num, item_info.wisher_id)))
|
||||
{
|
||||
sys_err ("item_num : %d, wisher_id : %d is not in wish auction.", item_info.item_num, item_info.wisher_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
if (!Sale.InsertItemInfo (&item_info))
|
||||
{
|
||||
sys_err ("item id : %d is already in SaleBoard", item_info.item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
item_cache->Get()->window = AUCTION;
|
||||
item_cache->Get()->pos = 999999;
|
||||
|
||||
InsertItemCache (item_cache);
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::EnrollInWish(TWishItemInfo &item_info)
|
||||
{
|
||||
if (!Wish.InsertItemInfo (&item_info))
|
||||
{
|
||||
sys_err ("wisher_id : %d, item_num : %d is already in WishBoard", item_info.offer_id, item_info.item_num);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::Bid(DWORD bidder_id, const char* bidder_name, DWORD item_id, DWORD bid_price)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_id);
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
if (MyBid.GetMoney (bidder_id, item_id) != 0)
|
||||
{
|
||||
return AUCTION_ALREADY_IN;
|
||||
}
|
||||
|
||||
CAuctionItemInfoCache* item_cache = Auction.GetItemInfoCache(item_id);
|
||||
TAuctionItemInfo* item_info = item_cache->Get(false);
|
||||
|
||||
if (item_info->is_expired())
|
||||
{
|
||||
return AUCTION_EXPIRED;
|
||||
}
|
||||
|
||||
if ((double)bid_price < (double)item_info->get_bid_price() * 1.05)
|
||||
{
|
||||
return AUCTION_NOT_ENOUGH_MONEY;
|
||||
}
|
||||
|
||||
item_info->set_bid_price(bid_price);
|
||||
item_info->bidder_id = bidder_id;
|
||||
item_info->set_bidder_name (bidder_name);
|
||||
item_cache->OnFlush();
|
||||
|
||||
InsertMyBid (bidder_id, item_id, bid_price);
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::Impur(DWORD purchaser_id, const char* purchaser_name, DWORD item_id)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_id);
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
CAuctionItemInfoCache* item_cache = Auction.GetItemInfoCache(item_id);
|
||||
TAuctionItemInfo* item_info = item_cache->Get(false);
|
||||
|
||||
if (item_info->is_expired())
|
||||
{
|
||||
return AUCTION_EXPIRED;
|
||||
}
|
||||
|
||||
// 즉구 해버렸으므로, 경매는 끝났다.
|
||||
item_info->expired_time = 0;
|
||||
item_info->bidder_id = purchaser_id;
|
||||
item_info->set_bidder_name (purchaser_name);
|
||||
item_info->set_bid_price (item_info->get_impur_price());
|
||||
item_cache->OnFlush();
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::GetAuctionedItem (DWORD actor_id, DWORD item_id, TPlayerItem& item)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_id);
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
CAuctionItemInfoCache* item_info_cache = Auction.GetItemInfoCache(item_id);
|
||||
if (item_info_cache == NULL)
|
||||
{
|
||||
sys_err ("how can this accident happen?");
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
TAuctionItemInfo* item_info = item_info_cache->Get(false);
|
||||
|
||||
if (!item_info->is_expired())
|
||||
{
|
||||
return AUCTION_NOT_EXPIRED;
|
||||
}
|
||||
|
||||
thecore_memcpy(&item, c->Get(), sizeof(TPlayerItem));
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::BuySoldItem (DWORD actor_id, DWORD item_id, TPlayerItem& item)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_id);
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
CSaleItemInfoCache* item_info_cache = Sale.GetItemInfoCache(item_id);
|
||||
if (item_info_cache == NULL)
|
||||
{
|
||||
sys_err ("how can this accident happen?");
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
TSaleItemInfo* item_info = item_info_cache->Get(false);
|
||||
|
||||
thecore_memcpy(&item, c->Get(), sizeof(TPlayerItem));
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::CancelAuction (DWORD actor_id, DWORD item_id, TPlayerItem& item)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_id);
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
CAuctionItemInfoCache* item_info_cache = Auction.GetItemInfoCache(item_id);
|
||||
if (item_info_cache == NULL)
|
||||
{
|
||||
sys_err ("how can this accident happen?");
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
TAuctionItemInfo* item_info = item_info_cache->Get(false);
|
||||
|
||||
thecore_memcpy(&item, c->Get(), sizeof(TPlayerItem));
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::CancelWish (DWORD actor_id, DWORD item_num)
|
||||
{
|
||||
if (!Wish.DeleteItemInfoCache (WishBoard::Key (actor_id, item_num)))
|
||||
{
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::CancelSale (DWORD actor_id, DWORD item_id, TPlayerItem& item)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_id);
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
CSaleItemInfoCache* item_info_cache = Sale.GetItemInfoCache(item_id);
|
||||
if (item_info_cache == NULL)
|
||||
{
|
||||
sys_err ("how can this accident happen?");
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
TSaleItemInfo* item_info = item_info_cache->Get(false);
|
||||
|
||||
thecore_memcpy(&item, c->Get(), sizeof(TPlayerItem));
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::DeleteAuctionItem (DWORD actor_id, DWORD item_id)
|
||||
{
|
||||
if (DeleteItemCache (item_id) == false)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
if (Auction.DeleteItemInfoCache (item_id) == NULL)
|
||||
{
|
||||
sys_err ("how can this accident happen?");
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::DeleteSaleItem (DWORD actor_id, DWORD item_id)
|
||||
{
|
||||
if (DeleteItemCache (item_id) == false)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
if (Sale.DeleteItemInfoCache (item_id) == NULL)
|
||||
{
|
||||
sys_err ("how can this accident happen?");
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::ReBid(DWORD bidder_id, const char* bidder_name, DWORD item_id, DWORD bid_price)
|
||||
{
|
||||
CItemCache* c = GetItemCache (item_id);
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("item id : %d does not exist in auction.", item_id);
|
||||
return AUCTION_FAIL;
|
||||
}
|
||||
|
||||
int money = MyBid.GetMoney (bidder_id, item_id);
|
||||
if (money == -1)
|
||||
{
|
||||
return AUCTION_NOT_IN;
|
||||
}
|
||||
|
||||
CAuctionItemInfoCache* item_cache = Auction.GetItemInfoCache(item_id);
|
||||
TAuctionItemInfo* item_info = item_cache->Get(false);
|
||||
|
||||
if (item_info->is_expired())
|
||||
{
|
||||
return AUCTION_EXPIRED;
|
||||
}
|
||||
|
||||
if ((double)(bid_price + money) < (double)item_info->get_bid_price() * 1.05)
|
||||
{
|
||||
return AUCTION_NOT_ENOUGH_MONEY;
|
||||
}
|
||||
|
||||
item_info->set_bid_price(bid_price + money);
|
||||
item_info->bidder_id = bidder_id;
|
||||
item_info->set_bidder_name (bidder_name);
|
||||
item_cache->OnFlush();
|
||||
|
||||
InsertMyBid (bidder_id, item_id, money + bid_price);
|
||||
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
|
||||
AuctionResult AuctionManager::BidCancel (DWORD bidder_id, DWORD item_id)
|
||||
{
|
||||
if (MyBid.Delete (bidder_id, item_id))
|
||||
{
|
||||
return AUCTION_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AUCTION_NOT_IN;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,370 +0,0 @@
|
||||
#ifdef __AUCTION__
|
||||
|
||||
#ifndef __INC_AUCTION_MANAGER_H__
|
||||
#define __INC_AUCTION_MANAGER_H__
|
||||
|
||||
#include <unordered_map>
|
||||
#include "Cache.h"
|
||||
#include "common/auction_table.h"
|
||||
|
||||
class CItemCache;
|
||||
class CAuctionItemInfoCache;
|
||||
class CSaleItemInfoCache;
|
||||
class CWishItemInfoCache;
|
||||
|
||||
template<>
|
||||
class hash<std::pair <DWORD, DWORD> >
|
||||
{ // hash functor
|
||||
public:
|
||||
typedef std::pair <DWORD, DWORD> _Kty;
|
||||
|
||||
size_t operator()(const _Kty& _Keyval) const
|
||||
{ // hash _Keyval to size_t value by pseudorandomizing transform
|
||||
ldiv_t _Qrem = ldiv((size_t)_Keyval.first + (size_t)_Keyval.second, 127773);
|
||||
|
||||
_Qrem.rem = 16807 * _Qrem.rem - 2836 * _Qrem.quot;
|
||||
if (_Qrem.rem < 0)
|
||||
_Qrem.rem += 2147483647;
|
||||
return ((size_t)_Qrem.rem);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AuctionBoard
|
||||
{
|
||||
public:
|
||||
typedef DWORD Key;
|
||||
typedef CAuctionItemInfoCache ItemInfoCache;
|
||||
typedef TAuctionItemInfo ItemInfo;
|
||||
|
||||
|
||||
public:
|
||||
AuctionBoard() {}
|
||||
~AuctionBoard() {}
|
||||
|
||||
void Boot(CPeer* peer)
|
||||
{
|
||||
peer->EncodeWORD(sizeof(ItemInfo));
|
||||
peer->EncodeWORD(item_cache_map.size());
|
||||
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.begin();
|
||||
|
||||
while (it != item_cache_map.end())
|
||||
peer->Encode((it++)->second->Get(), sizeof(ItemInfo));
|
||||
}
|
||||
|
||||
size_t Size()
|
||||
{
|
||||
return item_cache_map.size();
|
||||
}
|
||||
|
||||
ItemInfoCache* GetItemInfoCache (Key key)
|
||||
{
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.find (key);
|
||||
if (it == item_cache_map.end())
|
||||
return NULL;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool DeleteItemInfoCache (Key key)
|
||||
{
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.find (key);
|
||||
if (it == item_cache_map.end())
|
||||
return false;
|
||||
else
|
||||
{
|
||||
it->second->Delete();
|
||||
item_cache_map.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool InsertItemInfo (ItemInfo *pNew, bool bSkipQuery = false)
|
||||
{
|
||||
ItemInfoCache* c = GetItemInfoCache (Key (pNew->item_id));
|
||||
if (c != NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
c = new ItemInfoCache();
|
||||
|
||||
c->Put(pNew, bSkipQuery);
|
||||
|
||||
item_cache_map.insert(TItemInfoCacheMap::value_type(pNew->item_id, c));
|
||||
c->Flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
typedef std::unordered_map <Key, ItemInfoCache *> TItemInfoCacheMap;
|
||||
TItemInfoCacheMap item_cache_map;
|
||||
};
|
||||
|
||||
class SaleBoard
|
||||
{
|
||||
public:
|
||||
typedef DWORD Key;
|
||||
typedef CSaleItemInfoCache ItemInfoCache;
|
||||
typedef TSaleItemInfo ItemInfo;
|
||||
|
||||
SaleBoard() {}
|
||||
~SaleBoard() {}
|
||||
|
||||
void Boot(CPeer* peer)
|
||||
{
|
||||
peer->EncodeWORD(sizeof(ItemInfo));
|
||||
peer->EncodeWORD(item_cache_map.size());
|
||||
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.begin();
|
||||
|
||||
while (it != item_cache_map.end())
|
||||
peer->Encode((it++)->second->Get(), sizeof(ItemInfo));
|
||||
}
|
||||
|
||||
size_t Size()
|
||||
{
|
||||
return item_cache_map.size();
|
||||
}
|
||||
|
||||
ItemInfoCache* GetItemInfoCache (Key key)
|
||||
{
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.find (key);
|
||||
if (it == item_cache_map.end())
|
||||
return NULL;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool DeleteItemInfoCache (Key key)
|
||||
{
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.find (key);
|
||||
if (it == item_cache_map.end())
|
||||
return false;
|
||||
else
|
||||
{
|
||||
it->second->Delete();
|
||||
item_cache_map.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool InsertItemInfo (ItemInfo *pNew, bool bSkipQuery = false)
|
||||
{
|
||||
ItemInfoCache* c = GetItemInfoCache (Key (pNew->item_id));
|
||||
if (c != NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
c = new ItemInfoCache();
|
||||
|
||||
c->Put(pNew, bSkipQuery);
|
||||
|
||||
item_cache_map.insert(TItemInfoCacheMap::value_type(pNew->item_id, c));
|
||||
c->Flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::unordered_map <Key, ItemInfoCache *> TItemInfoCacheMap;
|
||||
TItemInfoCacheMap item_cache_map;
|
||||
};
|
||||
|
||||
class WishBoard
|
||||
{
|
||||
public:
|
||||
typedef std::pair <DWORD, DWORD> Key;
|
||||
typedef CWishItemInfoCache ItemInfoCache;
|
||||
typedef TWishItemInfo ItemInfo;
|
||||
|
||||
WishBoard() {}
|
||||
virtual ~WishBoard() {}
|
||||
|
||||
void Boot(CPeer* peer)
|
||||
{
|
||||
peer->EncodeWORD(sizeof(ItemInfo));
|
||||
peer->EncodeWORD(item_cache_map.size());
|
||||
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.begin();
|
||||
|
||||
while (it != item_cache_map.end())
|
||||
peer->Encode((it++)->second->Get(), sizeof(ItemInfo));
|
||||
}
|
||||
|
||||
size_t Size()
|
||||
{
|
||||
return item_cache_map.size();
|
||||
}
|
||||
|
||||
ItemInfoCache* GetItemInfoCache (Key key)
|
||||
{
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.find (key);
|
||||
if (it == item_cache_map.end())
|
||||
return NULL;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool DeleteItemInfoCache (Key key)
|
||||
{
|
||||
TItemInfoCacheMap::iterator it = item_cache_map.find (key);
|
||||
if (it == item_cache_map.end())
|
||||
return false;
|
||||
else
|
||||
{
|
||||
it->second->Delete();
|
||||
item_cache_map.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool InsertItemInfo (ItemInfo *pNew, bool bSkipQuery = false)
|
||||
{
|
||||
ItemInfoCache* c = GetItemInfoCache (Key (pNew->item_num, pNew->offer_id));
|
||||
if (c != NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
c = new ItemInfoCache();
|
||||
|
||||
c->Put(pNew, bSkipQuery);
|
||||
|
||||
item_cache_map.insert(TItemInfoCacheMap::value_type(Key (pNew->item_num, pNew->offer_id), c));
|
||||
c->Flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
typedef std::unordered_map <Key, ItemInfoCache *> TItemInfoCacheMap;
|
||||
TItemInfoCacheMap item_cache_map;
|
||||
};
|
||||
|
||||
// pc가 입찰에 참여했던 경매를 관리.
|
||||
class MyBidBoard
|
||||
{
|
||||
public:
|
||||
MyBidBoard() {}
|
||||
~MyBidBoard() {}
|
||||
|
||||
void Boot(CPeer* peer);
|
||||
size_t Size();
|
||||
|
||||
int GetMoney (DWORD player_id, DWORD item_id);
|
||||
bool Delete (DWORD player_id, DWORD item_id);
|
||||
// 이미 있으면 덮어 씌운다.
|
||||
void Insert (DWORD player_id, DWORD item_id, int money);
|
||||
|
||||
private:
|
||||
typedef std::map <DWORD, int> TItemMap;
|
||||
typedef std::unordered_map <DWORD, TItemMap*> TMyBidBoard;
|
||||
TMyBidBoard pc_map;
|
||||
};
|
||||
|
||||
class AuctionManager : public singleton <AuctionManager>
|
||||
{
|
||||
private:
|
||||
// auction에 등록된 아이템들.
|
||||
typedef std::unordered_map<DWORD, CItemCache *> TItemCacheMap;
|
||||
TItemCacheMap auction_item_cache_map;
|
||||
|
||||
// auction에 등록된 정보 중 가격, 등등 아이템 테이블에 포함되지 않는 정보들을 관리하는 것들
|
||||
AuctionBoard Auction;
|
||||
SaleBoard Sale;
|
||||
WishBoard Wish;
|
||||
MyBidBoard MyBid;
|
||||
|
||||
public:
|
||||
AuctionManager();
|
||||
~AuctionManager();
|
||||
|
||||
void Initialize ();
|
||||
void LoadAuctionItem ();
|
||||
|
||||
void LoadAuctionInfo ();
|
||||
void LoadSaleInfo ();
|
||||
void LoadWishInfo ();
|
||||
void LoadMyBidInfo ();
|
||||
|
||||
void Boot(CPeer* peer);
|
||||
|
||||
bool InsertItemCache (CItemCache *item_cache, bool bSkipQuery = false);
|
||||
bool InsertItemCache (TPlayerItem * pNew, bool bSkipQuery = false);
|
||||
bool DeleteItemCache (DWORD item_id);
|
||||
CItemCache* GetItemCache (DWORD item_id);
|
||||
|
||||
size_t GetAuctionItemSize()
|
||||
{
|
||||
return auction_item_cache_map.size();
|
||||
}
|
||||
size_t GetAuctionSize()
|
||||
{
|
||||
return Auction.Size();
|
||||
}
|
||||
size_t GetSaleSize()
|
||||
{
|
||||
return Sale.Size();
|
||||
}
|
||||
size_t GetWishSize()
|
||||
{
|
||||
return Wish.Size();
|
||||
}
|
||||
size_t GetMyBidSize()
|
||||
{
|
||||
return MyBid.Size();
|
||||
}
|
||||
|
||||
void InsertAuctionItemInfoCache (TAuctionItemInfo *pNew, bool bSkipQuery = false)
|
||||
{
|
||||
Auction.InsertItemInfo (pNew, bSkipQuery);
|
||||
}
|
||||
CAuctionItemInfoCache* GetAuctionItemInfoCache (DWORD item_id)
|
||||
{
|
||||
return Auction.GetItemInfoCache(item_id);
|
||||
}
|
||||
|
||||
void InsertSaleItemInfoCache (TSaleItemInfo *pNew, bool bSkipQuery = false)
|
||||
{
|
||||
Sale.InsertItemInfo (pNew, bSkipQuery);
|
||||
}
|
||||
CSaleItemInfoCache* GetSaleItemInfoCache (DWORD item_id)
|
||||
{
|
||||
return Sale.GetItemInfoCache(item_id);
|
||||
}
|
||||
|
||||
void InsertWishItemInfoCache (TWishItemInfo *pNew, bool bSkipQuery = false)
|
||||
{
|
||||
Wish.InsertItemInfo (pNew, bSkipQuery);
|
||||
}
|
||||
CWishItemInfoCache* GetWishItemInfoCache (DWORD item_id, DWORD wisher_id)
|
||||
{
|
||||
return Wish.GetItemInfoCache(WishBoard::Key (item_id, wisher_id));
|
||||
}
|
||||
|
||||
void InsertMyBid (DWORD player_id, DWORD item_id, DWORD money)
|
||||
{
|
||||
MyBid.Insert (player_id, item_id, money);
|
||||
}
|
||||
|
||||
AuctionResult EnrollInAuction(CItemCache* item_cache, TAuctionItemInfo &item_info);
|
||||
AuctionResult EnrollInSale(CItemCache* item_cache, TSaleItemInfo &item_info);
|
||||
AuctionResult EnrollInWish(TWishItemInfo &item_info);
|
||||
AuctionResult Bid(DWORD bidder_id, const char* bidder_name, DWORD item_id, DWORD bid_price);
|
||||
AuctionResult Impur(DWORD purchaser_id, const char* purchaser_name, DWORD item_id);
|
||||
AuctionResult GetAuctionedItem (DWORD actor_id, DWORD item_id, TPlayerItem& item);
|
||||
AuctionResult BuySoldItem (DWORD actor_id, DWORD item_id, TPlayerItem& item);
|
||||
AuctionResult CancelAuction (DWORD actor_id, DWORD item_id, TPlayerItem& item);
|
||||
AuctionResult CancelWish (DWORD actor_id, DWORD item_num);
|
||||
AuctionResult CancelSale (DWORD actor_id, DWORD item_id, TPlayerItem& item);
|
||||
AuctionResult DeleteAuctionItem (DWORD actor_id, DWORD item_id);
|
||||
AuctionResult DeleteSaleItem (DWORD actor_id, DWORD item_id);
|
||||
AuctionResult ReBid(DWORD bidder_id, const char* bidder_name, DWORD item_id, DWORD bid_price);
|
||||
AuctionResult BidCancel (DWORD bidder_id, DWORD item_id);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
#include "QID.h"
|
||||
#include "ClientManager.h"
|
||||
#ifdef __AUCTION__
|
||||
#include "AuctionManager.h"
|
||||
#endif
|
||||
#include "Main.h"
|
||||
|
||||
extern CPacketInfo g_item_info;
|
||||
@@ -18,7 +15,6 @@ extern int g_iItemPriceListTableCacheFlushSeconds;
|
||||
// END_OF_MYSHOP_PRICE_LIST
|
||||
//
|
||||
extern int g_item_count;
|
||||
const int auctionMinFlushSec = 1800;
|
||||
|
||||
CItemCache::CItemCache()
|
||||
{
|
||||
@@ -272,95 +268,3 @@ void CItemPriceListTableCache::OnFlush()
|
||||
m_bNeedQuery = false;
|
||||
}
|
||||
// END_OF_MYSHOP_PRICE_LIST
|
||||
#ifdef __AUCTION__
|
||||
CAuctionItemInfoCache::CAuctionItemInfoCache()
|
||||
{
|
||||
m_expireTime = MIN (auctionMinFlushSec, g_iItemCacheFlushSeconds);
|
||||
}
|
||||
|
||||
CAuctionItemInfoCache::~CAuctionItemInfoCache()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CAuctionItemInfoCache::Delete()
|
||||
{
|
||||
if (m_data.item_num == 0)
|
||||
return;
|
||||
|
||||
if (g_test_server)
|
||||
sys_log(0, "CAuctionItemInfoCache::Delete : DELETE %u", m_data.item_id);
|
||||
|
||||
m_data.item_num = 0;
|
||||
m_bNeedQuery = true;
|
||||
m_lastUpdateTime = time(0);
|
||||
OnFlush();
|
||||
delete this;
|
||||
}
|
||||
|
||||
void CAuctionItemInfoCache::OnFlush()
|
||||
{
|
||||
char szQuery[QUERY_MAX_LEN];
|
||||
|
||||
if (m_data.item_num == 0)
|
||||
{
|
||||
snprintf(szQuery, sizeof(szQuery), "DELETE FROM auction where item_id = %d", m_data.item_id);
|
||||
CDBManager::instance().AsyncQuery(szQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(szQuery, sizeof(szQuery), "REPLACE INTO auction VALUES (%u, %d, %d, %u, \"%s\", %u, %u, %u, %u)",
|
||||
m_data.item_num, m_data.offer_price, m_data.price, m_data.offer_id, m_data.shown_name, (DWORD)m_data.empire, (DWORD)m_data.expired_time,
|
||||
m_data.item_id, m_data.bidder_id);
|
||||
|
||||
CDBManager::instance().AsyncQuery(szQuery);
|
||||
}
|
||||
}
|
||||
|
||||
CSaleItemInfoCache::CSaleItemInfoCache()
|
||||
{
|
||||
m_expireTime = MIN (auctionMinFlushSec, g_iItemCacheFlushSeconds);
|
||||
}
|
||||
|
||||
CSaleItemInfoCache::~CSaleItemInfoCache()
|
||||
{
|
||||
}
|
||||
|
||||
void CSaleItemInfoCache::Delete()
|
||||
{
|
||||
}
|
||||
|
||||
void CSaleItemInfoCache::OnFlush()
|
||||
{
|
||||
char szQuery[QUERY_MAX_LEN];
|
||||
|
||||
snprintf(szQuery, sizeof(szQuery), "REPLACE INTO sale VALUES (%u, %d, %d, %u, \"%s\", %u, %u, %u, %u)",
|
||||
m_data.item_num, m_data.offer_price, m_data.price, m_data.offer_id, m_data.shown_name, (DWORD)m_data.empire, (DWORD)m_data.expired_time,
|
||||
m_data.item_id, m_data.wisher_id);
|
||||
|
||||
CDBManager::instance().AsyncQuery(szQuery);
|
||||
}
|
||||
|
||||
CWishItemInfoCache::CWishItemInfoCache()
|
||||
{
|
||||
m_expireTime = MIN (auctionMinFlushSec, g_iItemCacheFlushSeconds);
|
||||
}
|
||||
|
||||
CWishItemInfoCache::~CWishItemInfoCache()
|
||||
{
|
||||
}
|
||||
|
||||
void CWishItemInfoCache::Delete()
|
||||
{
|
||||
}
|
||||
|
||||
void CWishItemInfoCache::OnFlush()
|
||||
{
|
||||
char szQuery[QUERY_MAX_LEN];
|
||||
|
||||
snprintf(szQuery, sizeof(szQuery), "REPLACE INTO wish VALUES (%u, %d, %d, %u, \"%s\", %u, %d)",
|
||||
m_data.item_num, m_data.offer_price, m_data.price, m_data.offer_id, m_data.shown_name, (DWORD)m_data.empire, (DWORD)m_data.expired_time);
|
||||
|
||||
CDBManager::instance().AsyncQuery(szQuery);
|
||||
}
|
||||
#endif
|
||||
@@ -3,7 +3,6 @@
|
||||
#define __INC_DB_CACHE_H__
|
||||
|
||||
#include "common/cache.h"
|
||||
#include "common/auction_table.h"
|
||||
|
||||
class CItemCache : public cache<TPlayerItem>
|
||||
{
|
||||
@@ -59,39 +58,4 @@ class CItemPriceListTableCache : public cache< TItemPriceListTable >
|
||||
static const int s_nMinFlushSec; ///< Minimum cache expire time
|
||||
};
|
||||
// END_OF_MYSHOP_PRICE_LIST
|
||||
#ifdef __AUCTION__
|
||||
|
||||
class CAuctionItemInfoCache : public cache <TAuctionItemInfo>
|
||||
{
|
||||
public:
|
||||
typedef TWishItemInfo value_type;
|
||||
CAuctionItemInfoCache();
|
||||
virtual ~CAuctionItemInfoCache();
|
||||
|
||||
void Delete();
|
||||
virtual void OnFlush();
|
||||
};
|
||||
|
||||
class CSaleItemInfoCache : public cache <TSaleItemInfo>
|
||||
{
|
||||
public:
|
||||
typedef TWishItemInfo value_type;
|
||||
CSaleItemInfoCache();
|
||||
virtual ~CSaleItemInfoCache();
|
||||
|
||||
void Delete();
|
||||
virtual void OnFlush();
|
||||
};
|
||||
|
||||
class CWishItemInfoCache : public cache <TWishItemInfo>
|
||||
{
|
||||
public:
|
||||
typedef TWishItemInfo value_type;
|
||||
CWishItemInfoCache();
|
||||
virtual ~CWishItemInfoCache();
|
||||
|
||||
void Delete();
|
||||
virtual void OnFlush();
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -21,10 +21,6 @@
|
||||
#include "ItemIDRangeManager.h"
|
||||
#include "Cache.h"
|
||||
|
||||
#ifdef __AUCTION__
|
||||
#include "AuctionManager.h"
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
extern int g_iPlayerCacheFlushSeconds;
|
||||
@@ -275,13 +271,6 @@ void CClientManager::QUERY_BOOT(CPeer* peer, TPacketGDBoot * p)
|
||||
sizeof(WORD) + sizeof(WORD) + sizeof(building::TLand) * m_vec_kLandTable.size() +
|
||||
sizeof(WORD) + sizeof(WORD) + sizeof(building::TObjectProto) * m_vec_kObjectProto.size() +
|
||||
sizeof(WORD) + sizeof(WORD) + sizeof(building::TObject) * m_map_pkObjectTable.size() +
|
||||
#ifdef __AUCTION__
|
||||
sizeof(WORD) + sizeof(WORD) + sizeof(TPlayerItem) * AuctionManager::instance().GetAuctionItemSize() +
|
||||
sizeof(WORD) + sizeof(WORD) + sizeof(TAuctionItemInfo) * AuctionManager::instance().GetAuctionSize() +
|
||||
sizeof(WORD) + sizeof(WORD) + sizeof(TSaleItemInfo) * AuctionManager::instance().GetSaleSize() +
|
||||
sizeof(WORD) + sizeof(WORD) + sizeof(TWishItemInfo) * AuctionManager::instance().GetWishSize() +
|
||||
sizeof(WORD) + sizeof(WORD) + (sizeof(DWORD) + sizeof(DWORD) + sizeof(int)) * AuctionManager::instance().GetMyBidSize() +
|
||||
#endif
|
||||
sizeof(time_t) +
|
||||
sizeof(WORD) + sizeof(WORD) + sizeof(TItemIDRangeTable)*2 +
|
||||
//ADMIN_MANAGER
|
||||
@@ -363,10 +352,6 @@ void CClientManager::QUERY_BOOT(CPeer* peer, TPacketGDBoot * p)
|
||||
while (it != m_map_pkObjectTable.end())
|
||||
peer->Encode((it++)->second, sizeof(building::TObject));
|
||||
|
||||
// Auction Boot
|
||||
#ifdef __AUCTION__
|
||||
AuctionManager::instance().Boot (peer);
|
||||
#endif
|
||||
time_t now = time(0);
|
||||
peer->Encode(&now, sizeof(time_t));
|
||||
|
||||
@@ -1288,7 +1273,6 @@ void CClientManager::QUERY_ITEM_SAVE(CPeer * pkPeer, const char * c_pData)
|
||||
TPlayerItem * p = (TPlayerItem *) c_pData;
|
||||
|
||||
// 창고면 캐쉬하지 않고, 캐쉬에 있던 것도 빼버려야 한다.
|
||||
// auction은 이 루트를 타지 않아야 한다. EnrollInAuction을 타야한다.
|
||||
|
||||
if (p->window == SAFEBOX || p->window == MALL)
|
||||
{
|
||||
@@ -1342,13 +1326,6 @@ void CClientManager::QUERY_ITEM_SAVE(CPeer * pkPeer, const char * c_pData)
|
||||
|
||||
CDBManager::instance().ReturnQuery(szQuery, QID_ITEM_SAVE, pkPeer->GetHandle(), NULL);
|
||||
}
|
||||
#ifdef __AUCTION__
|
||||
else if (p->window == AUCTION)
|
||||
{
|
||||
sys_err("invalid window. how can you enter this route?");
|
||||
return ;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
if (g_test_server)
|
||||
@@ -2727,60 +2704,7 @@ void CClientManager::ProcessPackets(CPeer * peer)
|
||||
case HEADER_GD_REQUEST_CHANNELSTATUS:
|
||||
RequestChannelStatus(peer, dwHandle);
|
||||
break;
|
||||
#ifdef __AUCTION__
|
||||
case HEADER_GD_COMMAND_AUCTION:
|
||||
{
|
||||
TPacketGDCommnadAuction* auction_data = (TPacketGDCommnadAuction*)data;
|
||||
|
||||
switch (auction_data->get_cmd())
|
||||
{
|
||||
case AUCTION_ENR_AUC:
|
||||
EnrollInAuction (peer, dwHandle, (AuctionEnrollProductInfo*)data);
|
||||
break;
|
||||
case AUCTION_ENR_SALE:
|
||||
EnrollInSale (peer, dwHandle, (AuctionEnrollSaleInfo*)data);
|
||||
break;
|
||||
case AUCTION_ENR_WISH:
|
||||
EnrollInWish (peer, dwHandle, (AuctionEnrollWishInfo*)data);
|
||||
break;
|
||||
case AUCTION_BID:
|
||||
AuctionBid (peer, dwHandle, (AuctionBidInfo*)data);
|
||||
break;
|
||||
case AUCTION_IMME_PUR:
|
||||
AuctionImpur (peer, dwHandle, (AuctionImpurInfo*)data);
|
||||
break;
|
||||
case AUCTION_GET_AUC:
|
||||
AuctionGetAuctionedItem (peer, dwHandle, auction_data->get_item());
|
||||
break;
|
||||
case AUCTION_BUY_SOLD:
|
||||
AuctionBuySoldItem (peer, dwHandle, auction_data->get_item());
|
||||
break;
|
||||
case AUCTION_CANCEL_AUC:
|
||||
AuctionCancelAuction (peer, dwHandle, auction_data->get_item());
|
||||
break;
|
||||
case AUCTION_CANCEL_WISH:
|
||||
AuctionCancelWish (peer, dwHandle, auction_data->get_item());
|
||||
break;
|
||||
case AUCTION_CANCEL_SALE:
|
||||
AuctionCancelSale (peer, dwHandle, auction_data->get_item());
|
||||
break;
|
||||
case AUCTION_DELETE_AUCTION_ITEM:
|
||||
AuctionDeleteAuctionItem (peer, dwHandle, auction_data->get_item());
|
||||
break;
|
||||
case AUCTION_DELETE_SALE_ITEM:
|
||||
AuctionDeleteSaleItem (peer, dwHandle, auction_data->get_item());
|
||||
break;
|
||||
case AUCTION_REBID:
|
||||
AuctionReBid (peer, dwHandle, (AuctionBidInfo*)data);
|
||||
break;
|
||||
// case AUCTION_BID_CANCEL:
|
||||
// AuctionBidCancel (peer, dwHandle, data->get_item());
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
sys_err("Unknown header (header: %d handle: %d length: %d)", header, dwHandle, dwLength);
|
||||
break;
|
||||
@@ -4403,627 +4327,3 @@ void CClientManager::ChargeCash(const TRequestChargeCash* packet)
|
||||
|
||||
CDBManager::Instance().AsyncQuery(szQuery, SQL_ACCOUNT);
|
||||
}
|
||||
|
||||
#ifdef __AUCTION__
|
||||
void CClientManager::EnrollInAuction (CPeer * peer, DWORD owner_id, AuctionEnrollProductInfo* data)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (owner_id);
|
||||
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", owner_id);
|
||||
return;
|
||||
}
|
||||
CItemCache* c = GetItemCache (data->get_item_id());
|
||||
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("Item %d doesn't exist in db cache.", data->get_item_id());
|
||||
return;
|
||||
}
|
||||
TPlayerItem* item = c->Get(false);
|
||||
|
||||
if (item->owner != owner_id)
|
||||
{
|
||||
sys_err ("Player id %d doesn't have item %d.", owner_id, data->get_item_id());
|
||||
return;
|
||||
}
|
||||
// 현재 시각 + 24시간 후.
|
||||
time_t expired_time = time(0) + 24 * 60 * 60;
|
||||
TAuctionItemInfo auctioned_item_info (item->vnum, data->get_bid_price(),
|
||||
data->get_impur_price(), owner_id, "", expired_time, data->get_item_id(), 0, data->get_empire());
|
||||
|
||||
AuctionResult result = AuctionManager::instance().EnrollInAuction( c, auctioned_item_info );
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_ENR_AUC;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, owner_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
|
||||
peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode(c->Get(false), sizeof(TPlayerItem));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 아이템 케시를 Auction에 등록 했으니 ClientManager에서는 뺀다.
|
||||
TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(item->owner);
|
||||
|
||||
if (it != m_map_pkItemCacheSetPtr.end())
|
||||
{
|
||||
it->second->erase(c);
|
||||
}
|
||||
m_map_itemCache.erase(item->id);
|
||||
sys_log(0, "Enroll In Auction Success. owner_id item_id %d %d", owner_id, item->id);
|
||||
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_ENR_AUC;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, owner_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem) + sizeof(TAuctionItemInfo));
|
||||
(*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode(c->Get(false), sizeof(TPlayerItem));
|
||||
(*it)->Encode(&auctioned_item_info, sizeof(TAuctionItemInfo));
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::EnrollInSale (CPeer * peer, DWORD owner_id, AuctionEnrollSaleInfo* data)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (owner_id);
|
||||
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", owner_id);
|
||||
return;
|
||||
}
|
||||
|
||||
CPlayerTableCache* player_cache = it->second;
|
||||
TPlayerTable* player = player_cache->Get(false);
|
||||
|
||||
CItemCache* c = GetItemCache (data->get_item_id());
|
||||
|
||||
if (c == NULL)
|
||||
{
|
||||
sys_err ("Item %d doesn't exist in db cache.", data->get_item_id());
|
||||
return;
|
||||
}
|
||||
TPlayerItem* item = c->Get(false);
|
||||
|
||||
if (item->owner != owner_id)
|
||||
{
|
||||
sys_err ("Player id %d doesn't have item %d.", owner_id, data->get_item_id());
|
||||
return;
|
||||
}
|
||||
// 현재 시각 + 24시간 후.
|
||||
time_t expired_time = time(0) + 24 * 60 * 60;
|
||||
TSaleItemInfo sold_item_info (item->vnum, data->get_sale_price(),
|
||||
owner_id, player->name, data->get_item_id(), data->get_wisher_id());
|
||||
|
||||
AuctionResult result = AuctionManager::instance().EnrollInSale( c, sold_item_info );
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_ENR_SALE;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, owner_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
|
||||
peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode(c->Get(false), sizeof(TPlayerItem));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 아이템 케시를 Auction에 등록 했으니 ClientManager에서는 뺀다.
|
||||
TItemCacheSetPtrMap::iterator it = m_map_pkItemCacheSetPtr.find(item->owner);
|
||||
|
||||
if (it != m_map_pkItemCacheSetPtr.end())
|
||||
{
|
||||
it->second->erase(c);
|
||||
}
|
||||
m_map_itemCache.erase(item->id);
|
||||
sys_log(0, "Enroll In Sale Success. owner_id item_id %d %d", owner_id, item->id);
|
||||
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_ENR_SALE;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, owner_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem) + sizeof(TSaleItemInfo));
|
||||
(*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode(c->Get(false), sizeof(TPlayerItem));
|
||||
(*it)->Encode(&sold_item_info, sizeof(TSaleItemInfo));
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::EnrollInWish (CPeer * peer, DWORD wisher_id, AuctionEnrollWishInfo* data)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (wisher_id);
|
||||
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", wisher_id);
|
||||
return;
|
||||
}
|
||||
|
||||
CPlayerTableCache* player_cache = it->second;
|
||||
TPlayerTable* player = player_cache->Get(false);
|
||||
|
||||
// 현재 시각 + 24시간 후.
|
||||
time_t expired_time = time(0) + 24 * 60 * 60;
|
||||
TWishItemInfo wished_item_info (data->get_item_num(), data->get_wish_price(), wisher_id, player->name, expired_time, data->get_empire());
|
||||
|
||||
AuctionResult result = AuctionManager::instance().EnrollInWish ( wished_item_info );
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
sys_log(0, "Enroll In Wish Success. wisher_id item_num %d %d", wisher_id, data->get_item_num());
|
||||
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_ENR_WISH;
|
||||
enroll_result.target = data->get_item_num();
|
||||
enroll_result.result = result;
|
||||
peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, wisher_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
sys_log(0, "Enroll In Wish Fail. wisher_id item_num %d %d", wisher_id, data->get_item_num());
|
||||
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_ENR_WISH;
|
||||
enroll_result.target = data->get_item_num();
|
||||
enroll_result.result = result;
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, wisher_id, sizeof(TPacketDGResultAuction) + sizeof(TWishItemInfo));
|
||||
(*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode(&wished_item_info, sizeof(TWishItemInfo));
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionBid (CPeer * peer, DWORD bidder_id, AuctionBidInfo* data)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (bidder_id);
|
||||
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", bidder_id);
|
||||
return;
|
||||
}
|
||||
|
||||
CPlayerTableCache* player_cache = it->second;
|
||||
TPlayerTable* player = player_cache->Get(false);
|
||||
|
||||
AuctionResult result = AuctionManager::instance().Bid(bidder_id, player->name, data->get_item_id(), data->get_bid_price());
|
||||
|
||||
if (result == AUCTION_FAIL)
|
||||
{
|
||||
sys_log(0, "Bid Fail. bidder_id item_id %d %d", bidder_id, data->get_item_id());
|
||||
}
|
||||
else
|
||||
{
|
||||
sys_log(0, "Bid Success. bidder_id item_id %d %d", bidder_id, data->get_item_id());
|
||||
}
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_BID;
|
||||
enroll_result.target = data->get_bid_price();
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction) + sizeof(AuctionBidInfo));
|
||||
peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_BID;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
|
||||
TAuctionItemInfo* auctioned_item_info = AuctionManager::instance().GetAuctionItemInfoCache(data->get_item_id())->Get(false);
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction) + sizeof(TAuctionItemInfo));
|
||||
(*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode(auctioned_item_info, sizeof(TAuctionItemInfo));
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionImpur (CPeer * peer, DWORD purchaser_id, AuctionImpurInfo* data)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (purchaser_id);
|
||||
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", purchaser_id);
|
||||
return;
|
||||
}
|
||||
|
||||
CPlayerTableCache* player_cache = it->second;
|
||||
TPlayerTable* player = player_cache->Get(false);
|
||||
|
||||
AuctionResult result = AuctionManager::instance().Impur(purchaser_id, player->name, data->get_item_id());
|
||||
|
||||
if (result == AUCTION_FAIL)
|
||||
{
|
||||
sys_log(0, "Impur Fail. purchaser_id item_id %d %d", purchaser_id, data->get_item_id());
|
||||
}
|
||||
else
|
||||
{
|
||||
sys_log(0, "Impur Success. purchaser_id item_id %d %d", purchaser_id, data->get_item_id());
|
||||
}
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_IMME_PUR;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, purchaser_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_IMME_PUR;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
|
||||
TAuctionItemInfo* auctioned_item_info = AuctionManager::instance().GetAuctionItemInfoCache(data->get_item_id())->Get(false);
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, purchaser_id, sizeof(TPacketDGResultAuction) + sizeof(TAuctionItemInfo));
|
||||
(*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode(auctioned_item_info, sizeof(TAuctionItemInfo));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionGetAuctionedItem (CPeer * peer, DWORD actor_id, DWORD item_id)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
|
||||
AuctionResult result = AUCTION_FAIL;
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", actor_id);
|
||||
return;
|
||||
}
|
||||
|
||||
TPlayerItem item;
|
||||
result = AuctionManager::instance().GetAuctionedItem(actor_id, item_id, item);
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_GET_AUC;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_GET_AUC;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
|
||||
(*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode (&item, sizeof(TPlayerItem));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionBuySoldItem (CPeer * peer, DWORD actor_id, DWORD item_id)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
|
||||
AuctionResult result = AUCTION_FAIL;
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", actor_id);
|
||||
return;
|
||||
}
|
||||
|
||||
TPlayerItem item;
|
||||
result = AuctionManager::instance().BuySoldItem(actor_id, item_id, item);
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_BUY_SOLD;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_BUY_SOLD;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
|
||||
(*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode (&item, sizeof(TPlayerItem));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionCancelAuction (CPeer * peer, DWORD actor_id, DWORD item_id)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
|
||||
AuctionResult result = AUCTION_FAIL;
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", actor_id);
|
||||
return;
|
||||
}
|
||||
|
||||
TPlayerItem item;
|
||||
result = AuctionManager::instance().CancelAuction(actor_id, item_id, item);
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_CANCEL_AUC;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_CANCEL_AUC;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
|
||||
(*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode (&item, sizeof(TPlayerItem));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionCancelWish (CPeer * peer, DWORD actor_id, DWORD item_num)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
|
||||
AuctionResult result = AUCTION_FAIL;
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", actor_id);
|
||||
return;
|
||||
}
|
||||
|
||||
TPlayerItem item;
|
||||
result = AuctionManager::instance().CancelWish(actor_id, item_num);
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_CANCEL_WISH;
|
||||
enroll_result.target = item_num;
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_CANCEL_WISH;
|
||||
enroll_result.target = item_num;
|
||||
enroll_result.result = result;
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionCancelSale (CPeer * peer, DWORD actor_id, DWORD item_id)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
|
||||
AuctionResult result = AUCTION_FAIL;
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", actor_id);
|
||||
return;
|
||||
}
|
||||
|
||||
TPlayerItem item;
|
||||
result = AuctionManager::instance().CancelSale(actor_id, item_id, item);
|
||||
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_CANCEL_SALE;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_CANCEL_SALE;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader (HEADER_DG_AUCTION_RESULT, actor_id, sizeof(TPacketDGResultAuction) + sizeof(TPlayerItem));
|
||||
(*it)->Encode (&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode (&item, sizeof(TPlayerItem));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionDeleteAuctionItem (CPeer * peer, DWORD actor_id, DWORD item_id)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
|
||||
AuctionResult result = AUCTION_FAIL;
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", actor_id);
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionManager::instance().DeleteAuctionItem (actor_id, item_id);
|
||||
}
|
||||
void CClientManager::AuctionDeleteSaleItem (CPeer * peer, DWORD actor_id, DWORD item_id)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (actor_id);
|
||||
AuctionResult result = AUCTION_FAIL;
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", actor_id);
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionManager::instance().DeleteSaleItem (actor_id, item_id);
|
||||
}
|
||||
|
||||
// ReBid는 이전 입찰금액에 더해서 입찰한다.
|
||||
// ReBid에선 data->bid_price가 이전 입찰가에 더해져서
|
||||
// 그 금액으로 rebid하는 것.
|
||||
// 이렇게 한 이유는 rebid에 실패 했을 때,
|
||||
// 유저의 호주머니에서 뺀 돈을 돌려주기 편하게 하기 위함이다.
|
||||
|
||||
void CClientManager::AuctionReBid (CPeer * peer, DWORD bidder_id, AuctionBidInfo* data)
|
||||
{
|
||||
TPlayerTableCacheMap::iterator it = m_map_playerCache.find (bidder_id);
|
||||
|
||||
if (it == m_map_playerCache.end())
|
||||
{
|
||||
sys_err ("Invalid Player id %d. how can you get it?", bidder_id);
|
||||
return;
|
||||
}
|
||||
|
||||
CPlayerTableCache* player_cache = it->second;
|
||||
TPlayerTable* player = player_cache->Get(false);
|
||||
|
||||
AuctionResult result = AuctionManager::instance().ReBid(bidder_id, player->name, data->get_item_id(), data->get_bid_price());
|
||||
|
||||
if (result == AUCTION_FAIL)
|
||||
{
|
||||
sys_log(0, "ReBid Fail. bidder_id item_id %d %d", bidder_id, data->get_item_id());
|
||||
}
|
||||
else
|
||||
{
|
||||
sys_log(0, "ReBid Success. bidder_id item_id %d %d", bidder_id, data->get_item_id());
|
||||
}
|
||||
// 이건 FAIL이 떠서는 안돼.
|
||||
// FAIL이 뜰 수가 없는게, MyBid에 있는 bidder_id에 대한 컨텐츠는 bidder_id만이 접근 할 수 있거든?
|
||||
// 그러므로 다른 것이 다 정상적으로 작동한다고 가정 한다면
|
||||
// 한 게임 서버 내에서 bidder_id로 MyBid를 수정한다 할 지라도, 그건 동기화 문제가 없어.
|
||||
// 다른 게임 서버에 똑같은 bidder_id를 가진 놈이 있을 수가 없으니까.
|
||||
// 그러므로 그 게임 서버에서 BidCancel 명령을 db에 날렸다는 것은,
|
||||
// 이미 그 부분에 대해서는 검사가 완벽하다는 것이야.
|
||||
// 그래도 혹시나 싶어서, 디버깅을 위해 fail 코드를 남겨둔다.
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_REBID;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction) + sizeof(int));
|
||||
peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
peer->EncodeDWORD(data->get_bid_price());
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_REBID;
|
||||
enroll_result.target = data->get_item_id();
|
||||
enroll_result.result = result;
|
||||
|
||||
TAuctionItemInfo* auctioned_item_info = AuctionManager::instance().GetAuctionItemInfoCache(data->get_item_id())->Get(false);
|
||||
|
||||
for (TPeerList::iterator it = m_peerList.begin(); it != m_peerList.end(); it++)
|
||||
{
|
||||
(*it)->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction) + sizeof(TAuctionItemInfo));
|
||||
(*it)->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
(*it)->Encode(auctioned_item_info, sizeof(TAuctionItemInfo));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CClientManager::AuctionBidCancel (CPeer * peer, DWORD bidder_id, DWORD item_id)
|
||||
{
|
||||
AuctionResult result = AuctionManager::instance().BidCancel (bidder_id, item_id);
|
||||
|
||||
// 이건 FAIL이 떠서는 안돼.
|
||||
// FAIL이 뜰 수가 없는게, MyBid에 있는 bidder_id에 대한 컨텐츠는 bidder_id만이 접근 할 수 있거든?
|
||||
// 그러므로 다른 것이 다 정상적으로 작동한다고 가정 한다면
|
||||
// 한 게임 서버 내에서 bidder_id로 MyBid를 수정한다 할 지라도, 그건 동기화 문제가 없어.
|
||||
// 다른 게임 서버에 똑같은 bidder_id를 가진 놈이 있을 수가 없으니까.
|
||||
// 그러므로 그 게임 서버에서 BidCancel 명령을 db에 날렸다는 것은,
|
||||
// 이미 그 부분에 대해서는 검사가 완벽하다는 것이야.
|
||||
// 그래도 혹시나 싶어서, 디버깅을 위해 fail 코드를 남겨둔다.
|
||||
if (result <= AUCTION_FAIL)
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_BID_CANCEL;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
else
|
||||
{
|
||||
TPacketDGResultAuction enroll_result;
|
||||
enroll_result.cmd = AUCTION_BID_CANCEL;
|
||||
enroll_result.target = item_id;
|
||||
enroll_result.result = result;
|
||||
|
||||
peer->EncodeHeader(HEADER_DG_AUCTION_RESULT, bidder_id, sizeof(TPacketDGResultAuction));
|
||||
peer->Encode(&enroll_result, sizeof(TPacketDGResultAuction));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "common/stl.h"
|
||||
#include "common/building.h"
|
||||
#include "common/auction_table.h"
|
||||
|
||||
#include "Peer.h"
|
||||
#include "DBManager.h"
|
||||
@@ -547,22 +546,6 @@ class CClientManager : public CNetBase, public singleton<CClientManager>
|
||||
void DeleteAwardId(TPacketDeleteAwardID* data);
|
||||
void UpdateChannelStatus(TChannelStatus* pData);
|
||||
void RequestChannelStatus(CPeer* peer, DWORD dwHandle);
|
||||
#ifdef __AUCTION__
|
||||
void EnrollInAuction (CPeer * peer, DWORD owner_id, AuctionEnrollProductInfo* data);
|
||||
void EnrollInSale (CPeer * peer, DWORD owner_id, AuctionEnrollSaleInfo* data);
|
||||
void EnrollInWish (CPeer * peer, DWORD wisher_id, AuctionEnrollWishInfo* data);
|
||||
void AuctionBid (CPeer * peer, DWORD bidder_id, AuctionBidInfo* data);
|
||||
void AuctionImpur (CPeer * peer, DWORD purchaser_id, AuctionImpurInfo* data);
|
||||
void AuctionGetAuctionedItem (CPeer * peer, DWORD actor_id, DWORD item_id);
|
||||
void AuctionBuySoldItem (CPeer * peer, DWORD actor_id, DWORD item_id);
|
||||
void AuctionCancelAuction (CPeer * peer, DWORD actor_id, DWORD item_id);
|
||||
void AuctionCancelWish (CPeer * peer, DWORD actor_id, DWORD item_num);
|
||||
void AuctionCancelSale (CPeer * peer, DWORD actor_id, DWORD item_id);
|
||||
void AuctionDeleteAuctionItem (CPeer * peer, DWORD actor_id, DWORD item_id);
|
||||
void AuctionDeleteSaleItem (CPeer * peer, DWORD actor_id, DWORD item_id);
|
||||
void AuctionReBid (CPeer * peer, DWORD bidder_id, AuctionBidInfo* data);
|
||||
void AuctionBidCancel (CPeer * peer, DWORD bidder_id, DWORD item_id);
|
||||
#endif
|
||||
};
|
||||
|
||||
template<class Func>
|
||||
|
||||
@@ -12,9 +12,6 @@
|
||||
#include "Monarch.h"
|
||||
#include "BlockCountry.h"
|
||||
#include "ItemIDRangeManager.h"
|
||||
#ifdef __AUCTION__
|
||||
#include "AuctionManager.h"
|
||||
#endif
|
||||
#include <signal.h>
|
||||
#undef OS_FREEBSD
|
||||
void SetPlayerDBName(const char* c_pszPlayerDBName);
|
||||
@@ -82,9 +79,7 @@ int main()
|
||||
CMonarch Monarch;
|
||||
CBlockCountry BlockCountry;
|
||||
CItemIDRangeManager ItemIDRangeManager;
|
||||
#ifdef __AUCTION__
|
||||
AuctionManager auctionManager;
|
||||
#endif
|
||||
|
||||
if (!Start())
|
||||
return 1;
|
||||
|
||||
@@ -92,9 +87,7 @@ int main()
|
||||
MarriageManager.Initialize();
|
||||
BlockCountry.Load();
|
||||
ItemIDRangeManager.Build();
|
||||
#ifdef __AUCTION__
|
||||
AuctionManager::instance().Initialize();
|
||||
#endif
|
||||
|
||||
sys_log(0, "Metin2DBCacheServer Start\n");
|
||||
|
||||
CClientManager::instance().MainLoop();
|
||||
|
||||
Reference in New Issue
Block a user