diff options
-rw-r--r-- | src/Message.cpp | 18 | ||||
-rw-r--r-- | src/Message.h | 16 | ||||
-rw-r--r-- | src/murmur/Messages.cpp | 11 | ||||
-rw-r--r-- | src/murmur/Meta.cpp | 12 | ||||
-rw-r--r-- | src/murmur/Meta.h | 2 | ||||
-rw-r--r-- | src/murmur/Server.cpp | 26 | ||||
-rw-r--r-- | src/murmur/Server.h | 3 |
7 files changed, 84 insertions, 4 deletions
diff --git a/src/Message.cpp b/src/Message.cpp index 5a935abad..f0b985175 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -169,6 +169,9 @@ Message *Message::networkToMessage(PacketDataStream &qdsIn) { case ContextAddAction: mMsg = new MessageContextAddAction(); break; + case Resource: + mMsg = new MessageResource(); + break; default: qWarning("Message: Type %d (session %d, size %d) is unknown type", iMessageType, uiSession, qdsIn.capacity()); } @@ -285,6 +288,9 @@ void MessageHandler::dispatch(Connection *cCon, Message *msg) { case Message::ContextAddAction: msgContextAddAction(cCon, static_cast<MessageContextAddAction *>(msg)); break; + case Message::Resource: + msgResource(cCon, static_cast<MessageResource *>(msg)); + break; default: qFatal("MessageHandler called with unknown message type %d", msg->messageType()); } @@ -646,6 +652,18 @@ bool MessageContextAction::isValid() const { return (! qsAction.isEmpty()); } +void MessageResource::saveStream(PacketDataStream &qdsOut) const { + qdsOut << qbaResourceData; +} + +void MessageResource::restoreStream(PacketDataStream &qdsIn) { + qdsIn >> qbaResourceData; +} + +bool MessageResource::isValid() const { + return (! qbaResourceData.isEmpty()); +} + PacketDataStream & operator<< (PacketDataStream & out, const MessageEditACL::GroupStruct &gs) { out << gs.qsName; out << gs.bInherited; diff --git a/src/Message.h b/src/Message.h index 1d0908643..704dc5ca9 100644 --- a/src/Message.h +++ b/src/Message.h @@ -43,7 +43,7 @@ class Message { virtual void saveStream(PacketDataStream &) const; virtual void restoreStream(PacketDataStream &); public: - enum MessageType { ServerReject, ServerAuthenticate, Speex, ServerSync, ServerJoin, ServerLeave, ServerBanList, PlayerMute, PlayerDeaf, PlayerKick, PlayerRename, PlayerBan, PlayerMove, PlayerSelfMuteDeaf, ChannelAdd, ChannelRemove, ChannelMove, ChannelLink, ChannelRename, PermissionDenied, EditACL, QueryUsers, Ping, TextMessage, PlayerTexture, CryptSetup, CryptSync, PingStats, ContextAction, ContextAddAction }; + enum MessageType { ServerReject, ServerAuthenticate, Speex, ServerSync, ServerJoin, ServerLeave, ServerBanList, PlayerMute, PlayerDeaf, PlayerKick, PlayerRename, PlayerBan, PlayerMove, PlayerSelfMuteDeaf, ChannelAdd, ChannelRemove, ChannelMove, ChannelLink, ChannelRename, PermissionDenied, EditACL, QueryUsers, Ping, TextMessage, PlayerTexture, CryptSetup, CryptSync, PingStats, ContextAction, ContextAddAction, Resource }; unsigned int uiSession; Message(); @@ -464,6 +464,18 @@ class MessageContextAction : public Message { bool isValid() const; }; +class MessageResource : public Message { + protected: + void saveStream(PacketDataStream &) const; + void restoreStream(PacketDataStream &); + public: + QByteArray qbaResourceData; + Message::MessageType messageType() const { + return Resource; + } + bool isValid() const; +}; + class MessageHandler { protected: virtual void msgSpeex(Connection *, MessageSpeex *) = 0; @@ -496,12 +508,12 @@ class MessageHandler { virtual void msgCryptSync(Connection *, MessageCryptSync *) = 0; virtual void msgContextAddAction(Connection *, MessageContextAddAction *) = 0; virtual void msgContextAction(Connection *, MessageContextAction *) = 0; + virtual void msgResource(Connection *, MessageResource *) = 0; void dispatch(Connection *, Message *); public: virtual ~MessageHandler() { }; }; - #else class Message; #endif diff --git a/src/murmur/Messages.cpp b/src/murmur/Messages.cpp index ed9264cbf..dac801741 100644 --- a/src/murmur/Messages.cpp +++ b/src/murmur/Messages.cpp @@ -243,6 +243,13 @@ void Server::msgServerAuthenticate(Connection *cCon, MessageServerAuthenticate * sendMessage(cCon, &mpm); } + if (! qbaResource.isEmpty()) { + MessageResource mr; + mr.uiSession = uSource->uiSession; + mr.qbaResourceData = qbaResource; + sendMessage(cCon, &mr); + } + MessageServerSync mssMsg; mssMsg.uiSession = uSource->uiSession; mssMsg.qsWelcomeText = qsWelcomeText; @@ -941,3 +948,7 @@ void Server::msgContextAction(Connection *cCon, MessageContextAction *msg) { return; emit contextAction(uSource, msg->qsAction, msg->uiVictim, msg->iChannel); } + +void Server::msgResource(Connection *cCon, MessageResource *) { + cCon->disconnectSocket(); +} diff --git a/src/murmur/Meta.cpp b/src/murmur/Meta.cpp index 1e5c2d9d8..7d5dfdd57 100644 --- a/src/murmur/Meta.cpp +++ b/src/murmur/Meta.cpp @@ -176,6 +176,17 @@ void MetaParams::read(QString fname) { iObfuscate = qrand(); } + QString qsResource = qs.value("resourcefile").toString(); + if (! qsResource.isEmpty()) { + QFile qfRes(qsResource); + if (qfRes.open(QIODevice::ReadOnly)) { + qbaResource = qfRes.readAll(); + qfRes.close(); + } else { + qCritical("Failed to read resource file %s", qPrintable(qsResource)); + } + } + QString qsSSLCert = qs.value("sslCert").toString(); QString qsSSLKey = qs.value("sslKey").toString(); @@ -260,6 +271,7 @@ void MetaParams::read(QString fname) { qmConfig.insert(QLatin1String("obfuscate"),bObfuscate ? QLatin1String("true") : QLatin1String("false")); qmConfig.insert(QLatin1String("playername"),qrPlayerName.pattern()); qmConfig.insert(QLatin1String("channelname"),qrChannelName.pattern()); + qmConfig.insert(QLatin1String("resourcefile"),qsResource); } Meta::Meta() { diff --git a/src/murmur/Meta.h b/src/murmur/Meta.h index 7e3451573..e0a9fba1c 100644 --- a/src/murmur/Meta.h +++ b/src/murmur/Meta.h @@ -82,6 +82,8 @@ struct MetaParams { QSslCertificate qscCert; QSslKey qskKey; QByteArray qbaPassPhrase; + + QByteArray qbaResource; QMap<QString, QString> qmConfig; diff --git a/src/murmur/Server.cpp b/src/murmur/Server.cpp index eed3c4cb5..070bc2c2e 100644 --- a/src/murmur/Server.cpp +++ b/src/murmur/Server.cpp @@ -230,6 +230,28 @@ void Server::readParams() { qrPlayerName=QRegExp(getConf("playername", qrPlayerName.pattern()).toString()); qrChannelName=QRegExp(getConf("channelname", qrChannelName.pattern()).toString()); + + qbaResource = Meta::mp.qbaResource; + QString qsResource = getConf("resourcefile", QString()).toString(); + if (! qsResource.isEmpty()) { + QFile qfRes(qsResource); + if (qfRes.open(QIODevice::ReadOnly)) { + qbaResource = qfRes.readAll(); + qfRes.close(); + } else { + log("Failed to read resource file %s", qPrintable(qsResource)); + } + } + + if (! qbaResource.isEmpty()) { + if (QResource::registerResource(reinterpret_cast<const unsigned char *>(qbaResource.constData()), QString::fromLatin1("/%1").arg(iServerNum))) { + QResource::unregisterResource(reinterpret_cast<const unsigned char *>(qbaResource.constData()), QString::fromLatin1("/%1").arg(iServerNum)); + log("Resources loaded"); + } else { + log("Invalid resource data"); + qbaResource = QByteArray(); + } + } } void Server::setLiveConf(const QString &key, const QString &value) { @@ -643,7 +665,7 @@ void Server::connectionClosed(QString reason) { emit playerDisconnected(u); } - + { QWriteLocker wl(&qrwlUsers); @@ -663,7 +685,7 @@ void Server::connectionClosed(QString reason) { clearACLCache(u); u->deleteLater(); - + if (qhUsers.isEmpty()) stopThread(); } diff --git a/src/murmur/Server.h b/src/murmur/Server.h index 95add4292..b5aac5b77 100644 --- a/src/murmur/Server.h +++ b/src/murmur/Server.h @@ -132,6 +132,8 @@ class Server : public QThread, public MessageHandler { QSslCertificate qscCert; QSslKey qskKey; QByteArray qbaPassPhrase; + + QByteArray qbaResource; bool bValid; @@ -321,6 +323,7 @@ class Server : public QThread, public MessageHandler { virtual void msgCryptSync(Connection *, MessageCryptSync *); virtual void msgContextAddAction(Connection *, MessageContextAddAction *); virtual void msgContextAction(Connection *, MessageContextAction *); + virtual void msgResource(Connection *, MessageResource *); }; |