void CGSMSAddressListHandler::execute (CGSMSAddressList* pPacket , Player* pPlayer)
	 throw(ProtocolException, Error)
{
	__BEGIN_TRY __BEGIN_DEBUG_EX
		
#ifdef __GAME_SERVER__

	Assert(pPacket != NULL);
	Assert(pPlayer != NULL);

	GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);
	Assert(pGamePlayer != NULL);

	PlayerCreature* pPC = dynamic_cast<PlayerCreature*>(pGamePlayer->getCreature());
	Assert(pPC != NULL);

	SMSAddressBook* pBook = pPC->getAddressBook();
	if (pBook != NULL )
	{
		GCSMSAddressList* pPacket = pBook->getGCSMSAddressList();
		if (pPacket != NULL ) pGamePlayer->sendPacket(pPacket);
	}

#endif	// __GAME_SERVER__
		
	__END_DEBUG_EX __END_CATCH
}
Exemple #2
0
BOOL RecoverManager::Tick()	
{
	__ENTER_FUNCTION

	MySleep(100) ;


	if(m_Count==0)
		return TRUE;

	

	for(uint i=0;i<m_Count;i++)
	{
		GamePlayer* pPlayer = m_PlayerPtr[i];
		Assert(pPlayer);

		if(pPlayer->ShareMemSafe()) //Êý¾Ý¿â±£´æÍê±Ï
		{
			

		}

	}

	__LEAVE_FUNCTION

	return TRUE;
}
Exemple #3
0
UINT CGCountryAppointHandler::Execute( CGCountryAppoint* pPacket, Player* pPlayer )
{
    __ENTER_FUNCTION

    GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
    Assert( pGamePlayer ) ;

    Obj_Human* pHuman = pGamePlayer->GetHuman() ;
    Assert( pHuman ) ;

    Scene* pScene = pHuman->getScene() ;
    if( pScene==NULL )
    {
        Assert(FALSE) ;
        return PACKET_EXE_ERROR ;
    }

    //检查线程执行资源是否正确
    Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );

    CGCountryAppoint *pMsg = (CGCountryAppoint *)g_pPacketFactoryManager->CreatePacket(PACKET_GW_COUNTRY_APPOINT);
    pMsg->SetCountryAppointData(pPacket->GetCountryAppointData());
    g_pServerManager->SendPacket( pMsg, INVALID_ID );

    return PACKET_EXE_CONTINUE ;

    __LEAVE_FUNCTION

    return PACKET_EXE_ERROR ;
}
Exemple #4
0
BOOL RecoverManager::Init()
{

	__ENTER_FUNCTION

	m_Lock.Lock();

	for(uint i=0;i<MAX_POOL_SIZE;i++)
	{
		GamePlayer* pPlayer = g_pPlayerPool->GetPlayer(i);
		
		if(pPlayer->GetShareMemStatus())
		{
			
			g_pPlayerPool->NewPlayer(i);
			AddPlayer(pPlayer);
		}

	}
	
	m_Lock.Unlock();
	return TRUE;

	__LEAVE_FUNCTION

	m_Lock.Unlock();
	return FALSE;
}
UINT WGDetailOtherOnlineAttrib_HumanHandler::Execute( WGDetailOtherOnlineAttrib_Human* pPacket, Player* pPlayer )
{
    __ENTER_FUNCTION
		
	PlayerID_t PlayerID = pPacket->GetPlayerID(); //发起查看者的ID
	GamePlayer* pGamePlayer = g_pPlayerPool->GetPlayer(PlayerID);
	if( pGamePlayer==NULL )
	{
		Assert(FALSE);
		return PACKET_EXE_CONTINUE;
	}

	GCDetailAttrib Msg;
	Msg.SetLevel(pPacket->GetLevel());
	Msg.SetCountry(pPacket->GetCountry());
	Msg.SetMenpai(pPacket->GetMenpai());
	Msg.SetDataID(pPacket->GetDataID());
	
	pGamePlayer->SendPacket(&Msg);

	g_pLog->FastSaveLog( LOG_FILE_1, "WGDetailOtherOnlineAttrib_HumanHandler: ok obj=%d,scene=%d",
		pGamePlayer->GetHuman()->GetID(), pGamePlayer->GetHuman()->getScene()->SceneID());

    return PACKET_EXE_CONTINUE;

    __LEAVE_FUNCTION

        return PACKET_EXE_ERROR;
}
Exemple #6
0
bool GameSingleStage::onInit()
{
	if ( !BaseClass::onInit() )
		return false;


	GameSubStage* subStage = getSubStage();

	subStage->setupLocalGame( *mPlayerManager.get() );
	subStage->setupScene( *mPlayerManager.get() );

	for( IPlayerManager::Iterator iter = getPlayerManager()->getIterator();
		iter.haveMore() ; iter.goNext() )
	{
		GamePlayer* player = iter.getElement();
		if ( player->getAI() )
		{
			ActionInput* input = player->getAI()->getActionInput();
			if ( input )
				getActionProcessor().addInput( *input );
		}
	}

	if  ( !buildReplayRecorder() )
	{

	}

	ActionProcessor& processor = getActionProcessor();

	processor.addInput( getGame()->getController() );
	restart( true );
	return true;
}
UINT CGExchangeSynchMoneyIIHandler::Execute( CGExchangeSynchMoneyII* pPacket, Player* pPlayer )
{
    __ENTER_FUNCTION

    GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
    Assert( pGamePlayer ) ;

    Obj_Human* pHuman = pGamePlayer->GetHuman() ;
    Assert( pHuman ) ;

    Scene* pScene = pHuman->getScene() ;
    if( pScene==NULL )
    {
        Assert(FALSE) ;
        return PACKET_EXE_ERROR ;
    }

    //检查线程执行资源是否正确
    Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

    //验证
    EXCHANGE_CERTIFY_EACH_OTHER(pHuman)
    EXCHANGE_CERTIFY_ISLOCK(pHuman)

    ObjID_t    DestID = pHuman->m_ExchangBox.m_ObjID;
    Obj_Human* pDestHuman = pScene->GetHumanManager()->GetHuman( DestID );

    EXCHANGE_CERTIFY_STATUS(pHuman, EXCHANGE_SYNCH_DATA)
    EXCHANGE_CERTIFY_STATUS(pDestHuman, EXCHANGE_SYNCH_DATA)
    

    //操作
    UINT    Money     = pPacket->GetMoney();        

    if( Money<= pHuman->GetMoney() )
    {
        pHuman->m_ExchangBox.m_Money = Money;
        g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 设置交易金钱 [%d]",    pHuman->GetName(), Money ) ;

        //金钱改变不发给自己了,省条消息
        GCExchangeSynchII MsgToTarget;
        MsgToTarget.SetIsMyself(FALSE);
        MsgToTarget.SetOpt(EXCHANGE_MSG::OPT_MONEY);
        MsgToTarget.SetMoney(Money);
        pDestHuman->GetPlayer()->SendPacket(&MsgToTarget);
        return PACKET_EXE_CONTINUE;
    }
    else
    {
        GCExchangeError Msg;
        Msg.SetID(EXCHANGE_MSG::ERR_ILLEGAL);
        pHuman->GetPlayer()->SendPacket(&Msg);
        pHuman->m_ExchangBox.CleanUp();
        return PACKET_EXE_CONTINUE;
    }
    
    __LEAVE_FUNCTION

        return PACKET_EXE_ERROR ;
}
Exemple #8
0
void	ScenePlayerManager::getMaxMinFD(SOCK removedFD,SOCK& maxFD,SOCK& minFD)
{
    __ENTER_FUNCTION

    maxFD = minFD = INVALID_SOCKET;
    for( int i=0; i<getObjNum(); i++ )
    {
        GamePlayer* pPlayer = getObjByIndex(i);
        if (NULL == pPlayer)
        {
            continue;
        }
        Socket* pPlayerSocket = pPlayer->getSocket();
        if (NULL == pPlayerSocket)
        {
            continue;
        }
        SOCK playerSocket = pPlayerSocket->getSocket();
        if (removedFD == playerSocket)
        {
            continue;
        }
        if( maxFD < playerSocket )
        {
            maxFD = playerSocket ;
        }
        if (minFD > playerSocket)
        {
            minFD = playerSocket;
        }		
    }	
    __LEAVE_FUNCTION
}
void CGRequestRepairHandler::execute (CGRequestRepair* pPacket , Player* pPlayer)
	 throw(ProtocolException , Error)
{
	__BEGIN_TRY __BEGIN_DEBUG_EX

#ifdef __GAME_SERVER__

	Assert(pPacket != NULL);
	Assert(pPlayer != NULL);
	
	ObjectID_t  ITEMOID     = pPacket->getObjectID();
	GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);
	Creature*   pPC         = pGamePlayer->getCreature();
	bool        bSlayer     = false;
	bool        bVampire    = false;
	bool        bOusters    = false;
	Item*       pItem       = NULL;
	
	// 플레이어가 슬레이어인지 뱀파이어인지 구분.
	if (pPC->isSlayer())       bSlayer = true;
	else if (pPC->isVampire()) bVampire = true;
	else if (pPC->isOusters()) bOusters = true;
	else throw ProtocolException("CGRequestRepairHandler::execute() : Unknown player creature!");

	if (ITEMOID == 0)
	{
		// ObjectID가 0이라면 모든 아이템을 수리하고자 하는 것이다.
		executeAll(pPacket, pPlayer);
	}
	else
	{
		if (bSlayer) pItem = (dynamic_cast<Slayer*>(pPC))->findItemOID(ITEMOID);
		else if (bVampire) pItem = (dynamic_cast<Vampire*>(pPC))->findItemOID(ITEMOID);
		else if (bOusters) pItem = (dynamic_cast<Ousters*>(pPC))->findItemOID(ITEMOID);

		// 플레이어가 아이템을 가지고 있다면
		if (pItem != NULL)
		{
			// 그 아이템이 모터 사이클 키라면...
			if (pItem->getItemClass() == Item::ITEM_CLASS_KEY && pItem->getItemType() == 2)
			{
				executeMotorcycle(pPacket, pPlayer);
				return;
			}
			else executeNormal(pPacket, pPlayer);
		}
		else
		{
			// 아이템이 없으니, 당연히 수리할 수 없다.
			GCNPCResponse response;
			response.setCode(NPC_RESPONSE_REPAIR_FAIL_ITEM_NOT_EXIST);
			pPlayer->sendPacket(&response);
		}
	}
	
