mastermanager.h
1 //------------------------------------------------------------------------------
2 // mastermanager.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 #ifndef __MASTERMANAGER_H__
24 #define __MASTERMANAGER_H__
25 
26 #include "serverapi/masterclient.h"
27 #include "serverapi/message.h"
28 #include <QSharedPointer>
29 
30 class BroadcastManager;
31 class CustomServers;
32 class MasterClientSignalProxy;
33 
41 {
42  Q_OBJECT
43 
44 public:
45  MasterManager();
46  ~MasterManager() override;
47 
48  void addMaster(MasterClient *master);
49  QList<ServerPtr> allServers() const;
50  CustomServers *customServs() { return customServers; }
51 
52  int numMasters() const { return masters.size(); }
53  void setBroadcastManager(BroadcastManager *broadcastManagerPtr);
54  const EnginePlugin *plugin() const override { return nullptr; }
55 
56  MasterClient *operator[](int index) { return masters[index]; }
57 
58 public slots:
59  void refreshStarts() override;
60 
61 signals:
62  void masterMessage(MasterClient *pSender, const QString &title, const QString &content, bool isError);
63  void masterMessageImportant(MasterClient *pSender, const Message &objMessage);
64 
65 private:
66  CustomServers *customServers;
67  QList<MasterClient *> masters;
68  QSet<MasterClient *> mastersBeingRefreshed;
69 
70  BroadcastManager *broadcastManager;
71 
72  QByteArray createServerListRequest() override { return QByteArray(); }
73  Response readMasterResponse(const QByteArray &data) override;
74  void timeoutRefreshEx() override;
75 
76 private slots:
77  void masterListUpdated();
78 
79  void forwardMasterMessage(const QString &title, const QString &content, bool isError)
80  {
81  auto master = static_cast<MasterClient *>(sender());
82  emit masterMessage(master, title, content, isError);
83  }
84 
85  void forwardMasterMessageImportant(const Message &message)
86  {
87  auto master = static_cast<MasterClient *>(sender());
88  emit masterMessageImportant(master, message);
89  }
90 };
91 
92 #endif