GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/loginhandler.cpp Lines: 0 66 0.0 %
Date: 2017-11-29 Branches: 0 96 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-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/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
namespace EAthena
39
{
40
41
extern ServerInfo charServer;
42
43
LoginHandler::LoginHandler() :
44
    Ea::LoginHandler()
45
{
46
    loginHandler = this;
47
}
48
49
LoginHandler::~LoginHandler()
50
{
51
    loginHandler = nullptr;
52
}
53
54
void LoginHandler::connect() const
55
{
56
    if (Network::mInstance == nullptr)
57
        return;
58
59
    Network::mInstance->connect(mServer);
60
    if (serverFeatures->haveServerVersion())
61
    {
62
        sendVersion();
63
    }
64
    else
65
    {
66
        if (client->getState() != State::LOGIN)
67
            client->setState(State::LOGIN);
68
    }
69
}
70
71
bool LoginHandler::isConnected() const
72
{
73
    if (Network::mInstance == nullptr)
74
        return false;
75
76
    return Network::mInstance->isConnected();
77
}
78
79
void LoginHandler::disconnect() const
80
{
81
    if (Network::mInstance != nullptr &&
82
        Network::mInstance->getServer() == mServer)
83
    {
84
        Network::mInstance->disconnect();
85
    }
86
}
87
88
void LoginHandler::changePassword(const std::string &restrict oldPassword,
89
                                  const std::string &restrict newPassword)
90
                                  const
91
{
92
    if (serverVersion == 0)
93
        return;
94
    createOutPacket(CMSG_CHAR_PASSWORD_CHANGE);
95
    outMsg.writeStringNoLog(oldPassword, 24, "old password");
96
    outMsg.writeStringNoLog(newPassword, 24, "new password");
97
}
98
99
void LoginHandler::sendLoginRegister(const std::string &restrict username,
100
                                     const std::string &restrict password,
101
                                     const std::string &restrict email) const
102
{
103
    if (email.empty())
104
    {
105
        if (Net::getNetworkType() == ServerType::EATHENA)
106
        {
107
            createOutPacket(CMSG_LOGIN_REGISTER_HAN);
108
            outMsg.writeInt32(20, "client version");
109
            outMsg.writeString(username, 24, "login");
110
            outMsg.writeStringNoLog(password, 24, "password");
111
            outMsg.writeInt8(0x03, "client type");
112
            outMsg.writeString("127.0.0.1", 16, "ip address");
113
            outMsg.writeString("001122334455", 13, "mac address");
114
            outMsg.writeInt8(0, "is gravity id");
115
        }
116
        else
117
        {
118
            createOutPacket(CMSG_LOGIN_REGISTER);
119
            outMsg.writeInt32(20, "client version");
120
            outMsg.writeString(username, 24, "login");
121
            outMsg.writeStringNoLog(password, 24, "password");
122
            outMsg.writeInt8(0x03, "client type");
123
        }
124
    }
125
    else
126
    {
127
        createOutPacket(CMSG_LOGIN_REGISTER4);
128
        outMsg.writeString(username, 24, "login");
129
        outMsg.writeStringNoLog(password, 24, "password");
130
        outMsg.writeInt8(0x03, "client type");
131
        outMsg.writeString(email, 40, "email");
132
    }
133
}
134
135
ServerInfo *LoginHandler::getCharServer() const
136
{
137
    return &charServer;
138
}
139
140
void LoginHandler::sendVersion() const
141
{
142
    createOutPacket(CMSG_SERVER_VERSION_REQUEST);
143
    outMsg.writeInt32(CLIENT_PROTOCOL_VERSION, "protocol version");
144
    outMsg.writeInt32(0, "unused");
145
    outMsg.writeInt32(0, "unused");
146
    outMsg.writeInt32(0, "unused");
147
    outMsg.writeInt32(0, "unused");
148
    generalHandler->flushSend();
149
}
150
151
void LoginHandler::ping() const
152
{
153
    createOutPacket(CMSG_LOGIN_PING);
154
    outMsg.writeInt32(0, "unused");
155
    outMsg.writeInt32(0, "unused");
156
    outMsg.writeInt32(0, "unused");
157
    outMsg.writeInt32(0, "unused");
158
    outMsg.writeInt32(0, "unused");
159
    outMsg.writeInt32(0, "unused");
160
}
161
162
void LoginHandler::updatePacketVersion() const
163
{
164
    updateProtocol();
165
}
166
167
}  // namespace EAthena