#endif

	__END_DEBUG_EX __END_CATCH
}
UINT CGAskDetailAbilityInfoHandler::Execute( CGAskDetailAbilityInfo* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

    GamePlayer* pGamePlayer = (GamePlayer*)pPlayer;
    Assert( pGamePlayer );

    Obj_Human* pHuman = pGamePlayer->GetHuman();
    Assert( pHuman );

    Scene* pScene = pHuman->getScene();
    if( pScene==NULL )
    {
        Assert(FALSE);
        return PACKET_EXE_ERROR;
    }

    //检查线程执行资源是否正确
    Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );

    ObjID_t ObjID = pHuman->GetID();
    if( ObjID == INVALID_ID )
    {
        Assert(FALSE);
        return PACKET_EXE_ERROR;
    }

    Obj_Human *pTarget = (Obj_Human*)(pScene->GetObjManager()->GetObj(pPacket->getTargetID()));
    if( pTarget==NULL )
    {
        Assert( pTarget );
        return PACKET_EXE_ERROR;
    }

    // 权限判断
    // to be continue...
    if ( pTarget->GetObjType() != Obj::OBJ_TYPE_HUMAN )
    {
        return PACKET_EXE_ERROR;
    }

    GCDetailAbilityInfo Msg;

    Msg.setObjID( pTarget->GetID() );

    const _ABILITY_LIST *pAbilityList = pTarget->GetAbilityList();
    Msg.setAbilityList( g_pAbilityManager->MaxAbilityNum(), pAbilityList->m_aABility, pAbilityList->m_aPrescr );

    pGamePlayer->SendPacket( &Msg );

    g_pLog->FastSaveLog( LOG_FILE_1, "CGAskDetailAbilityInfoHandler: ok obj=%d scene=%d", 
        ObjID, pScene->SceneID() );

    return PACKET_EXE_CONTINUE;

