File indexing completed on 2024-05-12 05:39:51
0001 /************************************************************************* 0002 * Copyright (C) 2018 by Renaud Guezennec * 0003 * * 0004 * https://rolisteam.org/ * 0005 * * 0006 * Rolisteam is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published * 0008 * by the Free Software Foundation; either version 2 of the License, * 0009 * or (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0020 *************************************************************************/ 0021 #ifndef CHANNEL_H 0022 #define CHANNEL_H 0023 0024 #include "treeitem.h" 0025 #include <QString> 0026 0027 #include <QJsonArray> 0028 #include <QJsonObject> 0029 #include <QList> 0030 #include <QPointer> 0031 #include <QString> 0032 0033 #include "network/serverconnection.h" 0034 #include "network_global.h" 0035 #include "networkmessagewriter.h" 0036 0037 class NetworkMessage; 0038 class NetworkMessageReader; 0039 /** 0040 * @brief The Channel class 0041 */ 0042 class NETWORK_EXPORT Channel : public TreeItem 0043 { 0044 Q_OBJECT 0045 Q_PROPERTY(quint64 memorySize READ memorySize WRITE setMemorySize NOTIFY memorySizeChanged) 0046 Q_PROPERTY(bool locked READ locked WRITE setLocked NOTIFY lockedChanged) 0047 Q_PROPERTY(ServerConnection* currentGM READ currentGM WRITE setCurrentGM NOTIFY currentGMChanged) 0048 public: 0049 Channel(); 0050 explicit Channel(QString name); 0051 virtual ~Channel(); 0052 0053 QByteArray password() const; 0054 void setPassword(const QByteArray& password); 0055 0056 virtual int childCount() const override; 0057 0058 int indexOf(TreeItem* child) override; 0059 0060 QString description() const; 0061 void setDescription(const QString& description); 0062 0063 bool usersListed() const; 0064 void setUsersListed(bool usersListed); 0065 0066 bool isLeaf() const override; 0067 0068 void sendMessage(NetworkMessage*, ServerConnection*, bool mustBeSaved); 0069 void sendToAll(NetworkMessage*, ServerConnection* sender, bool deleteMsg= false); 0070 void sendToMany(NetworkMessage* msg, ServerConnection* sender, bool deleteMsg= false); 0071 0072 // void readFromJson(QJsonObject& json) override; 0073 // void writeIntoJson(QJsonObject& json) override; 0074 TreeItem* getChildAt(int row) override; 0075 const QList<QPointer<TreeItem>> childrenItem() const; 0076 0077 int addChild(TreeItem*) override; 0078 0079 bool addChildInto(QString id, TreeItem* child) override; 0080 0081 virtual void clear() override; 0082 0083 void updateNewClient(ServerConnection* newComer); 0084 0085 bool removeClient(ServerConnection* client); 0086 bool removeChild(TreeItem*) override; 0087 bool removeChildById(const QString&); 0088 0089 ServerConnection* currentGM() const; 0090 void setCurrentGM(ServerConnection* currentGM); 0091 0092 QString getCurrentGmId(); 0093 0094 virtual void kick(const QString& str, bool isAdmin, const QString& sourceId) override; 0095 TreeItem* getChildById(QString id) override; 0096 ServerConnection* getClientById(QString id); 0097 0098 quint64 memorySize() const; 0099 void setMemorySize(quint64 size); 0100 0101 bool locked() const; 0102 void setLocked(bool locked); 0103 0104 bool contains(QString id); 0105 public slots: 0106 void clearData(); 0107 void renamePlayer(const QString& id, const QString& name); 0108 signals: 0109 void memorySizeChanged(quint64 memorySize, Channel* id); 0110 void lockedChanged(); 0111 void currentGMChanged(); 0112 0113 protected: 0114 bool hasNoClient(); 0115 void sendOffGmStatus(ServerConnection* client); 0116 void findNewGM(); 0117 0118 private: 0119 QByteArray m_password; 0120 QString m_description; 0121 bool m_usersListed= false; 0122 0123 QList<QPointer<TreeItem>> m_child; 0124 QList<NetworkMessage*> m_dataToSend; 0125 quint64 m_memorySize= 0; 0126 QPointer<ServerConnection> m_currentGm; 0127 bool m_locked= false; 0128 }; 0129 0130 #endif // CHANNEL_H