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();
|
myQtToolsInterface = CreateQtToolsWrapper();
|
||||||
|
|
||||||
// !!!! Revisionsnummer der Configdefaults !!!!!
|
// !!!! Revisionsnummer der Configdefaults !!!!!
|
||||||
configRev = 57;
|
configRev = 58;
|
||||||
|
|
||||||
//standard defaults
|
//standard defaults
|
||||||
logOnOffDefault = "1";
|
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("ServerUseIpv6", CONFIG_TYPE_INT, "0"));
|
||||||
configList.push_back(ConfigInfo("ServerUseSctp", 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("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("InternetServerConfigMode", CONFIG_TYPE_INT, "0"));
|
||||||
configList.push_back(ConfigInfo("InternetServerListAddress", CONFIG_TYPE_STRING, "pokerth.net/serverlist.xml.z"));
|
configList.push_back(ConfigInfo("InternetServerListAddress", CONFIG_TYPE_STRING, "pokerth.net/serverlist.xml.z"));
|
||||||
configList.push_back(ConfigInfo("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org"));
|
configList.push_back(ConfigInfo("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org"));
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ class AvatarManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AvatarManager();
|
AvatarManager(bool useExternalServer = false, const std::string &externalServerAddress = "",
|
||||||
|
const std::string &externalServerUser = "", const std::string &externalServerPassword = "");
|
||||||
~AvatarManager();
|
~AvatarManager();
|
||||||
|
|
||||||
bool Init(const std::string &dataDir, const std::string &cacheDir);
|
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 GetHashForAvatar(const std::string &fileName, MD5Buf &md5buf) const;
|
||||||
bool GetAvatarFileName(const MD5Buf &md5buf, std::string &fileName) const;
|
bool GetAvatarFileName(const MD5Buf &md5buf, std::string &fileName) const;
|
||||||
bool HasAvatar(const MD5Buf &md5buf) 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);
|
static bool IsValidAvatarFileType(AvatarFileType avatarFileType, const unsigned char *fileHeader, unsigned fileHeaderSize);
|
||||||
|
|
||||||
@@ -79,6 +80,11 @@ private:
|
|||||||
mutable boost::mutex m_cacheDirMutex;
|
mutable boost::mutex m_cacheDirMutex;
|
||||||
std::string m_cacheDir;
|
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;
|
boost::shared_ptr<UploaderThread> m_uploader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ struct AvatarFileState
|
|||||||
ifstream inputStream;
|
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());
|
m_uploader.reset(new UploaderThread());
|
||||||
}
|
}
|
||||||
@@ -65,7 +68,7 @@ AvatarManager::~AvatarManager()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
AvatarManager::Init(const std::string &dataDir, const std::string &cacheDir)
|
AvatarManager::Init(const string &dataDir, const string &cacheDir)
|
||||||
{
|
{
|
||||||
bool retVal = true;
|
bool retVal = true;
|
||||||
bool tmpRet;
|
bool tmpRet;
|
||||||
@@ -324,7 +327,7 @@ AvatarManager::HasAvatar(const MD5Buf &md5buf) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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;
|
bool retVal = false;
|
||||||
string cacheDir;
|
string cacheDir;
|
||||||
@@ -361,7 +364,11 @@ AvatarManager::StoreAvatarInCache(const MD5Buf &md5buf, AvatarFileType avatarFil
|
|||||||
if (!o.fail())
|
if (!o.fail())
|
||||||
{
|
{
|
||||||
o.write((const char *)data, size);
|
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);
|
boost::mutex::scoped_lock lock(m_cachedAvatarsMutex);
|
||||||
m_cachedAvatars.insert(AvatarMap::value_type(md5buf, fileName));
|
m_cachedAvatars.insert(AvatarMap::value_type(md5buf, fileName));
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ ClientThread::CompleteTempAvatarData(unsigned playerId)
|
|||||||
LOG_ERROR("Client received invalid player id!");
|
LOG_ERROR("Client received invalid player id!");
|
||||||
else
|
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.");
|
LOG_ERROR("Failed to store avatar in cache directory.");
|
||||||
|
|
||||||
// Update player info, but never re-request avatar.
|
// Update player info, but never re-request avatar.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ DownloadHelper::~DownloadHelper()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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.
|
// Open target file for writing.
|
||||||
GetData()->targetFile = fopen(targetFileName.c_str(), "wb");
|
GetData()->targetFile = fopen(targetFileName.c_str(), "wb");
|
||||||
|
|||||||
@@ -611,7 +611,7 @@ ServerLobbyThread::HandleNetPacketAvatarEnd(SessionWrapper session, const NetPac
|
|||||||
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
|
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
|
||||||
if (avatarSize == tmpAvatar->reportedSize)
|
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());
|
session.playerData->SetAvatarMD5(MD5Buf());
|
||||||
LOG_ERROR("Failed to store avatar in cache directory.");
|
LOG_ERROR("Failed to store avatar in cache directory.");
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ TransferHelper::~TransferHelper()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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.
|
// Initialise curl.
|
||||||
m_data->curlHandle = curl_easy_init();
|
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)
|
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);
|
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.
|
// Use the multi interface for better abort handling.
|
||||||
if (curl_multi_add_handle(m_data->curlMultiHandle, m_data->curlHandle) != CURLM_OK)
|
if (curl_multi_add_handle(m_data->curlMultiHandle, m_data->curlHandle) != CURLM_OK)
|
||||||
@@ -157,3 +157,4 @@ TransferHelper::GetData()
|
|||||||
{
|
{
|
||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ UploaderThread::~UploaderThread()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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);
|
boost::mutex::scoped_lock lock(m_uploadQueueMutex);
|
||||||
m_uploadQueue.push(UploadData(filename, filesize));
|
m_uploadQueue.push(UploadData(url, user, pwd, filename, filesize));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -46,14 +46,8 @@ UploadHelper::~UploadHelper()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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.
|
||||||
// Open target file for writing.
|
// Open target file for writing.
|
||||||
GetData()->targetFile = fopen(targetFileName.c_str(), "rb");
|
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_USERPWD, GetData()->userCredentials.c_str());
|
||||||
curl_easy_setopt(GetData()->curlHandle, CURLOPT_UPLOAD, 1L);
|
curl_easy_setopt(GetData()->curlHandle, CURLOPT_UPLOAD, 1L);
|
||||||
curl_easy_setopt(GetData()->curlHandle, CURLOPT_PUT, 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:
|
protected:
|
||||||
virtual void InternalInit(const std::string &url, const std::string &targetFileName,
|
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
|
#endif
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public:
|
|||||||
// Set the parameters. Does not do any error checking.
|
// Set the parameters. Does not do any error checking.
|
||||||
// Throws an exception on failure.
|
// Throws an exception on failure.
|
||||||
void Init(const std::string &url, const std::string &targetFileName,
|
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.
|
// Returns true when done, false should call again.
|
||||||
// Throws an exception on error.
|
// Throws an exception on error.
|
||||||
@@ -49,7 +49,7 @@ protected:
|
|||||||
boost::shared_ptr<TransferData> GetData();
|
boost::shared_ptr<TransferData> GetData();
|
||||||
|
|
||||||
virtual void InternalInit(const std::string &url, const std::string &targetFileName,
|
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:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -36,14 +36,18 @@ public:
|
|||||||
UploaderThread();
|
UploaderThread();
|
||||||
virtual ~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:
|
protected:
|
||||||
struct UploadData
|
struct UploadData
|
||||||
{
|
{
|
||||||
UploadData() : filesize(0) {}
|
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;
|
std::string filename;
|
||||||
int filesize;
|
int filesize;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void InternalInit(const std::string &url, const std::string &targetFileName,
|
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
|
#endif
|
||||||
|
|||||||
+6
-1
@@ -59,7 +59,12 @@ Session::~Session()
|
|||||||
|
|
||||||
bool Session::init()
|
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(
|
bool retVal = myAvatarManager->Init(
|
||||||
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("AppDataDir")),
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("AppDataDir")),
|
||||||
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
|
||||||
|
|||||||
Reference in New Issue
Block a user