__LEAVE_FUNCTION

    return PACKET_EXE_ERROR;
}
Exemple #11
0
int main() {
  App::get();
  GamePlayer game;

  while (game.isOpen()) {
    game.update();
    game.draw();
  }
}
Exemple #12
0
int main() {
  common::App::get();
  GamePlayer game;

  while (game.isRunning()) {
    game.update();
    game.draw();
  }
}
void CGStashRequestBuyHandler::execute (CGStashRequestBuy* 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);
	Creature*       pPC             = pGamePlayer->getCreature();
	PlayerCreature* pPlayerCreature = dynamic_cast<PlayerCreature*>(pPC);

	BYTE curStashNum = pPlayerCreature->getStashNum();

	// 가지고 있는 보관함이 맥스라면 리턴
	if (curStashNum >= STASH_RACK_MAX)
	{
		GCNPCResponse failpkt;
		failpkt.setCode(NPC_RESPONSE_STASH_SELL_FAIL_MAX);
		pPlayer->sendPacket(&failpkt);
		return;
	}

	Price_t price = g_pPriceManager->getStashPrice(curStashNum+1);

	// 돈이 모자라도 실패쥐.
	if (pPlayerCreature->getGold() < price)
	{
		GCNPCResponse failpkt;
		failpkt.setCode(NPC_RESPONSE_STASH_SELL_FAIL_MONEY);
		pPlayer->sendPacket(&failpkt);
		return;
	}

	// 보관함 갯수를 한 칸 늘려주고...
	pPlayerCreature->setStashNumEx(curStashNum+1);

	// 돈을 줄인다.
	//pPlayerCreature->setGoldEx(pPlayerCreature->getGold() - price);

	// by sigi. 2002.9.4
	pPlayerCreature->decreaseGoldEx(price);

	// 마지막으로 OK 패킷을 날려준다.
	GCNPCResponse okpkt;
	okpkt.setCode(NPC_RESPONSE_STASH_SELL_OK);
	pPlayer->sendPacket(&okpkt);

