ManaPlus
whoisonline.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009 The Mana World Development Team
4  * Copyright (C) 2011-2019 The ManaPlus Developers
5  * Copyright (C) 2009-2021 Andrei Karas
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef GUI_WINDOWS_WHOISONLINE_H
24 #define GUI_WINDOWS_WHOISONLINE_H
25 
27 #include "gui/widgets/window.h"
28 
30 
31 class Button;
32 class OnlinePlayer;
33 class ScrollArea;
34 class StaticBrowserBox;
35 
41 class WhoIsOnline final : public Window,
42  public LinkHandler,
43  public ActionListener,
44  public ConfigListener
45 {
46  public:
50  WhoIsOnline();
51 
53 
54 
57  ~WhoIsOnline() override final;
58 
59  void postInit() override final;
60 
61 #ifdef TMWA_SUPPORT
65  void loadWebList();
66 #endif // TMWA_SUPPORT
67 
68  void loadList(const STD_VECTOR<OnlinePlayer*> &list);
69 
70  void handleLink(const std::string& link,
71  MouseEvent *event) override final;
72 
73  void logic() override final;
74 
75  void slowLogic();
76 
77  void action(const ActionEvent &event) override final;
78 
79  void widgetResized(const Event &event) override final;
80 
81  const std::set<OnlinePlayer*> &getOnlinePlayers() const noexcept2
83  { return mOnlinePlayers; }
84 
85  const std::set<std::string> &getOnlineNicks() const noexcept2
87  { return mOnlineNicks; }
88 
89  void setAllowUpdate(const bool n) noexcept2
90  { mAllowUpdate = n; }
91 
92  void optionChanged(const std::string &name) override final;
93 
94  void updateList(StringVect &list);
95 
96  void readFromWeb();
97 
98  static void setNeutralColor(OnlinePlayer *const player);
99 
100  void getPlayerNames(StringVect &names);
101 
102  private:
103  void download();
104 
105  void updateSize();
106 
107  void handlerPlayerRelation(const std::string &nick,
108  OnlinePlayer *const player);
109 
110 #ifdef TMWA_SUPPORT
114  static int downloadThread(void *ptr);
115 
119  static size_t memoryWrite(void *restrict ptr,
120  size_t size,
121  size_t nmemb,
122  FILE *restrict stream);
123 #endif // TMWA_SUPPORT
124 
125  const std::string prepareNick(const std::string &restrict nick,
126  const int level,
127  const std::string &restrict color)
128  const A_WARN_UNUSED;
129 
130  void updateWindow(size_t numOnline);
131 
133  {
137  };
138 
139  time_t mUpdateTimer;
140 
142  SDL_Thread *mThread;
143 
146 
149 
153 
154  std::set<OnlinePlayer*> mOnlinePlayers;
155  std::set<std::string> mOnlineNicks;
156 
157  STD_VECTOR<OnlinePlayer*> mFriends;
158  STD_VECTOR<OnlinePlayer*> mNeutral;
159  STD_VECTOR<OnlinePlayer*> mDisregard;
160  STD_VECTOR<OnlinePlayer*> mEnemy;
161 
164 
167 
174 #ifdef TMWA_SUPPORT
175  bool mWebList;
176 #endif
178 };
179 
180 extern WhoIsOnline *whoIsOnline;
181 
182 #endif // GUI_WINDOWS_WHOISONLINE_H
Definition: button.h:102
Definition: event.h:79
int mDownloadedBytes
Definition: whoisonline.h:163
void getPlayerNames(StringVect &names)
const std::set< OnlinePlayer * > & getOnlinePlayers() const
Definition: whoisonline.h:81
bool mDownloadComplete
Definition: whoisonline.h:169
std::set< std::string > mOnlineNicks
Definition: whoisonline.h:155
static size_t memoryWrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
bool mShowLevel
Definition: whoisonline.h:171
time_t mUpdateTimer
Definition: whoisonline.h:139
const std::set< std::string > & getOnlineNicks() const
Definition: whoisonline.h:85
Button * mUpdateButton
Definition: whoisonline.h:152
const std::string prepareNick(const std::string &nick, const int level, const std::string &color) const
void loadList(const std::vector< OnlinePlayer * > &list)
std::set< OnlinePlayer * > mOnlinePlayers
Definition: whoisonline.h:154
bool mAllowUpdate
Definition: whoisonline.h:170
std::vector< OnlinePlayer * > mNeutral
Definition: whoisonline.h:158
char * mMemoryBuffer
Definition: whoisonline.h:145
void updateSize()
void handlerPlayerRelation(const std::string &nick, OnlinePlayer *const player)
static int downloadThread(void *ptr)
void readFromWeb()
ScrollArea * mScrollArea
Definition: whoisonline.h:151
bool mGroupFriends
Definition: whoisonline.h:173
void slowLogic()
StaticBrowserBox * mBrowserBox
Definition: whoisonline.h:150
static void setNeutralColor(OnlinePlayer *const player)
std::vector< OnlinePlayer * > mFriends
Definition: whoisonline.h:157
void widgetResized(const Event &event)
char * mCurlError
Definition: whoisonline.h:148
std::vector< OnlinePlayer * > mEnemy
Definition: whoisonline.h:160
SDL_Thread * mThread
Definition: whoisonline.h:142
void postInit()
void optionChanged(const std::string &name)
void loadWebList()
void action(const ActionEvent &event)
WhoIsOnline::DownloadStatus mDownloadStatus
Definition: whoisonline.h:166
void updateList(StringVect &list)
void handleLink(const std::string &link, MouseEvent *event)
void updateWindow(size_t numOnline)
std::vector< OnlinePlayer * > mDisregard
Definition: whoisonline.h:159
void setAllowUpdate(const bool n)
Definition: whoisonline.h:89
void download()
bool mUpdateOnlineList
Definition: whoisonline.h:172
bool mServerSideList
Definition: whoisonline.h:177
Definition: window.h:102
#define restrict
Definition: localconsts.h:165
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
int size()
Definition: emotedb.cpp:306
std::vector< std::string > StringVect
Definition: stringvector.h:29
WhoIsOnline * whoIsOnline
Definition: whoisonline.cpp:82