Mana
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "video.h"
25
26#include "net/serverinfo.h"
27
28#include <guichan/actionlistener.hpp>
29
30#include <SDL.h>
31
32#include <string>
33
34class Game;
35class Button;
36class Desktop;
37class LoginData;
38class Window;
39class QuitDialog;
40
41//manaserv uses 9601
42//static const short DEFAULT_PORT = 9601;
43static const short DEFAULT_PORT = 6901;
44
45extern volatile int fps;
46
47extern std::string errorMessage;
48extern LoginData loginData;
49
54bool isDoubleClick(int selected);
55
97
99{
100 int mFpsLimit = 0;
103
104public:
105 void limitFps(int fpsLimit);
106};
107
112class Client final : public gcn::ActionListener
113{
114public:
119 struct Options
120 {
121 bool printHelp = false;
122 bool printVersion = false;
123 bool skipUpdate = false;
124 bool chooseDefault = false;
125 bool noOpenGL = false;
126 bool exitWithError = false;
127 std::string username;
128 std::string password;
129 std::string character;
130 std::string brandingPath;
131 std::string updateHost;
132 std::string dataPath;
133 std::string chatLogDir;
134 std::string configDir;
135 std::string localDataDir;
136 std::string screenshotDir;
138
139 std::string serverName;
140 uint16_t serverPort = 0;
141 };
142
143 Client(const Options &options);
144 ~Client() override;
145
149 static Client *instance() { return mInstance; }
150
151 int exec();
152
153 void update();
154
159 void showOkDialog(const std::string &title,
160 const std::string &message,
161 State state);
162
167 void showErrorDialog(const std::string &message, State state);
168
169 static void setState(State state)
170 { instance()->mState = state; }
171
173 { return instance()->mState; }
174
175 static const std::string &getPackageDirectory()
176 { return instance()->mPackageDir; }
177
178 static const std::string &getConfigDirectory()
179 { return instance()->mConfigDir; }
180
181 static const std::string &getLocalDataDirectory()
182 { return instance()->mLocalDataDir; }
183
184 static const std::string &getScreenshotDirectory()
185 { return instance()->mScreenshotDir; }
186
187 static Video &getVideo()
188 { return instance()->mVideo; }
189
190 void action(const gcn::ActionEvent &event) override;
191
196 void handleWindowSizeChanged(int width, int height);
197 void checkGraphicsSize();
198
199 static bool isActive();
200 static bool hasInputFocus();
201 static bool hasMouseFocus();
202
203private:
204 void initRootDir();
205 void initHomeDir();
206 void initConfiguration();
207 bool initUpdatesDir();
208 void initScreenshotDir();
209
211
213
215
216 std::string mPackageDir;
217 std::string mConfigDir;
218 std::string mLocalDataDir;
219 std::string mUpdateHost;
220 std::string mUpdatesDir;
221 std::string mScreenshotDir;
222 std::string mRootDir;
223
226
227 Game *mGame = nullptr;
230 Desktop *mDesktop = nullptr;
232
236
237 SDL_Surface *mIcon = nullptr;
238
239 SDL_TimerID mSecondsCounterId = 0;
241
242#if defined(_WIN32) || defined(__APPLE__)
248 class ExposeEventWatcher
249 {
250 public:
251 ExposeEventWatcher() { SDL_AddEventWatch(&watch, nullptr); }
252 ~ExposeEventWatcher() { SDL_DelEventWatch(&watch, nullptr); }
253
254 static int watch(void *, SDL_Event *event)
255 {
256 if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_EXPOSED)
258 return 0;
259 }
260 };
261
262 ExposeEventWatcher mExposeEventWatcher;
263#endif
264};
Button widget.
Definition button.h:38
The core part of the client.
Definition client.h:113
SDL_Surface * mIcon
Definition client.h:237
State mStateAfterOkDialog
Definition client.h:235
std::string mUpdatesDir
Definition client.h:220
std::string mRootDir
Definition client.h:222
void initConfiguration()
Initialize configuration.
Definition client.cpp:1110
void showErrorDialog(const std::string &message, State state)
Pops up an error dialog with the given message, and switches to the given state when Ok is pressed.
Definition client.cpp:979
int exec()
Definition client.cpp:435
std::string mPackageDir
Definition client.h:216
void action(const gcn::ActionEvent &event) override
Definition client.cpp:984
Button * mSetupButton
Definition client.h:231
State mState
Definition client.h:233
void update()
Definition client.cpp:509
Game * mGame
Definition client.h:227
bool initUpdatesDir()
Parse the update host and determine the updates directory Then verify that the directory exists (crea...
Definition client.cpp:1128
static const std::string & getConfigDirectory()
Definition client.h:178
void accountLogin(LoginData *loginData)
Definition client.cpp:1226
static bool isActive()
Definition client.cpp:1271
void initHomeDir()
Initializes the home directory.
Definition client.cpp:1058
static bool hasMouseFocus()
Definition client.cpp:1281
Video mVideo
Definition client.h:225
void checkGraphicsSize()
Definition client.cpp:1253
State mOldState
Definition client.h:234
std::string mLocalDataDir
Definition client.h:218
void initRootDir()
Definition client.cpp:1003
static void setState(State state)
Definition client.h:169
static bool hasInputFocus()
Definition client.cpp:1276
SDL_TimerID mSecondsCounterId
Definition client.h:239
static const std::string & getLocalDataDirectory()
Definition client.h:181
static Video & getVideo()
Definition client.h:187
static const std::string & getPackageDirectory()
Definition client.h:175
FpsManager mFpsManager
Definition client.h:240
void initScreenshotDir()
Definition client.cpp:1195
std::string mConfigDir
Definition client.h:217
void showOkDialog(const std::string &title, const std::string &message, State state)
Pops up an OkDialog with the given title and message, and switches to the given state when Ok is pres...
Definition client.cpp:970
std::string mScreenshotDir
Definition client.h:221
std::string mUpdateHost
Definition client.h:219
static const std::string & getScreenshotDirectory()
Definition client.h:184
ServerInfo mCurrentServer
Definition client.h:224
static Client * mInstance
Definition client.h:212
static State getState()
Definition client.h:172
QuitDialog * mQuitDialog
Definition client.h:229
void handleWindowSizeChanged(int width, int height)
Should be called after the window has been resized.
Definition client.cpp:1246
Desktop * mDesktop
Definition client.h:230
Options mOptions
Definition client.h:214
~Client() override
Definition client.cpp:398
Window * mCurrentDialog
Definition client.h:228
static Client * instance()
Provides access to the client instance.
Definition client.h:149
Desktop widget, for drawing a background image and color.
Definition desktop.h:48
uint32_t mFrameCount
Definition client.h:101
uint32_t mBaseTicks
Definition client.h:102
int mFpsLimit
Definition client.h:100
void limitFps(int fpsLimit)
A simple but effective frame rate limiter.
Definition client.cpp:143
The main class responsible for running the game.
Definition game.h:37
The quit dialog.
Definition quitdialog.h:40
Definition video.h:72
A window.
Definition window.h:59
State
All client states.
Definition client.h:59
@ STATE_LOGIN_ERROR
Definition client.h:75
@ STATE_CONNECT_SERVER
Definition client.h:63
@ STATE_GET_CHARACTERS
Definition client.h:70
@ STATE_CHANGEPASSWORD_SUCCESS
Definition client.h:82
@ STATE_START
Definition client.h:61
@ STATE_CHOOSE_SERVER
Definition client.h:62
@ STATE_CHANGEEMAIL
Definition client.h:83
@ STATE_CONNECT_GAME
Definition client.h:72
@ STATE_CHANGEEMAIL_SUCCESS
Definition client.h:85
@ STATE_LOAD_DATA
Definition client.h:69
@ STATE_REGISTER
Definition client.h:78
@ STATE_UNREGISTER
Definition client.h:86
@ STATE_REGISTER_ATTEMPT
Definition client.h:79
@ STATE_REGISTER_PREP
Definition client.h:77
@ STATE_CHANGE_MAP
Definition client.h:74
@ STATE_LOGOUT_ATTEMPT
Definition client.h:92
@ STATE_UNREGISTER_ATTEMPT
Definition client.h:87
@ STATE_SWITCH_LOGIN
Definition client.h:90
@ STATE_SWITCH_SERVER
Definition client.h:89
@ STATE_WAIT
Definition client.h:93
@ STATE_EXIT
Definition client.h:94
@ STATE_ACCOUNTCHANGE_ERROR
Definition client.h:76
@ STATE_CHANGEPASSWORD
Definition client.h:80
@ STATE_UNREGISTER_SUCCESS
Definition client.h:88
@ STATE_LOGIN_ATTEMPT
Definition client.h:65
@ STATE_CHAR_SELECT
Definition client.h:71
@ STATE_CHANGEPASSWORD_ATTEMPT
Definition client.h:81
@ STATE_CHANGEEMAIL_ATTEMPT
Definition client.h:84
@ STATE_WORLD_SELECT
Definition client.h:66
@ STATE_ERROR
Definition client.h:60
@ STATE_UPDATE
Definition client.h:68
@ STATE_GAME
Definition client.h:73
@ STATE_FORCE_QUIT
Definition client.h:95
@ STATE_SWITCH_CHARACTER
Definition client.h:91
@ STATE_WORLD_SELECT_ATTEMPT
Definition client.h:67
@ STATE_LOGIN
Definition client.h:64
std::string errorMessage
Definition client.cpp:94
bool isDoubleClick(int selected)
Returns whether this call and the last call were done for the same selected index and within a short ...
Definition client.cpp:126
volatile int fps
Frames counted in the last second.
Definition client.cpp:111
LoginData loginData
Definition client.cpp:95
ServerType
Definition serverinfo.h:29
unsigned int uint32_t
Definition sha256.cpp:82
A structure holding the values of various options that can be passed from the command line.
Definition client.h:120
std::string chatLogDir
Definition client.h:133
bool chooseDefault
Definition client.h:124
std::string dataPath
Definition client.h:132
ServerType serverType
Definition client.h:137
bool exitWithError
Definition client.h:126
std::string screenshotDir
Definition client.h:136
std::string brandingPath
Definition client.h:130
std::string serverName
Definition client.h:139
uint16_t serverPort
Definition client.h:140
std::string updateHost
Definition client.h:131
std::string character
Definition client.h:129
bool printVersion
Definition client.h:122
std::string localDataDir
Definition client.h:135
bool skipUpdate
Definition client.h:123
std::string username
Definition client.h:127
std::string password
Definition client.h:128
std::string configDir
Definition client.h:134