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

📄 gameplayer.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//////////////////////////////////////////////////////////////////////////////// Filename    : GamePlyaer.cpp // Written By  : reiot@ewestsoft.com// Description ://////////////////////////////////////////////////////////////////////////////#include "GamePlayer.h"#include "Assert.h"#include "Creature.h"#include "Slayer.h"#include "Vampire.h"#include "Ousters.h"#include "LogClient.h"#include "Zone.h"#include "RelicUtil.h"#include "PacketFactoryManager.h"#include "PacketValidator.h"#include "IncomingPlayerManager.h"#include "PCFinder.h"#include "TelephoneCenter.h"#include "DB.h"#include "VSDateTime.h"#include "Thread.h"#include "GuildManager.h"#include "Guild.h"#include "VariableManager.h"#include "SharedServerManager.h"#include "BillingInfo.h"#include "BillingPlayerManager.h"#include <fstream>#include "Properties.h"#include "EventKick.h"#include "StringPool.h"#include "Cpackets/CGConnect.h"#include "Gpackets/GSGuildMemberLogOn.h"#include "Gpackets/GCKickMessage.h"#include "Gpackets/GCSystemMessage.h"#include "ServiceDeadline.h"#include "chinabilling/CBillingInfo.h"#ifdef __CONNECT_CBILLING_SYSTEM__	#include "chinabilling/CBillingPlayerManager.h"#endif#include <stdio.h>//////////////////////////////////////////////////////////////////////////////// 葛电 packet甸俊 措秦辑 profiling茄促. by sigi. 2002.5.6//// 窜, 捞吧 荤侩窍扁 困秦辑绰 // Profile.h俊 MAX_PROFILE_SAMPLES += 300阑 秦拎具 茄促.////////////////////////////////////////////////////////////////////////////////#define __PROFILE_PACKETS__#ifdef __PROFILE_PACKETS__	#include "Profile.h"#endif// by sigi. 2002.11.12const int defaultGamePlayerInputStreamSize = 1024;const int defaultGamePlayerOutputStreamSize = 20480;static int maxIdleSec         = 60* 5;		// 5盒//static int maxSpeedVerifyTime = 2;  		// 0.3 檬static int maxVerifyCount     = 3;      	// 3 锅.static int maxTimeGap         =	5;			// 5檬static int SpeedCheckDelay    = 60;			// 1盒const int PCRoomLottoSec = 3600;			// 3600 檬. 1矫埃const int PCRoomLottoMaxAmount = 3;			// 茄锅俊 阶老 荐 乐绰 弥措 汗鼻荐// CLLoginHandler.cpp俊 乐绰 窃荐促.void addLogoutPlayerData(Player* pPlayer);//////////////////////////////////////////////////////////////////////////////// constructor//////////////////////////////////////////////////////////////////////////////GamePlayer::GamePlayer (Socket* pSocket)	 throw (Error): //Player(pSocket), 	// by sigi. 2002.11.12	m_pCreature(NULL), m_PlayerStatus(GPS_NONE), m_pReconnectPacket(NULL){	__BEGIN_TRY	Assert( pSocket != NULL );	m_pSocket = pSocket;#ifdef __USE_ENCRYPTER__	// create socket input stream	m_pInputStream = new SocketEncryptInputStream( m_pSocket, defaultGamePlayerInputStreamSize );	Assert( m_pInputStream != NULL );		// create socket output stream	m_pOutputStream = new SocketEncryptOutputStream( m_pSocket, defaultGamePlayerOutputStreamSize );	Assert( m_pOutputStream != NULL );#else	// create socket input stream	m_pInputStream = new SockettInputStream( m_pSocket, defaultGamePlayerInputStreamSize );	Assert( m_pInputStream != NULL );		// create socket output stream	m_pOutputStream = new SockettOutputStream( m_pSocket, defaultGamePlayerOutputStreamSize );	Assert( m_pOutputStream != NULL );#endif	m_Mutex.setName("GamePlayer");			getCurrentTime(m_ExpireTime);	m_ExpireTime.tv_sec += maxIdleSec;    // 泅犁 矫埃阑 罐酒柯促	//getCurrentTime(m_SpeedVerify);	m_SpeedVerify.tv_sec = 0;;	m_SpeedVerify.tv_usec = 0;;	getCurrentTime(m_MoveSpeedVerify);	getCurrentTime(m_AttackSpeedVerify);	m_VerifyCount = 0;		m_SpecialEventCount = 0;	m_bKickForLogin = false;		m_bFreePass = false;	m_bMetroFreePlayer = false;//	if ( m_bPCRoomPlay )//		m_ItemRatioBonusPoint = g_pVariableManager->getPCRoomItemRatioBonusPercent();//	else		m_ItemRatioBonusPoint = 0;	m_PCRoomLottoStartTime.tv_sec = 0;	m_PCRoomLottoStartTime.tv_usec = 0;	m_PCRoomLottoSumTime = 0;	m_bPacketLog = false;	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// destructor//////////////////////////////////////////////////////////////////////////////GamePlayer::~GamePlayer ()	 throw (Error){	__BEGIN_TRY	//__ENTER_CRITICAL_SECTION(m_Mutex)	// 弊 绢恫 敲饭捞绢 按眉啊 昏力瞪 锭俊档, 弊 惑怕绰 肺弊酒眶捞绢具 茄促.	// 溜 绢恫 敲饭捞绢甫 立加 辆丰 矫虐妨搁, 弊 惑怕甫 肺弊酒眶栏肺 父甸绢具 茄促.	Assert(m_PlayerStatus == GPS_END_SESSION);	try	{		// Delete creature		if (m_pCreature != NULL) 		{			// 己辑 冻绢哆府扁			if ( m_pCreature->hasRelicItem() )			{				dropRelicToZone( m_pCreature, false );			}			dropFlagToZone( m_pCreature, false );			dropSweeperToZone( m_pCreature );			//try 			//{				// NoSuch力芭. by sigi. 2002.5.2				g_pPCFinder->deleteCreature(m_pCreature->getName());			//} 			//catch (NoSuchElementException & t) 			//{			//}		#ifdef __CONNECT_BILLING_SYSTEM__			// Pay 辆丰茄促绊 舅妨霖促. by sigi. 2002.11.18			if ( isBillingPlayAvaiable() && !m_bMetroFreePlayer )	// by sigi. 2002.11.23			{				g_pBillingPlayerManager->sendPayLogout( this );			}		#elif defined(__CONNECT_CBILLING_SYSTEM__ )			// 吝惫 呼傅 辑滚俊 logout 菩哦阑 焊辰促.			g_pCBillingPlayerManager->sendLogout( this );		#endif			Statement* pStmt = NULL;			// 辨靛 泅犁 立加 糕滚 府胶飘俊辑 昏力茄促.			if ( m_pCreature->isSlayer() )			{				Slayer* pSlayer = dynamic_cast<Slayer*>(m_pCreature);				if ( pSlayer->getGuildID() != 99 )				{					Guild* pGuild = g_pGuildManager->getGuild( pSlayer->getGuildID() );					if ( pGuild != NULL )					{						pGuild->deleteCurrentMember( pSlayer->getName() );						GSGuildMemberLogOn gsGuildMemberLogOn;						gsGuildMemberLogOn.setGuildID( pGuild->getID() );						gsGuildMemberLogOn.setName( pSlayer->getName() );						gsGuildMemberLogOn.setLogOn( false );						g_pSharedServerManager->sendPacket( &gsGuildMemberLogOn );												// 叼厚俊 诀单捞飘 茄促.						BEGIN_DB						{							pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();							pStmt->executeQuery( "UPDATE GuildMember SET LogOn = 0 WHERE Name = '%s'", pSlayer->getName().c_str() );						}						END_DB(pStmt)					}					else						filelog( "GuildMissing.log", "[NoSuchGuild] GuildID : %d, Name : %s\n", (int)pSlayer->getGuildID(), pSlayer->getName().c_str() );				}			}			else if ( m_pCreature->isVampire() )			{				Vampire* pVampire = dynamic_cast<Vampire*>(m_pCreature);				if ( pVampire->getGuildID() != 0 )				{					Guild* pGuild = g_pGuildManager->getGuild( pVampire->getGuildID() );					if ( pGuild != NULL )					{						pGuild->deleteCurrentMember( pVampire->getName() );						GSGuildMemberLogOn gsGuildMemberLogOn;						gsGuildMemberLogOn.setGuildID( pGuild->getID() );						gsGuildMemberLogOn.setName( pVampire->getName() );						gsGuildMemberLogOn.setLogOn( false );						g_pSharedServerManager->sendPacket( &gsGuildMemberLogOn );						// 叼厚俊 诀单捞飘 茄促.						BEGIN_DB						{							pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();							pStmt->executeQuery( "UPDATE GuildMember SET LogOn = 0 WHERE Name = '%s'", pVampire->getName().c_str() );						}						END_DB(pStmt)					}					else						filelog( "GuildMissing.log", "[NoSuchGuild] GuildID : %d, Name : %s\n", (int)pVampire->getGuildID(), pVampire->getName().c_str() );				}			}			else if ( m_pCreature->isOusters() )			{				Ousters* pOusters = dynamic_cast<Ousters*>(m_pCreature);				if ( pOusters->getGuildID() != 66 )				{					Guild* pGuild = g_pGuildManager->getGuild( pOusters->getGuildID() );					if ( pGuild != NULL )					{						pGuild->deleteCurrentMember( pOusters->getName() );						GSGuildMemberLogOn gsGuildMemberLogOn;						gsGuildMemberLogOn.setGuildID( pGuild->getID() );						gsGuildMemberLogOn.setName( pOusters->getName() );						gsGuildMemberLogOn.setLogOn( false );						g_pSharedServerManager->sendPacket( &gsGuildMemberLogOn );						// 叼厚俊 诀单捞飘 茄促.						BEGIN_DB						{							pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();							pStmt->executeQuery( "UPDATE GuildMember SET LogOn = 0 WHERE Name = '%s'", pOusters->getName().c_str() );						}						END_DB(pStmt)					}					else						filelog( "GuildMissing.log", "[NoSuchGuild] GuildID : %d, Name : %s\n", (int)pOusters->getGuildID(), pOusters->getName().c_str() );				}			}			int PartyID = m_pCreature->getPartyID();			if (PartyID != 0)			{				Zone* pZone = m_pCreature->getZone();				if (pZone != NULL)				{					LocalPartyManager* pLocalPartyManager = pZone->getLocalPartyManager();					pLocalPartyManager->deletePartyMember(PartyID, m_pCreature);				}			}			SAFE_DELETE(m_pCreature);			//m_pCreature->setPlayer( NULL );		}	}	catch (NoSuchElementException& nsee)	{		cerr << "GamePlayer::~GamePlayer() : " << nsee.toString() << endl;		throw ("GamePlayer::~GamePlayer() : NoSuchElementException");	}	catch (Throwable& t )	{		t.addStack( __PRETTY_FUNCTION__ );		throw;	}	// 菩哦阑 昏力茄促.	while (!m_PacketHistory.empty()) 	{		Packet* pPacket = m_PacketHistory.front();		SAFE_DELETE(pPacket);		m_PacketHistory.pop_front();	}	SAFE_DELETE(m_pReconnectPacket);	//__LEAVE_CRITICAL_SECTION(m_Mutex)	__END_CATCH}////////////////////////////////////////////////////////////////////////// parse packet and execute handler for the packet////////////////////////////////////////////////////////////////////////void GamePlayer::processCommand (bool Option)      throw (IOException , Error){	__BEGIN_TRY	// 庆歹甫 烙矫历厘且 滚欺 积己	char header[szPacketHeader];	PacketID_t packetID;	PacketSize_t packetSize;	Packet* pPacket = NULL;	try {		// 菩澄萍甫 罐绊 乐绰 荤侩磊 老 版快 捞 何盒俊辑 贸府 秦霖促.		// 菩澄萍甫 罐绰 版快 绢恫 抗寇 惑炔捞 惯积且瘤 葛福骨肺,		// 沥惑利牢 贸府甫 促 茄促澜 菩澄萍甫 贸府窍档废 茄促.		if (isPenaltyFlag(PENALTY_TYPE_KICKED))		{			filelog("GamePlayer.txt", "Penalty Kicked. Name[%s],Host[%s],Type[%d]", 												((getCreature()==NULL)?"NULL":getCreature()->getName().c_str()), 												((getSocket()==NULL)?"NULL":getSocket()->getHost().c_str()),												m_ItemRatioBonusPoint);			throw DisconnectException("He is had penalty");		}		if (Option) 		{			m_EventManager.heartbeat();		}		// 涝仿滚欺俊 甸绢乐绰 肯傈茄 菩哦甸阑 葛炼府 贸府茄促.		while (true) 		{			// 涝仿胶飘覆俊辑 菩哦庆歹农扁父怒 佬绢夯促.			// 父距 瘤沥茄 农扁父怒 胶飘覆俊辑 佬阑 荐 绝促搁,			// Insufficient 抗寇啊 惯积窍绊, 风橇甫 狐廉唱埃促.			// NoSuch力芭. by sigi. 2002.5.4			if (!m_pInputStream->peek(&header[0] , szPacketHeader))			{				Timeval currentTime;				getCurrentTime(currentTime);				if (currentTime >= m_ExpireTime)				{					filelog("GamePlayer.txt", "Timeout Disconnect1. Name[%s],Host[%s]", 												((getCreature()==NULL)?"NULL":getCreature()->getName().c_str()), 												((getSocket()==NULL)?"NULL":getSocket()->getHost().c_str()));					throw DisconnectException("老沥 矫埃悼救 涝仿窍瘤 臼阑 版快, 楷搬阑 辆丰钦聪促.");				}				break;			}						// 菩哦酒捞叼 棺 菩哦农扁甫 舅酒辰促.			// 捞锭 菩哦农扁绰 庆歹甫 器窃茄促.			memcpy(&packetID   , &header[0] , szPacketID);				memcpy(&packetSize , &header[szPacketID] , szPacketSize);			// 菩哦 酒捞叼啊 捞惑窍搁 橇肺配妮 俊矾肺 埃林茄促.			if (packetID >= (int)Packet::PACKET_MAX)			{				filelog("GamePlayer.txt", "Packet ID exceed MAX, RECV [%d/%d],Name[%s],Host[%s]", 					packetID, 					Packet::PACKET_MAX,					getCreature()->getName().c_str(), 					getSocket()->getHost().c_str());				throw InvalidProtocolException("too large packet id");			}			try 			{				// 菩哦 鉴辑啊 棵官弗瘤 八刘茄促.				if (! g_pPacketValidator->isValidPacketID(getPlayerStatus() , packetID))				{					filelog("GamePlayer.txt", "Not Valid Packet, RECV [%d],Name[%s],Host[%s]", 						packetID, 						getCreature()->getName().c_str(), 						getSocket()->getHost().c_str());					throw InvalidProtocolException("invalid packet order");				}							// 菩哦 农扁啊 呈公 农搁 橇肺配妮 俊矾肺 埃林茄促.				if (packetSize > g_pPacketFactoryManager->getPacketMaxSize(packetID))				{					filelog("GamePlayer.txt", "Too Larget Packet Size, RECV [%d],PacketSize[%d],Name[%s],Host[%s]", 						packetID, packetSize,						getCreature()->getName().c_str(), 						getSocket()->getHost().c_str());					throw InvalidProtocolException("too large packet size");				}							// 涝仿滚欺郴俊 菩哦农扁父怒狼 单捞鸥啊 甸绢乐绰瘤 犬牢茄促.				// 弥利拳矫 break 甫 荤侩窍搁 等促. (咯扁辑绰 老窜 exception阑 镜 巴捞促.)				if (m_pInputStream->length() < szPacketHeader + packetSize)					//throw InsufficientDataException();					break;				// 菩哦 窍唱甫 佬菌栏聪, expire time 阑 楷扁茄促.				getCurrentTime(m_ExpireTime);				m_ExpireTime.tv_sec += maxIdleSec;							// 咯扁鳖瘤 吭促搁 涝仿滚欺俊绰 肯傈茄 菩哦 窍唱 捞惑捞 甸绢乐促绰 舵捞促.				// 菩哦蒲配府概聪历肺何磐 菩哦酒捞叼甫 荤侩秦辑 菩哦 胶飘钒贸甫 积己窍搁 等促.				// 菩哦酒捞叼啊 肋给瞪 版快绰 菩哦蒲配府概聪历俊辑 贸府茄促.				pPacket = g_pPacketFactoryManager->createPacket(packetID);

⌨️ 快捷键说明

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