コード例 #1
0
ファイル: g_tdm_client.c プロジェクト: jar3817/opentdm-pf
/*
==============
JoinTeam2
==============
Player joined Team B via menu
*/
void JoinTeam2 (edict_t *ent)
{
	if (!CanJoin (ent, TEAM_B))
		return;

	if (ent->client->pers.team)
		TDM_LeftTeam (ent, true);

	ent->client->pers.team = TEAM_B;
	JoinedTeam (ent, false, true);
}
コード例 #2
0
ファイル: RoomBase.cpp プロジェクト: BillXu/MJGame
bool CRoomBase::OnPeerMsg(CRoomPeer* pPeer, stMsg* pmsg )
{
	// process common msg that don't assocaite with specail card game ;
	// for example : speak work , look other player info ,and make firend , and so on ;
	// when processed , return true , other case return false ;
	switch ( pmsg->usMsgType )
	{
	case MSG_ROOM_SPEAK:
		{
			stMsgRoomPlayerSpeakRet msgBackRet ;
			msgBackRet.nRet = 0 ;
			stMsgRoomPlayerSpeak* pMsgRet = (stMsgRoomPlayerSpeak*)pmsg ;
			if ( 3 == pMsgRet->nContentType ) // interactive speak ;
			{
				CPlayerItemComponent* pItemMgr = (CPlayerItemComponent*)pPeer->GetPlayer()->GetComponent(ePlayerComponent_PlayerItemMgr);	
				if ( !pItemMgr->OnUserItem(ITEM_ID_INTERACTIVE) )
				{
					msgBackRet.nRet = 1 ;
					pPeer->SendMsgToClient((char*)&msgBackRet,sizeof(msgBackRet)) ;
					break;
				}

				if ( pMsgRet->nInteraciveWithPeerRoomIdx < 0 || pMsgRet->nInteraciveWithPeerRoomIdx >= GetMaxSeat() || m_vRoomPeer[pMsgRet->nInteraciveWithPeerRoomIdx] == NULL )
				{
					msgBackRet.nRet = 2 ;
					pPeer->SendMsgToClient((char*)&msgBackRet,sizeof(msgBackRet)) ;
					break;
				}
			}

			stMsgRoomOtherPlayerSpeak msg ;
			msg.nContentLen = pMsgRet->nContentLen ;
			msg.nContentType = pMsgRet->nContentType ;
			msg.nSpeakerRoomIdx = pPeer->GetPeerIdxInRoom() ;
			msg.nSpeakSex = pPeer->GetPlayerBaseData()->GetSex() ;
			msg.nSystemChatID = pMsgRet->nSystemChatID ;
			msg.nInteraciveWithPeerRoomIdx = pMsgRet->nInteraciveWithPeerRoomIdx;
			memcpy(msg.pSpeakName,pPeer->GetPlayerBaseData()->GetPlayerName(),sizeof(msg.pSpeakName));
			char* pBuffer = new char[sizeof(msg) + msg.nContentLen] ;
			unsigned short nOffset = 0 ;
			memcpy(pBuffer,&msg,sizeof(msg));
			nOffset += sizeof(msg);
			memcpy(pBuffer + nOffset,((char*)pMsgRet) + sizeof(stMsgRoomPlayerSpeak),msg.nContentLen );
			nOffset += msg.nContentLen ;
			SendMsgRoomPeers((stMsg*)pBuffer,nOffset) ;
			delete[] pBuffer ;
		}
		break;
	case MSG_ROOM_KICK_PEER:
		{
			stMsgKickPeerRet msgBack ;
			stMsgKickPeer* pRealMsg = (stMsgKickPeer*)pmsg ;
			msgBack.nRet = 0 ;
			if ( pRealMsg->nIdxToBeKick == pPeer->GetPeerIdxInRoom() )
			{
				msgBack.nRet = 4 ;
				pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack) ) ;
				break;
			}
			
			if (pRealMsg->nIdxToBeKick >= GetMaxSeat() || m_vRoomPeer[pRealMsg->nIdxToBeKick] == NULL )
			{
				msgBack.nRet = 1 ;
				pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack) ) ;
				break;				
			}

			if ( m_vRoomPeer[pRealMsg->nIdxToBeKick]->GetPlayerBaseData()->GetVipLevel() > pPeer->GetPlayerBaseData()->GetVipLevel() )
			{
				msgBack.nRet = 3 ;
				pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack) ) ;
				break;
			}

			CPlayerItemComponent* pItemMgr = (CPlayerItemComponent*)pPeer->GetPlayer()->GetComponent(ePlayerComponent_PlayerItemMgr);	
			if ( pItemMgr->OnUserItem(ITEM_ID_KICK_CARD) )
			{
				// tell all other peer ;
				stMsgKickOtherPeerKickPeer msg ;
				msg.nIdxWhoBeKicked = pRealMsg->nIdxToBeKick ;
				msg.nIdxWhoKick = pPeer->GetPeerIdxInRoom();
				SendMsgRoomPeers(&msg,sizeof(msg));
				// can kick ;
				stKicPlayer stKickInfo;
				stKickInfo.nIdxInRoom = pRealMsg->nIdxToBeKick ;
				stKickInfo.bDoKicked = false ;
				stKickInfo.nUserUIDLimit = m_vRoomPeer[stKickInfo.nIdxInRoom]->GetPlayer()->GetUserUID();
				//memcpy(stKickInfo.cNameBeKicked,m_vRoomPeer[pRealMsg->nIdxToBeKick]->GetPlayerBaseData()->GetPlayerName(),sizeof(stKickInfo.cNameBeKicked));
				memcpy(stKickInfo.cNameKicker,pPeer->GetPlayerBaseData()->GetPlayerName(),sizeof(stKickInfo.cNameKicker));
				m_vAllKickedPeers.push_back(stKickInfo) ;
				ProcessKickedPeers();
			}
			else
			{
				msgBack.nRet = 2 ;
			}
			pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack) ) ;
		}
		break;
	case MSG_ROOM_REQUEST_PEER_DETAIL:
		{
// 			stMsgRoomRequestPeerDetailRet msgBack ;
// 			stMsgRoomRequestPeerDetail* pMsgRet = (stMsgRoomRequestPeerDetail*)pmsg ;
// 			msgBack.nPeerIdxInRoom = pMsgRet->nPeerIdxInRoom ;
// 			CRoomPeer* pFindPeer = NULL ;
// 			if ( pMsgRet->nPeerIdxInRoom >= GetMaxSeat() || m_vRoomPeer[pMsgRet->nPeerIdxInRoom] == NULL )
// 			{
// 				msgBack.nRet = 1 ;
// 			}
// 			else
// 			{
// 				pFindPeer = m_vRoomPeer[pMsgRet->nPeerIdxInRoom];
// 				msgBack.nRet = 0 ;
// 				CPlayerBaseData* pBaseData = pFindPeer->GetPlayerBaseData() ;
// 				pBaseData->GetPlayerDetailData(&msgBack.stDetailInfo) ;
// 			}
// 			pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ;
		}
		break;
	case MSG_PlAYER_INVITED_FRIEND_TO_JOIN_ROOM:
		{
			stMsgPlayerInviteFriendToJoinRoomRet msgBack ;
			msgBack.nRet = 0 ;
			stMsgPlayerInviteFriendToJoinRoom* pMsgRet = (stMsgPlayerInviteFriendToJoinRoom*)pmsg ;
			if ( pMsgRet->nRoomIdx >= GetMaxSeat() || m_vRoomPeer[pMsgRet->nRoomIdx] != NULL )
			{
				msgBack.nRet = 1 ;
				pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ;
				break; ;
			}

			CPlayer* pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(pMsgRet->nPlayerUID) ;
			if ( !pPlayer )
			{
				msgBack.nRet = 2 ;
				pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ;
				break; ;
			}

			//if ( pPlayer->GetState() != CPlayer::ePlayerState_Free )
			//{
			//	msgBack.nRet = 4 ;
			//	pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ;
			//	break; ;
			//}

			if ( CanJoin(pPlayer) != 0 )
			{
				msgBack.nRet = 3 ;
				pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ;
				break; ;
			}
			pPeer->SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ;

			// tell the player you invite ;
			stMsgPlayerBeInvitedToJoinRoom msgInfom ;
			memcpy(msgInfom.pNameWhoInviteMe,pPeer->GetPlayerBaseData()->GetPlayerName(),sizeof(msgInfom.pNameWhoInviteMe));
			msgInfom.nRoomID = GetRoomID();
			msgInfom.nRoomLevel = GetRoomLevel();
			msgInfom.nRoomType = GetRoomType() ;
			msgInfom.nSitIdx = pMsgRet->nRoomIdx ;
			msgInfom.nUserUIDWhoInviteMe = pPeer->GetPlayer()->GetUserUID() ;
			pPlayer->SendMsgToClient((char*)&msgInfom,sizeof(msgInfom)) ;
		}
		break;
	default:
		return false ;
	}
	return true ;
}