Mana
Loading...
Searching...
No Matches
gamehandler.cpp
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
23
24#include "client.h"
25#include "localplayer.h"
26
31
33
35
36namespace ManaServ {
37
38extern Connection *chatServerConnection;
39extern Connection *gameServerConnection;
40extern std::string netToken;
43
45{
46 static const Uint16 _messages[] = {
49 0
50 };
51 handledMessages = _messages;
52 gameHandler = this;
53}
54
56{
57 switch (msg.getId())
58 {
60 break;
61
63 {
64 int errMsg = msg.readInt8();
65 // Successful logout
66 if (errMsg == ERRMSG_OK)
67 {
68 netToken = msg.readString(32);
69
70 if (!netToken.empty())
71 {
73 }
74 else
75 {
76 // TODO: Handle logout
77 }
78 }
79 // Logout failed
80 else
81 {
82 switch (errMsg)
83 {
84 case ERRMSG_NO_LOGIN:
85 errorMessage = "Gameserver: Not logged in";
86 break;
87 default:
88 errorMessage = "Gameserver: Unknown error";
89 break;
90 }
92 }
93 }
94 break;
95 }
96}
97
99{
101
102 // Will already be connected if we just changed gameservers
105}
106
108{
110 chatHandler->isConnected();
111}
112
114{
116
117 // No need if we're just changing gameservers
119 chatHandler->disconnect();
120}
121
122void GameHandler::quit(bool reconnectAccount)
123{
125 msg.writeInt8((unsigned char) reconnectAccount);
127}
128
130{
132 msg.writeString(netToken, 32);
134
135 chatHandler->connect();
136
137 // Attack range from item DB
138 // TODO: Deharcode it through equipment handling
140}
141
142} // namespace ManaServ
static void setState(State state)
Definition client.h:169
static State getState()
Definition client.h:172
void setAttackRange(int range)
Sets the attack range.
bool isConnected()
Returns whether the server is connected.
void send(const ManaServ::MessageOut &msg)
Sends a message.
bool connect(const std::string &address, enet_uint16 port)
Connects to the given server with the specified address and port.
void disconnect()
Disconnects from the given server.
void quit() override
Definition gamehandler.h:47
void handleMessage(MessageIn &msg) override
void connect() override
bool isConnected() override
void disconnect() override
Used for parsing an incoming message from manaserv.
Definition messagein.h:37
std::string readString(int length=-1)
Reads a string.
Definition messagein.cpp:92
uint16_t getId() const
Returns the message ID.
Definition messagein.h:44
uint8_t readInt8()
Reads an unsigned 8-bit integer from the message.
Definition messagein.cpp:43
Used for building an outgoing message to manaserv.
Definition messageout.h:37
void writeInt8(uint8_t value)
Writes an unsigned 8-bit integer to the message.
void writeString(const std::string &string, int length=-1)
Writes a string.
const uint16_t * handledMessages
std::string hostname
Definition serverinfo.h:42
uint16_t port
Definition serverinfo.h:43
std::string errorMessage
Definition client.cpp:94
@ STATE_CHANGE_MAP
Definition client.h:74
@ STATE_ERROR
Definition client.h:60
@ STATE_SWITCH_CHARACTER
Definition client.h:91
LocalPlayer * local_player
ManaServ::GameHandler * gameHandler
Definition net.cpp:52
Net::ChatHandler * chatHandler
Definition net.cpp:48
ManaServ::ChatHandler * chatHandler
Definition net.cpp:48
Net::GameHandler * gameHandler
Definition net.cpp:52
ServerInfo gameServer
Connection * gameServerConnection
std::string netToken
Connection * chatServerConnection
ServerInfo chatServer