⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 billingplayer.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////// // Filename    : BillingPlayer.cpp // Written By  : Reiot// //////////////////////////////////////////////////////////////////////// include files#include "BillingPlayer.h"#include "Socket.h"#include "SocketInputStream.h"#include "SocketOutputStream.h"#include "Assert.h"#include "Packet.h"#include "Properties.h"#include "PacketFactoryManager.h"#include "CommonBillingPacket.h"#ifdef __GAME_SERVER__	#include "PCFinder.h"	#include "GamePlayer.h"#elif defined(__LOGIN_SERVER__)	#include "LoginPlayer.h"#endif// by sigi. 2002.11.12const int defaultBillingPlayerInputStreamSize = 10240;const int defaultBillingPlayerOutputStreamSize = 10240;////////////////////////////////////////////////////////////////////////// constructor////////////////////////////////////////////////////////////////////////BillingPlayer::BillingPlayer ()	 throw ( Error )//: m_pSocket(NULL), m_pInputStream(NULL), m_pOutputStream(NULL){}BillingPlayer::BillingPlayer (Socket * pSocket)	 throw ( Error )//: Player( pSocket )//m_pSocket(pSocket), m_pInputStream(NULL), m_pOutputStream(NULL){	__BEGIN_TRY			Assert( pSocket != NULL );	m_pSocket = pSocket;	// create socket input stream	m_pInputStream = new SocketInputStream( m_pSocket, defaultBillingPlayerInputStreamSize );	Assert( m_pInputStream != NULL );		// create socket output stream	m_pOutputStream = new SocketOutputStream( m_pSocket, defaultBillingPlayerOutputStreamSize );	Assert( m_pOutputStream != NULL );	m_RetryCount = 0;	m_RetryValue = 0;	__END_CATCH}////////////////////////////////////////////////////////////////////////// destructor////////////////////////////////////////////////////////////////////////BillingPlayer::~BillingPlayer ()	 throw ( Error ){	__BEGIN_TRY			// delete socket input stream	SAFE_DELETE(m_pInputStream);	// delete socket output stream	SAFE_DELETE(m_pOutputStream);	// delete socket	if ( m_pSocket != NULL ) 	{		m_pSocket->close();		delete m_pSocket;		m_pSocket = NULL;		filelog(LOGFILE_BILLING_PLAYER, "Close Socket" );	}	__END_CATCH}void BillingPlayer::processInput()	throw ( IOException, Error ){	__BEGIN_TRY	try	{		m_pInputStream->fill();	}	catch ( NonBlockingIOException& nbie )	{	}	__END_CATCH}void BillingPlayer::processOutput()	throw ( IOException, Error ){	__BEGIN_TRY	try	{		m_pOutputStream->flush();	}	catch ( InvalidProtocolException& )	{		throw DisconnectException( "捞惑茄 菩哦烙" );	}	__END_CATCH}////////////////////////////////////////////////////////////////////////// parse packet and execute handler for the packet////////////////////////////////////////////////////////////////////////void BillingPlayer::processCommand ()      throw ( IOException , Error ){	__BEGIN_TRY	try {		// 庆歹甫 烙矫历厘且 滚欺 积己		//char header[szPacketHeader];		//PacketID_t packetID;		//PacketSize_t packetSize;		CommonBillingPacket	cbPacket;		// 涝仿滚欺俊 甸绢乐绰 肯傈茄 菩哦甸阑 葛炼府 贸府茄促.		while ( true ) {					/*			// 涝仿胶飘覆俊辑 菩哦庆歹农扁父怒 佬绢夯促.			// 父距 瘤沥茄 农扁父怒 胶飘覆俊辑 佬阑 荐 绝促搁,			// Insufficient 抗寇啊 惯积窍绊, 风橇甫 狐廉唱埃促.			if ( !m_pInputStream->peek( header , szPacketHeader ) )				break;			// 菩哦酒捞叼 棺 菩哦农扁甫 舅酒辰促.			// 捞锭 菩哦农扁绰 庆歹甫 器窃茄促.			memcpy( &packetID   , &header[0] , szPacketID );				memcpy( &packetSize , &header[szPacketID] , szPacketSize );			// 菩哦 酒捞叼啊 捞惑窍搁 橇肺配妮 俊矾肺 埃林茄促.			if ( packetID >= Packet::PACKET_MAX )				throw InvalidProtocolException("invalid packet id");						// 菩哦 农扁啊 呈公 农搁 橇肺配妮 俊矾肺 埃林茄促.			if ( packetSize > g_pPacketFactoryManager->getPacketMaxSize(packetID) )				throw InvalidProtocolException("too large packet size");			*/						// 涝仿滚欺郴俊 菩哦农扁父怒狼 单捞鸥啊 甸绢乐绰瘤 犬牢茄促.			// 弥利拳矫 break 甫 荤侩窍搁 等促. (咯扁辑绰 老窜 exception阑 镜 巴捞促.)			//if ( m_pInputStream->length() < szPacketHeader + packetSize )			if ( m_pInputStream->length() < cbPacket.getPacketSize())			{				//throw InsufficientDataException();				return;			}						// 咯扁鳖瘤 吭促搁 涝仿滚欺俊绰 肯傈茄 菩哦 窍唱 捞惑捞 甸绢乐促绰 舵捞促.			// 菩哦蒲配府概聪历肺何磐 菩哦酒捞叼甫 荤侩秦辑 菩哦 胶飘钒贸甫 积己窍搁 等促.			// 菩哦酒捞叼啊 肋给瞪 版快绰 菩哦蒲配府概聪历俊辑 贸府茄促.			//pPacket = g_pPacketFactoryManager->createPacket( packetID );			// 捞力 捞 菩哦胶飘钒贸甫 檬扁拳茄促.			// 菩哦窍困努贰胶俊 沥狼等 read()啊 virtual 皋目聪硫俊 狼秦辑 龋免登绢			// 磊悼利栏肺 檬扁拳等促.			//m_pInputStream->read( pPacket );			// packetHeader何盒捞 鞘夸绝促.			cbPacket.read( *m_pInputStream );						// 捞力 捞 菩哦胶飘钒贸甫 啊瘤绊 菩哦勤甸矾甫 荐青窍搁 等促.			// 菩哦酒捞叼啊 肋给瞪 版快绰 菩哦勤甸矾概聪历俊辑 贸府茄促.			//pPacket->execute( this );			cbPacket.execute( this );			// 菩哦阑 昏力茄促			//delete pPacket;		}	} catch ( NoSuchElementException & nsee ) {		// PacketFactoryManager::createPacket(PacketID_t)		// PacketFactoryManager::getPacketMaxSize(PacketID_t)		// 俊辑 带龙 啊瓷己捞 乐促.		throw Error( nsee.toString() );	} catch ( InsufficientDataException ) {		// do nothing	} 	__END_CATCH}		    ////////////////////////////////////////////////////////////////////////// send packet to player's output buffer////////////////////////////////////////////////////////////////////////void BillingPlayer::sendPacket ( Packet * pPacket )	throw ( ProtocolException , Error ){	__BEGIN_TRY	//m_pOutputStream->write( pPacket );	// packetHeader绰 鞘夸绝促.	pPacket->write( *m_pOutputStream );	/*	cout << endl;	cout << "=== BillingPlayer::sendPacket() ===" << endl;	cout << pPacket->toString() << endl;	cout << "============================" << endl;	*/	__END_CATCH}////////////////////////////////////////////////////////////////////////// disconnect ( close socket )////////////////////////////////////////////////////////////////////////void BillingPlayer::disconnect ( bool bDisconnected )	throw (InvalidProtocolException, Error){	__BEGIN_TRY	try 	{		// 沥寸窍霸 肺弊酒眶茄 版快俊绰 免仿 滚欺甫 敲矾矫且 荐 乐促.		// 弊矾唱, 阂过利牢 叼胶甫 吧菌促搁 家南捞 摧板栏骨肺		// 敲矾矫且 版快 SIG_PIPE 阑 罐霸 等促.		if ( bDisconnected == UNDISCONNECTED ) 		{			m_pOutputStream->flush();		}		m_pSocket->close();	} 	catch ( InvalidProtocolException & t ) 	{		cerr << "BillingPlayer::disconnect Exception Check!!" << endl;		cerr << t.toString() << endl;		m_pSocket->close();		//throw Error("揪官...");	}	__END_CATCH}//////////////////////////////////////////////////////////////////////// set socket//////////////////////////////////////////////////////////////////////void BillingPlayer::setSocket ( Socket * pSocket )	throw (){	__BEGIN_TRY	m_pSocket = pSocket;	if ( m_pInputStream != NULL ) 	{		delete m_pInputStream;		m_pInputStream = new SocketInputStream( m_pSocket );	}	if ( m_pOutputStream != NULL ) {		delete m_pOutputStream;		m_pOutputStream = new SocketOutputStream( m_pSocket );	}	__END_CATCH}//////////////////////////////////////////////////////////////////////// 霸烙 辑滚啊 贸澜 躲 锭 焊辰促.//////////////////////////////////////////////////////////////////////void BillingPlayer::sendPayInit()	throw( ProtocolException, Error ){	__BEGIN_TRY			CommonBillingPacket cbPacket;	BillingInfo* pBillingInfo = &cbPacket;	memset((char*)pBillingInfo, 0, sizeof(BillingInfo));	cbPacket.setPacket_Type( BILLING_PACKET_INIT );	cbPacket.setUser_CC();	sendPacket( &cbPacket );	filelog(LOGFILE_BILLING_PLAYER, "-------------------- send BillingInit --------------------");	filelog(LOGFILE_BILLING_PLAYER, "%s", cbPacket.toString().c_str());#ifdef __COUT_BILLING_SYSTEM__	cout << "[send] BillingPlayer::sendPayInit" << endl;#endif	__END_CATCH}//////////////////////////////////////////////////////////////////////// 某腐磐狼 立加 惑怕甫 焊辰促.//////////////////////////////////////////////////////////////////////void BillingPlayer::sendPayCheck( CommonBillingPacket* pPacket )	throw( ProtocolException, Error ){	__BEGIN_TRY		#ifdef __COUT_BILLING_SYSTEM__	cout << "BillingPlayer::sendPayCheck" << endl;#endif	string PlayerID = pPacket->User_ID;	CommonBillingPacket cbPacket;	BillingInfo* pBillingInfo = &cbPacket;	memset((char*)pBillingInfo, 0, sizeof(BillingInfo));	cbPacket.setPacket_Type( BILLING_PACKET_CHECK );	cbPacket.setSession( pPacket->Session );	// 立加 吝牢瘤 酒囱瘤 PlayerID肺 眉农茄促.#ifdef __GAME_SERVER__	Creature* pCreature = g_pPCFinder->getCreatureByID(PlayerID);	bool isPlaying = ( pCreature != NULL );#else	bool isPlaying = true;#endif	if (isPlaying)	{		cbPacket.setResult( BILLING_RESULT_CHECK_PLAYING );		filelog(LOGFILE_BILLING_PLAYER, "SEND PayCheck : (%s) Playing", PlayerID.c_str());	}	else	{		cbPacket.setExpire_Date(PlayerID);		cbPacket.setResult( BILLING_RESULT_CHECK_DISCONNECTED );		//filelog(LOGFILE_BILLING_PLAYER, "SEND PayCheck : Disconnected(%s, %s)", PlayerID.c_str(), cbPacket.getExpire_DateToString().c_str());		filelog(LOGFILE_BILLING_PLAYER, "SEND PayCheck : Disconnected(%s, %s)", PlayerID.c_str(), cbPacket.Expire_Date );	}	cbPacket.setUser_CC();	sendPacket( &cbPacket );	/*	cout << "[send] BillingPlayer::sendPayCheck (" << PlayerID.c_str() << ") - " << (int)isPlaying << endl;	cbPacket.setExpire_Date(PlayerID);	cout << "[CHECK_EXPIRE_TIME] " << cbPacket.toString().c_str() << endl;	*/	__END_CATCH}//////////////////////////////////////////////////////////////////////// 某腐磐啊 霸烙俊 贸澜 立加且锭 焊郴绰巴//////////////////////////////////////////////////////////////////////void BillingPlayer::sendPayLogin( Player* pPlayer ) 	throw( ProtocolException, Error ){	__BEGIN_TRY	static int GameNo = g_pConfig->getPropertyInt("BillingGameNo");	CommonBillingPacket cbPacket;	BillingInfo* pBillingInfo = &cbPacket;	memset((char*)pBillingInfo, 0, sizeof(BillingInfo));#ifdef __GAME_SERVER__	GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);	if (pGamePlayer!=NULL)	{		cbPacket.setPacket_Type( BILLING_PACKET_LOGIN );		cbPacket.setSession( pGamePlayer->getBillingSession() );		cbPacket.setUser_CC();		cbPacket.setUser_No(pGamePlayer->getBillingUserKey());		cbPacket.setUser_ID(pGamePlayer->getID());		cbPacket.setUser_IP(pGamePlayer->getSocket()->getHost());		cbPacket.setGame_No( GameNo );		// for TEST		cbPacket.setExpire_Date(pPlayer->getID());		int requestCount = pGamePlayer->getBillingLoginRequestCount();		if (requestCount==0)		{			filelog(LOGFILE_BILLING_PLAYER, "SEND PayLogin(%s)", pPlayer->getID().c_str());		}		else		{			filelog(LOGFILE_BILLING_PLAYER, "SEND PayLogin(%s) Retrying[%d]", pPlayer->getID().c_str(), requestCount);		}		sendPacket( &cbPacket );	#ifdef __COUT_BILLING_SYSTEM__		cout << "[send] BillingPlayer::sendPayLogin (" << pPlayer->getID().c_str() << ") trying[" << requestCount << "]" << endl;	#endif	}	else	{		filelog(LOGFILE_BILLING_PLAYER, "ERROR Not GamePlayer(%s)", pPlayer->getID().c_str());	#ifdef __COUT_BILLING_SYSTEM__		cout << "[ERROR] BillingPlayer::Not GamePlayer (" << pPlayer->getID().c_str() << ")" << endl;	#endif	}#elif defined(__LOGIN_SERVER__)	LoginPlayer* pLoginPlayer = dynamic_cast<LoginPlayer*>(pPlayer);	if (pLoginPlayer!=NULL)	{		cbPacket.setPacket_Type( BILLING_PACKET_LOGIN_CHECK );		cbPacket.setSession( pLoginPlayer->getBillingSession() );		cbPacket.setUser_CC();		cbPacket.setUser_No(pLoginPlayer->getBillingUserKey());		cbPacket.setUser_ID(pLoginPlayer->getID());		cbPacket.setUser_IP(pLoginPlayer->getSocket()->getHost());		cbPacket.setGame_No( GameNo );		int requestCount = pLoginPlayer->getBillingLoginRequestCount();		if (requestCount==0)		{			filelog(LOGFILE_BILLING_PLAYER, "SEND PayLoginCheck(%s)", pPlayer->getID().c_str());		}		else		{			filelog(LOGFILE_BILLING_PLAYER, "SEND PayLoginCheck(%s) Retrying[%d]", pPlayer->getID().c_str(), requestCount);			if ( requestCount > 1 )			{				m_RetryCount++;				m_RetryValue += requestCount;			}		}		sendPacket( &cbPacket );	#ifdef __COUT_BILLING_SYSTEM__		cout << "[send] BillingPlayer::sendPayLoginCheck (" << pPlayer->getID().c_str() << ") trying[" << requestCount << "]" << endl;	#endif	}	else	{		filelog(LOGFILE_BILLING_PLAYER, "ERROR Not GamePlayer(%s)", pPlayer->getID().c_str());	#ifdef __COUT_BILLING_SYSTEM__		cout << "[ERROR] BillingPlayer::Not GamePlayer (" << pPlayer->getID().c_str() << ")" << endl;	#endif	}#endif	__END_CATCH}//////////////////////////////////////////////////////////////////////// 某腐磐啊 霸烙俊辑 唱哎锭 焊郴绰巴//////////////////////////////////////////////////////////////////////void BillingPlayer::sendPayLogout( Player* pPlayer ) 	throw( ProtocolException, Error ){	__BEGIN_TRY			CommonBillingPacket cbPacket;	BillingInfo* pBillingInfo = &cbPacket;	memset((char*)pBillingInfo, 0, sizeof(BillingInfo));#ifdef __GAME_SERVER__	GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);	if (pGamePlayer!=NULL)	{		cbPacket.setPacket_Type( BILLING_PACKET_LOGOUT );		cbPacket.setSession( pGamePlayer->getBillingSession() );		cbPacket.setUser_CC();		cbPacket.setUser_ID(pGamePlayer->getID());		cbPacket.setUser_IP(pGamePlayer->getSocket()->getHost());		cbPacket.setUser_Status(pGamePlayer->getBillingUserStatus());		filelog(LOGFILE_BILLING_PLAYER, "SEND PayLogout(%s)", pPlayer->getID().c_str());		sendPacket( &cbPacket );	#ifdef __COUT_BILLING_SYSTEM__		cout << "[send] BillingPlayer::sendPayLogout (" << pPlayer->getID().c_str() << ")" << endl;	#endif	}	else	{		filelog(LOGFILE_BILLING_PLAYER, "ERROR Not GamePlayer(%s)", pPlayer->getID().c_str());	#ifdef __COUT_BILLING_SYSTEM__		cout << "[ERROR] BillingPlayer::Not GamePlayer (" << pPlayer->getID().c_str() << ")" << endl;	#endif	}#endif	__END_CATCH}////////////////////////////////////////////////////////////////////////// get debug string////////////////////////////////////////////////////////////////////////string BillingPlayer::toString () const       throw ( Error ){	__BEGIN_TRY			StringStream msg;		msg << "BillingPlayer("		<< "SocketID:" << m_pSocket->getSOCKET() 		<< ",Host:" << m_pSocket->getHost() 		<< ",ID:" << m_ID		<< ")" ;	return msg.toString();	__END_CATCH}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -