GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/gamehandler.cpp Lines: 1 108 0.9 %
Date: 2021-03-17 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
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#include "net/eathena/gamehandler.h"
25
26
#include "client.h"
27
28
#include "being/localplayer.h"
29
30
#include "net/serverfeatures.h"
31
32
#include "net/ea/token.h"
33
34
#include "net/ea/gamerecv.h"
35
36
#include "net/eathena/loginhandler.h"
37
#include "net/eathena/messageout.h"
38
#include "net/eathena/network.h"
39
#include "net/eathena/protocolout.h"
40
41
#include "debug.h"
42
43
extern int packetVersion;
44
extern int packetVersionMain;
45
extern int packetVersionRe;
46
extern int packetVersionZero;
47
48
namespace EAthena
49
{
50
51
extern ServerInfo mapServer;
52
53
GameHandler::GameHandler() :
54
    Ea::GameHandler()
55
{
56
    gameHandler = this;
57
}
58
59
GameHandler::~GameHandler()
60
{
61
    gameHandler = nullptr;
62
}
63
64
void GameHandler::mapLoadedEvent() const
65
{
66
    createOutPacket(CMSG_MAP_LOADED);
67
}
68
69
void GameHandler::connect() const
70
{
71
    if (Network::mInstance == nullptr)
72
        return;
73
74
    Network::mInstance->connect(mapServer);
75
76
    const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
77
78
79
    if (client->getState() == State::CONNECT_GAME)
80
    {
81
        // Change the player's ID to the account ID to match what eAthena uses
82
        if (localPlayer != nullptr)
83
        {
84
            Ea::GameRecv::mCharID = localPlayer->getId();
85
            localPlayer->setId(token.account_ID);
86
        }
87
        else
88
        {
89
            Ea::GameRecv::mCharID = BeingId_zero;
90
        }
91
    }
92
93
    // Send login infos
94
    createOutPacket(CMSG_MAP_SERVER_CONNECT);
95
    outMsg.writeBeingId(token.account_ID, "account id");
96
    outMsg.writeBeingId(Ea::GameRecv::mCharID, "char id");
97
    outMsg.writeInt32(token.session_ID1, "session key1");
98
    outMsg.writeInt32(0, "tick");
99
    outMsg.writeInt8(Being::genderToInt(token.sex), "sex");
100
    if (serverFeatures->haveMapServerVersion())
101
        loginHandler->sendVersion();
102
103
    // We get 4 useless bytes before the real answer comes in (what are these?)
104
//    Network::mInstance->skip(4);
105
}
106
107
bool GameHandler::isConnected() const
108
{
109
    if (Network::mInstance == nullptr)
110
        return false;
111
    return Network::mInstance->isConnected();
112
}
113
114
void GameHandler::disconnect() const
115
{
116
    if (Network::mInstance != nullptr)
117
        Network::mInstance->disconnect();
118
}
119
120
void GameHandler::quit() const
121
{
122
    createOutPacket(CMSG_CLIENT_QUIT);
123
}
124
125
void GameHandler::ping(const int tick) const
126
{
127
    createOutPacket(CMSG_MAP_PING);
128
    if (packetVersion >= 20101124)
129
    {
130
        // nothing here
131
    }
132
    else if (packetVersion >= 20080827)
133
    {
134
        outMsg.writeInt16(0, "unknown");
135
        outMsg.writeInt8(0, "unknown");
136
        outMsg.writeInt8(0, "unknown");
137
        outMsg.writeInt8(0, "unknown");
138
    }
139
    else if (packetVersion >= 20070212)
140
    {
141
        outMsg.writeInt16(0, "unknown");
142
    }
143
    else if (packetVersion >= 20070108)
144
    {
145
        outMsg.writeInt16(0, "unknown");
146
        outMsg.writeInt16(0, "unknown");
147
        outMsg.writeInt8(0, "unknown");
148
    }
149
    else if (packetVersion >= 20050719)
150
    {
151
        outMsg.writeInt16(0, "unknown");
152
        outMsg.writeInt16(0, "unknown");
153
        outMsg.writeInt16(0, "unknown");
154
        outMsg.writeInt8(0, "unknown");
155
    }
156
    else if (packetVersion >= 20050718)
157
    {
158
        outMsg.writeInt8(0, "unknown");
159
    }
160
    else if (packetVersion >= 20050628)
161
    {
162
        outMsg.writeInt16(0, "unknown");
163
        outMsg.writeInt16(0, "unknown");
164
        outMsg.writeInt16(0, "unknown");
165
        outMsg.writeInt8(0, "unknown");
166
    }
167
    else if (packetVersion >= 20050509)
168
    {
169
        outMsg.writeInt16(0, "unknown");
170
    }
171
    else if (packetVersion >= 20050110)
172
    {
173
        outMsg.writeInt16(0, "unknown");
174
        outMsg.writeInt8(0, "unknown");
175
    }
176
    else if (packetVersion >= 20041129)
177
    {
178
        outMsg.writeInt8(0, "unknown");
179
    }
180
    else if (packetVersion >= 20041025)
181
    {
182
        outMsg.writeInt8(0, "unknown");
183
        outMsg.writeInt8(0, "unknown");
184
        outMsg.writeInt8(0, "unknown");
185
    }
186
    else if (packetVersion >= 20041005)
187
    {
188
        outMsg.writeInt8(0, "unknown");
189
        outMsg.writeInt8(0, "unknown");
190
        outMsg.writeInt8(0, "unknown");
191
        outMsg.writeInt8(0, "unknown");
192
    }
193
    else if (packetVersion >= 20040920)
194
    {
195
        outMsg.writeInt16(0, "unknown");
196
        outMsg.writeInt16(0, "unknown");
197
        outMsg.writeInt8(0, "unknown");
198
        outMsg.writeInt8(0, "unknown");
199
        outMsg.writeInt8(0, "unknown");
200
        outMsg.writeInt8(0, "unknown");
201
    }
202
    else if (packetVersion >= 20040906)
203
    {
204
        outMsg.writeInt16(0, "unknown");
205
        outMsg.writeInt8(0, "unknown");
206
        outMsg.writeInt8(0, "unknown");
207
        outMsg.writeInt8(0, "unknown");
208
    }
209
    else if (packetVersion >= 20040809)
210
    {
211
        outMsg.writeInt16(0, "unknown");
212
        outMsg.writeInt16(0, "unknown");
213
        outMsg.writeInt8(0, "unknown");
214
        outMsg.writeInt8(0, "unknown");
215
        outMsg.writeInt8(0, "unknown");
216
    }
217
    else if (packetVersion >= 20040726)
218
    {
219
        outMsg.writeInt16(0, "unknown");
220
        outMsg.writeInt16(0, "unknown");
221
    }
222
    outMsg.writeInt32(tick, "tick");
223
}
224
225
void GameHandler::disconnect2() const
226
{
227
    createOutPacket(CMSG_CLIENT_QUIT);
228
}
229
230
void GameHandler::reqRemainTime() const
231
{
232
    createOutPacket(CMSG_REQ_REMAIN_TIME);
233
}
234
235
void GameHandler::ping2() const
236
{
237
    if (packetVersionMain < 20190227 &&
238
        packetVersionRe < 20190220 &&
239
        packetVersionZero < 20190220)
240
    {
241
        return;
242
    }
243
    createOutPacket(CMSG_MAP_PING2);
244
}
245
246
2
}  // namespace EAthena