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

📄 cbillingplayer.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//////////////////////////////////////////////////////////////////// filename		: CBillingPlayer.cpp//////////////////////////////////////////////////////////////////// include files#include "CBillingPlayer.h"#include "Socket.h"#include "SocketInputStream.h"#include "SocketOutputStream.h"#include "Assert.h"#include "Packet.h"#include "CBillingPlayerManager.h"#include "CBillingPacketHeader.h"#include "CBillingPacketErrorBody.h"#include <stdio.h>#include "signal.h"#ifdef __GAME_SERVER__	#include "PCFinder.h"	#include "GamePlayer.h"	#include "CBillingPacketRequestLoginBody.h"	#include "CBillingPacketResponseLoginBody.h"	#include "CBillingPacketRequestMinusPointBody.h"	#include "CBillingPacketRequestMinusMinuteBody.h"	#include "CBillingPacketRequestLogoutBody.h"	#include "CBillingPacketRequestIntervalValidationBody.h"	#include "CBillingPacketResponseMinusPointBody.h"	#include "CBillingPacketResponseMinusMinuteBody.h"	#include "CBillingPacketResponseLogoutBody.h"	#include "CBillingPacketResponseIntervalValidationBody.h"	#include "DB.h"	#include "Gpackets/GCSystemMessage.h"	#include "gameserver/StringPool.h"#elif defined(__LOGIN_SERVER__)	#include "LoginPlayer.h"	#include "LoginPlayerManager.h"	#include "CBillingPacketRequestLoginBody.h"	#include "CBillingPacketResponseLoginBody.h"#endifconst int defaultCBillingPlayerInputStreamSize = 10240;const int defaultCBillingPlayerOutputStreamSize = 10240;// constructorCBillingPlayer::CBillingPlayer()	throw ( Error ){}// constructorCBillingPlayer::CBillingPlayer( Socket* pSocket )	throw ( Error ){	__BEGIN_TRY	Assert( pSocket != NULL );	m_pSocket = pSocket;	// create socket input stream	m_pInputStream = new SocketInputStream( m_pSocket, defaultCBillingPlayerInputStreamSize );	Assert( m_pInputStream != NULL );	// create socket output stream	m_pOutputStream = new SocketOutputStream( m_pSocket, defaultCBillingPlayerOutputStreamSize );	Assert( m_pOutputStream != NULL );	__END_CATCH}// destructorCBillingPlayer::~CBillingPlayer()	throw ( Error ){	__BEGIN_TRY	// delete socket intput stream	SAFE_DELETE( m_pInputStream );	// delete socket output stream	SAFE_DELETE( m_pOutputStream );	// delete socket	if ( m_pSocket != NULL )	{		m_pSocket->close();		SAFE_DELETE( m_pSocket );		filelog( LOGFILE_CBILLING_PLAYER, "Close Socket" );	}	__END_CATCH}void CBillingPlayer::processInput()	throw ( IOException, Error ){	__BEGIN_TRY	try	{		m_pInputStream->fill();	}	catch ( NonBlockingIOException& nbie )	{	}	__END_CATCH}void CBillingPlayer::processOutput()	throw ( IOException, Error ){	__BEGIN_TRY	try	{		m_pOutputStream->flush();	}	catch ( InvalidProtocolException& )	{		throw DisconnectException( "捞惑茄 菩哦烙" );	}	__END_CATCH}// parse packet and execute packet handlervoid CBillingPlayer::processCommand()	throw ( IOException, Error ){	__BEGIN_TRY	try	{		// 涝仿 滚欺俊 甸绢乐绰 肯傈茄 菩哦甸阑 葛炼府 贸府茄促.		while ( true )		{			// 庆歹甫 历厘且 滚欺 积己			CBillingPacketHeader header;			// 老窜 庆歹甫 佬绰促. peek. 涝仿滚欺俊辑 瘤快瘤绰 臼绰促.			// 庆歹啊 肯傈窍瘤 臼栏搁 菩胶			if ( !m_pInputStream->peek( (char*)&header, szCBillingPacketHeaderInfo ) )				return;			header.Version_No  = ntohl( header.Version_No );			header.Packet_Type = ntohl( header.Packet_Type );			header.Method_Code = ntohl( header.Method_Code );			header.Return_Code = ntohl( header.Return_Code );			header.Body_Length = ntohl( header.Body_Length );			////////////////////////////////////////////////////////////////////////////////////			// Packet_Type, Method_Code, Return_Code 俊 蝶扼 官叼啊 肯傈洒 粮犁窍绰瘤 犬牢茄促.			////////////////////////////////////////////////////////////////////////////////////			if ( header.Packet_Type != CBILLING_PACKET_RESPONSE )			{				cout << "error" << endl;				cout << "try to disconnect to china billing server" << endl;				filelog( LOGFILE_CBILLING_PLAYER, "!!!!!!!!!!!!!!!! try to disconnect to china billing server" );				g_pCBillingPlayerManager->setForceDisconnect();				return;				// 俊矾促 扯菩~			}			// 角菩老 版快			if ( header.Return_Code != CBILLING_RETURN_CODE_SUCCESS )			{				// 官叼啊 肯傈洒 甸绢乐绰瘤 犬牢茄促.				if ( m_pInputStream->length() < szCBillingPacketHeaderInfo + szCBillingPacketErrorBodyInfo )					return;				// 捞力 角力肺 葛炼府 佬绢 郴磊.				CBillingPacketErrorBody body;				header.read( *m_pInputStream );				body.read( *m_pInputStream );				executeError( header, body );			}			else // 己傍老 版快			{				switch ( header.Method_Code )				{#ifdef __LOGIN_SERVER__				case CBILLING_METHOD_CODE_LOGIN :					{						// 官叼啊 肯傈洒 甸绢乐绰瘤 犬牢茄促.						if ( m_pInputStream->length() < szCBillingPacketHeaderInfo + szCBillingPacketResponseLoginBodyInfo )							return;						// 捞力 角力肺 葛炼府 佬绢 郴磊.						CBillingPacketResponseLoginBody body;						header.read( *m_pInputStream );						body.read( *m_pInputStream );						// 角青						executeLogin( header, body );						break;					}#elif defined(__GAME_SERVER__)				case CBILLING_METHOD_CODE_INTERVAL_VALIDATION:					{						// 官叼啊 肯傈洒 甸绢乐绰瘤 犬牢茄促.						if ( m_pInputStream->length() < szCBillingPacketHeaderInfo + szCBillingPacketResponseIntervalValidationBodyInfo )							return;												// 捞力 角力肺 葛炼府 佬绢 郴磊.						CBillingPacketResponseIntervalValidationBody body;						header.read( *m_pInputStream );						body.read( *m_pInputStream );						// 角青						executeIntervalValidation( header, body );						break;					}				case CBILLING_METHOD_CODE_LOGIN :					{						// 官叼啊 肯傈洒 甸绢乐绰瘤 犬牢茄促.						if ( m_pInputStream->length() < szCBillingPacketHeaderInfo + szCBillingPacketResponseLoginBodyInfo )							return;						// 捞力 角力肺 葛炼府 佬绢 郴磊.						CBillingPacketResponseLoginBody body;						header.read( *m_pInputStream );						body.read( *m_pInputStream );						// 角青						executeLogin( header, body );						break;					}				case CBILLING_METHOD_CODE_MINUS_POINT:					{						// 官叼啊 肯傈洒 甸绢乐绰瘤 犬牢茄促.						if ( m_pInputStream->length() < szCBillingPacketHeaderInfo + szCBillingPacketResponseMinusPointBodyInfo )							return;						// 捞力 角力肺 葛炼府 佬绢 郴磊.						CBillingPacketResponseMinusPointBody body;						header.read( *m_pInputStream );						body.read( *m_pInputStream );						// 角青						executeMinusPoint( header, body );						break;					}				case CBILLING_METHOD_CODE_MINUS_MINUTE:					{						// 官叼啊 肯傈洒 甸绢乐绰瘤 犬牢茄促.						if ( m_pInputStream->length() < szCBillingPacketHeaderInfo + szCBillingPacketResponseMinusMinuteBodyInfo )							return;						// 捞力 角力肺 葛炼府 佬绢 郴磊.						CBillingPacketResponseMinusMinuteBody body;						header.read( *m_pInputStream );						body.read( *m_pInputStream );						// 角青						executeMinusMinute( header, body );						break;					}				case CBILLING_METHOD_CODE_LOGOUT:					{						// 官叼啊 肯傈洒 甸绢乐绰瘤 犬牢茄促.						if ( m_pInputStream->length() < szCBillingPacketHeaderInfo + szCBillingPacketResponseLogoutBodyInfo )							return;						// 捞力 角力肺 葛炼府 佬绢 郴磊.						CBillingPacketResponseLogoutBody body;						header.read( *m_pInputStream );						body.read( *m_pInputStream );						// 角青						executeLogout( header, body );						break;					}#endif				default:					{						throw Error( "Invaild Code" );						// 俊矾促.						break;					}				}			}		}	}	catch ( NoSuchElementException& nsee )	{		throw Error( nsee.toString() );	}	catch ( InsufficientDataException )	{		// do nothing	}	__END_CATCH}// send packet to player's output buffervoid CBillingPlayer::sendPacket( Packet* pPacket )	throw ( ProtocolException, Error ){	__BEGIN_TRY	//pPacket->write( *m_pOutputStream );	__END_CATCH}// disconnectvoid CBillingPlayer::disconnect( bool bDisconnected )	throw ( InvalidProtocolException, Error ){	__BEGIN_TRY	try	{		if ( bDisconnected == UNDISCONNECTED )		{			m_pOutputStream->flush();		}		m_pSocket->close();	}	catch ( InvalidProtocolException& t )	{		cerr << "CBillingPlayer::disconnect Exception occur!!" << endl;		cerr << t.toString() << endl;		m_pSocket->close();	}	__END_CATCH}// set socketvoid CBillingPlayer::setSocket( Socket* pSocket )	throw (){	__BEGIN_TRY	m_pSocket = pSocket;	SAFE_DELETE( m_pInputStream );	m_pInputStream = new SocketInputStream( m_pSocket );	SAFE_DELETE( m_pOutputStream );	m_pOutputStream = new SocketOutputStream( m_pSocket );	__END_CATCH}#ifdef __LOGIN_SERVER__// send login packetvoid CBillingPlayer::sendLogin( LoginPlayer* pLoginPlayer )	throw ( ProtocolException, Error ){	__BEGIN_TRY	CBillingPacketHeader header;	CBillingPacketRequestLoginBody body;	header.Packet_Type	= CBILLING_PACKET_REQUEST;	header.Method_Code	= CBILLING_METHOD_CODE_LOGIN;	header.Session_ID	= pLoginPlayer->increaseSendID();	header.Body_Length	= szCBillingPacketRequestLoginBodyInfo;	strcpy( body.Login_Name, pLoginPlayer->getID().c_str() );	strcpy( body.Player_IP, pLoginPlayer->getSocket()->getHost().c_str() );	char macstring[20];	const BYTE* macaddress = pLoginPlayer->getMacAddress();	sprintf( macstring, "%02X:%02X:%02X:%02X:%02X:%02X", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5] );	strcpy( body.Player_MAC, macstring );	header.write( *m_pOutputStream );	body.write( *m_pOutputStream );

⌨️ 快捷键说明

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