#endif

	__END_DEBUG
	__END_DEBUG_EX __END_CATCH
}
BOOL IncomingPlayerManager::ProcessOutputs( )
{
__ENTER_FUNCTION

	BOOL ret = FALSE ;

	if (m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET) // no player exist
	{ 
		return TRUE ;
	}

	//数据发送
	uint nPlayerCount = GetPlayerNumber() ;
	for( uint i=0; i<nPlayerCount; i++ )
	{
		if( m_pPlayers[i]==INVALID_ID )
			continue ;

		GamePlayer* pPlayer = g_pPlayerPool->GetPlayer(m_pPlayers[i]) ;
		Assert( pPlayer ) ;

		SOCKET s = pPlayer->GetSocket()->getSOCKET() ;
		if( s == m_SocketID )
			continue ;

		if( FD_ISSET( s, &m_WriteFDs[SELECT_USE] ) )
		{
			if( pPlayer->GetSocket()->isSockError() )
			{//连接出现错误
				RemovePlayer( pPlayer ) ;
			}
			else
			{//连接正常
				_MY_TRY
				{
					ret = pPlayer->ProcessOutput( ) ;
					if( !ret )
					{
						RemovePlayer( pPlayer ) ;
					}
				}
				_MY_CATCH
				{
					SaveCodeLog( ) ;
					RemovePlayer( pPlayer ) ;
				}
			}
		}
	}

	return TRUE ;

__LEAVE_FUNCTION

	return FALSE ;
}
Exemple #15
0
uint WGTeamLeaderAskInviteHandler::Execute( WGTeamLeaderAskInvite* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	PlayerID_t PlayerID = pPacket->GetPlayerID() ;
	GamePlayer* pGamePlayer = g_pPlayerPool->GetPlayer(PlayerID) ;
	if( pGamePlayer==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_CONTINUE ;
	}

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL ) return PACKET_EXE_CONTINUE ;

	if( pPlayer->IsServerPlayer() )
	{//服务器收到世界服务器发来的数据
		Assert( MyGetCurrentThreadID()==g_pServerManager->m_ThreadID ) ;

		pScene->SendPacket( pPacket, PlayerID ) ;

		g_pLog->FastSaveLog( LOG_FILE_1, "WGTeamAskInviteHandler: ServerPlayer sGUID=%X, dGUID=%X ",
			pPacket->GetSourGUID(), pPacket->GetDestGUID() ) ;

		return PACKET_EXE_NOTREMOVE ;
	}
	else if( pPlayer->IsGamePlayer() )
	{//场景收到Cache里的消息
		Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

		GCTeamLeaderAskInvite tMsg ;
		tMsg.SetSourGUID( pPacket->GetSourGUID() );
		tMsg.SetDestGUID( pPacket->GetDestGUID() );
		tMsg.SetSourName( pPacket->GetSourName() );
		tMsg.SetDestName( pPacket->GetDestName() );

		pGamePlayer->SendPacket( &tMsg ) ;

		g_pLog->FastSaveLog( LOG_FILE_1, "WGTeamLeaderAskInviteHandler: GamePlayer sGUID=%X,dGUID=%X ",
			pPacket->GetSourGUID(),pPacket->GetDestGUID() ) ;
	}
	else
	{
		Assert(FALSE) ;
	}


	return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
void PgntestTest::GamePlayer_ifMoveIsNotExistsReturnFalse()
{
    vector<pgn::Ply> moves;
    moves.push_back(pgn::Ply("e4"));

    GamePlayer player;
    player.setMoves(moves);

    QVERIFY(!player.goToMove(10));
}
uint CGAskJoinMenpaiHandler::Execute( CGAskJoinMenpai* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

	
	
	//设置门派
	//pHuman->GetDB()->SetMenPai(pPacket->GetMenpaiID());

	//设置心法
	

	//设置技能
	

	//通知客户端加入的结果,由客户端自己去用模板内的数据改变自己的值
	//GCJoinMenpai Msg;
	//Msg.SetIsSucceedJoin(JOINMENPAI_SUCCEED);

	//pPlayer = pHuman->GetPlayer();
	//pPlayer->SendPacket( &Msg ) ;

	//INT nTemp = pPacket->GetMenpaiID();
	//INT nNum = g_XinFaDataMgr.m_nSize;

	//_XINFA_LIST   listMenpaiXinfa;

	//for(INT i=0,k=0; i<nNum; i++)
	//{
	//	if( g_XinFaDataMgr.m_vTemplateList[i].MenPai == nTemp)
	//		listMenpaiXinfa.m_aXinFa
	//}

	return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
uint CGCharDefaultEventHandler::Execute(CGCharDefaultEvent* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION
	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer != NULL ) ;
	if ( pGamePlayer == NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGCharDefaultEventHandler: Error (pGamePlayer == NULL) " ) ;
		return PACKET_EXE_CONTINUE ;
	}

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman != NULL ) ;
	if ( pHuman == NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGCharDefaultEventHandler: Error (pHuman == NULL) " ) ;
		return PACKET_EXE_CONTINUE ;
	}

	Scene* pScene = pHuman->getScene() ;
	Assert( pScene != NULL ) ;
	if ( pScene == NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGCharDefaultEventHandler: Error Obj = %d (pScene == NULL) ", pHuman->GetID() ) ;
		return PACKET_EXE_CONTINUE ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
	if ( MyGetCurrentThreadID() != pScene->m_ThreadID )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGCharDefaultEventHandler: Error Obj = %d (MyGetCurrentThreadID() != pScene->m_ThreadID) ", pHuman->GetID() ) ;
		return PACKET_EXE_CONTINUE ;
	}

	ObjID_t ObjID = pHuman->GetID() ;
	ObjID_t idTarget	= pPacket->getObjID();

	ORESULT oResult = pHuman->GetHumanAI()->PushCommand_DefaultEvent( idTarget );
	if ( OR_FAILED( oResult ) )
	{
		pHuman->SendOperateResultMsg(oResult);
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGCharDefaultEventHandler: TargetObjID:%d ", 
		pPacket->getObjID() ) ;


	return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;

}
uint CGLockTargetHandler::Execute( CGLockTarget* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;

	if(NULL==pHuman)
	{
		AssertEx(FALSE,"[CGLockTargetHandler::Execute]: NULL Obj_Human pointer found!!");
		return PACKET_EXE_ERROR ;
	}
	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

	ObjID_t nMeID = pHuman->GetID();
	if( nMeID == INVALID_ID )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}
	//update target
	if(NULL==pPacket)
	{
		AssertEx(FALSE,"[CGLockTargetHandler::Execute]: NULL packet pointer found!!");
		return PACKET_EXE_ERROR ;
	}

	pHuman->SetLockedTarget(pPacket->getTargetID());
	// 当锁定的目标是NPC时将会触发NPC的泡泡说话
	Obj* pTarget = pScene->GetObjManager()->GetObj(pPacket->getTargetID());
	if (pTarget->GetObjType() == Obj::OBJ_TYPE_MONSTER)
	{
		((Obj_Monster*)pTarget)->ProcessPaoPao();
	}
	
	g_pLog->FastSaveLog( LOG_FILE_1, "CGLockTargetHandler: ok obj=%d scene=%d", 
		nMeID, pScene->SceneID() ) ;

	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
