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