uint GWAskTeamRecruitInfoHandler::Execute( GWAskTeamRecruitInfo* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	ServerPlayer* pServerPlayer = (ServerPlayer*)pPlayer;
	GUID_t guid = pPacket->GetGUID(); // 被请求信息的玩家的 GUID

	USER* pUser = g_pOnlineUser->FindUser( guid );
	if( pUser == NULL )
	{
		Log::SaveLog( WORLD_LOGFILE, "GWAskTeamRecruitInfo...User GUID=%X not find!", 
			guid ) ;
		return PACKET_EXE_CONTINUE;
	}

	WGRetTeamRecruitInfo Msg;
	Msg.SetPlayerID( pUser->GetPlayerID() );

	if ( pPacket->GetType() == LEADER_RECRUIT )
	{//队长请求得到征兵信息
		if( pUser->GetTeamID() == INVALID_ID )
		{ 
			Assert( FALSE && "该玩家没有队伍!" );
			return PACKET_EXE_CONTINUE;
		}

		Team* pTeam = g_pTeamList->GetTeam( pUser->GetTeamID() );
		if( pTeam==NULL )
		{
			Assert(FALSE) ;
			return PACKET_EXE_CONTINUE ;
		}

		if ( pTeam->Leader()->m_Member != guid )
		{
			//Assert(FALSE&&"不是队长不可以请求!") ;
			return PACKET_EXE_CONTINUE ;
		}

		//得到自己的征兵条件
		LEADER_INFO_NODE *pLeaderInfo = 0;
		pLeaderInfo = (LEADER_INFO_NODE*)g_pTeamRecruitManager->Get(guid,LEADER_RECRUIT);
		LEADER_RECRUIT_ATTRIB *pMyself = &pLeaderInfo->m_LeaderRecruit;

		//查找满足条件的所有玩家
		IDTable* pTable = g_pTeamRecruitManager->GetMemberTable();

		for( uint i=0; i<MAX_TEAMS; i++ )
		{//分页请求,一次最多50条
			if ( Msg.GetMemberCount() >= ONCE_RECRUIT_LIST_LEN)
			{
				break;
			}			
			
			BOOL IsContinue = FALSE;

			MEMBER_INFO_NODE *pMemberInfo = &g_pTeamRecruitManager->GetMemberRecruitInfo(i);
			if ( pMemberInfo->m_NodeState == NODE_NULL )
			{
				continue;
			}

			RECRUIT_OWNER_INFO *pOther = &pMemberInfo->m_OwnerInfo ;

			if ( pOther->m_Level <= pMyself->m_MaxLevel && pOther->m_Level >= pMyself->m_MinLevel )
			{//等级匹配
				for( int i=0;i<COUATTRIBUTE_NUMBER;i++ )
				{
					if ( pMyself->m_IsInCountry[i] == TRUE && i == pOther->m_Country )
					{//国家匹配
						IsContinue = TRUE;
						break;
					}
				}

				if ( IsContinue == FALSE )
					continue ;

				IsContinue = FALSE;

				//组队目的
				for( int i=0;i<TARGET_NUMBER;i++ )
				{
					if ( pMyself->m_IsTarget[i] == TRUE && 
						pMemberInfo->m_MemberRecruit.m_IsTarget[i] == TRUE )
					{//组队目标有一个匹配就OK
						IsContinue = TRUE;
						break;
					}
				}	

				if ( IsContinue == FALSE )
					continue ;

				IsContinue = FALSE;

				//职业范围
				for( int i=0;i<MATTRIBUTE_NUMBER;i++ )
				{
					if ( pMyself->m_IsMenPaiID[i] == TRUE && i == pOther->m_ManPai )
					{//职业有一个匹配就OK
						IsContinue = TRUE;
						break;
					}
				}	

				if ( IsContinue == TRUE )
				{//增加
					RETURN_RECRUIT_INFO info;
					memset(&info,0,sizeof(RETURN_RECRUIT_INFO));
					info.m_Level = pOther->m_Level;
					info.m_ManPai = pOther->m_ManPai;
					info.m_Country = pOther->m_Country;
					info.m_NameLen = pOther->m_NameLen;

					memcpy(info.m_TeamTarget,pMemberInfo->m_MemberRecruit.m_IsTarget,sizeof(info.m_TeamTarget));
					strncpy((char*)info.m_szUserName,(char*)pOther->m_szUserName,info.m_NameLen);
					memcpy(info.m_szTeamEnounce,pMemberInfo->m_MemberRecruit.m_szTeamEnounce,TEAM_ENOUNCE_LEN-1);

					Msg.AddMember(info);
				}
			}
		}

	}
	else if ( pPacket->GetType() == MEMBER_RECRUIT )
	{//队员请求得到征兵信息
		//得到自己的征兵条件
		MEMBER_INFO_NODE *pMemberInfo = 0;
		pMemberInfo = (MEMBER_INFO_NODE*)g_pTeamRecruitManager->Get(guid,MEMBER_RECRUIT);
		MEMBER_RECRUIT_ATTRIB *pMyself = &pMemberInfo->m_MemberRecruit;

		//查找满足条件的所有玩家
		IDTable* pTable = g_pTeamRecruitManager->GetLeaderTable();

		for( uint i=0; i<MAX_TEAMS; i++ )
		{//分页请求,一次最多50条
			if ( Msg.GetMemberCount() >= ONCE_RECRUIT_LIST_LEN)
			{
				break;
			}			

			BOOL IsContinue = FALSE;

			LEADER_INFO_NODE *pLeaderInfo = &g_pTeamRecruitManager->GetLeaderRecruitInfo(i);
			if ( pLeaderInfo->m_NodeState == NODE_NULL )
			{
				continue;
			}

			RECRUIT_OWNER_INFO *pOther = &pLeaderInfo->m_OwnerInfo ;

			if ( pOther->m_Level <= pMyself->m_MaxLevel && pOther->m_Level >= pMyself->m_MinLevel )
			{//等级匹配
				for( int i=0;i<COUATTRIBUTE_NUMBER;i++ )
				{
					if ( pMyself->m_IsInCountry[i] == TRUE && i == pOther->m_Country )
					{//国家匹配
						IsContinue = TRUE;
						break;
					}
				}

				if ( IsContinue == FALSE )
					continue ;

				IsContinue = FALSE;

				//组队目的
				for( int i=0;i<TARGET_NUMBER;i++ )
				{
					if ( pMyself->m_IsTarget[i] == TRUE && 
						pLeaderInfo->m_LeaderRecruit.m_IsTarget[i] == TRUE )
					{//组队目标有一个匹配就OK
						IsContinue = TRUE;
						break;
					}
				}	

				if ( IsContinue == FALSE )
					continue ;

				if ( IsContinue == TRUE )
				{//增加
					RETURN_RECRUIT_INFO info;
					memset(&info,0,sizeof(RETURN_RECRUIT_INFO));

					info.m_Level = pOther->m_Level;
					info.m_ManPai = pOther->m_ManPai;
					info.m_Country = pOther->m_Country;
					info.m_NameLen = pOther->m_NameLen;

					memcpy(info.m_TeamTarget,pLeaderInfo->m_LeaderRecruit.m_IsTarget,sizeof(info.m_TeamTarget));
					strncpy((char*)info.m_szUserName,(char*)pOther->m_szUserName,info.m_NameLen);
					memcpy(info.m_szTeamEnounce,pLeaderInfo->m_LeaderRecruit.m_szTeamEnounce,TEAM_ENOUNCE_LEN-1);

					Msg.AddMember(info);
				}

			}
		}
	}
	else
	{
		Assert(FALSE&&"组队征兵时类型错误");
	}

	pServerPlayer->SendPacket( &Msg ) ;

	Log::SaveLog( WORLD_LOGFILE, "GWAskTeamRecruitInfo...Success!  GUID=%X", guid );

	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR;
}
uint GWTeamKickHandler::Execute( GWTeamKick* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	ServerPlayer* pSourServerPlayer = (ServerPlayer*)pPlayer;

	GUID_t sGuid = pPacket->GetSourGUID(); // 队长
	GUID_t dGuid = pPacket->GetDestGUID(); // 倒霉蛋

	USER* pSourUser = g_pOnlineUser->FindUser( sGuid );
	if( pSourUser==NULL )
	{
		Log::SaveLog( WORLD_LOGFILE, "GWTeamKickHandler...User Sour GUID=%X not find!", 
			sGuid );

		return PACKET_EXE_CONTINUE;
	}

	TeamID_t tid = pSourUser->GetTeamID();
	Team* pTeam = g_pTeamList->GetTeam( tid );
	if( pTeam==NULL )
	{
		Log::SaveLog( WORLD_LOGFILE, "GWTeamKickHandler...User sGUID=%X TeamID=%d not find team!", 
			sGuid, tid );

		return PACKET_EXE_CONTINUE;
	}

	INT nMemberCount = pTeam->MemberCount();
	INT i;
	for( i=0; i<nMemberCount; ++i )
	{
		if ( pTeam->Member(i)->m_Member == dGuid )
		{
			break;
		}
	}

	if( i >= nMemberCount )
	{ // 被踢者不在队伍里
		Log::SaveLog( WORLD_LOGFILE, "GWTeamKickHandler...User dGUID=%X not in sTeamID=%d(sGUID=%X)!", 
			dGuid, tid, sGuid );

		return PACKET_EXE_CONTINUE;
	}

	if( pTeam->Leader()->m_Member != sGuid )
	{ // 踢人者不是队长
		WGTeamError Msg;
		Msg.SetPlayerID( pSourUser->GetPlayerID() );
		Msg.SetGUID( pSourUser->GetGUID() );
		Msg.SetErrorCode( TEAM_ERROR_KICKNOTLEADER );

		pSourServerPlayer->SendPacket( &Msg );

		Log::SaveLog( WORLD_LOGFILE, "GWTeamKickHandler...User sGUID=%X TeamID=%d not leader!", 
			sGuid, tid );

		return PACKET_EXE_CONTINUE;
	}

	WGTeamResult Msg;
	Msg.SetReturn( TEAM_RESULT_TEAMKICK );
	Msg.SetGUID( dGuid );
	Msg.SetTeamID( tid );

	//通知所有组内的玩家
	for( int i=0; i<pTeam->MemberCount(); i++ )
	{
		TEAMMEMBER* pMember = pTeam->Member( i );
		if( pMember==NULL )
		{
			Assert(FALSE);
			continue;
		}

		USER* pUser = g_pOnlineUser->FindUser( pMember->m_Member );
		if( pUser==NULL )
		{//如果队员离线,则用户数据是空
			continue;
		}
		
		ID_t ServerID = pUser->GetServerID();
		ServerPlayer* pServerPlayer = g_pServerManager->GetServerPlayer( ServerID );
		if( pServerPlayer==NULL )
		{
			Assert(FALSE);
			continue;
		}

		Msg.SetPlayerID( pUser->GetPlayerID() );

		pServerPlayer->SendPacket( &Msg );
	}

	//剔除队员
	TEAMMEMBER Member;
	Member.m_Member = dGuid;
	pTeam->DelMember( &Member );

	//设置被踢者的队伍信息
	USER* pDestUser = g_pOnlineUser->FindUser( dGuid );
	if ( pDestUser!=NULL )
	{
		pDestUser->SetTeamID( INVALID_ID );
	}

	Log::SaveLog( WORLD_LOGFILE, "GWTeamKickHandler...User sGUID=%X TeamID=%d Success!", 
		sGuid, tid );

	return PACKET_EXE_CONTINUE;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR;
}
uint GWTeamRetApplyHandler::Execute( GWTeamRetApply* pPacket, Player* pPlayer )
{
    __ENTER_FUNCTION

    GUID_t sGuid = pPacket->GetSourGUID();//申请人的GUID
    GUID_t lGuid = pPacket->GetLeaderGUID();//队长的GUID

    USER* pLeaderUser = g_pOnlineUser->FindUser( lGuid );
    if( pLeaderUser==NULL )
    {
        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetApplyHandler...User Leader GUID=%X not find!",
                      lGuid );

        return PACKET_EXE_CONTINUE;
    }

    ServerPlayer* pLeaderServerPlayer = (ServerPlayer*)pPlayer;

    USER* pSourUser = g_pOnlineUser->FindUser( sGuid );
    if( pSourUser==NULL )
    {
        if( pPacket->GetReturn()==TRUE )
        {
            WGTeamError dMsg;
            dMsg.SetPlayerID( pLeaderUser->GetPlayerID() );
            dMsg.SetGUID( pLeaderUser->GetGUID() );
            dMsg.SetErrorCode( TEAM_ERROR_TARGETNOTONLINE );
            pLeaderServerPlayer->SendPacket( &dMsg );
        }

        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetApplyHandler...User Sour GUID=%X not find!",
                      sGuid );

        return PACKET_EXE_CONTINUE;
    }

    ID_t SourServerID = pSourUser->GetServerID();
    ServerPlayer* pSourServerPlayer = g_pServerManager->GetServerPlayer( SourServerID );
    if( pSourServerPlayer==NULL )
    {
        Assert(FALSE);
        return PACKET_EXE_CONTINUE;
    }

    if( pLeaderUser->IsEnemy( pSourUser->GetUserCampData() ) )
    {
        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetApplyHandler...Lead Name=%s, Invite Name=%s are enemy!",
                      pLeaderUser->GetName(), pSourUser->GetName() );

        return PACKET_EXE_CONTINUE;
    }

    if( pPacket->GetReturn()==FALSE )
    {   //队长不同意
        WGTeamError sMsg;
        sMsg.SetPlayerID( pSourUser->GetPlayerID() );
        sMsg.SetGUID( pLeaderUser->GetGUID() );
        sMsg.SetErrorCode( TEAM_ERROR_APPLYLEADERREFUSE );
        pSourServerPlayer->SendPacket( &sMsg );

        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetApplyHandler...Leader lGUID=%X Refuse sGUID=%X join team!",
                      lGuid, sGuid );
    }
    else if( pSourUser->GetTeamID() != INVALID_ID )
    {   //申请人已经属于某个队伍
        //WGTeamError sMsg;
        //sMsg.SetPlayerID( pSourUser->m_PlayerID );
        //sMsg.SetErrorCode( TEAM_ERROR_APPLYSOURHASTEAM );
        //pSourServerPlayer->SendPacket( &sMsg );

        WGTeamError lMsg;
        lMsg.SetPlayerID( pLeaderUser->GetPlayerID() );
        lMsg.SetGUID( pLeaderUser->GetGUID() );
        lMsg.SetErrorCode( TEAM_ERROR_APPLYSOURHASTEAM );
        pLeaderServerPlayer->SendPacket( &lMsg );

        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetApplyHandler...Leader lGUID=%X, sGUID=%X has team!",
                      lGuid, sGuid );
    }
    else
    {   //队伍存在
        TeamID_t tid = pLeaderUser->GetTeamID();
        Team* pTeam = g_pTeamList->GetTeam( tid );
        Assert( pTeam );

        if( pTeam->IsFull() )
        {   //队伍人数已经满了
            WGTeamError sMsg;
            sMsg.SetPlayerID( pSourUser->GetPlayerID() );
            sMsg.SetGUID( pLeaderUser->GetGUID() );
            sMsg.SetErrorCode( TEAM_ERROR_APPLYTEAMFULL );
            pSourServerPlayer->SendPacket( &sMsg );

            WGTeamError lMsg;
            lMsg.SetPlayerID( pLeaderUser->GetPlayerID() );
            lMsg.SetGUID( pLeaderUser->GetGUID() );
            lMsg.SetErrorCode( TEAM_ERROR_TEAMFULL );
            pLeaderServerPlayer->SendPacket( &lMsg );

            Log::SaveLog( WORLD_LOGFILE, "GWTeamRetApplyHandler...Team Full  sGUID=%X lGUID=%X",
                          sGuid, lGuid );
        }
        else if( pTeam->Leader()->m_Member != lGuid )
        {   //队长GUID和队伍中记录的队长GUID不符
            WGTeamError sMsg;
            sMsg.SetPlayerID( pSourUser->GetPlayerID() );
            sMsg.SetGUID( pLeaderUser->GetGUID() );
            sMsg.SetErrorCode( TEAM_ERROR_APPLYLEADERGUIDERROR );
            pSourServerPlayer->SendPacket( &sMsg );

            WGTeamError lMsg;
            lMsg.SetPlayerID( pLeaderUser->GetPlayerID() );
            lMsg.SetGUID( pLeaderUser->GetGUID() );
            lMsg.SetErrorCode( TEAM_ERROR_APPLYLEADERGUIDERROR );
            pLeaderServerPlayer->SendPacket( &lMsg );

            Log::SaveLog( WORLD_LOGFILE, "GWTeamRetApplyHandler...Team Full  sGUID=%X lGUID=%X",
                          sGuid, lGuid );
        }
        else
        {   //加入
            //将玩家加入队伍
            TEAMMEMBER Member;
            Member.m_Member = sGuid;
            pTeam->AddMember( &Member );

            //设置玩家队伍信息
            pSourUser->SetTeamID( pTeam->GetTeamID() );
            WGTeamResult Msg1; // 发给新队员的
            Msg1.SetPlayerID( pSourUser->GetPlayerID() );
            Msg1.SetTeamID( tid );
            WGTeamResult Msg2; // 发给每个队员的
            Msg2.SetReturn( TEAM_RESULT_MEMBERENTERTEAM );
            Msg2.SetTeamID( tid );
            Msg2.SetGUID( sGuid );
            Msg2.SetGUIDEx( pSourUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
            Msg2.SetSceneID( pSourUser->GetSceneID() );
            Msg2.SetName( pSourUser->GetName() );
            Msg2.SetIcon( pSourUser->GetPortrait() );
            Msg2.SetDataID( pSourUser->GetSex() );

            //通知所有组内的玩家
            for( int i=0; i<pTeam->MemberCount(); i++ )
            {
                TEAMMEMBER* pMember = pTeam->Member( i );
                if( pMember==NULL )
                {
                    Assert(FALSE);
                    continue;
                }

                USER* pUser = g_pOnlineUser->FindUser( pMember->m_Member );
                if( pUser==NULL )
                {
                    Assert(FALSE);
                    continue;
                }

                ID_t ServerID = pUser->GetServerID();
                ServerPlayer* pServerPlayer = g_pServerManager->GetServerPlayer( ServerID );
                if( pServerPlayer==NULL )
                {
                    Assert(FALSE);
                    continue;
                }

                Msg2.SetPlayerID( pUser->GetPlayerID() );
                pServerPlayer->SendPacket( &Msg2 );

                if( pMember->m_Member != sGuid )
                {   // 将自己以外的玩家传给新玩家
                    Msg1.SetReturn( TEAM_RESULT_TEAMREFRESH );
                    Msg1.SetName( pUser->GetName() );
                    Msg1.SetIcon( pUser->GetPortrait() );
                    Msg1.SetDataID( pUser->GetSex() );

                    Msg1.SetGUID( pMember->m_Member );
                    Msg1.SetGUIDEx( pUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
                    Msg1.SetSceneID( pUser->GetSceneID() );

                    pSourServerPlayer->SendPacket( &Msg1 );
                }
            }//end for

            Log::SaveLog( WORLD_LOGFILE, "GWTeamRetApplyHandler...Success!  sGUID=%X lGUID=%X",
                          sGuid, lGuid );
        }

    }




    return PACKET_EXE_CONTINUE;

    __LEAVE_FUNCTION

    return PACKET_EXE_ERROR;
}
Пример #4
0
UINT GWTeamRetInviteHandler::Execute( GWTeamRetInvite* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

    GUID_t sGuid = pPacket->GetSourGUID();//邀请人的GUID
    GUID_t dGuid = pPacket->GetDestGUID();//被邀请人的GUID

    USER* pDestUser = g_pOnlineUser->FindUser( dGuid );
    if( pDestUser==NULL )
    {
        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...User Dest GUID=%X not find!", 
            dGuid );

        return PACKET_EXE_CONTINUE;
    }

    ServerPlayer* pDestServerPlayer = (ServerPlayer*)pPlayer;

    USER* pSourUser = g_pOnlineUser->FindUser( sGuid );
    if( pSourUser==NULL )
    {
        if( pPacket->GetReturn()==TRUE )
        {
            WGTeamError dMsg;
            dMsg.SetPlayerID( pDestUser->GetPlayerID() );
            dMsg.SetGUID( pDestUser->GetGUID() );
            dMsg.SetErrorCode( TEAM_ERROR_TARGETNOTONLINE );
            pDestServerPlayer->SendPacket( &dMsg );
        }

        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...User Sour GUID=%X not find!", 
            sGuid );
        return PACKET_EXE_CONTINUE;
    }

    if( pSourUser->IsEnemy( pDestUser->GetUserCampData() ) )
    {
        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...Sour Name=%X, Dest Name=%s are enemy!", 
            pSourUser->GetName(), pDestUser->GetName() );

        return PACKET_EXE_CONTINUE;
    }

    ID_t SourServerID = pSourUser->GetServerID();
    ServerPlayer* pSourServerPlayer = g_pServerManager->GetServerPlayer( SourServerID );
    if( pSourServerPlayer==NULL )
    {
        Assert(FALSE);
        return PACKET_EXE_CONTINUE;
    }

    USER* pLeader = NULL;
    ServerPlayer* pLeaderServerPlayer;

    if ( pSourUser->GetTeamID() != INVALID_ID )
    {
        Team* pTeam = g_pTeamList->GetTeam( pSourUser->GetTeamID() );

        if ( pTeam == NULL )
        {
            Assert( pTeam );
            pSourUser->SetTeamID( INVALID_ID );
        }
        else if ( pTeam->Leader()->m_Member != sGuid )
        { // 邀请人不是队长
            pLeader = g_pOnlineUser->FindUser( pTeam->Leader()->m_Member );

            pLeaderServerPlayer = g_pServerManager->GetServerPlayer( pLeader->GetServerID() );
            if ( pLeaderServerPlayer == NULL )
            {
                Assert( FALSE );
                pLeader = NULL;
            }
        }
    }


    if( pPacket->GetReturn()==FALSE )
    {//被邀请人不同意加入队伍
        WGTeamError Msg;
        Msg.SetPlayerID( pSourUser->GetPlayerID() );
        Msg.SetGUID( pDestUser->GetGUID() );
        Msg.SetErrorCode( TEAM_ERROR_INVITEREFUSE );

        pSourServerPlayer->SendPacket( &Msg );

        if ( pLeader != NULL )
        {
            Msg.SetPlayerID( pLeader->GetPlayerID() );
            pLeaderServerPlayer->SendPacket( &Msg );
        }

        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...Invite Refuse SourGUID=%X DestGUID=%X", 
            sGuid, dGuid );
    }
    else if( pDestUser->GetTeamID() != INVALID_ID )
    {//被邀请人已经有队伍
        WGTeamError Msg;
        Msg.SetPlayerID( pSourUser->GetPlayerID() );
        Msg.SetGUID( pDestUser->GetGUID() );
        Msg.SetErrorCode(TEAM_ERROR_INVITEDESTHASTEAM);

        pSourServerPlayer->SendPacket( &Msg );

        if ( pLeader != NULL )
        {
            Msg.SetPlayerID( pLeader->GetPlayerID() );
            pLeaderServerPlayer->SendPacket( &Msg );
        }

        Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...DestInTeam SourGUID=%X DestGUID=%X", 
            sGuid, dGuid );
    }
    else if( pSourUser->GetTeamID()==INVALID_ID )
    {//邀请人和被邀请人都无队伍
        TeamID_t tid = g_pTeamList->CreateTeam( );
        Assert( tid!=INVALID_ID );
        Team* pTeam = g_pTeamList->GetTeam( tid );
        Assert( pTeam );

        if ( pSourUser->GetGUID() == pDestUser->GetGUID() )
        {

            //将玩家加入队伍中
            TEAMMEMBER Member;
            Member.m_Member = sGuid;
            pTeam->AddMember( &Member );

            //设置玩家队伍数据
            pSourUser->SetTeamID( tid );

            //返回结果
            WGTeamResult Msg;
            Msg.SetPlayerID( pSourUser->GetPlayerID() );
            Msg.SetReturn( TEAM_RESULT_MEMBERENTERTEAM );
            Msg.SetGUID( sGuid );
            Msg.SetTeamID( tid );
            Msg.SetGUIDEx( pSourUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
            Msg.SetIcon( pSourUser->GetPortrait() );
            Msg.SetSceneID( pSourUser->GetSceneID() );
            Msg.SetDataID( pSourUser->GetSex() );


            pSourServerPlayer->SendPacket( &Msg );

            Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...CreateTeam GUID=%X TeamID=%d", 
                sGuid, tid );
        }
        else
        {
            //将玩家加入队伍中
            TEAMMEMBER sMember;
            sMember.m_Member = sGuid;
            pTeam->AddMember( &sMember );
            TEAMMEMBER dMember;
            dMember.m_Member = dGuid;
            pTeam->AddMember( &dMember );

            //设置玩家队伍数据
            pSourUser->SetTeamID( tid );
            pDestUser->SetTeamID( tid );

            //返回结果
            WGTeamResult sMsg1;
            sMsg1.SetPlayerID( pSourUser->GetPlayerID() );
            sMsg1.SetReturn( TEAM_RESULT_TEAMREFRESH );
            sMsg1.SetGUID( sGuid );
            sMsg1.SetTeamID( tid );
            sMsg1.SetGUIDEx( pSourUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
            sMsg1.SetSceneID( pSourUser->GetSceneID() );
            pSourServerPlayer->SendPacket( &sMsg1 );

            WGTeamResult sMsg2;
            sMsg2.SetPlayerID( pSourUser->GetPlayerID() );
            sMsg2.SetReturn( TEAM_RESULT_MEMBERENTERTEAM );
            sMsg2.SetGUID( dGuid );
            sMsg2.SetTeamID( tid );
            sMsg2.SetGUIDEx( pDestUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
            sMsg2.SetSceneID( pDestUser->GetSceneID() );
            sMsg2.SetName( pDestUser->GetName() );
            sMsg2.SetIcon( pDestUser->GetPortrait() );
            sMsg2.SetDataID( pDestUser->GetSex() );
            pSourServerPlayer->SendPacket( &sMsg2 );

            WGTeamResult dMsg1;
            dMsg1.SetPlayerID( pDestUser->GetPlayerID() );
            dMsg1.SetReturn( TEAM_RESULT_TEAMREFRESH );
            dMsg1.SetGUID( sGuid );
            dMsg1.SetTeamID( tid );
            dMsg1.SetGUIDEx( pSourUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
            dMsg1.SetSceneID( pSourUser->GetSceneID() );
            dMsg1.SetName( pSourUser->GetName() );
            dMsg1.SetIcon( pSourUser->GetPortrait() );
            dMsg1.SetDataID( pSourUser->GetSex() );
            pDestServerPlayer->SendPacket( &dMsg1 );

            WGTeamResult dMsg2;
            dMsg2.SetPlayerID( pDestUser->GetPlayerID() );
            dMsg2.SetReturn( TEAM_RESULT_MEMBERENTERTEAM );
            dMsg2.SetGUID( dGuid );
            dMsg2.SetTeamID( tid );
            dMsg2.SetGUIDEx( pDestUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
            dMsg2.SetSceneID( pDestUser->GetSceneID() );
            pDestServerPlayer->SendPacket( &dMsg2 );

            Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...CreateTeam sGUID=%X dGUID=%X TeamID=%d", 
                sGuid, dGuid, tid );
        }

    }
    else
    {//邀请人有队伍, 被邀请人无队伍
        TeamID_t tid = pSourUser->GetTeamID();
        Team* pTeam = g_pTeamList->GetTeam( tid );
        Assert( pTeam );
        if( pTeam->IsFull() )
        {//队伍人数已经满了
            WGTeamError sMsg;
            sMsg.SetPlayerID( pSourUser->GetPlayerID() );
            sMsg.SetGUID( pDestUser->GetGUID() );
            sMsg.SetErrorCode( TEAM_ERROR_INVITETEAMFULL );
            pSourServerPlayer->SendPacket( &sMsg );

            WGTeamError dMsg;
            dMsg.SetPlayerID( pDestUser->GetPlayerID() );
            dMsg.SetGUID( pDestUser->GetGUID() );
            dMsg.SetErrorCode( TEAM_ERROR_APPLYTEAMFULL );
            pDestServerPlayer->SendPacket( &dMsg );
    
            Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...Team Full sGUID=%X dGUID=%X TeamID=%d", 
                sGuid, dGuid, tid );
        }
        else
        { //将玩家加入队伍
            TEAMMEMBER Member;
            Member.m_Member = dGuid;
            pTeam->AddMember( &Member );

            //设置玩家队伍信息
            pDestUser->SetTeamID( pTeam->GetTeamID() );
            WGTeamResult Msg1; // 发给新队员的
            Msg1.SetPlayerID( pDestUser->GetPlayerID() );
            Msg1.SetTeamID( tid );
            WGTeamResult Msg2; // 发给每个队员的
            Msg2.SetReturn( TEAM_RESULT_MEMBERENTERTEAM );
            Msg2.SetTeamID( tid );
            Msg2.SetGUID( dGuid );
            Msg2.SetGUIDEx( pDestUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
            Msg2.SetSceneID( pDestUser->GetSceneID() );
            Msg2.SetName( pDestUser->GetName() );
            Msg2.SetIcon( pDestUser->GetPortrait() );
            Msg2.SetDataID( pDestUser->GetSex() );

            //通知所有组内的玩家
            for( int i=0; i<pTeam->MemberCount(); i++ )
            {
                TEAMMEMBER* pMember = pTeam->Member( i );
                if( pMember==NULL )
                {
                    Assert(FALSE);
                    continue;
                }

                USER* pUser = g_pOnlineUser->FindUser( pMember->m_Member );
                if( pUser==NULL )
                {//如果队员离线,则用户数据是空
                    continue;
                }
                
                ID_t ServerID = pUser->GetServerID();
                ServerPlayer* pServerPlayer = g_pServerManager->GetServerPlayer( ServerID );
                if( pServerPlayer==NULL )
                {
                    Assert(FALSE);
                    continue;
                }

                Msg2.SetPlayerID( pUser->GetPlayerID() );
                pServerPlayer->SendPacket( &Msg2 );

                if( pMember->m_Member != dGuid )
                { // 将自己以外的玩家传给新玩家
                    Msg1.SetReturn( TEAM_RESULT_TEAMREFRESH );
                    Msg1.SetName( pUser->GetName() );
                    Msg1.SetIcon( pUser->GetPortrait() );
                    Msg1.SetDataID( pUser->GetSex() );

                    Msg1.SetGUID( pMember->m_Member );
                    Msg1.SetGUIDEx( pUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
                    Msg1.SetSceneID( pUser->GetSceneID() );

                    pDestServerPlayer->SendPacket( &Msg1 );
                }

            }

            Log::SaveLog( WORLD_LOGFILE, "GWTeamRetInviteHandler...Success! sGUID=%X dGUID=%X TeamID=%d", 
                sGuid, dGuid, tid );
        }
    }

    return PACKET_EXE_CONTINUE;

__LEAVE_FUNCTION

    return PACKET_EXE_ERROR;
}
Пример #5
0
uint GWSetTeamDistribModeHandler::Execute( GWSetTeamDistribMode* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	BYTE nMode = pPacket->getMode();//mode
	TeamID_t nTeamID = pPacket->getTeamID();//TeamID
	GUID_t LeaderGuid = pPacket->getLeaderID();//Leader的GUID

	USER* pLeaderUser = g_pOnlineUser->FindUser( LeaderGuid );
	if( pLeaderUser==NULL )
	{
		Log::SaveLog( WORLD_LOGFILE, "GWSetTeamDistribMode...User Leader GUID=%X not find!", LeaderGuid );

		return PACKET_EXE_CONTINUE;
	}
	
	if (nMode>=ITEM_DISTRIB_NUM)
	{
		Log::SaveLog( WORLD_LOGFILE, "GWSetTeamDistribMode...MODE=%X error!", nMode );
		return PACKET_EXE_CONTINUE;
	}
	ServerPlayer* pLeaderServerPlayer = (ServerPlayer*)pPlayer;

	if( pLeaderUser->GetTeamID() == INVALID_ID )
	{
		//无队伍
		WGTeamError lMsg;
		lMsg.SetPlayerID( pLeaderUser->GetPlayerID() );
		lMsg.SetErrorCode( TEAM_ERROR_DISTRIBNOLEADER );
		pLeaderServerPlayer->SendPacket( &lMsg );

		Log::SaveLog( WORLD_LOGFILE, "GWSetTeamDistribMode... LeaderGuid=%X!", LeaderGuid );
	}
	else
	{//队伍存在
		TeamID_t tid = pLeaderUser->GetTeamID();
		Team* pTeam = g_pTeamList->GetTeam( tid );
		Assert( pTeam );

		if( pTeam->Leader()->m_Member != LeaderGuid )
		{
			//队长GUID和队伍中记录的队长GUID不符
			WGTeamError sMsg;
			sMsg.SetPlayerID( pLeaderUser->GetPlayerID() );
			sMsg.SetErrorCode( TEAM_ERROR_DISTRIBNOLEADER );
			pLeaderServerPlayer->SendPacket( &sMsg );

			Log::SaveLog( WORLD_LOGFILE, "GWSetTeamDistribMode... LeaderGuid=%X!", LeaderGuid );
		}
		else 
		{//
			pTeam->SetDistribMode(nMode);
			WGRetTeamDistribMode Msg;
			Msg.setLeaderID( pLeaderUser->GetPlayerID() );
			Msg.setTeamID(pLeaderUser->GetTeamID());
			Msg.setMode(nMode);

			pLeaderServerPlayer->SendPacket( &Msg );

		}//end for

		Log::SaveLog( WORLD_LOGFILE, "GWSetTeamDistribMode...Success!  GUID=%X", LeaderGuid );

	}

	return PACKET_EXE_CONTINUE;

	__LEAVE_FUNCTION

		return PACKET_EXE_CONTINUE;	
}
uint GWRegisterTeamRecruitHandler::Execute( GWRegisterTeamRecruit* pPacket, Player* pPlayer )
{
    __ENTER_FUNCTION

    ServerPlayer* pServerPlayer = (ServerPlayer*)pPlayer;
    GUID_t guid = pPacket->GetGUID(); // 被请求信息的玩家的 GUID

    USER* pUser = g_pOnlineUser->FindUser( guid );
    if( pUser == NULL )
    {
        Log::SaveLog( WORLD_LOGFILE, "GWRegisterTeamRecruit...User GUID=%X not find!",
                      guid ) ;
        return PACKET_EXE_CONTINUE;
    }

    if ( pPacket->GetType() == LEADER_RECRUIT )
    {   //队长发布征兵请示
        if( pUser->GetTeamID() == INVALID_ID )
        {
            //Assert( FALSE && "该玩家没有队伍!" );
            return PACKET_EXE_CONTINUE;
        }

        Team* pTeam = g_pTeamList->GetTeam( pUser->GetTeamID() );
        if( pTeam==NULL )
        {
            Assert(FALSE) ;
            return PACKET_EXE_CONTINUE ;
        }

        if ( pTeam->Leader()->m_Member != guid )
        {
            //Assert(FALSE&&"不是队长不可以申请招收队员!") ;
            return PACKET_EXE_CONTINUE ;
        }

        LEADER_RECRUIT_ATTRIB* pRecruit = pPacket->GetLeaderRecruit();

        LEADER_INFO_NODE *pData = g_pTeamRecruitManager->GetLeaderNullNode();
        pData->m_OwnerInfo.m_Level = pUser->GetLevel() ;
        pData->m_OwnerInfo.m_ManPai = pUser->GetMenpai();
        pData->m_OwnerInfo.m_Country = pUser->GetCountry();
        pData->m_OwnerInfo.m_NameLen = (UCHAR)strlen( pUser->GetName() );
        strncpy((char*)pData->m_OwnerInfo.m_szUserName,(char*)pUser->GetName(),pData->m_OwnerInfo.m_NameLen) ;

        pData->SetRecruitData(*pRecruit);
        g_pTeamRecruitManager->Remove(guid,LEADER_RECRUIT);
        g_pTeamRecruitManager->Add(guid,pData,LEADER_RECRUIT);
    }
    else if ( pPacket->GetType() == MEMBER_RECRUIT )
    {   //队员发布征兵请示
        MEMBER_RECRUIT_ATTRIB* pRecruit = pPacket->GetMemberRecruit();

        MEMBER_INFO_NODE *pData = g_pTeamRecruitManager->GetMemberNullNode();

        pData->m_OwnerInfo.m_Level = pUser->GetLevel() ;
        pData->m_OwnerInfo.m_ManPai = pUser->GetMenpai();
        pData->m_OwnerInfo.m_Country = pUser->GetCountry();
        pData->m_OwnerInfo.m_NameLen = (UCHAR)strlen( pUser->GetName() );
        strncpy((char*)pData->m_OwnerInfo.m_szUserName,(char*)pUser->GetName(),pData->m_OwnerInfo.m_NameLen) ;

        pData->SetRecruitData(*pRecruit);
        g_pTeamRecruitManager->Remove(guid,MEMBER_RECRUIT);
        g_pTeamRecruitManager->Add(guid,pData,MEMBER_RECRUIT);
    }
    else
    {
        //Assert(FALSE&&"组队征兵时类型错误");
    }

    Log::SaveLog( WORLD_LOGFILE, "GWRegisterTeamRecruit...Success!  GUID=%X", guid );

    return PACKET_EXE_CONTINUE;

    __LEAVE_FUNCTION

    return PACKET_EXE_ERROR;
}
uint GWTeamInviteHandler::Execute( GWTeamInvite* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	ServerPlayer* pSourServerPlayer = (ServerPlayer*)pPlayer;

	GUID_t sGuid = pPacket->GetSourGUID();

	USER* pSourUser = g_pOnlineUser->FindUser( sGuid );
	if( pSourUser==NULL )
	{
		Log::SaveLog( WORLD_LOGFILE, "GWTeamInviteHandler...User Sour GUID=%X not find!", 
			sGuid );

		return PACKET_EXE_CONTINUE;
	}

	USER* pDestUser = g_pOnlineUser->FindUser( pPacket->GetDestName() );
	if( pDestUser==NULL )
	{
		Log::SaveLog( WORLD_LOGFILE, "GWTeamInviteHandler...User Dest Name=%s not find!", 
			pPacket->GetDestName() );

		return PACKET_EXE_CONTINUE;
	}

	GUID_t dGuid = pDestUser->GetGUID();

	if( pSourUser->IsEnemy( pDestUser->GetUserCampData() ) )
	{
		Log::SaveLog( WORLD_LOGFILE, "GWTeamInviteHandler...Sour Name=%s, Dest Name=%s are enemy!", 
			pSourUser->GetName(), pDestUser->GetName() );

		return PACKET_EXE_CONTINUE;
	}

	// 设置了拒绝被邀请
	if( pDestUser->IsRefuseTeamInvite() )
	{
		WGTeamError Msg;
		Msg.SetPlayerID( pSourUser->GetPlayerID() );
		Msg.SetGUID(sGuid);
		Msg.SetErrorCode(TEAM_ERROR_REFUSEINVITESETTING);
		pSourServerPlayer->SendPacket( &Msg );

		Log::SaveLog( WORLD_LOGFILE, "GWTeamInviteHandler...DestGUID=%X refuse to be invited. ", 
			dGuid );
		return PACKET_EXE_CONTINUE;
	}

	if( pDestUser->GetTeamID() != INVALID_ID )
	{//被邀请人已经属于某个队伍了
		WGTeamError Msg;
		Msg.SetPlayerID( pSourUser->GetPlayerID() );
		Msg.SetGUID(sGuid);
		Msg.SetErrorCode(TEAM_ERROR_INVITEDESTHASTEAM);
		pSourServerPlayer->SendPacket( &Msg );

		Log::SaveLog( WORLD_LOGFILE, "GWTeamInviteHandler...DestInTeam SourGUID=%X DestGUID=%X", 
			sGuid, dGuid );
	}
	else if( sGuid==dGuid && pSourUser->GetTeamID()==INVALID_ID )
	{//邀请人和被邀请人属于同一个人, 且不属于某个队伍
		//自建队伍
		TeamID_t tid = g_pTeamList->CreateTeam( );
		Assert( tid!=INVALID_ID );
		Team* pTeam = g_pTeamList->GetTeam( tid );
		Assert( pTeam );

		//将玩家加入队伍中
		TEAMMEMBER Member;
		Member.m_Member = sGuid;
		pTeam->AddMember( &Member );

		//设置玩家队伍数据
		pSourUser->SetTeamID( tid );

		//返回结果
		WGTeamResult Msg;
		Msg.SetPlayerID( pSourUser->GetPlayerID() );
		Msg.SetReturn( TEAM_RESULT_MEMBERENTERTEAM );
		Msg.SetGUID( sGuid );
		Msg.SetTeamID( tid );
		Msg.SetGUIDEx( pSourUser->GetPlayerID() ); // 将玩家的 PlayerID 传回
		Msg.SetSceneID( pSourUser->GetSceneID() );
		Msg.SetDataID( pSourUser->GetSex() );
		Msg.SetIcon( pSourUser->GetPortrait() );

		pSourServerPlayer->SendPacket( &Msg );

		Log::SaveLog( WORLD_LOGFILE, "GWTeamInviteHandler...CreateTeam GUID=%X TeamID=%d", 
			sGuid, tid );
	}
	else
	{
		if ( pSourUser->GetTeamID() != INVALID_ID )
		{
			//邀请人已经有一个队伍
			Team* pTeam = g_pTeamList->GetTeam( pSourUser->GetTeamID() );
			Assert( pTeam );

			GUID_t tlGUID = pTeam->Leader()->m_Member; // 队长GUID

			//邀请人不是队长,要给队长发送请求
			if ( tlGUID != sGuid )
			{ // 不是队长的情况
				USER* pLeaderUser = g_pOnlineUser->FindUser( tlGUID );
				if( pLeaderUser == NULL )
				{
					Assert(FALSE);
				}

				ID_t LeaderServerID = pLeaderUser->GetServerID();
				ServerPlayer* pLeaderServerPlayer = g_pServerManager->GetServerPlayer( LeaderServerID );
				if( pLeaderServerPlayer==NULL )
				{
					Assert(FALSE);
				}

				WGTeamLeaderAskInvite Msg;
				Msg.SetPlayerID( pLeaderUser->GetPlayerID() );//队长的Player_t
				Msg.SetSourGUID( sGuid );		//邀请人
				Msg.SetDestGUID( dGuid );		//被要请人
				Msg.SetSourName( pSourUser->GetName() );
				Msg.SetDestName( pDestUser->GetName() );
				Msg.SetGUID(tlGUID);

				pLeaderServerPlayer->SendPacket( &Msg );

				Log::SaveLog( WORLD_LOGFILE, "GWTeamInviteHandler...TeamLeaderAskInvite SourGUID=%X DestGUID=%X", 
					sGuid, dGuid );
				return PACKET_EXE_CONTINUE;
			}
		}

		ID_t DestServerID = pDestUser->GetServerID();
		ServerPlayer* pDestServerPlayer = g_pServerManager->GetServerPlayer( DestServerID );
		if( pDestServerPlayer )
		{//向被邀请人发送邀请消息
			WGTeamAskInvite Msg;
			Msg.SetPlayerID( pDestUser->GetPlayerID() );
			Msg.SetdGUID( dGuid );
			Msg.SetsGUID( sGuid );

			if ( pSourUser->GetTeamID() != INVALID_ID )
			{
				Team* pTeam = g_pTeamList->GetTeam( pSourUser->GetTeamID() );
				Assert( pTeam );

			//	Msg.SetMemberCount( pTeam->MemberCount() );

				for( INT i=0; i<pTeam->MemberCount(); ++i )
				{
					WGTeamAskInvite::InviterInfo info;
					TEAMMEMBER* pMember = pTeam->Member( i );
					if( pMember == NULL )
					{
						Assert(FALSE);
						continue ;
					}

					USER* pUser = g_pOnlineUser->FindUser( pMember->m_Member );
					if( pUser == NULL )
					{//如果队员离线,则用户数据是空
						continue ;
					}

					info.m_PlayerID = pUser->GetPlayerID();
					info.m_NickSize = (UCHAR)strlen(pUser->GetName());
					strncpy( (CHAR*)info.m_szNick, pUser->GetName(), info.m_NickSize );
					info.m_uFamily = pUser->GetMenpai();
					info.m_Scene = pUser->GetSceneID();
					info.m_Level = pUser->GetLevel();
					info.m_uDataID = pUser->GetSex();

					Msg.AddInviterInfo( info );
				}
			}
			else
			{
			//	Msg.SetMemberCount( 1 );
				WGTeamAskInvite::InviterInfo info;
				info.m_PlayerID = pSourUser->GetPlayerID();
				info.m_NickSize = (UCHAR)strlen(pSourUser->GetName());
				strncpy( (CHAR*)info.m_szNick, pSourUser->GetName(), info.m_NickSize );
				info.m_uFamily = pSourUser->GetMenpai();
				info.m_Scene = pSourUser->GetSceneID();
				info.m_Level = pSourUser->GetLevel();
				info.m_uDataID = pSourUser->GetSex();

				Msg.AddInviterInfo( info );
			}

			pDestServerPlayer->SendPacket( &Msg );
		}
		else
		{
			Assert(FALSE);
		}

		Log::SaveLog( WORLD_LOGFILE, "GWTeamInviteHandler...AskInvite SourGUID=%X DestGUID=%X", 
			sGuid, dGuid );

	}


	return PACKET_EXE_CONTINUE;

__LEAVE_FUNCTION

	return PACKET_EXE_ERROR;
}