bool MetalineEnemy::isPlayerVisible()
{
	GameState *gs = GameState::GetInstance();
	GameRoom *gr = gs->GetRoom();
	vector<GameObject *> gobjs = gr->GetGameObjects();
	vector<GamePlayer *> players = gr->GetPlayers();
	int objSize = gobjs.size();
	int playerSize = players.size();
	
	Vector3f playerPos = gs->GetPlayerPosition();
	
	Vertex playerDir;
	playerDir.x = playerPos(0) - this->center.x;
	playerDir.y = playerPos(1) - this->center.y;
	playerDir.z = playerPos(2) - this->center.z;
	
	float length = (playerDir.x * playerDir.x) + (playerDir.y * playerDir.y) + (playerDir.z * playerDir.z);
	
	float xIntervalFraction = playerDir.x / NUM_RAY_TRACE_INTERVALS;
	float yIntervalFraction = playerDir.y / NUM_RAY_TRACE_INTERVALS;
	float zIntervalFraction = playerDir.z / NUM_RAY_TRACE_INTERVALS;
	
	float radiusSquared = this->radius * this->radius;
	
	for (int i = 0; i < NUM_RAY_TRACE_INTERVALS; i++)
	{
		Vec3f v = Vec3f(this->center.x + playerDir.x * xIntervalFraction,
						this->center.y + playerDir.y * yIntervalFraction,
						this->center.z + playerDir.z * zIntervalFraction);
		
		for (int j; j < playerSize; j++)
		{
			GamePlayer *player = players[j];
			
			if (player->IsInBoundingBox(v))
			{
				return true;
			}
		}
		
		if ((i * length / NUM_RAY_TRACE_INTERVALS) > radiusSquared)
		{
			for (int k = 0; k < objSize; k++){
				GameObject *obj = gobjs[k];
				if (obj->IsInBoundingBox(v))
				{
					return false;
				}
			}
		}
	}
	
	return true;
}
uint WGNotifyMailHandler::Execute( WGNotifyMail* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	PlayerID_t PlayerID = pPacket->GetPlayerID() ;
	GamePlayer* pGamePlayer = g_pPlayerPool->GetPlayer(PlayerID) ;
	if( pGamePlayer==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_CONTINUE ;
	}

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL ) return PACKET_EXE_CONTINUE ;

	if( pPlayer->IsServerPlayer() )
	{//服务器收到世界服务器发来的数据
		Assert( MyGetCurrentThreadID()==g_pServerManager->m_ThreadID ) ;

		pScene->SendPacket( pPacket, PlayerID ) ;

		g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyMailHandler: ServerPlayer MailCount=%d",
			pPacket->GetMailCount() ) ;

		return PACKET_EXE_NOTREMOVE ;
	}
	else if( pPlayer->IsGamePlayer() )
	{//场景收到Cache里的消息
		Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

		GCNotifyMail Msg ;

		Msg.SetMailCount( pPacket->GetMailCount() ) ;

		pGamePlayer->SendPacket( &Msg ) ;

		g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyMailHandler: GamePlayer MailCount=%d",
			pPacket->GetMailCount() ) ;
	}
	else
	{
		Assert(FALSE) ;
	}

	return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
