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 |
|
|
|
26 |
|
|
#include "gui/widgets/linkhandler.h" |
27 |
|
|
#include "gui/widgets/window.h" |
28 |
|
|
|
29 |
|
|
#include "listeners/actionlistener.h" |
30 |
|
|
|
31 |
|
|
class Button; |
32 |
|
|
class OnlinePlayer; |
33 |
|
|
class ScrollArea; |
34 |
|
|
class StaticBrowserBox; |
35 |
|
|
|
36 |
|
|
/** |
37 |
|
|
* Update progress window GUI |
38 |
|
|
* |
39 |
|
|
* \ingroup GUI |
40 |
|
|
*/ |
41 |
|
|
class WhoIsOnline final : public Window, |
42 |
|
|
public LinkHandler, |
43 |
|
|
public ActionListener, |
44 |
|
|
public ConfigListener |
45 |
|
|
{ |
46 |
|
|
public: |
47 |
|
|
/** |
48 |
|
|
* Constructor. |
49 |
|
|
*/ |
50 |
|
|
WhoIsOnline(); |
51 |
|
|
|
52 |
|
|
A_DELETE_COPY(WhoIsOnline) |
53 |
|
|
|
54 |
|
|
/** |
55 |
|
|
* Destructor |
56 |
|
|
*/ |
57 |
|
|
~WhoIsOnline() override final; |
58 |
|
|
|
59 |
|
|
void postInit() override final; |
60 |
|
|
|
61 |
|
|
#ifdef TMWA_SUPPORT |
62 |
|
|
/** |
63 |
|
|
* Loads and display online list from the memory buffer. |
64 |
|
|
*/ |
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 |
82 |
|
|
A_WARN_UNUSED |
83 |
|
|
{ return mOnlinePlayers; } |
84 |
|
|
|
85 |
|
|
const std::set<std::string> &getOnlineNicks() const noexcept2 |
86 |
|
|
A_WARN_UNUSED |
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 |
111 |
|
|
/** |
112 |
|
|
* The thread function that download the files. |
113 |
|
|
*/ |
114 |
|
|
static int downloadThread(void *ptr); |
115 |
|
|
|
116 |
|
|
/** |
117 |
|
|
* A libcurl callback for writing to memory. |
118 |
|
|
*/ |
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 |
|
|
|
132 |
|
|
enum DownloadStatus |
133 |
|
|
{ |
134 |
|
|
UPDATE_ERROR = 0, |
135 |
|
|
UPDATE_COMPLETE, |
136 |
|
|
UPDATE_LIST |
137 |
|
|
}; |
138 |
|
|
|
139 |
|
|
time_t mUpdateTimer; |
140 |
|
|
|
141 |
|
|
/** A thread that use libcurl to download updates. */ |
142 |
|
|
SDL_Thread *mThread; |
143 |
|
|
|
144 |
|
|
/** Buffer for files downloaded to memory. */ |
145 |
|
|
char *mMemoryBuffer; |
146 |
|
|
|
147 |
|
|
/** Buffer to handler human readable error provided by curl. */ |
148 |
|
|
char *mCurlError A_NONNULLPOINTER; |
149 |
|
|
|
150 |
|
|
StaticBrowserBox *mBrowserBox A_NONNULLPOINTER; |
151 |
|
|
ScrollArea *mScrollArea A_NONNULLPOINTER; |
152 |
|
|
Button *mUpdateButton A_NONNULLPOINTER; |
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 |
|
|
|
162 |
|
|
/** Byte count currently downloaded in mMemoryBuffer. */ |
163 |
|
|
int mDownloadedBytes; |
164 |
|
|
|
165 |
|
|
/** Status of the current download. */ |
166 |
|
|
WhoIsOnline::DownloadStatus mDownloadStatus; |
167 |
|
|
|
168 |
|
|
/** Flag that show if current download is complete. */ |
169 |
|
|
bool mDownloadComplete; |
170 |
|
|
bool mAllowUpdate; |
171 |
|
|
bool mShowLevel; |
172 |
|
|
bool mUpdateOnlineList; |
173 |
|
|
bool mGroupFriends; |
174 |
|
|
#ifdef TMWA_SUPPORT |
175 |
|
|
bool mWebList; |
176 |
|
|
#endif |
177 |
|
|
bool mServerSideList; |
178 |
|
|
}; |
179 |
|
|
|
180 |
|
|
extern WhoIsOnline *whoIsOnline; |
181 |
|
|
|
182 |
|
|
#endif // GUI_WINDOWS_WHOISONLINE_H |