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:
66  void listUpdatedForMaster(MasterClient *pSender);
67  void masterMessage(MasterClient *pSender, const QString &title, const QString &content, bool isError);
68  void masterMessageImportant(MasterClient *pSender, const Message &objMessage);
69 
70 private:
71  CustomServers *customServers;
72  QList<MasterClient *> masters;
73  QSet<MasterClient *> mastersBeingRefreshed;
74 
75  BroadcastManager *broadcastManager;
76 
77  QByteArray createServerListRequest() override { return QByteArray(); }
78  Response readMasterResponse(const QByteArray &data) override;
79  void timeoutRefreshEx() override;
80 
81 private slots:
82  void masterListUpdated();
83 
84  void forwardMasterMessage(const QString &title, const QString &content, bool isError)
85  {
86  auto master = static_cast<MasterClient *>(sender());
87  emit masterMessage(master, title, content, isError);
88  }
89 
90  void forwardMasterMessageImportant(const Message &message)
91  {
92  auto master = static_cast<MasterClient *>(sender());
93  emit masterMessageImportant(master, message);
94  }
95 };
96 
97 #endif