//////////////////////////////////////////////////////////////////////////////
// 머리위에 GlobalChat 스트링을 띄울때 사용하는 패킷이다.
// 이 크리처를 볼 수 있는 모든 플레이어에게 브로드캐스트한다.
// 일단은 현재 존의 모든 플레이어(또는 전체 플레이어)에게 
// GCGlobalChat 패킷을 브로드캐스트한다.
//////////////////////////////////////////////////////////////////////////////
void CGGlobalChatHandler::execute (CGGlobalChat* pPacket , Player* pPlayer)
	 throw(ProtocolException , Error)
{
	__BEGIN_TRY __BEGIN_DEBUG_EX
		
#ifdef __GAME_SERVER__

	Assert(pPacket != NULL);
	Assert(pPlayer != NULL);

	GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);

	if (pGamePlayer->getPlayerStatus() == GPS_NORMAL) {

		if (pGamePlayer->isPenaltyFlag(PENALTY_TYPE_MUTE)) {
			return;
		}
		Creature* pCreature = pGamePlayer->getCreature();

		Assert(pCreature != NULL);

		// 서버에서 클라이언트로 전송하므로 GC- 패킷을 사용해야 한다.
		GCGlobalChat gcGlobalChat;

		uint i = pPacket->getMessage().find_first_of('*' , 0);

		if (i == 0) return;

		// text color setting
		gcGlobalChat.setColor(pPacket->getColor());

		// 크리처 이름과 메시지를 패킷에 대입한다.
		StringStream msg;
		msg << pCreature->getName() << " " << pPacket->getMessage();
	
		gcGlobalChat.setMessage(msg.toString());
		gcGlobalChat.setRace(pCreature->getRace());
	
		// 주변 PC들에게 브로드캐스트한다.
		pCreature->getZone()->broadcastPacket(&gcGlobalChat , pCreature);


		// 채팅 로그를 남긴다. by sigi. 2002.10.30
		if (LogNameManager::getInstance().isExist(pCreature->getName() ))
		{
			filelog("chatLog.txt", "[Global] %s> %s", pCreature->getName().c_str(), pPacket->getMessage().c_str());
		}
	}
	
#endif
		
	__END_DEBUG_EX __END_CATCH
}
void PgntestTest::GamePlayer_checkEndState()
{
    vector<pgn::Ply> moves;
    moves.push_back(pgn::Ply("e4"));
    moves.push_back(pgn::Ply("e5"));

    GamePlayer player;
    player.setMoves(moves);
    player.goToEnd();

    QCOMPARE((int)player.chessBoard().getPiece(3, 4).type, (int)Pawn);
}
void CGAbsorbSoulHandler::execute (CGAbsorbSoul* pPacket , Player* pPlayer)
	     throw(Error)
{
	__BEGIN_TRY __BEGIN_DEBUG_EX
	__BEGIN_DEBUG

#ifdef __GAME_SERVER__

	Assert(pPacket != NULL);
	Assert(pPlayer != NULL);

	try 
	{
		GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);
		Assert(pGamePlayer != NULL);

		if (pGamePlayer->getPlayerStatus() == GPS_NORMAL) 
		{
			Creature* pCreature = pGamePlayer->getCreature();
			Assert(pCreature != NULL);

			// 아우스터즈가 아닌 놈이 흡영을 할 수는 없다.
			if (!pCreature->isOusters()) return;

			Ousters* pOusters = dynamic_cast<Ousters*>(pCreature);

			// 완전 안전지대라면 기술 사용 불가. by sigi. 2002.11.14
			ZoneLevel_t ZoneLevel = pCreature->getZone()->getZoneLevel(pCreature->getX(), pCreature->getY());
			if ((ZoneLevel & COMPLETE_SAFE_ZONE)
				|| (!isAbleToUseObjectSkill(pOusters, SKILL_ABSORB_SOUL)))
			{
				GCSkillFailed1 gcSkillFailed1;
				gcSkillFailed1.setSkillType(SKILL_ABSORB_SOUL);
				pPlayer->sendPacket(&gcSkillFailed1);
				return;
			}
			
			SkillHandler* pSkillHandler = g_pSkillHandlerManager->getSkillHandler(SKILL_ABSORB_SOUL);
			Assert(pSkillHandler != NULL);
			pSkillHandler->execute(pOusters, pPacket->getObjectID(), pPacket->getTargetZoneX(), pPacket->getTargetZoneY(), pPacket->getInvenObjectID(), pPacket->getInvenX(), pPacket->getInvenY(), pPacket->getTargetInvenX(), pPacket->getTargetInvenY());
		}
	} 
	catch (Throwable & t) 
	{ 
		//cout << t.toString(); 
	}

