GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/gamehandler.cpp Lines: 1 100 1.0 %
Date: 2017-11-29 Branches: 0 160 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
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
#include "net/eathena/gamehandler.h"
24
25
#include "client.h"
26
27
#include "being/localplayer.h"
28
29
#include "net/serverfeatures.h"
30
31
#include "net/ea/token.h"
32
33
#include "net/ea/gamerecv.h"
34
35
#include "net/eathena/loginhandler.h"
36
#include "net/eathena/messageout.h"
37
#include "net/eathena/network.h"
38
#include "net/eathena/protocolout.h"
39
40
#include "debug.h"
41
42
extern int packetVersion;
43
44
namespace EAthena
45
{
46
47
extern ServerInfo mapServer;
48
49
GameHandler::GameHandler() :
50
    Ea::GameHandler()
51
{
52
    gameHandler = this;
53
}
54
55
GameHandler::~GameHandler()
56
{
57
    gameHandler = nullptr;
58
}
59
60
void GameHandler::mapLoadedEvent() const
61
{
62
    createOutPacket(CMSG_MAP_LOADED);
63
}
64
65
void GameHandler::connect() const
66
{
67
    if (Network::mInstance == nullptr)
68
        return;
69
70
    Network::mInstance->connect(mapServer);
71
72
    const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
73
74
75
    if (client->getState() == State::CONNECT_GAME)
76
    {
77
        // Change the player's ID to the account ID to match what eAthena uses
78
        if (localPlayer != nullptr)
79
        {
80
            Ea::GameRecv::mCharID = localPlayer->getId();
81
            localPlayer->setId(token.account_ID);
82
        }
83
        else
84
        {
85
            Ea::GameRecv::mCharID = BeingId_zero;
86
        }
87
    }
88
89
    // Send login infos
90
    createOutPacket(CMSG_MAP_SERVER_CONNECT);
91
    outMsg.writeBeingId(token.account_ID, "account id");
92
    outMsg.writeBeingId(Ea::GameRecv::mCharID, "char id");
93
    outMsg.writeInt32(token.session_ID1, "session key1");
94
    outMsg.writeInt32(0, "tick");
95
    outMsg.writeInt8(Being::genderToInt(token.sex), "sex");
96
    if (serverFeatures->haveMapServerVersion())
97
        loginHandler->sendVersion();
98
99
    // We get 4 useless bytes before the real answer comes in (what are these?)
100
//    Network::mInstance->skip(4);
101
}
102
103
bool GameHandler::isConnected() const
104
{
105
    if (Network::mInstance == nullptr)
106
        return false;
107
    return Network::mInstance->isConnected();
108
}
109
110
void GameHandler::disconnect() const
111
{
112
    if (Network::mInstance != nullptr)
113
        Network::mInstance->disconnect();
114
}
115
116
void GameHandler::quit() const
117
{
118
    createOutPacket(CMSG_CLIENT_QUIT);
119
}
120
121
void GameHandler::ping(const int tick) const
122
{
123
    createOutPacket(CMSG_MAP_PING);
124
    if (packetVersion >= 20101124)
125
    {
126
        // nothing here
127
    }
128
    else if (packetVersion >= 20080827)
129
    {
130
        outMsg.writeInt16(0, "unknown");
131
        outMsg.writeInt8(0, "unknown");
132
        outMsg.writeInt8(0, "unknown");
133
        outMsg.writeInt8(0, "unknown");
134
    }
135
    else if (packetVersion >= 20070212)
136
    {
137
        outMsg.writeInt16(0, "unknown");
138
    }
139
    else if (packetVersion >= 20070108)
140
    {
141
        outMsg.writeInt16(0, "unknown");
142
        outMsg.writeInt16(0, "unknown");
143
        outMsg.writeInt8(0, "unknown");
144
    }
145
    else if (packetVersion >= 20050719)
146
    {
147
        outMsg.writeInt16(0, "unknown");
148
        outMsg.writeInt16(0, "unknown");
149
        outMsg.writeInt16(0, "unknown");
150
        outMsg.writeInt8(0, "unknown");
151
    }
152
    else if (packetVersion >= 20050718)
153
    {
154
        outMsg.writeInt8(0, "unknown");
155
    }
156
    else if (packetVersion >= 20050628)
157
    {
158
        outMsg.writeInt16(0, "unknown");
159
        outMsg.writeInt16(0, "unknown");
160
        outMsg.writeInt16(0, "unknown");
161
        outMsg.writeInt8(0, "unknown");
162
    }
163
    else if (packetVersion >= 20050509)
164
    {
165
        outMsg.writeInt16(0, "unknown");
166
    }
167
    else if (packetVersion >= 20050110)
168
    {
169
        outMsg.writeInt16(0, "unknown");
170
        outMsg.writeInt8(0, "unknown");
171
    }
172
    else if (packetVersion >= 20041129)
173
    {
174
        outMsg.writeInt8(0, "unknown");
175
    }
176
    else if (packetVersion >= 20041025)
177
    {
178
        outMsg.writeInt8(0, "unknown");
179
        outMsg.writeInt8(0, "unknown");
180
        outMsg.writeInt8(0, "unknown");
181
    }
182
    else if (packetVersion >= 20041005)
183
    {
184
        outMsg.writeInt8(0, "unknown");
185
        outMsg.writeInt8(0, "unknown");
186
        outMsg.writeInt8(0, "unknown");
187
        outMsg.writeInt8(0, "unknown");
188
    }
189
    else if (packetVersion >= 20040920)
190
    {
191
        outMsg.writeInt16(0, "unknown");
192
        outMsg.writeInt16(0, "unknown");
193
        outMsg.writeInt8(0, "unknown");
194
        outMsg.writeInt8(0, "unknown");
195
        outMsg.writeInt8(0, "unknown");
196
        outMsg.writeInt8(0, "unknown");
197
    }
198
    else if (packetVersion >= 20040906)
199
    {
200
        outMsg.writeInt16(0, "unknown");
201
        outMsg.writeInt8(0, "unknown");
202
        outMsg.writeInt8(0, "unknown");
203
        outMsg.writeInt8(0, "unknown");
204
    }
205
    else if (packetVersion >= 20040809)
206
    {
207
        outMsg.writeInt16(0, "unknown");
208
        outMsg.writeInt16(0, "unknown");
209
        outMsg.writeInt8(0, "unknown");
210
        outMsg.writeInt8(0, "unknown");
211
        outMsg.writeInt8(0, "unknown");
212
    }
213
    else if (packetVersion >= 20040726)
214
    {
215
        outMsg.writeInt16(0, "unknown");
216
        outMsg.writeInt16(0, "unknown");
217
    }
218
    outMsg.writeInt32(tick, "tick");
219
}
220
221
void GameHandler::disconnect2() const
222
{
223
    createOutPacket(CMSG_CLIENT_QUIT);
224
}
225
226
4
}  // namespace EAthena