New configuration options for automatically uploading the avatars to an external server.
This commit is contained in:
@@ -48,7 +48,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
|
||||
myQtToolsInterface = CreateQtToolsWrapper();
|
||||
|
||||
// !!!! Revisionsnummer der Configdefaults !!!!!
|
||||
configRev = 57;
|
||||
configRev = 58;
|
||||
|
||||
//standard defaults
|
||||
logOnOffDefault = "1";
|
||||
@@ -189,6 +189,10 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
|
||||
configList.push_back(ConfigInfo("ServerUseIpv6", CONFIG_TYPE_INT, "0"));
|
||||
configList.push_back(ConfigInfo("ServerUseSctp", CONFIG_TYPE_INT, "0"));
|
||||
configList.push_back(ConfigInfo("ServerPort", CONFIG_TYPE_INT, "7234"));
|
||||
configList.push_back(ConfigInfo("ServerUsePutAvatars", CONFIG_TYPE_INT, "0"));
|
||||
configList.push_back(ConfigInfo("ServerPutAvatarsAddress", CONFIG_TYPE_STRING, ""));
|
||||
configList.push_back(ConfigInfo("ServerPutAvatarsUser", CONFIG_TYPE_STRING, ""));
|
||||
configList.push_back(ConfigInfo("ServerPutAvatarsPassword", CONFIG_TYPE_STRING, ""));
|
||||
configList.push_back(ConfigInfo("InternetServerConfigMode", CONFIG_TYPE_INT, "0"));
|
||||
configList.push_back(ConfigInfo("InternetServerListAddress", CONFIG_TYPE_STRING, "pokerth.net/serverlist.xml.z"));
|
||||
configList.push_back(ConfigInfo("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org"));
|
||||
|
||||
@@ -41,7 +41,8 @@ class AvatarManager
|
||||
{
|
||||
public:
|
||||
|
||||
AvatarManager();
|
||||
AvatarManager(bool useExternalServer = false, const std::string &externalServerAddress = "",
|
||||
const std::string &externalServerUser = "", const std::string &externalServerPassword = "");
|
||||
~AvatarManager();
|
||||
|
||||
bool Init(const std::string &dataDir, const std::string &cacheDir);
|
||||
@@ -56,7 +57,7 @@ public:
|
||||
bool GetHashForAvatar(const std::string &fileName, MD5Buf &md5buf) const;
|
||||
bool GetAvatarFileName(const MD5Buf &md5buf, std::string &fileName) const;
|
||||
bool HasAvatar(const MD5Buf &md5buf) const;
|
||||
bool StoreAvatarInCache(const MD5Buf &md5buf, AvatarFileType avatarFileType, const unsigned char *data, unsigned size);
|
||||
bool StoreAvatarInCache(const MD5Buf &md5buf, AvatarFileType avatarFileType, const unsigned char *data, unsigned size, bool upload);
|
||||
|
||||
static bool IsValidAvatarFileType(AvatarFileType avatarFileType, const unsigned char *fileHeader, unsigned fileHeaderSize);
|
||||
|
||||
@@ -79,6 +80,11 @@ private:
|
||||
mutable boost::mutex m_cacheDirMutex;
|
||||
std::string m_cacheDir;
|
||||
|
||||
const bool m_useExternalServer;
|
||||
const std::string m_externalServerAddress;
|
||||
const std::string m_externalServerUser;
|
||||
const std::string m_externalServerPassword;
|
||||
|
||||
boost::shared_ptr<UploaderThread> m_uploader;
|
||||
};
|
||||
|
||||
|
||||
@@ -53,7 +53,10 @@ struct AvatarFileState
|
||||
ifstream inputStream;
|
||||
};
|
||||
|
||||
AvatarManager::AvatarManager()
|
||||
AvatarManager::AvatarManager(bool useExternalServer, const std::string &externalServerAddress,
|
||||
const string &externalServerUser, const string &externalServerPassword)
|
||||
: m_useExternalServer(useExternalServer), m_externalServerAddress(externalServerAddress),
|
||||
m_externalServerUser(externalServerUser), m_externalServerPassword(externalServerPassword)
|
||||
{
|
||||
m_uploader.reset(new UploaderThread());
|
||||
}
|
||||
@@ -65,7 +68,7 @@ AvatarManager::~AvatarManager()
|
||||
}
|
||||
|
||||
bool
|
||||
AvatarManager::Init(const std::string &dataDir, const std::string &cacheDir)
|
||||
AvatarManager::Init(const string &dataDir, const string &cacheDir)
|
||||
{
|
||||
bool retVal = true;
|
||||
bool tmpRet;
|
||||
@@ -324,7 +327,7 @@ AvatarManager::HasAvatar(const MD5Buf &md5buf) const
|
||||
}
|
||||
|
||||
bool
|
||||
AvatarManager::StoreAvatarInCache(const MD5Buf &md5buf, AvatarFileType avatarFileType, const unsigned char *data, unsigned size)
|
||||
AvatarManager::StoreAvatarInCache(const MD5Buf &md5buf, AvatarFileType avatarFileType, const unsigned char *data, unsigned size, bool upload)
|
||||
{
|
||||
bool retVal = false;
|
||||
string cacheDir;
|
||||
@@ -361,7 +364,11 @@ AvatarManager::StoreAvatarInCache(const MD5Buf &md5buf, AvatarFileType avatarFil
|
||||
if (!o.fail())
|
||||
{
|
||||
o.write((const char *)data, size);
|
||||
//m_uploader->QueueUpload(fileName, size);
|
||||
if (upload && m_useExternalServer)
|
||||
{
|
||||
m_uploader->QueueUpload(m_externalServerAddress, m_externalServerUser, m_externalServerPassword, fileName, size);
|
||||
}
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_cachedAvatarsMutex);
|
||||
m_cachedAvatars.insert(AvatarMap::value_type(md5buf, fileName));
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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)
|
||||
@@ -157,3 +157,4 @@ TransferHelper::GetData()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
+6
-1
@@ -59,7 +59,12 @@ Session::~Session()
|
||||
|
||||
bool Session::init()
|
||||
{
|
||||
myAvatarManager.reset(new AvatarManager);
|
||||
myAvatarManager.reset(new AvatarManager(
|
||||
myConfig->readConfigInt("ServerUsePutAvatars") == 1,
|
||||
myConfig->readConfigString("ServerPutAvatarsAddress"),
|
||||
myConfig->readConfigString("ServerPutAvatarsUser"),
|
||||
myConfig->readConfigString("ServerPutAvatarsPassword")
|
||||
));
|
||||
bool retVal = myAvatarManager->Init(
|
||||
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("AppDataDir")),
|
||||
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
|
||||
|
||||
Reference in New Issue
Block a user