#include "StdAfx.h" #include "ShopEventHandler.h" CShopEventHandler::CShopEventHandler() { } CShopEventHandler::~CShopEventHandler() { } void CShopEventHandler::OnConnect(bool success, DWORD error) { WriteLog("OnConnect (errorcode: %d)\r\n", error); OnNetConnect(success, error); } void CShopEventHandler::OnSend( int size ) { WriteLog("OnSend (size: %d)\r\n", size); OnNetSend(size); } void CShopEventHandler::OnClose( DWORD error ) { WriteLog("OnClose (errorcode: %d)\r\n", error); OnNetClose(error); } bool CShopEventHandler::CreateSession(WBANetwork::LPFN_ErrorHandler errhandler) { bool bret = CClientSession::CreateSession(errhandler); if(bret) WriteLog("CreateSession success\r\n"); else WriteLog("CreateSession fail\r\n"); return bret; } void CShopEventHandler::OnReceive( PBYTE buffer, int size ) { switch(((ShopProtocol::MSG_REQUEST_BASE*)buffer)->dwProtocolID) { case PROTOCOL_SERVER_INQUIRE_SALESVERSION: {//版本号查询消息 ShopProtocol::MSG_SERVER_INQUIRE_SALESVERSION* msg = \ (ShopProtocol::MSG_SERVER_INQUIRE_SALESVERSION *)buffer; OnInquireSalesZoneScriptVersion(msg->SalesZone, msg->Year, msg->YearIdentity, msg->ResultCode); } break; case PROTOCOL_SERVER_INQUIRE_CASH: {//点劵查询消息 ShopProtocol::MSG_SERVER_INQUIRE_CASH *msg = \ (ShopProtocol::MSG_SERVER_INQUIRE_CASH *)buffer; OnInquireCash( msg->AccountSeq, msg->CashPoint, msg->PPCashPoint, msg->MileagePoint, msg->ListCount ); } break; case PROTOCOL_SERVER_BUYPRODUCT: {//商品购买 ShopProtocol::MSG_SERVER_BUYPRODUCT * msg = \ (ShopProtocol::MSG_SERVER_BUYPRODUCT*)buffer; OnBuyProduct(msg->AccountSeq,msg->ResultCode); } break; case PROTOCOL_SERVER_GIFTPRODUCT: {//礼品赠送 ShopProtocol::MSG_SERVER_GIFTPRODUCT* msg = \ (ShopProtocol::MSG_SERVER_GIFTPRODUCT*)buffer; OnGiftProduct(msg->SenderSeq,msg->ReceiverSeq,msg->ResultCode); } break; case PROTOCOL_SERVER_STORAGELIST: {//保管盒查询 ShopProtocol::MSG_SERVER_STORAGELIST* msg = \ (ShopProtocol::MSG_SERVER_STORAGELIST*)buffer; ShopProtocol::STStorage* StorageList = \ ((ShopProtocol::STStorage*)(buffer + msg->PackHeader)); OnInquireStorageList(msg->AccountSeq,msg->ListCount,msg->ResultCode,StorageList); } break; case PROTOCOL_SERVER_STORAGEUSE: {//保管盒物品领取 ShopProtocol::MSG_SERVER_STORAGEUSE_ONE* msg = \ (ShopProtocol::MSG_SERVER_STORAGEUSE_ONE*)buffer; OnUseStorage(msg->AccountSeq, msg->ResultCode, msg->InGameProductID, msg->StorageSeq, msg->ItemProperty); } break; case PROTOCOL_SERVER_STORAGEUSE_ALL: { ShopProtocol::MSG_SERVER_STORAGEUSE_MULIT * msg =\ (ShopProtocol::MSG_SERVER_STORAGEUSE_MULIT*)buffer; ShopProtocol::MSG_SERVER_STORAGEUSE_ONE* ProductInfoList = \ ((ShopProtocol::MSG_SERVER_STORAGEUSE_ONE*)(buffer + msg->PackHeader)); for(int i = 0;iiListCount;++i) { OnUseStorage( ProductInfoList[i].AccountSeq, ProductInfoList[i].ResultCode, ProductInfoList[i].InGameProductID, ProductInfoList[i].StorageSeq, ProductInfoList[i].ItemProperty ); } } break; default: WriteLog("Not Define Receive Code (code: %d)\r\n", ((ShopProtocol::MSG_REQUEST_BASE*)buffer)->dwProtocolID); break; } } bool CShopEventHandler::InquireCash(long GameCode, DWORD AccountSeq) { ShopProtocol::MSG_CLIENT_INQUIRE_CASH msg(GameCode); msg.AccountSeq = AccountSeq; USES_CONVERSION; bool bret = SendData(&msg, msg.dwPacketSize); if(bret) WriteLog("InquireCash Send success\r\n"); else WriteLog("InquireCash Send fail\r\n"); return bret; } bool CShopEventHandler::InquireSalesZoneScriptVersion(long GameCode) {//发送查询出售版本号信息 ShopProtocol::MSG_CLIENT_INQUIRE_SALESVERSION msg; msg.GameCode = GameCode; USES_CONVERSION; bool bret = SendData(&msg, msg.dwPacketSize); if(bret) WriteLog("InquireSalesZoneScriptVersion Send success\r\n"); else WriteLog("InquireSalesZoneScriptVersion Send fail\r\n"); return bret; } bool CShopEventHandler::BuyProduct(long GameCode, DWORD AccountSeq, long PackageProductSeq, long PriceSeq, WCHAR CharName[MAX_CHARACTERID_LENGTH]) { ShopProtocol::MSG_CLIENT_BUYPRODUCT msg(GameCode); msg.AccountSeq = AccountSeq; msg.PackageSeq = PackageProductSeq; msg.PriceSeq = PriceSeq; StringCchCopyW(msg.CharName, MAX_CHARACTERID_LENGTH, CharName); USES_CONVERSION; bool bret = SendData(&msg, msg.dwPacketSize); if(bret) { WriteLog("BuyProduct Send success(AccountSeq:%d, GameCode:%d, PackageProductSeq:%d, \r\n\t\tPriceSeq:%d, CharName:%s, )\r\n", AccountSeq, msg.GetGameCode(), PackageProductSeq, PriceSeq,W2A(CharName)); } else { WriteLog("BuyProduct Send fail(AccountSeq:%d, GameCode:%d, PackageProductSeq:%d,\r\n\t\tPriceSeq:%d, CharName:%s)\r\n", AccountSeq, msg.GetGameCode(), PackageProductSeq, PriceSeq,W2A(CharName)); } return bret; } bool CShopEventHandler::GiftProduct(long GameCode, DWORD SenderSeq, WCHAR SenderCharName[MAX_CHARACTERID_LENGTH], DWORD ReceiverSeq, WCHAR ReceiverCharName[MAX_CHARACTERID_LENGTH], WCHAR Message[MAX_MESSAGE_LENGTH], long PackageProductSeq, long PriceSeq) { ShopProtocol::MSG_CLIENT_GIFTPRODUCT msg(GameCode); msg.SenderSeq = SenderSeq; StringCchCopyW(msg.SenderCharName, MAX_CHARACTERID_LENGTH, SenderCharName); msg.ReceiverSeq = ReceiverSeq; StringCchCopyW(msg.ReceiverCharName, MAX_CHARACTERID_LENGTH, ReceiverCharName); StringCchCopyW(msg.Message, MAX_MESSAGE_LENGTH, Message); msg.PackageSeq = PackageProductSeq; msg.PriceSeq = PriceSeq; USES_CONVERSION; bool bret = SendData(&msg, msg.dwPacketSize); if(bret) { WriteLog("GiftProduct Send success(Sender:%d, , SenderCharName:%s, Receiver:%d, ReceiverCharName:%s,\r\n\t\tMessage:%s, GameCode:%d, PackageProductSeq:%d, PriceSeq:%d )\r\n", SenderSeq, W2A(SenderCharName), ReceiverSeq, W2A(ReceiverCharName), W2A(Message), msg.GetGameCode(), PackageProductSeq, PriceSeq); } else { WriteLog("GiftProduct Send fail(Sender:%d, SenderCharName:%s, Receiver:%d, ReceiverCharName:%s,\r\n\t\tMessage:%s, GameCode:%d, PackageProductSeq:%d, PriceSeq:%d)\r\n", SenderSeq, W2A(SenderCharName), ReceiverSeq, W2A(ReceiverCharName), W2A(Message), msg.GetGameCode(), PackageProductSeq, PriceSeq); } return bret; } bool CShopEventHandler::InquireStorageList(DWORD AccountSeq, long GameCode) { ShopProtocol::MSG_CLIENT_STORAGELIST msg; msg.AccountSeq = AccountSeq; msg.GameCode = GameCode; bool bret = SendData(&msg, msg.dwPacketSize); if(bret) WriteLog("InquireStorageList Send success(%d, %d)\r\n", AccountSeq, GameCode); else WriteLog("InquireStorageList Send fail(%d, %d)\r\n", AccountSeq, GameCode); return bret; } bool CShopEventHandler::UseStorageRollback(DWORD AccountSeq, long StorageSeq ) { ShopProtocol::MSG_CLIENT_STORAGEUSEROLLBACK msg; msg.AccountSeq = AccountSeq; msg.StorageSeq = StorageSeq; USES_CONVERSION; bool bret = SendData(&msg, msg.dwPacketSize); if(bret) WriteLog("UseStorageRollback Send success(%d, %d)\r\n", AccountSeq, StorageSeq); else WriteLog("UseStorageRollback Send fail(%d, %d)\r\n", AccountSeq,StorageSeq); return bret; } bool CShopEventHandler::UseStorage(DWORD AccountSeq, long GameCode, DWORD IPAddress, long StorageSeq, WCHAR CharName[MAX_CHARACTERID_LENGTH], bool bUseAll, POSTYPE EmptySlotNum) { ShopProtocol::MSG_CLIENT_STORAGEUSE msg; if(bUseAll) msg.dwProtocolID = PROTOCOL_CLINET_STORAGEUSE_ALL; msg.AccountSeq = AccountSeq; msg.GameCode = GameCode; msg.IPAddress = IPAddress; msg.StorageSeq = StorageSeq; msg.EmptySlotNum = EmptySlotNum; StringCchCopyW(msg.CharName, MAX_CHARACTERID_LENGTH, CharName); USES_CONVERSION; bool bret = SendData(&msg, msg.dwPacketSize); if(bret) WriteLog("UseStorage Send success(%d, %d, %u, %d, %s)\r\n", AccountSeq, GameCode, IPAddress, StorageSeq, W2A(CharName)); else WriteLog("UseStorage Send fail(%d, %d, %u, %d, %s)\r\n", AccountSeq, GameCode, IPAddress, StorageSeq , W2A(CharName)); return bret; } void CShopEventHandler::WriteLog(const char* szFormat, ...) { char szBuf[4096] = {0}; va_list list; va_start (list, szFormat); StringCchVPrintfA(szBuf, 4096, szFormat, list); va_end (list); WriteLog(szBuf); }