GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/gamehandler.cpp Lines: 1 108 0.9 %
Date: 2019-10-15 Branches: 0 170 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-2019  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
extern int packetVersionMain;
44
extern int packetVersionRe;
45
extern int packetVersionZero;
46
47
namespace EAthena
48
{
49
50
extern ServerInfo mapServer;
51
52
GameHandler::GameHandler() :
53
    Ea::GameHandler()
54
{
55
    gameHandler = this;
56
}
57
58
GameHandler::~GameHandler()
59
{
60
    gameHandler = nullptr;
61
}
62
63
void GameHandler::mapLoadedEvent() const
64
{
65
    createOutPacket(CMSG_MAP_LOADED);
66
}
67
68
void GameHandler::connect() const
69
{
70
    if (Network::mInstance == nullptr)
71
        return;
72
73
    Network::mInstance->connect(mapServer);
74
75
    const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
76
77
78
    if (client->getState() == State::CONNECT_GAME)
79
    {
80
        // Change the player's ID to the account ID to match what eAthena uses
81
        if (localPlayer != nullptr)
82
        {
83
            Ea::GameRecv::mCharID = localPlayer->getId();
84
            localPlayer->setId(token.account_ID);
85
        }
86
        else
87
        {
88
            Ea::GameRecv::mCharID = BeingId_zero;
89
        }
90
    }
91
92
    // Send login infos
93
    createOutPacket(CMSG_MAP_SERVER_CONNECT);
94
    outMsg.writeBeingId(token.account_ID, "account id");
95
    outMsg.writeBeingId(Ea::GameRecv::mCharID, "char id");
96
    outMsg.writeInt32(token.session_ID1, "session key1");
97
    outMsg.writeInt32(0, "tick");
98
    outMsg.writeInt8(Being::genderToInt(token.sex), "sex");
99
    if (serverFeatures->haveMapServerVersion())
100
        loginHandler->sendVersion();
101
102
    // We get 4 useless bytes before the real answer comes in (what are these?)
103
//    Network::mInstance->skip(4);
104
}
105
106
bool GameHandler::isConnected() const
107
{
108
    if (Network::mInstance == nullptr)
109
        return false;
110
    return Network::mInstance->isConnected();
111
}
112
113
void GameHandler::disconnect() const
114
{
115
    if (Network::mInstance != nullptr)
116
        Network::mInstance->disconnect();
117
}
118
119
void GameHandler::quit() const
120
{
121
    createOutPacket(CMSG_CLIENT_QUIT);
122
}
123
124
void GameHandler::ping(const int tick) const
125
{
126
    createOutPacket(CMSG_MAP_PING);
127
    if (packetVersion >= 20101124)
128
    {
129
        // nothing here
130
    }
131
    else if (packetVersion >= 20080827)
132
    {
133
        outMsg.writeInt16(0, "unknown");
134
        outMsg.writeInt8(0, "unknown");
135
        outMsg.writeInt8(0, "unknown");
136
        outMsg.writeInt8(0, "unknown");
137
    }
138
    else if (packetVersion >= 20070212)
139
    {
140
        outMsg.writeInt16(0, "unknown");
141
    }
142
    else if (packetVersion >= 20070108)
143
    {
144
        outMsg.writeInt16(0, "unknown");
145
        outMsg.writeInt16(0, "unknown");
146
        outMsg.writeInt8(0, "unknown");
147
    }
148
    else if (packetVersion >= 20050719)
149
    {
150
        outMsg.writeInt16(0, "unknown");
151
        outMsg.writeInt16(0, "unknown");
152
        outMsg.writeInt16(0, "unknown");
153
        outMsg.writeInt8(0, "unknown");
154
    }
155
    else if (packetVersion >= 20050718)
156
    {
157
        outMsg.writeInt8(0, "unknown");
158
    }
159
    else if (packetVersion >= 20050628)
160
    {
161
        outMsg.writeInt16(0, "unknown");
162
        outMsg.writeInt16(0, "unknown");
163
        outMsg.writeInt16(0, "unknown");
164
        outMsg.writeInt8(0, "unknown");
165
    }
166
    else if (packetVersion >= 20050509)
167
    {
168
        outMsg.writeInt16(0, "unknown");
169
    }
170
    else if (packetVersion >= 20050110)
171
    {
172
        outMsg.writeInt16(0, "unknown");
173
        outMsg.writeInt8(0, "unknown");
174
    }
175
    else if (packetVersion >= 20041129)
176
    {
177
        outMsg.writeInt8(0, "unknown");
178
    }
179
    else if (packetVersion >= 20041025)
180
    {
181
        outMsg.writeInt8(0, "unknown");
182
        outMsg.writeInt8(0, "unknown");
183
        outMsg.writeInt8(0, "unknown");
184
    }
185
    else if (packetVersion >= 20041005)
186
    {
187
        outMsg.writeInt8(0, "unknown");
188
        outMsg.writeInt8(0, "unknown");
189
        outMsg.writeInt8(0, "unknown");
190
        outMsg.writeInt8(0, "unknown");
191
    }
192
    else if (packetVersion >= 20040920)
193
    {
194
        outMsg.writeInt16(0, "unknown");
195
        outMsg.writeInt16(0, "unknown");
196
        outMsg.writeInt8(0, "unknown");
197
        outMsg.writeInt8(0, "unknown");
198
        outMsg.writeInt8(0, "unknown");
199
        outMsg.writeInt8(0, "unknown");
200
    }
201
    else if (packetVersion >= 20040906)
202
    {
203
        outMsg.writeInt16(0, "unknown");
204
        outMsg.writeInt8(0, "unknown");
205
        outMsg.writeInt8(0, "unknown");
206
        outMsg.writeInt8(0, "unknown");
207
    }
208
    else if (packetVersion >= 20040809)
209
    {
210
        outMsg.writeInt16(0, "unknown");
211
        outMsg.writeInt16(0, "unknown");
212
        outMsg.writeInt8(0, "unknown");
213
        outMsg.writeInt8(0, "unknown");
214
        outMsg.writeInt8(0, "unknown");
215
    }
216
    else if (packetVersion >= 20040726)
217
    {
218
        outMsg.writeInt16(0, "unknown");
219
        outMsg.writeInt16(0, "unknown");
220
    }
221
    outMsg.writeInt32(tick, "tick");
222
}
223
224
void GameHandler::disconnect2() const
225
{
226
    createOutPacket(CMSG_CLIENT_QUIT);
227
}
228
229
void GameHandler::reqRemainTime() const
230
{
231
    createOutPacket(CMSG_REQ_REMAIN_TIME);
232
}
233
234
void GameHandler::ping2() const
235
{
236
    if (packetVersionMain < 20190227 &&
237
        packetVersionRe < 20190220 &&
238
        packetVersionZero < 20190220)
239
    {
240
        return;
241
    }
242
    createOutPacket(CMSG_MAP_PING2);
243
}
244
245
2
}  // namespace EAthena