ByteBufferPtr WIMDecoder::EncodeToBuffer(RawImagePtr theImage)
{
	if(theImage->GetType()!=RawImageType_32)
		return NULL;

	RawImage32 *anImage = (RawImage32*)theImage.get();
	
	WriteBuffer aBuf;
	aBuf.AppendBytes("WIM",3); // file format identifier
	aBuf.AppendLong(32); // file subtype (32-bit raw)
	aBuf.AppendByte(anImage->GetDoTransparency()?1:0); // apply transparency bit?
	aBuf.AppendLong(anImage->GetWidth());
	aBuf.AppendLong(anImage->GetHeight());
	aBuf.AppendBytes(anImage->GetImageData(), 4*anImage->GetWidth()*anImage->GetHeight());
	return aBuf.ToByteBuffer();
}
SPAuthCheckPrv::SPAuthCheckPrv(const char *theProduct)
{
	mAPI = NULL;
	mStatus = WS_None;
	mStartedChecking = false;
	mOnlyForceCheck = false;
	mStartTime = time(NULL);
	mGameSecondsBeforeNextCheck = 1;

	WriteBuffer aBuf;
	aBuf.Reserve(8);
	aBuf.AppendLong(0x87ab3215);
	aBuf.AppendLong(CDKey::GetMachineId());
	mEncryptKey.SetKey(aBuf.data(),aBuf.length());
	
	mAuthContext = new AuthContext;
	mCommunity = StringToWString(theProduct);
	mProductDir = L"/" + mCommunity;

	mCDKey.SetProductString(theProduct);
	mCDKey.LoadFromRegistry();
	if(!mCDKey.IsValid())
	{
		mStatus = WS_AuthServ_InvalidCDKey;
		return;
	}
		
	if(!AsyncSocket::HasInternetConnection())
	{
		mStatus = WS_NoInternetConnection;
		return;
	}

	if(WONAPICoreEx::GetInstance()==NULL)
	{
		mAPI = new WONAPICoreEx;
		mAPI->SetDoPumpThread(true);
		mAPI->Startup();
	}	

	ReadCheckFile();
}
ByteBufferPtr MultiPingOp::GetRequest(MultiPingStruct *theStruct)
{
	theStruct->mPingId = rand();
	theStruct->mStartPingTick = GetTickCount();

	WriteBuffer aBuf;
	aBuf.AppendByte(3);
	aBuf.AppendByte(1);
	aBuf.AppendByte(5);
	aBuf.AppendLong(theStruct->mPingId);
	aBuf.AppendBool(false);
	return aBuf.ToByteBuffer();
}
void SPAuthCheckPrv::WriteCheckFile()
{
	
	if(mGameSecondsBeforeNextCheck==1) // Remove file to force check next time
	{
		WONFile aFile(gSPAuthCheck_FileName);
		aFile.Remove();
		return;
	}

	// Write new file
	try
	{
		FileWriter aWriter;
		if(!aWriter.Open(gSPAuthCheck_FileName))
			return;

		WONFile aFile(gSPAuthCheck_FileName);

		WriteBuffer anEncrypt;
		anEncrypt.AppendString("magic");
		anEncrypt.AppendLong(aFile.GetCreateTime()); // file creation time
		anEncrypt.AppendLong(mGameSecondsBeforeNextCheck);

		ByteBufferPtr aBuf = mEncryptKey.Encrypt(anEncrypt.data(),anEncrypt.length());
		if(aBuf.get()==NULL)
			return;

		aWriter.WriteShort(aBuf->length());
		aWriter.WriteBytes(aBuf->data(),aBuf->length());
	}
	catch(FileWriterException&)
	{
	}


}
void InsertBannedKeyOp::RunHook()
{
	SetMessageType(DBProxyAccount);
	SetSubMessageType(MSGTYPE);
	mStatusList.clear();

	// Stores the message data
	WriteBuffer requestData;
	requestData.AppendWString(mCommunityName);
	requestData.AppendString(mProductName);
	requestData.AppendLong(mBannedUntil);

	requestData.AppendShort(mKeyList.size());
	for(std::list<std::string>::const_iterator anItr = mKeyList.begin(); anItr != mKeyList.end(); ++anItr)
		requestData.AppendString(*anItr,1);

	// Copy buffer into the class
	SetProxyRequestData(requestData.ToByteBuffer());

	DBProxyOp::RunHook();
}
Example #6
0
void AuthContext::AppendCommunityData(WriteBuffer &theBuf)
{
	AutoCrit aCrit(mDataCrit);
	theBuf.AppendByte(0);									// 0 community ids
	theBuf.AppendByte(mCommunityMap.size());				// num community names
	AuthLoginCommunityMap::iterator anItr = mCommunityMap.begin(); 
	while(anItr!=mCommunityMap.end())
	{
		theBuf.AppendWString(anItr->first);	// community name
		++anItr;
	}


	int aNumCommnityElementsPos = theBuf.length();
	theBuf.SkipBytes(2); 
	int aNumCommunityElements = 0;

	anItr = mCommunityMap.begin();
	while(anItr!=mCommunityMap.end()) // Append CD Keys
	{
		AuthLoginCommunityData &aData = anItr->second;
		if(aData.mCDKey.IsValid())
		{
			ByteBufferPtr aKey = anItr->second.mCDKey.GetRaw();
			if(aKey.get()!=NULL)
			{
				theBuf.AppendByte(1);			// Type = CD Key
				theBuf.AppendShort(anItr->first.length()*2 + aKey->length() + 2); // length of community + data
				theBuf.AppendWString(anItr->first);
				theBuf.AppendBytes(aKey->data(),aKey->length());
				aNumCommunityElements++;
			}
		}
		++anItr;
	}

	CDKeyCommunityJoinMap::iterator aKeyJoinItr = mCDKeyCommunityJoinMap.begin(); // Append Community Join By CDKey Info
	while(aKeyJoinItr!=mCDKeyCommunityJoinMap.end())
	{
		ByteBufferPtr aKey = aKeyJoinItr->second.GetRaw();
		if(aKey.get()!=NULL)
		{
			theBuf.AppendByte(7);			// Type = Join Community with CD Key
			theBuf.AppendShort(aKeyJoinItr->first.length()*2+2 + 4 + aKey->length()); // community name + commnityseq + key
			theBuf.AppendWString(aKeyJoinItr->first);
			theBuf.AppendLong(0);
			theBuf.AppendBytes(aKey->data(),aKey->length());
			aNumCommunityElements++;
		}
		++aKeyJoinItr;
	}

	SetCommunityUserDataMap::iterator aUserDataItr = mSetCommunityUserDataMap.begin(); // Append User Data for communities
	while(aUserDataItr!=mSetCommunityUserDataMap.end())
	{
		const ByteBuffer *aData = aUserDataItr->second;
		if(aData!=NULL)
		{
			theBuf.AppendByte(8);			// Type = SetCommunityUserData
			theBuf.AppendShort(aUserDataItr->first.length()*2+2 + 4 + aData->length()); // community name + commnityseq + key
			theBuf.AppendWString(aUserDataItr->first);
			theBuf.AppendLong(0);
			theBuf.AppendBuffer(aData);
			aNumCommunityElements++;
		}

		++aUserDataItr;
	}

	if(mSecretList.size()>0) 				// CD Keys -> append login secret
	{
		theBuf.AppendByte(6);				// Type = LoginSecret
		unsigned long aPos = theBuf.length();
		theBuf.SkipBytes(2);

		AppendLoginSecrets(theBuf);
		theBuf.SetShort(aPos,theBuf.length()-aPos-2);
		aNumCommunityElements++;
	}

	NicknameMap::iterator aNickItr = mNicknameMap.begin();
	while(aNickItr!=mNicknameMap.end())
	{
		const wstring& aKey = aNickItr->first;
		const wstring& aVal = aNickItr->second;

		theBuf.AppendByte(4); // retrieve nickname
		unsigned long aPos = theBuf.length();
		theBuf.SkipBytes(2);
		theBuf.AppendWString(aKey);
		theBuf.SetShort(aPos,theBuf.length()-aPos-2);
		aNumCommunityElements++;

		if(!aVal.empty())
		{
			theBuf.AppendByte(3); // set nickname
			unsigned long aPos = theBuf.length();
			theBuf.SkipBytes(2);
			theBuf.AppendWString(aKey);
			theBuf.AppendWString(aVal);
			theBuf.SetShort(aPos,theBuf.length()-aPos-2);

			aNumCommunityElements++;
		}

		++aNickItr;
	}

	theBuf.SetShort(aNumCommnityElementsPos,aNumCommunityElements);
}
Example #7
0
ByteBufferPtr ElGamal::Encrypt(const void *thePlainText, int thePlainTextLen) const
{
    if(!IsPublic())
        return NULL;

    const unsigned char *aPlainText = (const unsigned char*)thePlainText;

    int aBlockLen = modulusLen - 3;
    int aNumBlock = thePlainTextLen / aBlockLen;
    if ((thePlainTextLen % aBlockLen) != 0) aNumBlock++;

    WriteBuffer anEncrypt;
    anEncrypt.Reserve(4+modulusLen*2*aNumBlock);

    int anOffset = 0;

    anEncrypt.AppendLong(aNumBlock);

    while(anOffset < thePlainTextLen)
    {
        int thisBlockLen = aBlockLen;

        if(thePlainTextLen - anOffset < aBlockLen)
            thisBlockLen = thePlainTextLen - anOffset;

        RawBuffer anEncryptBlock(modulusLen-1,(unsigned char)0);

        for(int k=0,j=modulusLen-2-thisBlockLen; j<modulusLen-2; j++,k++)
            anEncryptBlock[j] = aPlainText[anOffset+k];

        anEncryptBlock[modulusLen - 2] = (unsigned char)thisBlockLen;


        BigInteger ab[2];

        if(!encrypt(BigInteger(anEncryptBlock),ab))
            return NULL;


        RawBuffer aa,bb;
        ab[0].toBinary(aa);
        ab[1].toBinary(bb);

        if(aa.length()==modulusLen)
            anEncrypt.AppendBytes(aa.data(),aa.length());
        else if(aa.length()>modulusLen)
            anEncrypt.AppendBytes(aa.data()+aa.length()-modulusLen,modulusLen);
        else
        {
            for(int i=aa.length(); i<modulusLen; i++)
                anEncrypt.AppendByte(0);

            anEncrypt.AppendBytes(aa.data(),aa.length());
        }


        if(bb.length()==modulusLen)
            anEncrypt.AppendBytes(bb.data(),bb.length());
        else if(bb.length()>modulusLen)
            anEncrypt.AppendBytes(bb.data()+bb.length()-modulusLen,modulusLen);
        else
        {
            for(int i=bb.length(); i<modulusLen; i++)
                anEncrypt.AppendByte(0);

            anEncrypt.AppendBytes(bb.data(),bb.length());
        }
        anOffset+=thisBlockLen;
    }

    return anEncrypt.ToByteBuffer();
}