78 lines
2.2 KiB
C++
78 lines
2.2 KiB
C++
|
|
#include "StdAfx.h"
|
|
#include "ProtocolInvoker.h"
|
|
#include "PCCShopInquireSalesVersion.hpp"
|
|
#include "PCCShopInquireCash.hpp"
|
|
#include "PCCShopStorageList.hpp"
|
|
#include "PCCShopBuyProduct.hpp"
|
|
#include "PCCShopGiftProduct.hpp"
|
|
#include "PCCShopStorageUse.hpp"
|
|
|
|
CProtocolInvoker::CProtocolInvoker(void)
|
|
{
|
|
}
|
|
|
|
CProtocolInvoker::~CProtocolInvoker(void)
|
|
{
|
|
RemoveConCreateCommands();
|
|
}
|
|
|
|
void CProtocolInvoker::SetProtocalCommand()
|
|
{
|
|
InsertConCreateCommands();
|
|
}
|
|
|
|
void CProtocolInvoker::InsertConCreateCommand(DWORD key, CProtocolCommand* value)
|
|
{
|
|
std::pair<CONCRETE_COMMAND_MAP::iterator, bool> result =
|
|
m_ConcreteCommand.insert(CONCRETE_COMMAND_MAP::value_type(key, value));
|
|
|
|
if(!result.second)
|
|
{
|
|
BILLING_LOG(WZPUBLIC::LEVEL_ERROR, "网络协议命令绑定失败(%ld)", key);
|
|
}
|
|
}
|
|
|
|
void CProtocolInvoker::InsertConCreateCommands()
|
|
{
|
|
InsertConCreateCommand(PROTOCOL_CLIENT_INQUIRE_CASH, new CPCCShopInquireCash);
|
|
InsertConCreateCommand(PROTOCOL_CLIENT_BUYPRODUCT, new CPCCShopBuyProduct);
|
|
InsertConCreateCommand(PROTOCOL_CLIENT_GIFTPRODUCT, new CPCCShopGiftProduct);
|
|
|
|
InsertConCreateCommand(PROTOCOL_CLIENT_STORAGELIST, new CPCCShopStorageList);
|
|
|
|
InsertConCreateCommand(PROTOCOL_CLIENT_STORAGEUSE, new CPCCShopStorageUse);
|
|
InsertConCreateCommand(PROTOCOL_CLINET_STORAGEUSE_ALL, new CPCCShopStorageUseAll);
|
|
InsertConCreateCommand(PROTOCOL_CLINET_STORAGEUSE_ROLLBACK, new CPCCShopStorageUseRollback);
|
|
|
|
InsertConCreateCommand(PROTOCOL_CLIENT_INQUIRE_SALESVERSION, new CPCCShopInquireSalesVersion);
|
|
}
|
|
|
|
void CProtocolInvoker::RemoveConCreateCommands()
|
|
{
|
|
for( CONCRETE_COMMAND_MAP::iterator iter = m_ConcreteCommand.begin() ; iter != m_ConcreteCommand.end() ; ++iter )
|
|
{
|
|
CProtocolCommand* pCommand = iter->second;
|
|
if( NULL != pCommand )
|
|
{
|
|
delete pCommand;
|
|
}
|
|
}
|
|
m_ConcreteCommand.clear();
|
|
}
|
|
|
|
void CProtocolInvoker::ProcessCommand(DWORD_PTR pSession, PBYTE pBuf)
|
|
{
|
|
CONCRETE_COMMAND_MAP::iterator iterFind =
|
|
m_ConcreteCommand.find(((ShopProtocol::MSG_REQUEST_BASE<void>*)pBuf)->dwProtocolID);
|
|
|
|
if(m_ConcreteCommand.end() == iterFind)
|
|
{
|
|
BILLING_LOG(WZPUBLIC::LEVEL_WARN, "接受到未知消息 MsgID (%ld)",
|
|
((ShopProtocol::MSG_REQUEST_BASE<void>*)pBuf)->dwProtocolID);
|
|
}
|
|
else
|
|
{
|
|
((CProtocolCommand*)iterFind->second)->Execute(pSession, pBuf);
|
|
}
|
|
} |