コード例 #1
0
ファイル: PeerAuthClient.cpp プロジェクト: Joincheng/lithtech
WONStatus PeerAuthClient::HandleChallenge1(ReadBuffer &theChallenge, ByteBufferPtr &challenge2)
{
	unsigned short aSecretLenWithLen = theChallenge.ReadShort();
	ByteBufferPtr aSecretBuf = mPeerData->GetPrivateKey().Decrypt(theChallenge.ReadBytes(aSecretLenWithLen),aSecretLenWithLen);
	if(aSecretBuf.get()==NULL)
		return WS_PeerAuthClient_Challenge1DecryptFailure;
		
	unsigned short aSecretLen = aSecretBuf->data()[0] | (aSecretBuf->data()[1]<<8);
	if(aSecretLen>aSecretBuf->length()-2)
		return WS_PeerAuthClient_Challenge1InvalidSecretLen;
		
	mSecretA.Create(8);		
	if(!mSecretB.SetKey(aSecretBuf->data()+2, aSecretLen))
		return WS_PeerAuthClient_Challenge1InvalidSecretKey;

	unsigned short aCertLen = theChallenge.ReadShort();

	if(mUseAuth2)
	{
		mServerCertificate = new Auth2Certificate(theChallenge.ReadBytes(aCertLen),aCertLen);
		if(!mServerCertificate->IsValid())
			return WS_PeerAuthClient_Challenge1CertificateUnpackFailure;
	}
	else
	{
		mServerCertificate = new AuthCertificate(theChallenge.ReadBytes(aCertLen),aCertLen);
		if(!mServerCertificate->IsValid())
			return WS_PeerAuthClient_Challenge1CertificateUnpackFailure;
	}

	if(!mPeerData->Verify(mServerCertificate.get()))
		return WS_PeerAuthClient_Challenge1CertificateVerifyFailure;

	return GetChallenge2(challenge2);
}
コード例 #2
0
WONStatus PeerAuthServer::HandleRequest(ReadBuffer &theRequest, ByteBufferPtr &theChallenge)
{
	unsigned char authMode = theRequest.ReadByte();
	unsigned char encryptType = theRequest.ReadByte();
	unsigned short encryptFlags = theRequest.ReadShort();

	if(authMode!=1)
		return WS_PeerAuthServer_InvalidAuthMode;

	if(encryptType!=0 && encryptType!=1)
		return WS_PeerAuthServer_InvalidEncryptType;

	bool encrypted = encryptType==1;
	
	mAuthType = encrypted?AUTH_TYPE_PERSISTENT:AUTH_TYPE_PERSISTENT_NOCRYPT;

	unsigned short aLen = theRequest.ReadShort();
	if(mUseAuth2)
		mClientCertificate = new Auth2Certificate(theRequest.ReadBytes(aLen),aLen);
	else
		mClientCertificate = new AuthCertificate(theRequest.ReadBytes(aLen),aLen);
	
	if(!mClientCertificate->IsValid())
		return WS_PeerAuthServer_InvalidClientCertificate;
	else if(mClientCertificate->IsExpired(mPeerData->GetAuthDelta()))
		return WS_PeerAuthServer_ExpiredClientCertificate;
	else if(!mPeerData->Verify(mClientCertificate.get()))
		return WS_PeerAuthServer_FailedToVerifyClientCertificate;

	return GetChallenge1(theChallenge);
}
コード例 #3
0
WONStatus RoutingRegisterClientOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	WONStatus aStatus;

	if(theMsgType==RoutingGetClientListReply || theMsgType==RoutingGetClientListReplyEx)
	{
		if(!(mRegisterFlags&RoutingRegisterClientFlag_GetClientListEx)) // clientlistex includes clientlist ( == 0x14)
			return WS_RoutingOp_DontWantReply;

		RoutingGetClientListOpPtr anOp = new RoutingGetClientListOp(mConnection);
		aStatus = anOp->HandleReply(theMsgType,theMsg);
		mClientMap = anOp->GetClientMap();
		mReplyCount++;
	}
	else if(theMsgType==RoutingRegisterClientReply)
	{
		aStatus = (WONStatus)theMsg.ReadShort();
		if(aStatus==WS_Success)
		{
			mClientId = theMsg.ReadShort();
			theMsg.ReadWString(mClientName);
			mReconnectId = theMsg.ReadLong();
		}
		mReplyCount++;
	}
	else
		return WS_RoutingOp_DontWantReply;

	if(aStatus!=WS_Success || mReplyCount==mNumRepliesNeeded)
		return aStatus;
	else
		return WS_RoutingOp_NeedMoreReplies;
}
コード例 #4
0
short LobbyGame::HandleJoinGameReply(ReadBuffer &theMsg)
{
	short aStatus = LobbyGameStatus_None;
	try
	{
		aStatus = theMsg.ReadShort();

		if(aStatus!=LobbyGameStatus_Success)
			return aStatus;

		unsigned short aNumPlayers = theMsg.ReadShort();
		for(int i=0; i<aNumPlayers; i++)
		{
			unsigned short aClientId = theMsg.ReadShort();
			LobbyClient *aClient = GetClient(aClientId);
			if(aClient!=NULL)
			{
				LobbyPlayerPtr aPlayer = LobbyPlayer::CreatePlayer();
				if(aPlayer->ReadData(theMsg))
					aClient->SetPlayer(aPlayer);
			}
		}

		HandleJoinGameReplyHook(theMsg);
	}
	catch(ReadBufferException&)
	{
		aStatus = LobbyGameStatus_UnpackFailure;
	}

	return aStatus;
}
コード例 #5
0
bool Auth2Certificate::UnpackHook(ReadBuffer &theData)
{
	if(!AuthBase::UnpackHook(theData))
		return false;

	unsigned short aDataCount = theData.ReadShort();
	for(int i=0; i<aDataCount; i++)
	{
		unsigned short aTypeId = theData.ReadShort();
		unsigned short aDataLen = theData.ReadShort();
		int aPos = theData.pos();
		switch(aTypeId)
		{

			case 0:  // standard login data
			{
				mUserId = theData.ReadLong();
				unsigned short aKeyLen = theData.ReadShort();
				if(!mPubKey.SetPublicKey(theData.ReadBytes(aKeyLen),aKeyLen))
					return false;

				theData.ReadWString(mUserName);
				unsigned char aCommunityCount = theData.ReadByte();
				for(int i=0; i<aCommunityCount; i++)
					mCommunityTrustMap[theData.ReadLong()] = theData.ReadShort();
 
			}
			break;

			case 1: // user data
			{
				DWORD aCommunityId = theData.ReadLong();
				mUserDataMap[aCommunityId] = theData.ReadBuf(2);
			}
			break;

			case 2:	// nickname
			{
				wstring aKey, aVal;
				theData.ReadWString(aKey);
				theData.ReadWString(aVal);
				mNicknameMap[aKey] = aVal;
			}
			break;

			case 3: // KeyId data block
			{
				DWORD aCommunityId = theData.ReadLong();
				DWORD aKeyId = theData.ReadLong();
				mKeyIdMap[aCommunityId] = aKeyId;
			}
			break;
		}

		theData.ReadBytes(aDataLen - (theData.pos() - aPos));
	}

	return true;
}
コード例 #6
0
WONStatus RoutingGroupCaptainChangedOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingGroupCaptainChanged)
		return WS_RoutingOp_DontWantReply;

	mGroupId = theMsg.ReadShort();
	mNewCaptainId = theMsg.ReadShort();

	return WS_Success;
}
コード例 #7
0
WONStatus RoutingClientLeftGroupOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingClientLeftGroup)
		return WS_RoutingOp_DontWantReply;

	mGroupId = theMsg.ReadShort();
	mClientId = theMsg.ReadShort();

	return WS_Success;
}
コード例 #8
0
WONStatus RoutingGroupInvitationOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingGroupInvitation)
		return WS_RoutingOp_DontWantReply;

	mGroupId = theMsg.ReadShort();
	mCaptainId = theMsg.ReadShort();
	mAmInvited = theMsg.ReadBool();
	theMsg.ReadWString(mComment);

	return WS_Success;
}
コード例 #9
0
WONStatus RoutingGroupJoinAttemptOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingGroupJoinAttempt)
		return WS_RoutingOp_DontWantReply;

	mClientId = theMsg.ReadShort();
	mGroupId = theMsg.ReadShort();
	theMsg.ReadWString(mComment);
	mJoinGroupFlags = theMsg.ReadByte();

	return WS_Success;
}
コード例 #10
0
void RoutingGetGroupListOp::ParseReplyExceptForStatus(ReadBuffer &theMsg)
{
	mGroupMap.clear();

	mFlags = theMsg.ReadShort();
	unsigned short aNumGroups = theMsg.ReadShort();
	for(int i=0; i<aNumGroups; i++)
	{
		unsigned short aLen = theMsg.ReadShort();
		unsigned long aBeginPos = theMsg.pos();

		RoutingGroupInfoPtr anInfo = GetNewGroupInfo();
		anInfo->mId = theMsg.ReadShort();
		if (HasGroupName())
			theMsg.ReadWString(anInfo->mName);
		if (HasCaptainId())
			anInfo->mCaptainId = theMsg.ReadShort();
		if (HasMaxPlayers())
			anInfo->mMaxPlayers = theMsg.ReadShort();
		if (HasGroupFlags())
			anInfo->mFlags = theMsg.ReadLong();
		if (HasAsyncFlags())
			anInfo->mAsyncFlags = theMsg.ReadLong();
		if (HasObserverCount())
			anInfo->mObserverCount = theMsg.ReadShort();
		if (HasMemberCount())
			anInfo->mMemberCount = theMsg.ReadShort();
	
		if (HasMembers())
		{
			for(int j=0; j<anInfo->mMemberCount; j++)
			{
				RoutingMemberInfoPtr aMemberInfo = GetNewMemberInfo();
				aMemberInfo->mClientId = theMsg.ReadShort();
				aMemberInfo->mFlags = theMsg.ReadByte();
				anInfo->mMemberMap[aMemberInfo->mClientId] = aMemberInfo;
			}
		}

	//	if (theMsg.HasMoreBytes())
	//		anInfo->mParentId = theMsg.ReadShort();

		mGroupMap[anInfo->mId] = anInfo;
		
		theMsg.ReadBytes(aLen - (theMsg.pos() - aBeginPos));
	}

	if(HasClientCount() && theMsg.HasMoreBytes())
		mClientCount = theMsg.ReadShort();

}
コード例 #11
0
bool AuthCertificate::UnpackHook(ReadBuffer &theData)
{
	if(!AuthBase::UnpackHook(theData))
		return false;

	mUserId = theData.ReadLong();
	mCommunityId = theData.ReadLong();
	mTrustLevel = theData.ReadShort();

	unsigned short aKeyLen = theData.ReadShort();
	if(!mPubKey.SetPublicKey(theData.ReadBytes(aKeyLen),aKeyLen))
		return false;

	return true;
}
コード例 #12
0
WONStatus RoutingSetGroupPasswordOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingStatusReply)
		return WS_RoutingOp_DontWantReply;

	WONStatus aStatus = (WONStatus)theMsg.ReadShort();
	return aStatus;
}
コード例 #13
0
WONStatus RoutingCreateDataObjectOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingStatusReply)
		return WS_RoutingOp_DontWantReply;

	WONStatus aStatus = (WONStatus)theMsg.ReadShort();
	return aStatus;
}
コード例 #14
0
void StagingLogic::HandlePingChanged(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!theSender->IsCaptain(true))
		return;

	unsigned short aClientId = theMsg.ReadShort();
	unsigned short aPing = theMsg.ReadShort();

	LobbyClient *aClient = mGame->GetClient(aClientId);
	if(aClient==NULL)
		return;

	LobbyPlayer *aPlayer = aClient->GetPlayer();
	if(aPlayer==NULL)
		return;

	aPlayer->SetPing(aPing);
	LobbyEvent::BroadcastEvent(new PlayerChangedEvent(aClient,LobbyChangeType_Modify));
}
コード例 #15
0
bool LobbyGame::ReadSummary(ReadBuffer &theMsg)
{
	try
	{
		if(mGameType==LobbyGameType_Internet)
			mIPAddr.SetSixByte(theMsg.ReadBytes(6));
		else
		{
			unsigned short aLanProductId = theMsg.ReadShort();
			if(aLanProductId!=LobbyMisc::GetLanProductId())
				return false;
		}
			
		mInProgress = theMsg.ReadBool();
		if(mGameType!=LobbyGameType_Internet)
		{
			std::wstring aName;
			theMsg.ReadWString(aName);
			mName = aName;
		}

		mSkillLevel = (LobbySkillLevel)theMsg.ReadByte();
		if(mSkillLevel<LobbySkillLevel_None || mSkillLevel>=LobbySkillLevel_Max)
			mSkillLevel = LobbySkillLevel_None;

		if(mGameType!=LobbyGameType_Internet)
		{
			unsigned char aProtectionFlags = theMsg.ReadByte();
			mHasPassword = (aProtectionFlags & 0x01)?true:false;
			mInviteOnly = (aProtectionFlags & 0x02)?true:false;
			mAskToJoin = (aProtectionFlags & 0x04)?true:false;
		}

		mNumPlayers = theMsg.ReadShort();
		mMaxPlayers = theMsg.ReadShort();

		return ReadSummaryHook(theMsg);
	}
	catch(ReadBufferException&)
	{
	}
	return false;
}
コード例 #16
0
WONStatus RoutingYouWereBannedOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingYouWereBanned)
		return WS_RoutingOp_DontWantReply;

	mGroupId = theMsg.ReadShort();
	mAmBanned = theMsg.ReadBool();
	theMsg.ReadWString(mBanComment);
	mBanTime = theMsg.ReadLong();

	return WS_Success;
}
コード例 #17
0
WONStatus RoutingGetGroupListOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingGetGroupListReply)
		return WS_RoutingOp_DontWantReply;

	WONStatus aStatus = (WONStatus)theMsg.ReadShort();
	if(aStatus==WS_Success)
	{
		ParseReplyExceptForStatus(theMsg);
	}

	return aStatus;
}
コード例 #18
0
void StagingLogic::HandleClientKicked(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!theSender->IsCaptain(true))
		return;

	unsigned short aClientId = theMsg.ReadShort();
	bool isBan = theMsg.ReadBool();

	LobbyClient *aClient = mGame->GetClient(aClientId);
	if(aClient==NULL)
		return;

	NotifyClientKicked(aClient,isBan);
}
コード例 #19
0
ファイル: PeerAuthClient.cpp プロジェクト: Joincheng/lithtech
WONStatus PeerAuthClient::HandleComplete(ReadBuffer &theComplete)
{
	short aStatus = theComplete.ReadShort();
	if(aStatus<0)
	{		
		unsigned short aNumErrors = theComplete.ReadShort();
		for(int i=0; i<aNumErrors; i++)
		{
			string anError;
			theComplete.ReadString(anError);
		}
		
		return (WONStatus)aStatus;
	}
		
	unsigned short aLen = theComplete.ReadShort();
	ByteBufferPtr aDecrypt = mPeerData->GetPrivateKey().Decrypt(theComplete.ReadBytes(aLen),aLen);
	if(aDecrypt.get()==NULL)
		return WS_PeerAuthClient_CompleteDecryptFailure;

	if(aDecrypt->length()<2)
		return WS_PeerAuthClient_CompleteInvalidSecretLen;
	
	aLen = (aDecrypt->data()[0] | (aDecrypt->data()[1]<<8));
	if(aLen>aDecrypt->length()-2 || aLen!=mSecretA.GetKeyLen() || memcmp(mSecretA.GetKey(),aDecrypt->data()+2,aLen)!=0)
		return WS_PeerAuthClient_CompleteInvalidSecretKey;	

	unsigned short aSessionId = 0;
	if(mAuthType==AUTH_TYPE_SESSION)
		aSessionId = theComplete.ReadShort();

	if(mAuthType!=AUTH_TYPE_PERSISTENT_NOCRYPT)
		mSession = new AuthSession(mAuthType, aSessionId, mSecretB, mLengthFieldSize);

	return WS_Success;
}
コード例 #20
0
WONStatus PeerAuthServer::HandleChallenge2(ReadBuffer &theChallenge, ByteBufferPtr &theComplete)
{
	unsigned short anEncryptLen = theChallenge.ReadShort();
	ByteBufferPtr aDecrypt = mPeerData->GetPrivateKey().Decrypt(theChallenge.ReadBytes(anEncryptLen),anEncryptLen);
	if(aDecrypt.get()==NULL)
		return WS_PeerAuthServer_FailedToDecryptWithPrivateKey;

	ReadBuffer aBuf(aDecrypt->data(),aDecrypt->length());
	unsigned short aSecretBLen = aBuf.ReadShort();
	if(aSecretBLen!=mSecretB.GetKeyLen() || memcmp(mSecretB.GetKey(),aBuf.ReadBytes(aSecretBLen),aSecretBLen)!=0)
		return WS_PeerAuthServer_InvalidSecretB;

	if(!mSecretA.SetKey(aBuf.data()+aBuf.pos(),aBuf.Available()))
		return WS_PeerAuthServer_InvalidSecretA;

	return GetComplete(WS_Success, theComplete);
}
コード例 #21
0
void StagingLogic::HandlePingChangedRequest(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!IAmCaptain())
		return;

	unsigned short aPing = theMsg.ReadShort();

	LobbyPlayer *aPlayer = theSender->GetPlayer();
	if(aPlayer==NULL)
		return;

	WriteBuffer aMsg;
	aMsg.AppendByte(LobbyGameMsg_PingChanged);
	aMsg.AppendShort(theSender->GetClientId());
	aMsg.AppendShort(aPing);
	BroadcastGameMessage(aMsg.ToByteBuffer());
}
コード例 #22
0
void StagingLogic::HandlePlayerJoined(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!theSender->IsCaptain(true))
		return;

	unsigned short aClientId = theMsg.ReadShort();
	LobbyClient *aClient = mGame->GetClient(aClientId);
	if(aClient==NULL)
		return;

	if(!aClient->IsPlayer()) 
	{
		LobbyPlayerPtr aPlayer = LobbyPlayer::CreatePlayer();
		if(!aPlayer->ReadData(theMsg))
			return;

		aClient->SetPlayer(aPlayer);
	}
	else
	{
		// already know about him (can happen if we're the captain or it's our client right after we joined)
		if(!IAmCaptain()) // already got ourselves in the join game reply
			return;
	}

	LobbyEvent::BroadcastEvent(new PlayerChangedEvent(aClient,LobbyChangeType_Add));
	if(aClient->SameTeam(mMyClient))
		LobbyEvent::BroadcastEvent(new PlayerTeamChangedEvent(aClient,LobbyChangeType_Add));

	mGame->HandlePlayerJoined(aClient);
	if(LobbyPersistentData::GetStagingSoundEffects())
		LobbyMisc::PlaySound(LobbyGlobal_PlayerJoined_Sound);

	if(mEveryoneReadySoundState && !aClient->IsPlayerReady())
		mEveryoneReadySoundState = false;

	UpdateStartButton();
}
コード例 #23
0
void StagingLogic::HandlePlayerReady(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!theSender->IsCaptain(true))
		return;


	unsigned short aClientId = theMsg.ReadShort();
	bool isReady = theMsg.ReadBool();
	
	LobbyClient *aClient = mGame->GetClient(aClientId);
	if(aClient==NULL)
		return;

	LobbyPlayer *aPlayer = aClient->GetPlayer();
	if(aPlayer==NULL)
		return;

	aPlayer->SetReady(isReady);

	CheckPlayReadySound();
	
	LobbyEvent::BroadcastEvent(new PlayerChangedEvent(aClient,LobbyChangeType_Modify));
}
コード例 #24
0
WONStatus RoutingGetMembersOfGroupOp::HandleReply(unsigned char theMsgType, ReadBuffer &theMsg)
{
	if(theMsgType!=RoutingGetMembersOfGroupReply)
		return WS_RoutingOp_DontWantReply;

	WONStatus aStatus = (WONStatus)theMsg.ReadShort();
	unsigned short aGroupId = theMsg.ReadShort();
	if(aGroupId!=mGroupId)
		return WS_RoutingOp_DontWantReply;

	if(aStatus==WS_Success)
	{
		unsigned char aFlags = theMsg.ReadByte();
		mHasClientNames = ((aFlags & RoutingGroupAsyncFlag_DistributeClientName) != 0);
		mHasClientFlags = ((aFlags & RoutingGroupAsyncFlag_DistributeClientFlags) != 0);
		mObserverCount = theMsg.ReadShort();
		unsigned short aNumMembers = theMsg.ReadShort();
		for(int j=0; j<aNumMembers; j++)
		{
			unsigned short aLen = theMsg.ReadShort();
			unsigned long aBeginPos = theMsg.pos();

			RoutingMemberInfoPtr aMemberInfo = GetNewMemberInfo();
			aMemberInfo->mClientId = theMsg.ReadShort();
			aMemberInfo->mFlags = theMsg.ReadByte();
			mMemberMap[aMemberInfo->mClientId] = aMemberInfo;

			if(aFlags!=0)
				aMemberInfo->mClientInfo = GetNewClientInfo();

			if(mHasClientNames)  
				theMsg.ReadWString(aMemberInfo->mClientInfo->mName);

			if(mHasClientFlags)
				aMemberInfo->mClientInfo->mFlags = theMsg.ReadLong();

			theMsg.ReadBytes(aLen - (theMsg.pos() - aBeginPos));
		}			
	}

	return aStatus;
}
コード例 #25
0
short LobbyGame::HandleJoinGameRequest(ReadBuffer &theMsg, LobbyClient *theClient, WriteBuffer &theReply)
{
	LobbyPlayerPtr aPlayer;

	if(IsGameFull())
		return LobbyGameStatus_GameFull;
	else if(mInProgress)
		return LobbyGameStatus_GameInProgress;

	LobbyConfig *aConfig = LobbyConfig::GetLobbyConfig();
	if(aConfig!=NULL && !aConfig->mAllowDuplicateNames)
	{
		// check if the name is already used
		LobbyClientMap::const_iterator aClientItr = mClientList->GetClientMap().begin();
		for(; aClientItr != mClientList->GetClientMap().end(); ++aClientItr)
		{
			if (aClientItr->second->GetName() == theClient->GetName() && aClientItr->second.get() != theClient)
				return LobbyGameStatus_DuplicateName;
		}
	}
	


	aPlayer = LobbyPlayer::CreatePlayer();
	theClient->SetPlayer(aPlayer);

	try
	{
		unsigned short aPing = theMsg.ReadShort();	
		aPlayer->SetPing(aPing);

		short aStatus = HandleJoinGameRequestHook(theMsg, theClient);
		if(aStatus!=LobbyGameStatus_Success)
		{
			theClient->SetPlayer(NULL);
			return aStatus;
		}
	}
	catch(ReadBufferException&)
	{
		theClient->SetPlayer(NULL);
		return LobbyGameStatus_UnpackFailure;
	}


	// Send PlayerList back
	mNumPlayers++;	
	theReply.AppendShort(mNumPlayers); 

	LobbyPlayerList aList(mClientList);	
	while(aList.HasMorePlayers())
	{
		LobbyClient *aClient;
		LobbyPlayer *aPlayer = aList.GetNextPlayer(&aClient);
		if(aPlayer!=NULL)
		{
			theReply.AppendShort(aClient->GetClientId());
			aPlayer->WriteData(theReply);
		}
	}
	
	GetJoinGameReplyHook(theClient,theReply);
	return LobbyGameStatus_Success;

}