Mana
Loading...
Searching...
No Matches
generalhandler.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2009 The Mana World Development Team
4 * Copyright (C) 2009-2013 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
23
24#include "client.h"
25#include "configuration.h"
26#include "log.h"
27
28#include "gui/skilldialog.h"
29#include "gui/socialwindow.h"
30#include "gui/statuswindow.h"
31
32#include "net/serverinfo.h"
33
44#include "net/tmwa/messagein.h"
45#include "net/tmwa/network.h"
46#include "net/tmwa/npchandler.h"
49#include "net/tmwa/protocol.h"
52
55
56#include "resources/itemdb.h"
57
58#include "utils/gettext.h"
59
60#include <list>
61
62namespace TmwAthena {
63
66
67extern Guild *taGuild;
68extern Party *taParty;
69
71 mAdminHandler(new AdminHandler),
72 mBeingHandler(new BeingHandler(config.enableSync)),
73 mBuySellHandler(new BuySellHandler),
74 mCharHandler(new CharServerHandler),
75 mChatHandler(new ChatHandler),
76 mGameHandler(new GameHandler),
77 mGuildHandler(new GuildHandler),
78 mInventoryHandler(new InventoryHandler),
79 mItemHandler(new ItemHandler),
80 mLoginHandler(new LoginHandler),
81 mNpcHandler(new NpcHandler),
82 mPartyHandler(new PartyHandler),
83 mPlayerHandler(new PlayerHandler),
84 mAbilityHandler(new AbilityHandler),
85 mTradeHandler(new TradeHandler)
86{
87 static const Uint16 _messages[] = {
89 0
90 };
91 handledMessages = _messages;
92
93 std::list<ItemStat> stats;
94 stats.emplace_back("str", _("Strength %+d"));
95 stats.emplace_back("agi", _("Agility %+d"));
96 stats.emplace_back("vit", _("Vitality %+d"));
97 stats.emplace_back("int", _("Intelligence %+d"));
98 stats.emplace_back("dex", _("Dexterity %+d"));
99 stats.emplace_back("luck", _("Luck %+d"));
100
101 setStatsList(std::move(stats));
102
105}
106
111
113{
114 int code;
115
116 switch (msg.getId())
117 {
119 code = msg.readInt8();
120 Log::info("Connection problem: %i", code);
121
122 switch (code)
123 {
124 case 0:
125 errorMessage = _("Authentication failed.");
126 break;
127 case 1:
128 errorMessage = _("No servers available.");
129 break;
130 case 2:
132 errorMessage = _("Someone else is trying to use this "
133 "account.");
134 else
135 errorMessage = _("This account is already logged in.");
136 break;
137 case 3:
138 errorMessage = _("Speed hack detected.");
139 break;
140 case 8:
141 errorMessage = _("Duplicated login.");
142 break;
143 default:
144 errorMessage = _("Unknown connection error.");
145 break;
146 }
148 break;
149 }
150}
151
173
175{
176 if (mNetwork)
178
179 static_cast<LoginHandler*>(mLoginHandler.get())->clearWorlds();
180 static_cast<CharServerHandler*>(mCharHandler.get())->setCharCreateDialog(nullptr);
181 static_cast<CharServerHandler*>(mCharHandler.get())->setCharSelectDialog(nullptr);
182}
183
185{
186 if (mNetwork)
188}
189
191{
192 if (!mNetwork)
193 return;
194
195 mNetwork->flush();
197
199 {
200 if (!mNetwork->getError().empty())
202 else
203 errorMessage = _("Got disconnected from server!");
204
206 }
207}
208
210 const Event &event)
211{
212 if (channel == Event::GameChannel)
213 {
214 if (event.getType() == Event::GuiWindowsLoaded)
215 {
217
218 statusWindow->addAttribute(STRENGTH, _("Strength"), true, "");
219 statusWindow->addAttribute(AGILITY, _("Agility"), true, "");
220 statusWindow->addAttribute(VITALITY, _("Vitality"), true, "");
221 statusWindow->addAttribute(INTELLIGENCE, _("Intelligence"),
222 true, "");
223 statusWindow->addAttribute(DEXTERITY, _("Dexterity"), true, "");
224 statusWindow->addAttribute(LUCK, _("Luck"), true, "");
225
226 statusWindow->addAttribute(ATK, _("Attack"), false, "");
227 statusWindow->addAttribute(DEF, _("Defense"), false, "");
228 statusWindow->addAttribute(MATK, _("M.Attack"), false, "");
229 statusWindow->addAttribute(MDEF, _("M.Defense"), false, "");
230 // NOTE: Don't remove the gettext comments as they are used
231 // by the xgettext invocation.
232 //xgettext:no-c-format
233 statusWindow->addAttribute(HIT, _("% Accuracy"), false, "");
234 //xgettext:no-c-format
235 statusWindow->addAttribute(FLEE, _("% Evade"), false, "");
236 //xgettext:no-c-format
237 statusWindow->addAttribute(CRIT, _("% Critical"), false, "");
238 }
239 else if (event.getType() == Event::GuiWindowsUnloading)
240 {
243
244 delete guildTab;
245 guildTab = nullptr;
246
247 delete partyTab;
248 partyTab = nullptr;
249 }
250 }
251}
252
253} // namespace TmwAthena
static void setState(State state)
Definition client.h:169
static State getState()
Definition client.h:172
void listen(Event::Channel channel)
Definition event.h:42
@ GuiWindowsLoaded
Definition event.h:82
@ GuiWindowsUnloading
Definition event.h:85
Channel
Definition event.h:45
@ ClientChannel
Definition event.h:50
@ GameChannel
Definition event.h:52
Definition guild.h:55
const uint16_t * handledMessages
Definition party.h:59
void loadSkills()
bool removeTab(Guild *guild)
void addAttribute(int id, const std::string &name, bool modifiable, const std::string &description)
Deals with incoming messages from the character server.
MessageHandlerPtr mBeingHandler
MessageHandlerPtr mAbilityHandler
MessageHandlerPtr mGuildHandler
void handleMessage(MessageIn &msg) override
MessageHandlerPtr mChatHandler
MessageHandlerPtr mPartyHandler
MessageHandlerPtr mAdminHandler
MessageHandlerPtr mPlayerHandler
MessageHandlerPtr mBuySellHandler
void event(Event::Channel channel, const Event &event) override
MessageHandlerPtr mNpcHandler
MessageHandlerPtr mGameHandler
MessageHandlerPtr mTradeHandler
MessageHandlerPtr mInventoryHandler
MessageHandlerPtr mCharHandler
MessageHandlerPtr mLoginHandler
MessageHandlerPtr mItemHandler
Used for parsing an incoming message from eAthena.
Definition messagein.h:35
uint8_t readInt8()
Reads an unsigned 8-bit integer from the message.
Definition messagein.cpp:46
uint16_t getId() const
Returns the message ID.
Definition messagein.h:42
void registerHandler(MessageHandler *handler)
Definition network.cpp:332
void dispatchMessages()
Definition network.cpp:365
const std::string & getError() const
Definition network.h:73
int getState() const
Definition network.h:71
Config config
Global settings (config.xml)
Definition client.cpp:97
std::string errorMessage
Definition client.cpp:94
@ STATE_ERROR
Definition client.h:60
@ STATE_GAME
Definition client.h:73
SocialWindow * socialWindow
Definition game.cpp:108
StatusWindow * statusWindow
Definition game.cpp:94
SkillDialog * skillDialog
Definition game.cpp:97
#define _(s)
Definition gettext.h:38
void setStatsList(std::list< ItemStat > stats)
Definition itemdb.cpp:40
void info(const char *log_text,...) LOG_PRINTF_ATTR
Warning: buffers and other variables are shared, so there can be only one connection active at a time...
PartyTab * partyTab
ServerInfo mapServer
@ DEXTERITY
Definition protocol.h:37
@ INTELLIGENCE
Definition protocol.h:36
Guild * taGuild
Definition guildtab.cpp:38
ServerInfo charServer
Party * taParty
@ SMSG_CONNECTION_PROBLEM
Definition protocol.h:312
GuildTab * guildTab