GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/loginhandler.cpp Lines: 0 39 0.0 %
Date: 2021-03-17 Branches: 0 40 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
 *  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/tmwa/loginhandler.h"
25
26
#include "net/serverfeatures.h"
27
28
#include "net/ea/loginrecv.h"
29
30
#include "net/tmwa/messageout.h"
31
#include "net/tmwa/network.h"
32
#include "net/tmwa/protocolout.h"
33
34
#include "debug.h"
35
36
extern unsigned int tmwServerVersion;
37
extern int itemIdLen;
38
39
namespace TmwAthena
40
{
41
42
extern ServerInfo charServer;
43
44
LoginHandler::LoginHandler() :
45
    Ea::LoginHandler()
46
{
47
    loginHandler = this;
48
}
49
50
LoginHandler::~LoginHandler()
51
{
52
    loginHandler = nullptr;
53
}
54
55
void LoginHandler::connect() const
56
{
57
    if (Network::mInstance == nullptr)
58
        return;
59
60
    Network::mInstance->connect(mServer);
61
    if (serverFeatures->haveServerVersion())
62
    {
63
        createOutPacket(CMSG_SERVER_VERSION_REQUEST);
64
    }
65
}
66
67
bool LoginHandler::isConnected() const
68
{
69
    if (Network::mInstance == nullptr)
70
        return false;
71
72
    return Ea::LoginRecv::mVersionResponse &&
73
        Network::mInstance->isConnected();
74
}
75
76
void LoginHandler::disconnect() const
77
{
78
    if (Network::mInstance != nullptr &&
79
        Network::mInstance->getServer() == mServer)
80
    {
81
        Network::mInstance->disconnect();
82
    }
83
}
84
85
void LoginHandler::changePassword(const std::string &restrict oldPassword,
86
                                  const std::string &restrict newPassword)
87
                                  const
88
{
89
    createOutPacket(CMSG_CHAR_PASSWORD_CHANGE);
90
    outMsg.writeStringNoLog(oldPassword, 24, "old password");
91
    outMsg.writeStringNoLog(newPassword, 24, "new password");
92
}
93
94
void LoginHandler::sendLoginRegister(const std::string &restrict username,
95
                                     const std::string &restrict password,
96
                                     const std::string &restrict email
97
                                     A_UNUSED) const
98
{
99
    createOutPacket(CMSG_LOGIN_REGISTER);
100
    if (tmwServerVersion < 0x100408)
101
    {
102
        // hack to avoid bug in tmwa...
103
        outMsg.writeInt32(5,
104
            "client protocol version");
105
    }
106
    else
107
    {
108
        outMsg.writeInt32(CLIENT_PROTOCOL_VERSION,
109
            "client protocol version");
110
    }
111
    outMsg.writeString(username, 24, "login");
112
    outMsg.writeStringNoLog(password, 24, "password");
113
114
    /*
115
     * eAthena calls the last byte "client version 2", but it isn't used at
116
     * at all. We're retasking it, as a bit mask:
117
     *  0 - can handle the 0x63 "update host" packet
118
     *  1 - defaults to the first char-server (instead of the last)
119
     */
120
    outMsg.writeInt8(0x03, "flags");
121
}
122
123
ServerInfo *LoginHandler::getCharServer() const
124
{
125
    return &charServer;
126
}
127
128
void LoginHandler::requestUpdateHosts()
129
{
130
}
131
132
void LoginHandler::sendVersion() const
133
{
134
}
135
136
void LoginHandler::ping() const
137
{
138
}
139
140
void LoginHandler::updatePacketVersion() const
141
{
142
    itemIdLen = 2;
143
}
144
145
void LoginHandler::sendMobileCode(const BeingId accountId A_UNUSED,
146
                                  const std::string &code A_UNUSED) const
147
{
148
}
149
150
void LoginHandler::sendOtpCode(const std::string &code A_UNUSED) const
151
{
152
}
153
154
}  // namespace TmwAthena