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