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