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
+123 -119
View File
@@ -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";
@@ -57,7 +57,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
#ifdef _WIN32
const char *appDataPath = getenv("AppData");
if (appDataPath && appDataPath[0] != 0) {
configFileName = appDataPath;
configFileName = appDataPath;
}
else {
const int MaxPathSize = 1024;
@@ -101,8 +101,8 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
mkdir(logDir.c_str());
mkdir(dataDir.c_str());
mkdir(cacheDir.c_str());
#else
//define app-dir
const char *homePath = getenv("HOME");
@@ -124,7 +124,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
mkdir(dataDir.c_str(), MODUS);
mkdir(cacheDir.c_str(), MODUS);
}
#endif
ostringstream tempIntToString;
@@ -141,9 +141,9 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
configList.push_back(ConfigInfo("ShowFlipCardsAnimation", CONFIG_TYPE_INT, "1"));
configList.push_back(ConfigInfo("ShowBlindButtons", CONFIG_TYPE_INT, "1"));
configList.push_back(ConfigInfo("ShowCardsChanceMonitor", CONFIG_TYPE_INT, "1"));
configList.push_back(ConfigInfo("AntiPeekMode", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("AlternateFKeysUserActionMode", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("EnableBetInputFocusSwitch", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("AntiPeekMode", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("AlternateFKeysUserActionMode", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("EnableBetInputFocusSwitch", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("FlipsideTux", CONFIG_TYPE_INT, "1"));
configList.push_back(ConfigInfo("FlipsideOwn", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("FlipsideOwnFile", CONFIG_TYPE_STRING, ""));
@@ -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"));
@@ -232,7 +236,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
configList.push_back(ConfigInfo("LogStoreDuration", CONFIG_TYPE_INT, "2"));
configList.push_back(ConfigInfo("LogInterval", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("UserDataDir", CONFIG_TYPE_STRING, dataDir));
configList.push_back(ConfigInfo("CacheDir", CONFIG_TYPE_STRING, cacheDir));
configList.push_back(ConfigInfo("CacheDir", CONFIG_TYPE_STRING, cacheDir));
configList.push_back(ConfigInfo("CLA_NoWriteAccess", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("DisableBackToLobbyWarning", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("DlgGameLobbyGameListSortingSection", CONFIG_TYPE_INT, "2"));
@@ -246,34 +250,34 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
if(!noWriteAccess) {
configFileName += "config.xml";
//Prüfen ob Configfile existiert --> sonst anlegen
TiXmlDocument doc(configFileName);
if(!doc.LoadFile()){
TiXmlDocument doc(configFileName);
if(!doc.LoadFile()){
myConfigState = NONEXISTING;
updateConfig(myConfigState);
updateConfig(myConfigState);
}
else {
else {
//Check if config revision and AppDataDir is ok. Otherwise --> update()
int tempRevision = 0;
string tempAppDataPath ("");
TiXmlHandle docHandle( &doc );
TiXmlHandle docHandle( &doc );
TiXmlElement* confRevision = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement();
if ( confRevision ) { confRevision->QueryIntAttribute("value", &tempRevision ); }
TiXmlElement* confAppDataPath = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "AppDataDir" ).ToElement();
if ( confAppDataPath ) {
if ( confAppDataPath ) {
const char *tmpStr = confAppDataPath->Attribute("value");
if (tmpStr) tempAppDataPath = tmpStr;
}
if (tempRevision < configRev || tempAppDataPath != myQtToolsInterface->getDataPathStdString(myArgv0) ) { /*löschen()*/
if (tempRevision < configRev || tempAppDataPath != myQtToolsInterface->getDataPathStdString(myArgv0) ) { /*löschen()*/
myConfigState = OLD;
updateConfig(myConfigState) ;
}
}
fillBuffer();
}
}
@@ -283,7 +287,7 @@ ConfigFile::~ConfigFile()
{
delete myQtToolsInterface;
myQtToolsInterface = 0;
}
@@ -295,15 +299,15 @@ void ConfigFile::fillBuffer() {
string tempString1("");
string tempString2("");
TiXmlDocument doc(configFileName);
TiXmlDocument doc(configFileName);
if(doc.LoadFile()) {
TiXmlHandle docHandle( &doc );
TiXmlHandle docHandle( &doc );
for (i=0; i<configBufferList.size(); i++) {
for (i=0; i<configBufferList.size(); i++) {
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).ToElement();
if ( conf ) {
const char *tmpStr1 = conf->Attribute("value");
@@ -312,25 +316,25 @@ void ConfigFile::fillBuffer() {
const char *tmpStr2 = conf->Attribute("type");
if (tmpStr2) {
tempString2 = tmpStr2;
tempString2 = tmpStr2;
if(tempString2 == "list") {
list<string> tempStringList2;
TiXmlElement* confList = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).FirstChild().ToElement();
for( ; confList; confList=confList->NextSiblingElement()) {
tempStringList2.push_back(confList->Attribute("value"));
}
configBufferList[i].defaultListValue = tempStringList2;
}
}
}
}
else { LOG_ERROR("Could not find the root element in the config file!"); }
// cout << configBufferList[i].name << " " << configBufferList[i].defaultValue << endl;
}
}
@@ -342,31 +346,31 @@ void ConfigFile::writeBuffer() const {
//write buffer to disc if enabled
if(!noWriteAccess) {
TiXmlDocument doc;
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "PokerTH" );
doc.LinkEndChild( root );
TiXmlDocument doc;
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "PokerTH" );
doc.LinkEndChild( root );
TiXmlElement * config;
config = new TiXmlElement( "Configuration" );
root->LinkEndChild( config );
config = new TiXmlElement( "Configuration" );
root->LinkEndChild( config );
size_t i;
for (i=0; i<configBufferList.size(); i++) {
TiXmlElement *tmpElement = new TiXmlElement(configBufferList[i].name);
config->LinkEndChild( tmpElement );
tmpElement->SetAttribute("value", configBufferList[i].defaultValue);
if(configBufferList[i].type == CONFIG_TYPE_INT_LIST) {
tmpElement->SetAttribute("type", "list");
list<string> tempList = configBufferList[i].defaultListValue;
list<string>::iterator it;
for(it = tempList.begin(); it != tempList.end(); it++) {
TiXmlElement *tmpSubElement = new TiXmlElement(configBufferList[i].defaultValue);
tmpElement->LinkEndChild( tmpSubElement );
tmpSubElement->SetAttribute("value", *it);
@@ -374,7 +378,7 @@ void ConfigFile::writeBuffer() const {
}
}
doc.SaveFile( configFileName );
}
}
@@ -384,20 +388,20 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
boost::recursive_mutex::scoped_lock lock(m_configMutex);
size_t i;
if(myConfigState == NONEXISTING) {
//Create a new ConfigFile!
TiXmlDocument doc;
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "PokerTH" );
doc.LinkEndChild( root );
TiXmlDocument doc;
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "PokerTH" );
doc.LinkEndChild( root );
TiXmlElement * config;
config = new TiXmlElement( "Configuration" );
root->LinkEndChild( config );
config = new TiXmlElement( "Configuration" );
root->LinkEndChild( config );
for (i=0; i<configList.size(); i++) {
TiXmlElement *tmpElement = new TiXmlElement(configList[i].name);
@@ -410,7 +414,7 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
list<string> tempList = configList[i].defaultListValue;
list<string>::iterator it;
for(it = tempList.begin(); it != tempList.end(); it++) {
TiXmlElement *tmpSubElement = new TiXmlElement(configList[i].defaultValue);
tmpElement->LinkEndChild( tmpSubElement );
tmpSubElement->SetAttribute("value", *it);
@@ -418,84 +422,84 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
}
}
doc.SaveFile( configFileName );
}
if(myConfigState == OLD) {
TiXmlDocument oldDoc(configFileName);
TiXmlDocument oldDoc(configFileName);
//load the old one
if(oldDoc.LoadFile()) {
string tempString1("");
string tempString2("");
TiXmlDocument newDoc;
//Create the new one
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
newDoc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "PokerTH" );
newDoc.LinkEndChild( root );
TiXmlElement * config;
config = new TiXmlElement( "Configuration" );
root->LinkEndChild( config );
//change configRev and AppDataPath
TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" );
string tempString1("");
string tempString2("");
TiXmlDocument newDoc;
//Create the new one
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
newDoc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "PokerTH" );
newDoc.LinkEndChild( root );
TiXmlElement * config;
config = new TiXmlElement( "Configuration" );
root->LinkEndChild( config );
//change configRev and AppDataPath
TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" );
config->LinkEndChild( confElement0 );
confElement0->SetAttribute("value", configRev);
TiXmlElement * confElement1 = new TiXmlElement( "AppDataDir" );
TiXmlElement * confElement1 = new TiXmlElement( "AppDataDir" );
config->LinkEndChild( confElement1 );
confElement1->SetAttribute("value", myQtToolsInterface->getDataPathStdString(myArgv0));
TiXmlHandle oldDocHandle( &oldDoc );
TiXmlHandle oldDocHandle( &oldDoc );
for (i=0; i<configList.size(); i++) {
for (i=0; i<configList.size(); i++) {
TiXmlElement* oldConf = oldDocHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).ToElement();
// //HACK remove after 0.6
// TiXmlElement* ISAIRCChannelUpdateDone = oldDocHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "InternetServerAddressIRCChannelUpdateDone" ).ToElement();
if ( oldConf /*&& (ISAIRCChannelUpdateDone || !(configList[i].name == "IRCChannel" || (configList[i].name == "InternetServerAddress" )))*/ /*HACK remove after 0.6*/ ) {
// if element is already there --> take over the saved values
if(configList[i].name != "ConfigRevision" && configList[i].name != "AppDataDir") {
// dont update ConfigRevision and AppDataDir becaus it was already set ^
TiXmlElement *tmpElement = new TiXmlElement(configList[i].name);
config->LinkEndChild( tmpElement );
const char *tmpStr1 = oldConf->Attribute("value");
if (tmpStr1) tempString1 = tmpStr1;
tmpElement->SetAttribute("value", tempString1);
//for lists copy elements
const char *tmpStr2 = oldConf->Attribute("type");
if (tmpStr2) {
tempString2 = tmpStr2;
tempString2 = tmpStr2;
if(tempString2 == "list") {
list<string> tempStringList2;
TiXmlElement* oldConfList = oldDocHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).FirstChild().ToElement();
for( ; oldConfList; oldConfList=oldConfList->NextSiblingElement()) {
tempStringList2.push_back(oldConfList->Attribute("value"));
}
tmpElement->SetAttribute("type", "list");
list<string> tempList = tempStringList2;
list<string>::iterator it;
for(it = tempList.begin(); it != tempList.end(); it++) {
TiXmlElement *tmpSubElement = new TiXmlElement(tempString1);
tmpElement->LinkEndChild( tmpSubElement );
tmpSubElement->SetAttribute("value", *it);
@@ -509,26 +513,26 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
TiXmlElement *tmpElement = new TiXmlElement(configList[i].name);
config->LinkEndChild( tmpElement );
tmpElement->SetAttribute("value", myQtToolsInterface->stringToUtf8(configList[i].defaultValue));
if(configList[i].type == CONFIG_TYPE_INT_LIST) {
tmpElement->SetAttribute("type", "list");
list<string> tempList = configList[i].defaultListValue;
list<string>::iterator it;
for(it = tempList.begin(); it != tempList.end(); it++) {
TiXmlElement *tmpSubElement = new TiXmlElement(configList[i].defaultValue);
tmpElement->LinkEndChild( tmpSubElement );
tmpSubElement->SetAttribute("value", *it);
}
}
}
}
}
newDoc.SaveFile( configFileName );
}
else { LOG_ERROR("Cannot update config file: Unable to load configuration."); }
}
}
@@ -539,10 +543,10 @@ string ConfigFile::readConfigString(string varName) const
size_t i;
string tempString("");
for (i=0; i<configBufferList.size(); i++) {
for (i=0; i<configBufferList.size(); i++) {
if (configBufferList[i].name == varName) {
tempString = configBufferList[i].defaultValue;
tempString = configBufferList[i].defaultValue;
}
}
@@ -557,17 +561,17 @@ int ConfigFile::readConfigInt(string varName) const
string tempString("");
int tempInt=0;
for (i=0; i<configBufferList.size(); i++) {
for (i=0; i<configBufferList.size(); i++) {
if (configBufferList[i].name == varName) {
tempString = configBufferList[i].defaultValue;
}
}
istringstream isst;
isst.str (tempString);
isst >> tempInt;
return tempInt;
}
@@ -579,19 +583,19 @@ list<int> ConfigFile::readConfigIntList(string varName) const
list<string> tempStringList;
list<int> tempIntList;
for (i=0; i<configBufferList.size(); i++) {
for (i=0; i<configBufferList.size(); i++) {
if (configBufferList[i].name == varName) {
tempStringList = configBufferList[i].defaultListValue;
}
}
istringstream isst;
string tempString;
int tempInt;
list<string>::iterator it;
for(it = tempStringList.begin(); it != tempStringList.end(); it++) {
isst.str(*it);
isst >> tempInt;
tempIntList.push_back(tempInt);
@@ -611,11 +615,11 @@ void ConfigFile::writeConfigInt(string varName, int varCont)
string tempString;
ostringstream intToString;
for (i=0; i<configBufferList.size(); i++) {
for (i=0; i<configBufferList.size(); i++) {
if (configBufferList[i].name == varName) {
intToString << varCont;
configBufferList[i].defaultValue = intToString.str();
configBufferList[i].defaultValue = intToString.str();
}
}
}
@@ -629,20 +633,20 @@ void ConfigFile::writeConfigIntList(string varName, list<int> varCont)
ostringstream intToString;
list<string> stringList;
for (i=0; i<configBufferList.size(); i++) {
for (i=0; i<configBufferList.size(); i++) {
if (configBufferList[i].name == varName) {
string tempString;
list<int>::iterator it;
for(it = varCont.begin(); it != varCont.end(); it++) {
intToString << (*it);
intToString << (*it);
stringList.push_back(intToString.str());
intToString.str("");
intToString.clear();
}
configBufferList[i].defaultListValue = stringList;
configBufferList[i].defaultListValue = stringList;
}
}
}
@@ -653,7 +657,7 @@ void ConfigFile::writeConfigString(string varName, string varCont)
boost::recursive_mutex::scoped_lock lock(m_configMutex);
size_t i;
for (i=0; i<configBufferList.size(); i++) {
for (i=0; i<configBufferList.size(); i++) {
if (configBufferList[i].name == varName) { configBufferList[i].defaultValue = varCont; }
}
+8 -2
View File
@@ -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;
};
+11 -4
View File
@@ -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));
+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
+7 -2
View File
@@ -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")));
@@ -90,7 +95,7 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat
PlayerDataList playerDataList;
for(int i = 0; i < startData.numberOfPlayers; i++) {
//Namen und Avatarpfad abfragen
//Namen und Avatarpfad abfragen
ostringstream myName;
if (i==0) { myName << "MyName"; }
else { myName << "Opponent" << i << "Name"; }