cgconnecthandler.cpp

来自「天之炼狱1服务器端源文件游戏服务端不完整」· C++ 代码 · 共 1,006 行 · 第 1/3 页

CPP
1,006
字号
//////////////////////////////////////////////////////////////////////////////// Filename    : CGConnectHandler.cpp// Written By  : Reiot// Description ://////////////////////////////////////////////////////////////////////////////#include "CGConnect.h"#ifdef __GAME_SERVER__	#include "PlayerCreature.h"	#include "GamePlayer.h"	#include "Slayer.h"	#include "Vampire.h"	#include "Ousters.h"	#include "Zone.h"	#include "ZoneInfoManager.h"	#include "ZoneUtil.h"	#include "ZoneGroup.h"	#include "ZoneGroupManager.h"	#include "ZonePlayerManager.h"	#include "IncomingPlayerManager.h"	#include "WeatherManager.h"	#include "PCFinder.h"	#include "GuildManager.h"	#include "Guild.h"	#include "TelephoneCenter.h"	#include "EventSave.h"	#include "EventRegeneration.h"	#include "EventHeadCount.h"	#include "PCSlayerInfo2.h"	#include "PCVampireInfo2.h"	#include "NPCInfo.h"	#include "PacketUtil.h"	#include "DB.h"	#include "Properties.h"	#include "LogClient.h"	#include "Thread.h"	#include "PacketUtil.h"	#include "ResurrectLocationManager.h"	#include "SharedServerManager.h"	#include "BillingPlayerManager.h"	#include "Encrypter.h"	#include "LogDef.h"	#include "EventSystemMessage.h"	#include "CastleInfoManager.h"	#include "PKZoneInfoManager.h"	#include "EventZoneInfo.h"	#include "EffectGhost.h"	#include "skill/EffectGnomesWhisper.h"	#include "mission/QuestManager.h"	#include "CreatureUtil.h"	#include <fstream>	#include <list>	#include <stdio.h>	#include "Gpackets/GCDisconnect.h"	#include "Gpackets/GCUpdateInfo.h"	#include "Gpackets/GCSystemMessage.h"	#include "Gpackets/GSGuildMemberLogOn.h"	#include "SystemAvailabilitiesManager.h"	#include "chinabilling/CBillingInfo.h"#ifdef __CONNECT_CBILLING_SYSTEM__	#include "chinabilling/CBillingPlayerManager.h"	#include "EventCBilling.h"#endif#endif//////////////////////////////////////////////////////////////////////////////// CGConnectHandler::execute()//// 捞 菩哦篮 肺弊牢辑滚俊辑 弥檬肺 霸烙 辑滚肺 楷搬且 锭, 肚绰 霸烙 辑滚俊辑// 促弗 霸烙 辑滚肺 捞悼且 锭, 努扼捞攫飘啊 辑滚肺 傈价窍绰 弥檬狼 菩哦捞促.// 捞锭 敲饭捞绢 按眉绰 货肺 积败抄 惑怕捞绊, 捞 敲饭捞绢 按眉绰 IPM 俊辑// 包府登绰 惑怕捞促. //// 寸楷洒 弥檬狼 菩哦栏肺 促弗 菩哦捞 逞绢坷绰 版快扼搁, 捞巴篮 秦欧 矫档扼绊// 毫档 公规窍骨肺 捞 菩哦捞 弥檬牢瘤 八荤秦具 茄促. 捞甫 困秦辑 敲饭捞绢 按眉俊// 捞傈 菩哦阑 历厘窍绊 乐栏骨肺, 捞 蔼捞 NULL 牢瘤父 焊搁 登摆促.//// 肋给等 菩哦捞扼搁, ban 俊 殿废窍绊 立加阑 辆丰茄促.//////////////////////////////////////////////////////////////////////////////void CGConnectHandler::execute (CGConnect* pPacket , Player* pPlayer)	 throw (ProtocolException , Error){	__BEGIN_TRY __BEGIN_DEBUG_EX	__BEGIN_DEBUG		#ifdef __GAME_SERVER__	Assert(pPacket != NULL);	Assert(pPlayer != NULL);	GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);	// set MAC Address	pGamePlayer->setMacAddress( pPacket->getMacAddress() );	// 捞 菩哦阑 ConnectionInfo 按眉甫 爱绊 柯促.	// 农贰目绰 虐蔼苞 某腐磐 捞抚阑 老沥 矫埃救俊 嘎苗具父 立加捞 啊瓷窍促.	try 	{		ConnectionInfo* pConnectionInfo = g_pConnectionInfoManager->getConnectionInfo(pGamePlayer->getSocket()->getHost());		// 虐蔼阑 牢刘茄促.		if (pPacket->getKey() != pConnectionInfo->getKey())		{			FILELOG_INCOMING_CONNECTION("connectionError.log", "Wrong Key: [%s] %s", pConnectionInfo->getPCName().c_str(), pGamePlayer->getSocket()->getHost().c_str());			throw InvalidProtocolException("invalid key");		}		// 捞抚阑 牢刘茄促.		if (pPacket->getPCName() != pConnectionInfo->getPCName())		{			FILELOG_INCOMING_CONNECTION("connectionError.log", "Wrong PCName: [%s] %s", pConnectionInfo->getPCName().c_str(), pGamePlayer->getSocket()->getHost().c_str());			throw InvalidProtocolException("invalid pc name");		}		// 老窜 捞抚阑 历厘茄促. 绢瞒乔 促澜俊 角菩窍搁 按眉甫 昏力窍聪鳖 公规窍促.		pGamePlayer->setID(pConnectionInfo->getPlayerID());		// CIM狼 heartbeat啊 角青登扁 傈俊 犁荐亮霸 立加且 啊瓷己捞 乐促.		// (鸥捞怪捞 亮栏搁 heartbeat 角青林扁*2 救俊父 立加窍搁 等促.)		// 蝶扼辑, 泅犁 矫埃苞 expire time 阑 厚背茄促.		Timeval currentTime;		getCurrentTime(currentTime);		if (pConnectionInfo->getExpireTime() < currentTime) 		{			FILELOG_INCOMING_CONNECTION("connectionError.log", "Expired: [%s] %s", pConnectionInfo->getPCName().c_str(), pGamePlayer->getSocket()->getHost().c_str());			// 老窜 昏力茄促.			g_pConnectionInfoManager->deleteConnectionInfo(pConnectionInfo->getClientIP());			throw InvalidProtocolException("session already expired");		}       	// by sigi. 2002.12.7		FILELOG_INCOMING_CONNECTION("connectionInfo.log", "Login [%s:%s] %s (%u)",										pConnectionInfo->getPlayerID().c_str(),										pConnectionInfo->getPCName().c_str(),										pConnectionInfo->getClientIP().c_str(),										pConnectionInfo->getKey());		// 牢刘登菌栏聪, ConnectionInfo 甫 昏力茄促.		try {			g_pConnectionInfoManager->deleteConnectionInfo(pConnectionInfo->getClientIP());		} catch (NoSuchElementException& nsee)		{			FILELOG_INCOMING_CONNECTION("connectionInfoDelete.log", "DeleteNoSuch [%s:%s] %s (%u)",										pConnectionInfo->getPlayerID().c_str(),										pConnectionInfo->getPCName().c_str(),										pConnectionInfo->getClientIP().c_str(),										pConnectionInfo->getKey());		}	} 	catch (NoSuchElementException & nsee) // 弊繁 IP甫 啊柳 CI 啊 绝阑 版快	{ 		FILELOG_INCOMING_CONNECTION("connectionError.log", "NoSuchConnectionInfo: %s", pGamePlayer->getSocket()->getHost().c_str());		// 褥.. 楷搬 捞饶 CGConnect 菩哦阑 焊郴绰 掉饭捞啊 呈公 辨 版快		// session 捞 expire 等促. 捞凡 版快俊档 楼福磊!		// (抗甫 甸绢辑, 弥檬 楷搬俊辑绰 己傍沁栏唱 弊促澜俊 叼滚彪 惑怕肺		// 甸绢哎 版快, CGConnect 菩哦阑 焊尘 锭码俊绰 expire 等促.)		GCDisconnect gcDisconnect;		gcDisconnect.setMessage(nsee.toString());		pGamePlayer->sendPacket(&gcDisconnect);		// 捞犯霸 带瘤搁 惑困 IPM::processCommands()俊辑 disconnect 贸府茄促.		throw InvalidProtocolException(nsee.toString().c_str());	} 	catch (InvalidProtocolException & ipe) 	{		FILELOG_INCOMING_CONNECTION("connectionError.log", "%s: %s", ipe.toString().c_str(), pGamePlayer->getSocket()->getHost().c_str());		cout << endl			 << "+-----------------------+" << endl			 << "| Level 2 Access Denied |" << endl			 << "+-----------------------+" << endl			 << endl;		GCDisconnect gcDisconnect;		gcDisconnect.setMessage(ipe.toString());		pGamePlayer->sendPacket(&gcDisconnect);		// 捞犯霸 带瘤搁 惑困 IPM::processCommands()俊辑 disconnect 贸府茄促.		throw;	}	//----------------------------------------------------------------------	// 肺弊牢 眉农	//----------------------------------------------------------------------	Statement* pStmt   = NULL;	Result*    pResult = NULL; 	// 呼傅~	PayType         payType;	string          payPlayDate;	uint            payPlayHours;	uint            payPlayFlag;	int				billingUserKey = 0;	// by sigi. 2002.11.18	string          familyPayPlayDate;	try	{		pStmt   = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pResult = pStmt->executeQuery("SELECT PlayerID FROM Slayer WHERE Name = '%s'",pPacket->getPCName().c_str());		if (pResult->getRowCount() != 1)		{			StringStream msg;			msg << "Failed to load PlayerCreature data from DB. Not 1 PlayerID (" 				<< pPacket->getPCName().c_str() << ")";			filelog("connectDB_BUG.txt", "%s", msg.toString().c_str());			SAFE_DELETE(pStmt);			throw ProtocolException( msg.toString().c_str() );		}		if (pResult->next()) 		{			string spID = pResult->getString(1);			if (strcasecmp(spID.c_str(), pGamePlayer->getID().c_str()) != 0) 			{				StringStream msg;				msg << "Failed to load PlayerCreature data from DB. No Character(" 					<< spID.c_str() << "!="					<< pGamePlayer->getID().c_str() << ")";				filelog("connectDB_BUG.txt", "%s", msg.toString().c_str());				SAFE_DELETE(pStmt);				throw ProtocolException( msg.toString().c_str() );			}		}		SAFE_DELETE(pStmt);		//pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pStmt = g_pDatabaseManager->getDistConnection("PLAYER_DB")->createStatement();		pResult = pStmt->executeQuery("SELECT PlayerID, CurrentServerGroupID, LogOn, SpecialEventCount, PayType, PayPlayDate, PayPlayHours, PayPlayFlag, BillingUserKey, FamilyPayPlayDate FROM Player WHERE PlayerID = '%s'",										pGamePlayer->getID().c_str());		if (pResult->getRowCount() != 1)		{			StringStream msg;			msg << "Failed to load PlayerCreature data from DB. No Player(" 				<< pPacket->getPCName().c_str() << ")";			filelog("connectDB_BUG.txt", "%s", msg.toString().c_str());			SAFE_DELETE(pStmt);			throw ProtocolException(msg.toString().c_str());		}		pResult->next();		int i = 0;		string          playerID = pResult->getString(++i);		ServerGroupID_t GID      = pResult->getInt(++i);		string          logon    = pResult->getString(++i);		uint            scount	= pResult->getDWORD(++i);		payType      = (PayType)pResult->getInt(++i);		payPlayDate  = pResult->getString(++i);		payPlayHours = pResult->getInt(++i);		payPlayFlag  = pResult->getInt(++i);		billingUserKey  	= pResult->getInt(++i);		familyPayPlayDate	= pResult->getString(++i);		pGamePlayer->setServerGroupID(GID);		pGamePlayer->setSpecialEventCount(scount);		pGamePlayer->setBillingUserKey( billingUserKey );		if (logon != "LOGOFF")		{			SAFE_DELETE(pStmt);			char str[80];			sprintf(str, "Already connected player ID: %s, %s", playerID.c_str(), logon.c_str());			throw ProtocolException(str);		}		pStmt->executeQuery("UPDATE Player SET LogOn='GAME' WHERE PlayerID = '%s' AND LogOn='LOGOFF'", playerID.c_str());		// LogOn捞 LOGOFF啊 酒聪芭唱.. 殿殿.. by sigi. 2002.5.15		if (pStmt->getAffectedRowCount()==0)		{			SAFE_DELETE(pStmt);			char str[80];			sprintf(str, "Already connected player ID2: %s, %s", playerID.c_str(), logon.c_str());			throw ProtocolException(str);		}		string connectIP = pGamePlayer->getSocket()->getHost();		// 呼傅 by sigi. 2002.5.31#if defined(__CONNECT_BILLING_SYSTEM__)		if ( payType == PAY_TYPE_FREE )		{			pGamePlayer->setMetroFreePlayer();		}#elif defined(__PAY_SYSTEM_LOGIN__)		if (pGamePlayer->loginPayPlay(payType, 										payPlayDate, payPlayHours, payPlayFlag,										connectIP, playerID))		{			sendPayInfo(pGamePlayer);		}		else		{			SAFE_DELETE(pStmt);			throw ProtocolException("no pay account");		}// by sigi. 2002.11.18. 力茄利 公丰 荤侩磊. - -; 老窜 login#elif defined(__PAY_SYSTEM_FREE_LIMIT__)		if (pGamePlayer->loginPayPlay(payType, 										payPlayDate, payPlayHours, payPlayFlag,										connectIP, playerID))		{			sendPayInfo(pGamePlayer);		}#else //defined(__PAY_SYSTEM_ZONE__)		pGamePlayer->setPayPlayValue(payType, payPlayDate, payPlayHours, payPlayFlag, familyPayPlayDate);#endif		SAFE_DELETE(pStmt);

⌨️ 快捷键说明

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