GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/charserverhandler.cpp Lines: 1 75 1.3 %
Date: 2017-11-29 Branches: 0 86 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/charserverhandler.h"
24
25
#include "gui/windows/charcreatedialog.h"
26
27
#include "net/character.h"
28
29
#include "net/ea/token.h"
30
31
#include "net/tmwa/loginhandler.h"
32
#include "net/tmwa/messageout.h"
33
#include "net/tmwa/network.h"
34
#include "net/tmwa/protocolout.h"
35
36
#include "resources/db/chardb.h"
37
38
#include "utils/gettext.h"
39
40
#include "debug.h"
41
42
namespace TmwAthena
43
{
44
45
extern ServerInfo mapServer;
46
47
extern ServerInfo charServer;
48
49
CharServerHandler::CharServerHandler() :
50
    Ea::CharServerHandler()
51
{
52
    charServerHandler = this;
53
}
54
55
CharServerHandler::~CharServerHandler()
56
{
57
    charServerHandler = nullptr;
58
}
59
60
void CharServerHandler::chooseCharacter(Net::Character *const character) const
61
{
62
    if (character == nullptr)
63
        return;
64
65
    mSelectedCharacter = character;
66
    mCharSelectDialog = nullptr;
67
68
    createOutPacket(CMSG_CHAR_SELECT);
69
    outMsg.writeInt8(CAST_U8(mSelectedCharacter->slot),
70
        "slot");
71
}
72
73
void CharServerHandler::newCharacter(const std::string &name, const int slot,
74
                                     const GenderT gender A_UNUSED,
75
                                     const int hairstyle,
76
                                     const int hairColor,
77
                                     const unsigned char race A_UNUSED,
78
                                     const uint16_t look A_UNUSED,
79
                                     const STD_VECTOR<int> &stats) const
80
{
81
    createOutPacket(CMSG_CHAR_CREATE);
82
    outMsg.writeString(name, 24, "name");
83
    for (int i = 0; i < 6; i++)
84
        outMsg.writeInt8(CAST_U8(stats[i]), "stat");
85
86
    outMsg.writeInt8(CAST_U8(slot), "slot");
87
    outMsg.writeInt8(CAST_S8(hairColor), "hair color");
88
    outMsg.writeInt8(0, "unused");
89
    outMsg.writeInt8(CAST_S8(hairstyle), "hair style");
90
    outMsg.writeInt8(0, "unused");
91
}
92
93
void CharServerHandler::deleteCharacter(Net::Character *const character,
94
                                        const std::string &email A_UNUSED)
95
                                        const
96
{
97
    if (character == nullptr)
98
        return;
99
100
    mSelectedCharacter = character;
101
102
    createOutPacket(CMSG_CHAR_DELETE);
103
    outMsg.writeBeingId(mSelectedCharacter->dummy->getId(), "id?");
104
    outMsg.writeString("[email protected]", 40, "email");
105
}
106
107
void CharServerHandler::switchCharacter() const
108
{
109
    // This is really a map-server packet
110
    createOutPacket(CMSG_PLAYER_RESTART);
111
    outMsg.writeInt8(1, "flag");
112
}
113
114
void CharServerHandler::connect() const
115
{
116
    const Token &token =
117
        static_cast<LoginHandler*>(loginHandler)->getToken();
118
119
    if (Network::mInstance == nullptr)
120
        return;
121
122
    Network::mInstance->disconnect();
123
    Network::mInstance->connect(charServer);
124
    createOutPacket(CMSG_CHAR_SERVER_CONNECT);
125
    outMsg.writeBeingId(token.account_ID, "account id");
126
    outMsg.writeInt32(token.session_ID1, "session id1");
127
    outMsg.writeInt32(token.session_ID2, "session id2");
128
    // [Fate] The next word is unused by the old char server, so we squeeze in
129
    //        mana client version information
130
    outMsg.writeInt16(CLIENT_PROTOCOL_VERSION,
131
        "client protocol version");
132
    outMsg.writeInt8(Being::genderToInt(token.sex), "gender");
133
134
    // We get 4 useless bytes before the real answer comes in (what are these?)
135
    Network::mInstance->skip(4);
136
}
137
138
void CharServerHandler::setCharCreateDialog(CharCreateDialog *const window)
139
                                            const
140
{
141
    mCharCreateDialog = window;
142
143
    if (mCharCreateDialog == nullptr)
144
        return;
145
146
    StringVect attributes;
147
    // TRANSLATORS: playe stat
148
    attributes.push_back(_("Strength:"));
149
    // TRANSLATORS: playe stat
150
    attributes.push_back(_("Agility:"));
151
    // TRANSLATORS: playe stat
152
    attributes.push_back(_("Vitality:"));
153
    // TRANSLATORS: playe stat
154
    attributes.push_back(_("Intelligence:"));
155
    // TRANSLATORS: playe stat
156
    attributes.push_back(_("Dexterity:"));
157
    // TRANSLATORS: playe stat
158
    attributes.push_back(_("Luck:"));
159
160
    const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
161
162
    int minStat = CharDB::getMinStat();
163
    if (minStat == 0)
164
        minStat = 1;
165
    int maxStat = CharDB::getMaxStat();
166
    if (maxStat == 0)
167
        maxStat = 9;
168
    int sumStat = CharDB::getSumStat();
169
    if (sumStat == 0)
170
        sumStat = 30;
171
172
    mCharCreateDialog->setAttributes(attributes, sumStat, minStat, maxStat);
173
    mCharCreateDialog->setDefaultGender(token.sex);
174
}
175
176
void CharServerHandler::renameCharacter(const BeingId id A_UNUSED,
177
                                        const std::string &newName A_UNUSED)
178
                                        const
179
{
180
}
181
182
void CharServerHandler::changeSlot(const int oldSlot A_UNUSED,
183
                                   const int newSlot A_UNUSED) const
184
{
185
}
186
187
void CharServerHandler::ping() const
188
{
189
}
190
191
unsigned int CharServerHandler::hatSprite() const
192
{
193
    return 7;
194
}
195
196
4
}  // namespace TmwAthena