New configuration options for automatically uploading the avatars to an external server.

This commit is contained in:
lotodore
2009-03-01 23:09:14 +00:00
parent 4de0913bf2
commit 16decacb6b
14 changed files with 172 additions and 149 deletions
+2 -2
View File
@@ -230,7 +230,7 @@ ClientThread::SendResetTimeout()
{
boost::shared_ptr<NetPacket> reset(new NetPacketResetTimeout);
boost::mutex::scoped_lock lock(m_outPacketListMutex);
m_outPacketList.push_back(reset);
m_outPacketList.push_back(reset);
}
void
@@ -565,7 +565,7 @@ ClientThread::CompleteTempAvatarData(unsigned playerId)
LOG_ERROR("Client received invalid player id!");
else
{
if (!GetAvatarManager().StoreAvatarInCache(tmpPlayerInfo.avatar, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize))
if (!GetAvatarManager().StoreAvatarInCache(tmpPlayerInfo.avatar, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize, false))
LOG_ERROR("Failed to store avatar in cache directory.");
// Update player info, but never re-request avatar.
+1 -1
View File
@@ -37,7 +37,7 @@ DownloadHelper::~DownloadHelper()
}
void
DownloadHelper::InternalInit(const string &/*url*/, const string &targetFileName, const string &/*user*/, const string &/*password*/)
DownloadHelper::InternalInit(const string &/*url*/, const string &targetFileName, const string &/*user*/, const string &/*password*/, int /*filesize*/)
{
// Open target file for writing.
GetData()->targetFile = fopen(targetFileName.c_str(), "wb");
+1 -1
View File
@@ -611,7 +611,7 @@ ServerLobbyThread::HandleNetPacketAvatarEnd(SessionWrapper session, const NetPac
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
if (avatarSize == tmpAvatar->reportedSize)
{
if (!GetAvatarManager().StoreAvatarInCache(avatarMD5, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize))
if (!GetAvatarManager().StoreAvatarInCache(avatarMD5, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize, true))
{
session.playerData->SetAvatarMD5(MD5Buf());
LOG_ERROR("Failed to store avatar in cache directory.");
+4 -3
View File
@@ -42,7 +42,7 @@ TransferHelper::~TransferHelper()
}
void
TransferHelper::Init(const string &url, const string &targetFileName, const string &user, const string &password)
TransferHelper::Init(const string &url, const string &targetFileName, const string &user, const string &password, int filesize)
{
// Initialise curl.
m_data->curlHandle = curl_easy_init();
@@ -57,7 +57,7 @@ TransferHelper::Init(const string &url, const string &targetFileName, const stri
if (curl_easy_setopt(m_data->curlHandle, CURLOPT_URL, m_data->curlUrl.c_str()) != CURLE_OK)
throw NetException(__FILE__, __LINE__, ERR_SOCK_TRANSFER_INVALID_URL, 0);
InternalInit(url, targetFileName, user, password);
InternalInit(url, targetFileName, user, password, filesize);
// Use the multi interface for better abort handling.
if (curl_multi_add_handle(m_data->curlMultiHandle, m_data->curlHandle) != CURLM_OK)
@@ -156,4 +156,5 @@ boost::shared_ptr<TransferData>
TransferHelper::GetData()
{
return m_data;
}
}
+2 -2
View File
@@ -40,10 +40,10 @@ UploaderThread::~UploaderThread()
}
void
UploaderThread::QueueUpload(const std::string &filename, int filesize)
UploaderThread::QueueUpload(const string &url, const string &user, const string &pwd, const string &filename, int filesize)
{
boost::mutex::scoped_lock lock(m_uploadQueueMutex);
m_uploadQueue.push(UploadData(filename, filesize));
m_uploadQueue.push(UploadData(url, user, pwd, filename, filesize));
}
void
+3 -7
View File
@@ -46,14 +46,8 @@ UploadHelper::~UploadHelper()
}
void
UploadHelper::InternalInit(const string &/*url*/, const string &targetFileName, const string &user, const string &password)
UploadHelper::InternalInit(const string &/*url*/, const string &targetFileName, const string &user, const string &password, int filesize)
{
int filesize = 0;
struct stat filestat;
if (stat(targetFileName.c_str(), &filestat) == 0) /* success */
filesize = filestat.st_size;
// Open target file for writing.
// Open target file for writing.
GetData()->targetFile = fopen(targetFileName.c_str(), "rb");
@@ -68,5 +62,7 @@ UploadHelper::InternalInit(const string &/*url*/, const string &targetFileName,
curl_easy_setopt(GetData()->curlHandle, CURLOPT_USERPWD, GetData()->userCredentials.c_str());
curl_easy_setopt(GetData()->curlHandle, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(GetData()->curlHandle, CURLOPT_PUT, 1L);
curl_easy_setopt(GetData()->curlHandle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(GetData()->curlHandle, CURLOPT_SSL_VERIFYHOST, 0L);
}
+1 -1
View File
@@ -32,7 +32,7 @@ public:
protected:
virtual void InternalInit(const std::string &url, const std::string &targetFileName,
const std::string &user, const std::string &password);
const std::string &user, const std::string &password, int filesize);
};
#endif
+2 -2
View File
@@ -36,7 +36,7 @@ public:
// Set the parameters. Does not do any error checking.
// Throws an exception on failure.
void Init(const std::string &url, const std::string &targetFileName,
const std::string &user = "", const std::string &password = "");
const std::string &user = "", const std::string &password = "", int filesize = 0);
// Returns true when done, false should call again.
// Throws an exception on error.
@@ -49,7 +49,7 @@ protected:
boost::shared_ptr<TransferData> GetData();
virtual void InternalInit(const std::string &url, const std::string &targetFileName,
const std::string &user, const std::string &password) = 0;
const std::string &user, const std::string &password, int filesize) = 0;
private:
+6 -2
View File
@@ -36,14 +36,18 @@ public:
UploaderThread();
virtual ~UploaderThread();
void QueueUpload(const std::string &filename, int filesize);
void QueueUpload(const std::string &url, const std::string &user, const std::string &pwd, const std::string &filename, int filesize);
protected:
struct UploadData
{
UploadData() : filesize(0) {}
UploadData(const std::string &f, int s) : filename(f), filesize(s) {}
UploadData(const std::string &a, const std::string &u, const std::string &p, const std::string &f, int s)
: address(a), user(u), pwd(p), filename(f), filesize(s) {}
std::string address;
std::string user;
std::string pwd;
std::string filename;
int filesize;
};
+1 -1
View File
@@ -32,7 +32,7 @@ public:
protected:
virtual void InternalInit(const std::string &url, const std::string &targetFileName,
const std::string &user, const std::string &password);
const std::string &user, const std::string &password, int filesize);
};
#endif