#endif

	__END_DEBUG
    __END_DEBUG_EX __END_CATCH
}
GameEntity* InfluenceMap::GetObj(RegObjEntry* p_pObjEntry)
{
    GameEntity *pGameObj = nullptr;
    GamePlayer *pPlayer = nullptr;

    pPlayer = g_Game->GetPlayer(p_pObjEntry->OwnerId);
    _ASSERTE(pPlayer);

    pGameObj = pPlayer->GetEntity(p_pObjEntry->ObjId);
    _ASSERTE(pGameObj);

    return pGameObj;
}
Exemple #26
0
uint CGCharAskBaseAttribHandler::Execute( CGCharAskBaseAttrib* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer ) ;

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman ) ;
	
	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		Assert(FALSE) ;
		return PACKET_EXE_ERROR ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

	ObjID_t ObjID = pPacket->getTargetID() ;
	if( ObjID == INVALID_ID )
	{
		return PACKET_EXE_ERROR ;
	}
	
	Obj* pObj = pScene->GetObjManager()->GetObj( ObjID ) ;
	if( pObj==NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGCharAskBaseAttribHandler: not find obj=%d", ObjID ) ;
		return PACKET_EXE_CONTINUE ;
	}

	if( !IsCharacterObj( pObj->GetObjType() ) )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGCharAskBaseAttribHandler: not character obj=%d", ObjID ) ;
		return PACKET_EXE_CONTINUE ;
	}

	Obj_Character* pCharacter = (Obj_Character*)pObj ;
	pCharacter->AskMsg_BaseAttrib( pHuman );

	//影响效率关掉Log
	//g_pLog->FastSaveLog( LOG_FILE_1, "CGCharAskBaseAttribHandler: obj=%d", ObjID ) ;

	return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
//////////////////////////////////////////////////////////////////////////////
// 플레이어가 팔려고 하는 아이템을 가지고 있는지 확인한 다음에,
// 일반 아이템과 모터 사이클 처리 부분으로 분기한다.
//////////////////////////////////////////////////////////////////////////////
void CGShopRequestSellHandler::execute (CGShopRequestSell* pPacket , Player* pPlayer)
	 throw(ProtocolException , Error) {
	__BEGIN_TRY __BEGIN_DEBUG_EX

#ifdef __GAME_SERVER__

	Assert(pPacket != NULL);
	Assert(pPlayer != NULL);
	
	ObjectID_t      ITEMOID     = pPacket->getItemObjectID();
	BYTE            OPCODE      = pPacket->getOpCode();
	GamePlayer*     pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);
	Creature*       pCreature   = pGamePlayer->getCreature();
	PlayerCreature* pPC         = dynamic_cast<PlayerCreature*>(pCreature);

	if (OPCODE == SHOP_REQUEST_SELL_NORMAL) {
		// 플레이어가 팔려고 하는 아이템을 가지고 있는지 검사
		Inventory* pInventory = pPC->getInventory();
		if (pInventory->hasItem(ITEMOID) == false) 
			throw ProtocolException("CGShopRequestSellHandler::execute() : No such item to sell!");

		Item* pItem = pInventory->getItemWithObjectID(ITEMOID);
		if (pItem == NULL || pPC->getStore()->hasItem(pItem))
			return sendFailPacket(pPacket, pPlayer);

		//ItemInfo* pItemInfo = g_pItemInfoManager->getItemInfo(pItem->getItemClass(), pItem->getItemType());
		//Assert(pItemInfo!=NULL);

		// 유니크 아이템은 못판다.
		// 특정 아이템 클래스는 팔 수 없다. by sigi. 2002.8.29
		// 선물 상자는 팔 수 있다. by bezz. 2002.12.13
		// 커플링은 팔 수 없다. by Sequoia. 2003. 3. 3
		// ItemUtil 안에 canSell 로 Extract 2003. 3. 3
		if (!canSell(pItem))
			return sendFailPacket(pPacket, pPlayer);
		else if (pItem->getItemClass() == Item::ITEM_CLASS_KEY && pItem->getItemType() == 2) 
			executeMotorcycle(pPacket, pPlayer);
		else 
			executeNormal(pPacket, pPlayer);
	}
	else if (OPCODE == SHOP_REQUEST_SELL_ALL_SKULL)
		executeOpAllSkull(pPacket, pPlayer);
	else if (OPCODE == SHOP_REQUEST_SWAP_ADVANCEMENT_ITEM)
		executeOpSwapAdvancementItem(pPacket, pPlayer);
	else
		throw ProtocolException("CGShopRequestSellHandler::execute() : unknown op code");
	
