mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-10 01:09:34 +00:00
Merge with develop
This commit is contained in:
parent
0c63da38f1
commit
54c7e89e05
2 changed files with 63 additions and 42 deletions
|
@ -109,7 +109,7 @@ CMySQLResult::CMySQLResult(MYSQL_RES* res)
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
CMySQLResult::CMySQLResult(MYSQL* database)
|
CMySQLResult::CMySQLResult(MYSQL* database)
|
||||||
{
|
{
|
||||||
_Result = mysql_store_result(database);
|
_Result = mysql_store_result(database);
|
||||||
}
|
}
|
||||||
/// Destructor
|
/// Destructor
|
||||||
|
@ -174,7 +174,7 @@ MYSQL_ROW CMySQLResult::fetchRow()
|
||||||
/* ***************************************************************************
|
/* ***************************************************************************
|
||||||
Doc :
|
Doc :
|
||||||
|
|
||||||
When an entity is added in the service mirror, the service checks if its name is in the name cache. If
|
When an entity is added in the service mirror, the service checks if its name is in the name cache. If
|
||||||
the string ID is not known, the server ask the IOS for the string.
|
the string ID is not known, the server ask the IOS for the string.
|
||||||
|
|
||||||
When the IOS sends back a string, the server broadcasts this string to the connected clients.
|
When the IOS sends back a string, the server broadcasts this string to the connected clients.
|
||||||
|
@ -275,7 +275,7 @@ void clientWantsToConnect ( TSockId from, void *arg )
|
||||||
nlinfo ("Add client %d", Clients.size());
|
nlinfo ("Add client %d", Clients.size());
|
||||||
Clients.push_back (new CMonitorClient(from));
|
Clients.push_back (new CMonitorClient(from));
|
||||||
|
|
||||||
|
|
||||||
CMonitorService &ms = getMonitorService();
|
CMonitorService &ms = getMonitorService();
|
||||||
|
|
||||||
// send params about this sever the client
|
// send params about this sever the client
|
||||||
|
@ -284,7 +284,7 @@ void clientWantsToConnect ( TSockId from, void *arg )
|
||||||
uint32 version = 0;
|
uint32 version = 0;
|
||||||
msgout.serial(version);
|
msgout.serial(version);
|
||||||
msgout.serial(ms.LoginRequired);
|
msgout.serial(ms.LoginRequired);
|
||||||
Server->send(msgout, from);
|
Server->send(msgout, from);
|
||||||
Clients.back()->Authentificated = !ms.LoginRequired;
|
Clients.back()->Authentificated = !ms.LoginRequired;
|
||||||
|
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ void clientSetWindow (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
|
||||||
for (uint i = 0; i < Clients.size(); ++i)
|
for (uint i = 0; i < Clients.size(); ++i)
|
||||||
{
|
{
|
||||||
if (Clients[i]->getSock() == from && Clients[i]->Authentificated)
|
if (Clients[i]->getSock() == from && Clients[i]->Authentificated)
|
||||||
{
|
{
|
||||||
nlinfo ("Client %d sets window (%.0f,%.0f) (%.0f,%.0f)", i, xmin, ymin, xmax, ymax);
|
nlinfo ("Client %d sets window (%.0f,%.0f) (%.0f,%.0f)", i, xmin, ymin, xmax, ymax);
|
||||||
Clients[i]->setWindow(xmin,ymin,xmax,ymax);
|
Clients[i]->setWindow(xmin,ymin,xmax,ymax);
|
||||||
Clients[i]->resetVision();
|
Clients[i]->resetVision();
|
||||||
|
@ -377,17 +377,21 @@ void clientAuthentication(CMessage &msgin, TSockId from, CCallbackNetBase &netba
|
||||||
{
|
{
|
||||||
if (!Clients[i]->Authentificated && Clients[i]->getSock() == from)
|
if (!Clients[i]->Authentificated && Clients[i]->getSock() == from)
|
||||||
{
|
{
|
||||||
if (!Clients[i]->BadLogin) // don't allow new login attempt while thisflag is set
|
if (!Clients[i]->BadLogin) // don't allow new login attempt while this flag is set
|
||||||
{
|
{
|
||||||
|
// escape login
|
||||||
|
char esccapedLogin[100];
|
||||||
|
size_t len = mysql_real_escape_string(DatabaseConnection, esccapedLogin, login.c_str(), login.length());
|
||||||
|
|
||||||
// make a db request to to db to see if password is valid
|
// make a db request to to db to see if password is valid
|
||||||
std::string queryStr = toString("SELECT Password FROM user where Login='%s'", login.c_str());
|
std::string queryStr = toString("SELECT Password FROM user where Login='%s'", esccapedLogin);
|
||||||
int result = mysql_query(DatabaseConnection, queryStr.c_str());
|
int result = mysql_query(DatabaseConnection, queryStr.c_str());
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
CMySQLResult sqlResult(DatabaseConnection);
|
CMySQLResult sqlResult(DatabaseConnection);
|
||||||
if (sqlResult.success() && sqlResult.numRows() == 1)
|
if (sqlResult.success() && sqlResult.numRows() == 1)
|
||||||
{
|
{
|
||||||
MYSQL_ROW row = sqlResult.fetchRow();
|
MYSQL_ROW row = sqlResult.fetchRow();
|
||||||
if (sqlResult.numFields() == 1)
|
if (sqlResult.numFields() == 1)
|
||||||
{
|
{
|
||||||
if (strlen(row[0]) > 2)
|
if (strlen(row[0]) > 2)
|
||||||
|
@ -407,19 +411,19 @@ void clientAuthentication(CMessage &msgin, TSockId from, CCallbackNetBase &netba
|
||||||
Clients[i]->Authentificated = true;
|
Clients[i]->Authentificated = true;
|
||||||
// password is good
|
// password is good
|
||||||
CMessage msgout;
|
CMessage msgout;
|
||||||
msgout.setType("AUTHENT_VALID");
|
msgout.setType("AUTHENT_VALID");
|
||||||
Server->send(msgout, from);
|
Server->send(msgout, from);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fail the authentication
|
// fail the authentication
|
||||||
// Do not send result immediatly to avoid a potential hacker
|
// Do not send result immediatly to avoid a potential hacker
|
||||||
// to try a dictionnary or that dort of things
|
// to try a dictionnary or that dort of things
|
||||||
BadLoginClients.insert(std::pair<NLMISC::TTime, NLMISC::CRefPtr<CMonitorClient> >(
|
BadLoginClients.insert(std::pair<NLMISC::TTime, NLMISC::CRefPtr<CMonitorClient> >(
|
||||||
NLMISC::CTime::getLocalTime() + LOGIN_RETRY_DELAY_IN_MILLISECONDS,
|
NLMISC::CTime::getLocalTime() + LOGIN_RETRY_DELAY_IN_MILLISECONDS,
|
||||||
(NLMISC::CRefPtr<CMonitorClient>)Clients[i]));
|
(NLMISC::CRefPtr<CMonitorClient>)Clients[i]));
|
||||||
Clients[i]->BadLogin =true;
|
Clients[i]->BadLogin =true;
|
||||||
return;
|
return;
|
||||||
|
@ -527,9 +531,9 @@ void CMonitorService::init ()
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
||||||
void CMonitorService::release ()
|
void CMonitorService::release ()
|
||||||
{
|
{
|
||||||
disconnectFromDatabase();
|
disconnectFromDatabase();
|
||||||
// release sub systems
|
// release sub systems
|
||||||
// CMessages::release();
|
// CMessages::release();
|
||||||
CMirrors::release();
|
CMirrors::release();
|
||||||
|
@ -568,7 +572,7 @@ bool CMonitorService::update ()
|
||||||
client.update();
|
client.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sent bad login msg to clients at the right time
|
// Sent bad login msg to clients at the right time
|
||||||
NLMISC::TTime currentTime = NLMISC::CTime::getLocalTime();
|
NLMISC::TTime currentTime = NLMISC::CTime::getLocalTime();
|
||||||
while (!BadLoginClients.empty() && BadLoginClients.begin()->first <= currentTime)
|
while (!BadLoginClients.empty() && BadLoginClients.begin()->first <= currentTime)
|
||||||
|
@ -577,9 +581,9 @@ bool CMonitorService::update ()
|
||||||
if (client != NULL)
|
if (client != NULL)
|
||||||
{
|
{
|
||||||
CMessage msgout;
|
CMessage msgout;
|
||||||
msgout.setType("AUTHENT_INVALID");
|
msgout.setType("AUTHENT_INVALID");
|
||||||
Server->send(msgout, client->getSock());
|
Server->send(msgout, client->getSock());
|
||||||
client->BadLogin = false; // allow to accept login again for that client
|
client->BadLogin = false; // allow to accept login again for that client
|
||||||
}
|
}
|
||||||
BadLoginClients.erase(BadLoginClients.begin());
|
BadLoginClients.erase(BadLoginClients.begin());
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,28 +408,53 @@ bool CFilesExtractor::extract7z()
|
||||||
QString path = QString::fromUtf16(temp);
|
QString path = QString::fromUtf16(temp);
|
||||||
QString filename = QFileInfo(path).fileName();
|
QString filename = QFileInfo(path).fileName();
|
||||||
|
|
||||||
if (!isDir)
|
|
||||||
{
|
|
||||||
if (m_listener) m_listener->operationProgress(totalUncompressed, filename);
|
|
||||||
|
|
||||||
res = SzArEx_Extract(&db, &lookStream.s, i, &blockIndex, &outBuffer, &outBufferSize,
|
|
||||||
&offset, &outSizeProcessed, &allocImp, &allocTempImp);
|
|
||||||
|
|
||||||
if (res != SZ_OK) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString destPath = m_destinationDirectory + '/' + path;
|
QString destPath = m_destinationDirectory + '/' + path;
|
||||||
|
|
||||||
QDir dir;
|
// get uncompressed size
|
||||||
|
quint64 uncompressedSize = SzArEx_GetFileSize(&db, i);
|
||||||
|
|
||||||
|
// get modification time
|
||||||
|
quint32 modificationTime = 0;
|
||||||
|
|
||||||
|
if (SzBitWithVals_Check(&db.MTime, i))
|
||||||
|
{
|
||||||
|
modificationTime = convertWindowsFileTimeToUnixTimestamp(db.MTime.Vals[i]);
|
||||||
|
}
|
||||||
|
|
||||||
if (isDir)
|
if (isDir)
|
||||||
{
|
{
|
||||||
dir.mkpath(destPath);
|
QDir().mkpath(destPath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir.mkpath(QFileInfo(destPath).absolutePath());
|
// check if file exists
|
||||||
|
if (QFile::exists(destPath))
|
||||||
|
{
|
||||||
|
QFileInfo currentFileInfo(destPath);
|
||||||
|
|
||||||
|
// skip file if same size and same modification date
|
||||||
|
if (currentFileInfo.lastModified().toTime_t() == modificationTime && currentFileInfo.size() == uncompressedSize)
|
||||||
|
{
|
||||||
|
// update progress
|
||||||
|
totalUncompressed += uncompressedSize;
|
||||||
|
|
||||||
|
if (m_listener) m_listener->operationProgress(totalUncompressed, filename);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_listener) m_listener->operationProgress(totalUncompressed, filename);
|
||||||
|
|
||||||
|
res = SzArEx_Extract(&db, &lookStream.s, i, &blockIndex, &outBuffer, &outBufferSize,
|
||||||
|
&offset, &outSizeProcessed, &allocImp, &allocTempImp);
|
||||||
|
|
||||||
|
if (res != SZ_OK) break;
|
||||||
|
|
||||||
|
// create file directory
|
||||||
|
QDir().mkpath(QFileInfo(destPath).absolutePath());
|
||||||
|
|
||||||
|
// create file
|
||||||
QFile outFile(destPath);
|
QFile outFile(destPath);
|
||||||
|
|
||||||
if (!outFile.open(QFile::WriteOnly))
|
if (!outFile.open(QFile::WriteOnly))
|
||||||
|
@ -446,10 +471,7 @@ bool CFilesExtractor::extract7z()
|
||||||
qint64 currentProcessedSize = outFile.write((const char*)(outBuffer + offset), currentSizeToProcess);
|
qint64 currentProcessedSize = outFile.write((const char*)(outBuffer + offset), currentSizeToProcess);
|
||||||
|
|
||||||
// errors only occur when returned size is -1
|
// errors only occur when returned size is -1
|
||||||
if (currentProcessedSize < 0)
|
if (currentProcessedSize < 0) break;
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += currentProcessedSize;
|
offset += currentProcessedSize;
|
||||||
currentSizeToProcess -= currentProcessedSize;
|
currentSizeToProcess -= currentProcessedSize;
|
||||||
|
@ -465,25 +487,20 @@ bool CFilesExtractor::extract7z()
|
||||||
|
|
||||||
outFile.close();
|
outFile.close();
|
||||||
|
|
||||||
totalUncompressed += SzArEx_GetFileSize(&db, i);
|
totalUncompressed += uncompressedSize;
|
||||||
|
|
||||||
if (m_listener) m_listener->operationProgress(totalUncompressed, filename);
|
if (m_listener) m_listener->operationProgress(totalUncompressed, filename);
|
||||||
|
|
||||||
// set attrinbutes
|
// set attributes
|
||||||
if (SzBitWithVals_Check(&db.Attribs, i))
|
if (SzBitWithVals_Check(&db.Attribs, i))
|
||||||
{
|
{
|
||||||
Set7zFileAttrib(destPath, db.Attribs.Vals[i]);
|
Set7zFileAttrib(destPath, db.Attribs.Vals[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set modification time
|
// set modification time
|
||||||
if (SzBitWithVals_Check(&db.MTime, i))
|
if (!NLMISC::CFile::setFileModificationDate(qToUtf8(destPath), modificationTime))
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
qDebug() << "Unable to change date of " << destPath;
|
||||||
|
|
||||||
if (!NLMISC::CFile::setFileModificationDate(qToUtf8(destPath), convertWindowsFileTimeToUnixTimestamp(db.MTime.Vals[i])))
|
|
||||||
{
|
|
||||||
qDebug() << "Unable to change date of " << destPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue