X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcore.cpp;h=9c41b560f27dd4d592337e75e1250716dfe900cb;hp=01b341c8f46d0645d51db70998eb226d1f817a3b;hb=70f360989331414e89072122a038d1675b7581b0;hpb=a0c839394a714783966a4282b30b4025fe9fa76e diff --git a/src/core/core.cpp b/src/core/core.cpp index 01b341c8..9c41b560 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -26,6 +26,7 @@ #include "core.h" #include "coresession.h" #include "coresettings.h" +#include "quassel.h" #include "signalproxy.h" #include "sqlitestorage.h" #include "network.h" @@ -49,7 +50,7 @@ void Core::destroy() { } Core::Core() : storage(0) { - _startTime = QDateTime::currentDateTime(); // for uptime :) + _startTime = QDateTime::currentDateTime().toUTC(); // for uptime :) // Register storage backends here! registerStorageBackend(new SqliteStorage(this)); @@ -87,7 +88,7 @@ void Core::init() { connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); - if(!startListening(cs.port())) exit(1); // TODO make this less brutal + if(!startListening()) exit(1); // TODO make this less brutal } Core::~Core() { @@ -341,22 +342,25 @@ QHash Core::bufferLastSeenMsgIds(UserId user) { /*** Network Management ***/ -bool Core::startListening(uint port) { +bool Core::startListening() { bool success = false; + uint port = Quassel::optionValue("port").toUInt(); if(_server.listen(QHostAddress::Any, port)) { - quInfo() << "Listening for GUI clients on IPv6 port" << _server.serverPort() << "using protocol version" << Global::protocolVersion; + quInfo() << "Listening for GUI clients on IPv6 port" << _server.serverPort() + << "using protocol version" << Quassel::buildInfo().protocolVersion; success = true; } if(_v6server.listen(QHostAddress::AnyIPv6, port)) { - quInfo() << "Listening for GUI clients on IPv4 port" << _v6server.serverPort() << "using protocol version" << Global::protocolVersion; + quInfo() << "Listening for GUI clients on IPv4 port" << _v6server.serverPort() + << "using protocol version" << Quassel::buildInfo().protocolVersion; success = true; } if(!success) { quError() << qPrintable(QString("Could not open GUI client port %1: %2").arg(port).arg(_server.errorString())); } - + return success; } @@ -374,7 +378,7 @@ void Core::incomingConnection() { connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); connect(socket, SIGNAL(readyRead()), this, SLOT(clientHasData())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError))); - + QVariantMap clientInfo; blocksizes.insert(socket, (quint32)0); quInfo() << qPrintable(tr("Client connected from")) << qPrintable(socket->peerAddress().toString()); @@ -410,31 +414,29 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) { QVariantMap reply; // Just version information -- check it! - uint ver = 0; - if(!msg.contains("ProtocolVersion") && msg["ClientBuild"].toUInt() >= 732) ver = 1; // FIXME legacy - if(msg.contains("ProtocolVersion")) ver = msg["ProtocolVersion"].toUInt(); - if(ver < Global::coreNeedsProtocol) { + uint ver = msg["ProtocolVersion"].toUInt(); + if(ver < Quassel::buildInfo().coreNeedsProtocol) { reply["MsgType"] = "ClientInitReject"; reply["Error"] = tr("Your Quassel Client is too old!
" "This core needs at least client/core protocol version %1.
" - "Please consider upgrading your client.").arg(Global::coreNeedsProtocol); + "Please consider upgrading your client.").arg(Quassel::buildInfo().coreNeedsProtocol); SignalProxy::writeDataToDevice(socket, reply); quWarning() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("too old, rejecting.")); socket->close(); return; } - reply["CoreVersion"] = Global::quasselVersion; - reply["CoreDate"] = Global::quasselBuildDate; - reply["CoreBuild"] = 860; // FIXME legacy - reply["ProtocolVersion"] = Global::protocolVersion; + reply["CoreVersion"] = Quassel::buildInfo().fancyVersionString; + reply["CoreDate"] = Quassel::buildInfo().buildDate; + reply["ProtocolVersion"] = Quassel::buildInfo().protocolVersion; // TODO: Make the core info configurable - int uptime = startTime().secsTo(QDateTime::currentDateTime()); + int uptime = startTime().secsTo(QDateTime::currentDateTime().toUTC()); int updays = uptime / 86400; uptime %= 86400; int uphours = uptime / 3600; uptime %= 3600; int upmins = uptime / 60; reply["CoreInfo"] = tr("Quassel Core Version %1
" "Built: %2
" - "Up %3d%4h%5m (since %6)").arg(Global::quasselVersion).arg(Global::quasselBuildDate) + "Up %3d%4h%5m (since %6)").arg(Quassel::buildInfo().fancyVersionString) + .arg(Quassel::buildInfo().buildDate) .arg(updays).arg(uphours,2,10,QChar('0')).arg(upmins,2,10,QChar('0')).arg(startTime().toString(Qt::TextDate)); #ifdef HAVE_SSL @@ -491,7 +493,7 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) { quDebug() << "Using compression for Client:" << qPrintable(socket->peerAddress().toString()); } #endif - + } else { // for the rest, we need an initialized connection if(!clientInfo.contains(socket)) { @@ -546,7 +548,7 @@ void Core::clientDisconnected() { // DO NOT CALL ANY METHODS ON socket!! socket = static_cast(sender()); - + QHash::iterator blockSizeIter = blocksizes.begin(); while(blockSizeIter != blocksizes.end()) { if(blockSizeIter.key() == socket) { @@ -590,6 +592,17 @@ void Core::setupClientSession(QTcpSocket *socket, UserId uid) { sess->addClient(socket); } +void Core::setupInternalClientSession(SignalProxy *proxy) { + UserId uid = 3; // FIXME!!!11 + // Find or create session for validated user + SessionThread *sess; + if(sessions.contains(uid)) + sess = sessions[uid]; + else + sess = createSession(uid); + sess->addClient(proxy); +} + SessionThread *Core::createSession(UserId uid, bool restore) { if(sessions.contains(uid)) { quWarning() << "Calling createSession() when a session for the user already exists!";