#endif

	__END_DEBUG_EX __END_CATCH
}
UINT CGIssuePetPlacardHandler::Execute( CGIssuePetPlacard* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

    GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
    Assert( pGamePlayer ) ;

    Obj_Human* pHuman = pGamePlayer->GetHuman() ;
    Assert( pHuman ) ;
    
    Scene* pScene = pHuman->getScene() ;
    if( pScene==NULL )
    {
        Assert(FALSE) ;
        return PACKET_EXE_ERROR ;
    }

    //检查线程执行资源是否正确
    Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;

    Obj_Monster *pNpc = (Obj_Monster*)(pScene->GetObjManager()->GetObj(pPacket->GetNpcID()));
    if(pNpc != NULL)
    {
        PetPlacardSystem *pPetPlacardSystem = pNpc->GetPetPlacardSystem();
        if(pPetPlacardSystem == NULL)
        {
            pNpc->CreatePetPlacardSystem();
            pPetPlacardSystem = pNpc->GetPetPlacardSystem();
        }
        if(pPetPlacardSystem != NULL)
        {
            CHAR* pMessage = pPacket->GetMessage();
            BYTE nMessageSize = (BYTE)strlen( pMessage );
            if( nMessageSize >= PET_PLACARD_ITEM_MESSAGE_SIZE ) nMessageSize = PET_PLACARD_ITEM_MESSAGE_SIZE-1;
            pMessage[PET_PLACARD_ITEM_MESSAGE_SIZE-1] = 0;
            ReplaceIllegalString( pMessage, nMessageSize );

            ORESULT oResult = pPetPlacardSystem->IssuePlacard(pHuman, pPacket->GetGUID(), pMessage);
            if(OR_FAILED(oResult))
            {
                pHuman->SendOperateResultMsg(oResult);
            }
        }
    }

    return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

    return PACKET_EXE_ERROR ;
}
UINT CGPlayerCallOfResultHandler::Execute( CGPlayerCallOfResult* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ;
	Assert( pGamePlayer != NULL ) ;
	if ( pGamePlayer == NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerCallOfResultHandler: Error (pGamePlayer == NULL) " ) ;
		return PACKET_EXE_CONTINUE ;
	}

	Obj_Human* pHuman = pGamePlayer->GetHuman() ;
	Assert( pHuman != NULL ) ;
	if ( pHuman == NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerCallOfResultHandler: Error (pHuman == NULL) " ) ;
		return PACKET_EXE_CONTINUE ;
	}

	Scene* pScene = pHuman->getScene() ;
	Assert( pScene != NULL ) ;
	if ( pScene == NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerCallOfResultHandler: Error Obj = %d (pScene == NULL) ", pHuman->GetID() ) ;
		return PACKET_EXE_CONTINUE ;
	}

	//检查线程执行资源是否正确
	Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ;
	if ( MyGetCurrentThreadID() != pScene->m_ThreadID )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerCallOfResultHandler: Error Obj = %d (MyGetCurrentThreadID() != pScene->m_ThreadID) ", pHuman->GetID() ) ;
		return PACKET_EXE_CONTINUE ;
	}

	ORESULT oResult = pHuman->GetHumanAI()->PushCommand_CallOfResult( pPacket->GetResultCode() );
	if ( OR_FAILED( oResult ) )
	{
		pHuman->SendOperateResultMsg(oResult);
	}

	g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerCallOfResultHandler: ok obj=%d guid=%X scene=%d", 
		pHuman->GetID(), pHuman->GetGUID(), pScene->SceneID() ) ;

	return PACKET_EXE_CONTINUE ;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
void CGRangerSayHandler::execute (CGRangerSay* pPacket , Player* pPlayer)
	 throw(ProtocolException , Error)
{
	__BEGIN_TRY

#ifdef __GAME_SERVER__

	Assert(pPacket != NULL);
	Assert(pPlayer != NULL);

	GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);
	Assert(pGamePlayer != NULL);

	Creature* pCreature = pGamePlayer->getCreature();
	Assert(pCreature != NULL);

	// 크리쳐 이름과 메시지를 패킷에 넣는다.
	StringStream msg;
	msg << pCreature->getName() << " " << pPacket->getMessage();

	Race_t race = pCreature->getRace();

	// 패킷 생성
	GCSystemMessage gcSystemMessage;
	gcSystemMessage.setMessage(msg.toString());
	gcSystemMessage.setType(SYSTEM_MESSAGE_RANGER_SAY);

	// 필터 생성
	BroadcastFilterRace filter(race);

	// 모든 사용자에게 뿌리기
	g_pZoneGroupManager->pushBroadcastPacket(&gcSystemMessage, &filter);

/*	map<ZoneGroupID_t, ZoneGroup*>::const_iterator itr = g_pZoneGroupManager->getZoneGroups().begin();
	map<ZoneGroupID_t, ZoneGroup*>::const_iterator endItr = g_pZoneGroupManager->getZoneGroups().end();

	for (; itr != endItr; ++itr )
	{
		GCSystemMessage* pSystemMessage = new GCSystemMessage();
		pSystemMessage->setMessage(msg.toString());
		pSystemMessage->setType(SYSTEM_MESSAGE_RANGER_SAY);
		pSystemMessage->setRace(race);

		itr->second->getZonePlayerManager()->pushBroadcastPacket(pSystemMessage);
	}
*/
#endif

	__END_CATCH
}