diff options
author | Thorvald Natvig <slicer@users.sourceforge.net> | 2007-05-24 13:36:57 +0400 |
---|---|---|
committer | Thorvald Natvig <slicer@users.sourceforge.net> | 2007-05-24 13:36:57 +0400 |
commit | e81c5229030c450077832b63252e35ee47e8a838 (patch) | |
tree | c0c040000b7bd475ef88e0cc984b2ede91a0cd86 /src/Message.h | |
parent | 3be4aec86a167f6faa262a2baf3a32a912046e5f (diff) |
Refactoring
git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@444 05730e5d-ab1b-0410-a4ac-84af385074fa
Diffstat (limited to 'src/Message.h')
-rw-r--r-- | src/Message.h | 361 |
1 files changed, 361 insertions, 0 deletions
diff --git a/src/Message.h b/src/Message.h new file mode 100644 index 000000000..859b9e26b --- /dev/null +++ b/src/Message.h @@ -0,0 +1,361 @@ +/* Copyright (C) 2005-2006, Thorvald Natvig <thorvald@natvig.com> + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + - Neither the name of the Mumble Developers nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _MESSAGE_H +#define _MESSAGE_H + +#define MESSAGE_STREAM_VERSION 8 + +#include "ACL.h" + +class Connection; + +class Message { + protected: + virtual void saveStream(QDataStream &) const; + virtual void restoreStream(QDataStream &); + public: + enum MessageType { Speex, MultiSpeex, ServerAuthenticate, ServerReject, ServerSync, ServerJoin, ServerLeave, ServerBanList, PlayerMute, PlayerDeaf, PlayerKick, PlayerRename, PlayerBan, PlayerMove, PlayerSelfMuteDeaf, ChannelAdd, ChannelRemove, ChannelMove, ChannelLink, PermissionDenied, EditACL, QueryUsers, Ping}; + unsigned short sPlayerId; + + Message(); + virtual ~Message(); + virtual Message::MessageType messageType() const = 0; + virtual void process(Connection *) = 0; + virtual bool isValid() const; + + void messageToNetwork(QByteArray &) const; + static Message *networkToMessage(QByteArray &); +}; + +class MessageSpeex : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + unsigned short iSeq; + QByteArray qbaSpeexPacket; + unsigned char ucFlags; + MessageSpeex(); + Message::MessageType messageType() const { return Speex; }; + void process(Connection *); + bool isValid() const; +}; + +class MessageMultiSpeex : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + unsigned short iSeq; + unsigned char ucFlags; + QList<QByteArray> qlFrames; + MessageMultiSpeex(); + Message::MessageType messageType() const { return MultiSpeex; }; + void process(Connection *); +}; + + +class MessageServerAuthenticate : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + int iVersion; + int iMaxBandwidth; + QString qsUsername; + QString qsPassword; + MessageServerAuthenticate(); + Message::MessageType messageType() const { return ServerAuthenticate; }; + void process(Connection *); +}; + +class MessagePing : public Message { + public: + MessagePing(); + Message::MessageType messageType() const { return Ping; }; + void process(Connection *); +}; + +class MessageServerReject : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + QString qsReason; + MessageServerReject(); + Message::MessageType messageType() const { return ServerReject; }; + void process(Connection *); +}; + +class MessageServerSync : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + int iMaxBandwidth; + QString qsWelcomeText; + MessageServerSync(); + Message::MessageType messageType() const { return ServerSync; }; + void process(Connection *); +}; + +class MessageServerJoin : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + QString qsPlayerName; + int iId; + MessageServerJoin(); + Message::MessageType messageType() const { return ServerJoin; }; + void process(Connection *); +}; + +class MessageServerLeave : public Message { + public: + Message::MessageType messageType() const { return ServerLeave; }; + void process(Connection *); +}; + +class MessagePlayerMute : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + short sVictim; + bool bMute; + MessagePlayerMute(); + Message::MessageType messageType() const { return PlayerMute; }; + void process(Connection *); +}; + +class MessagePlayerDeaf : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + short sVictim; + bool bDeaf; + MessagePlayerDeaf(); + Message::MessageType messageType() const { return PlayerDeaf; }; + void process(Connection *); +}; + +class MessagePlayerSelfMuteDeaf : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + bool bMute; + bool bDeaf; + MessagePlayerSelfMuteDeaf(); + Message::MessageType messageType() const { return PlayerSelfMuteDeaf; }; + void process(Connection *); +}; + +class MessagePlayerKick : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + short sVictim; + QString qsReason; + MessagePlayerKick(); + Message::MessageType messageType() const { return PlayerKick; }; + void process(Connection *); +}; + +class MessagePlayerBan : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + short sVictim; + QString qsReason; + MessagePlayerBan(); + Message::MessageType messageType() const { return PlayerBan; }; + void process(Connection *); +}; + +class MessagePlayerMove : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + short sVictim; + int iChannelId; + MessagePlayerMove(); + Message::MessageType messageType() const { return PlayerMove; }; + void process(Connection *); +}; + +class MessagePlayerRename : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + QString qsName; + MessagePlayerRename(); + Message::MessageType messageType() const { return PlayerRename; }; + void process(Connection *); +}; + +class MessageChannelAdd : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + int iId; + int iParent; + QString qsName; + MessageChannelAdd(); + Message::MessageType messageType() const { return ChannelAdd; }; + void process(Connection *); +}; + +class MessageChannelRemove : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + int iId; + MessageChannelRemove(); + Message::MessageType messageType() const { return ChannelRemove; }; + void process(Connection *); +}; + +class MessageChannelMove : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + int iId; + int iParent; + MessageChannelMove(); + Message::MessageType messageType() const { return ChannelMove; }; + void process(Connection *); +}; + +class MessageChannelLink : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + enum LinkType { + Link, Unlink, UnlinkAll, PushLink, PushUnlink + }; + int iId; + LinkType ltType; + QList<int> qlTargets; + MessageChannelLink(); + Message::MessageType messageType() const { return ChannelLink; }; + void process(Connection *); +}; + +class MessageServerBanList : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + bool bQuery; + QList<QPair<quint32, int> > qlBans; + MessageServerBanList(); + Message::MessageType messageType() const { return ServerBanList; }; + void process(Connection *); +}; + +class MessagePermissionDenied : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + QString qsReason; + MessagePermissionDenied(); + Message::MessageType messageType() const { return PermissionDenied; }; + void process(Connection *); +}; + +class MessageEditACL : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + struct GroupStruct { + QString qsName; + bool bInherited; + bool bInherit; + bool bInheritable; + QSet<int> qsAdd; + QSet<int> qsRemove; + QSet<int> qsInheritedMembers; + }; + + struct ACLStruct { + bool bApplyHere; + bool bApplySubs; + bool bInherited; + int iPlayerId; + QString qsGroup; + ChanACL::Permissions pAllow; + ChanACL::Permissions pDeny; + }; + + int iId; + bool bQuery; + bool bInheritACL; + QList<GroupStruct> groups; + QList<ACLStruct> acls; + MessageEditACL(); + Message::MessageType messageType() const { return EditACL; }; + void process(Connection *); +}; + +QDataStream & operator<< ( QDataStream & out, const MessageEditACL::GroupStruct &gs ); +QDataStream & operator>> ( QDataStream & in, MessageEditACL::GroupStruct &gs ); +QDataStream & operator<< ( QDataStream & out, const MessageEditACL::ACLStruct &gs ); +QDataStream & operator>> ( QDataStream & in, MessageEditACL::ACLStruct &gs ); + +class MessageQueryUsers : public Message { + protected: + void saveStream(QDataStream &) const; + void restoreStream(QDataStream &); + public: + QList<int> qlIds; + QList<QString> qlNames; + MessageQueryUsers(); + Message::MessageType messageType() const { return QueryUsers; }; + void process(Connection *); + bool isValid() const; +}; + +#else +class Message; +#endif |