📄 patcher.cpp.svn-base
字号:
#include "StdAfx.h"
#include "../VENICE/Auth/MD5.h"
#ifndef WIN32
#include <fcntl.h>
#include <dirent.h>
#include <sys/stat.h>
#endif
initialiseSingleton(PatchMgr);
PatchMgr::PatchMgr()
{
// load patches
void PatchMgr::UpdateJobs()
{
list<PatchJob*>::iterator itr, itr2;
m_patchJobLock.Acquire();
for(itr = m_patchJobs.begin(); itr != m_patchJobs.end();)
{
itr2 = itr;
++itr;
if(!(*itr2)->Update())
{
(*itr2)->GetClient()->m_patchJob=NULL;
delete (*itr2);
m_patchJobs.erase(itr2);
}
}
m_patchJobLock.Release();
}
void PatchMgr::AbortPatchJob(PatchJob * pJob)
{
list<PatchJob*>::iterator itr;
m_patchJobLock.Acquire();
for(itr = m_patchJobs.begin(); itr != m_patchJobs.end(); ++itr)
{
if((*itr)==pJob)
{
m_patchJobs.erase(itr);
break;
}
}
delete pJob;
m_patchJobLock.Release();
}
// this is what blizz sends.
// Data (1412 bytes)
// Data (91 bytes)
// 1412+91=1503 (minus header bytes, 3) = 1500
#define TRANSFER_CHUNK_SIZE 1500
#pragma pack(push,1)
struct TransferInitiatePacket
{
uint8 cmd;
uint8 strsize;
char name[5];
uint64 filesize;
uint8 md5hash[MD5_DIGEST_LENGTH];
};
struct TransferDataPacket
{
uint8 cmd;
uint16 chunk_size;
};
#pragma pack(pop)
bool PatchJob::Update()
{
// don't update unless the write buffer is empty
m_client->BurstBegin();
if(m_client->GetWriteBuffer().GetSize()!=0)
{
m_client->BurstEnd();
return true;
}
// send 1500 byte chunks
TransferDataPacket header;
bool result;
header.cmd = 0x31;
header.chunk_size = (m_bytesLeft>1500)?1500:m_bytesLeft;
//Log.Debug("PatchJob", "Sending %u byte chunk", header.chunk_size);
result = m_client->BurstSend((const uint8*)&header,sizeof(TransferDataPacket));
if(result)
{
result = m_client->BurstSend(m_dataPointer, header.chunk_size);
if(result)
{
m_dataPointer += header.chunk_size;
m_bytesSent += header.chunk_size;
m_bytesLeft -= header.chunk_size;
}
}
if(result)
m_client->BurstPush();
m_client->BurstEnd();
// no need to check the result here, could just be a full buffer and not necessarily a fatal error.
return (m_bytesLeft>0)?true:false;
}
bool PatchMgr::InitiatePatch(Patch * pPatch, AuthSocket * pClient)
{
// send initiate packet
TransferInitiatePacket init;
bool result;
init.cmd = 0x30;
init.strsize=5;
init.name[0] = 'P'; init.name[1] = 'a'; init.name[2] = 't'; init.name[3] = 'c'; init.name[4] = 'h'; init.name[5] = 0;
init.filesize = pPatch->FileSize;
memcpy(init.md5hash, pPatch->MD5, MD5_DIGEST_LENGTH);
// send it to the client
pClient->BurstBegin();
result = pClient->BurstSend((const uint8*)&init,sizeof(TransferInitiatePacket));
if(result)
pClient->BurstPush();
pClient->BurstEnd();
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -