GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/loginhandler.cpp Lines: 0 81 0.0 %
Date: 2019-06-27 Branches: 0 118 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-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/loginhandler.h"
24
25
#include "client.h"
26
27
#include "net/generalhandler.h"
28
#include "net/net.h"
29
#include "net/serverfeatures.h"
30
31
#include "net/eathena/messageout.h"
32
#include "net/eathena/network.h"
33
#include "net/eathena/updateprotocol.h"
34
#include "net/eathena/protocolout.h"
35
36
#include "debug.h"
37
38
extern int packetVersionMain;
39
extern int packetVersionRe;
40
extern bool packets_zero;
41
42
namespace EAthena
43
{
44
45
extern ServerInfo charServer;
46
47
LoginHandler::LoginHandler() :
48
    Ea::LoginHandler()
49
{
50
    loginHandler = this;
51
}
52
53
LoginHandler::~LoginHandler()
54
{
55
    loginHandler = nullptr;
56
}
57
58
void LoginHandler::connect() const
59
{
60
    if (Network::mInstance == nullptr)
61
        return;
62
63
    Network::mInstance->connect(mServer);
64
    if (serverFeatures->haveServerVersion())
65
    {
66
        sendVersion();
67
    }
68
    else
69
    {
70
        if (client->getState() != State::LOGIN)
71
            client->setState(State::LOGIN);
72
    }
73
}
74
75
bool LoginHandler::isConnected() const
76
{
77
    if (Network::mInstance == nullptr)
78
        return false;
79
80
    return Network::mInstance->isConnected();
81
}
82
83
void LoginHandler::disconnect() const
84
{
85
    if (Network::mInstance != nullptr &&
86
        Network::mInstance->getServer() == mServer)
87
    {
88
        Network::mInstance->disconnect();
89
    }
90
}
91
92
void LoginHandler::changePassword(const std::string &restrict oldPassword,
93
                                  const std::string &restrict newPassword)
94
                                  const
95
{
96
    if (serverVersion == 0)
97
        return;
98
    createOutPacket(CMSG_CHAR_PASSWORD_CHANGE);
99
    outMsg.writeStringNoLog(oldPassword, 24, "old password");
100
    outMsg.writeStringNoLog(newPassword, 24, "new password");
101
}
102
103
void LoginHandler::sendLoginRegister(const std::string &restrict username,
104
                                     const std::string &restrict password,
105
                                     const std::string &restrict email) const
106
{
107
    if (email.empty())
108
    {
109
        if (Net::getNetworkType() == ServerType::EATHENA)
110
        {
111
            createOutPacket(CMSG_LOGIN_REGISTER_HAN);
112
            outMsg.writeInt32(20, "client version");
113
            outMsg.writeString(username, 24, "login");
114
            outMsg.writeStringNoLog(password, 24, "password");
115
            outMsg.writeInt8(0x03, "client type");
116
            outMsg.writeString("127.0.0.1", 16, "ip address");
117
            outMsg.writeString("001122334455", 13, "mac address");
118
            outMsg.writeInt8(0, "is gravity id");
119
        }
120
        else
121
        {
122
            createOutPacket(CMSG_LOGIN_REGISTER);
123
            outMsg.writeInt32(20, "client version");
124
            outMsg.writeString(username, 24, "login");
125
            outMsg.writeStringNoLog(password, 24, "password");
126
            outMsg.writeInt8(0x03, "client type");
127
        }
128
    }
129
    else
130
    {
131
        createOutPacket(CMSG_LOGIN_REGISTER4);
132
        outMsg.writeString(username, 24, "login");
133
        outMsg.writeStringNoLog(password, 24, "password");
134
        outMsg.writeInt8(0x03, "client type");
135
        outMsg.writeString(email, 40, "email");
136
    }
137
}
138
139
ServerInfo *LoginHandler::getCharServer() const
140
{
141
    return &charServer;
142
}
143
144
void LoginHandler::sendVersion() const
145
{
146
    createOutPacket(CMSG_SERVER_VERSION_REQUEST);
147
    outMsg.writeInt32(CLIENT_PROTOCOL_VERSION, "protocol version");
148
    outMsg.writeInt32(0, "unused");
149
    outMsg.writeInt32(0, "unused");
150
    outMsg.writeInt32(0, "unused");
151
    outMsg.writeInt32(0, "unused");
152
    generalHandler->flushSend();
153
}
154
155
void LoginHandler::ping() const
156
{
157
    createOutPacket(CMSG_LOGIN_PING);
158
    outMsg.writeInt32(0, "unused");
159
    outMsg.writeInt32(0, "unused");
160
    outMsg.writeInt32(0, "unused");
161
    outMsg.writeInt32(0, "unused");
162
    outMsg.writeInt32(0, "unused");
163
    outMsg.writeInt32(0, "unused");
164
}
165
166
void LoginHandler::updatePacketVersion() const
167
{
168
    updateProtocol();
169
}
170
171
void LoginHandler::sendMobileCode(const BeingId accountId,
172
                                  const std::string &code) const
173
{
174
    if (packetVersionMain < 20181114 &&
175
        packetVersionRe < 20181114)
176
    {
177
        return;
178
    }
179
    createOutPacket(CMSG_LOGIN_MOBILE_OTP);
180
    outMsg.writeInt16(14, "len");
181
    outMsg.writeBeingId(accountId, "account id");
182
    outMsg.writeStringNoLog(code, 6, "code");
183
}
184
185
void LoginHandler::sendOtpCode(const std::string &code) const
186
{
187
    if (packetVersionMain < 20181114 &&
188
        packetVersionRe < 20181114 &&
189
        packets_zero == false)
190
    {
191
        return;
192
    }
193
    createOutPacket(CMSG_LOGIN_OTP_CODE);
194
    outMsg.writeStringNoLog(code, 9, "code");
195
}
196
197
}  // namespace EAthena