ManaPlus
charserverhandler.cpp
Go to the documentation of this file.
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 
25 
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 
52 {
53  charServerHandler = this;
54 }
55 
57 {
58  charServerHandler = nullptr;
59 }
60 
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 
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 
109 {
110  // This is really a map-server packet
111  createOutPacket(CMSG_PLAYER_RESTART);
112  outMsg.writeInt8(1, "flag");
113 }
114 
116 {
117  const Token &token =
118  static_cast<LoginHandler*>(loginHandler)->getToken();
119 
120  if (Network::mInstance == nullptr)
121  return;
122 
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?)
137 }
138 
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);
175 }
176 
178  const std::string &newName A_UNUSED)
179  const
180 {
181 }
182 
184  const int newSlot A_UNUSED) const
185 {
186 }
187 
189 {
190 }
191 
192 unsigned int CharServerHandler::hatSprite() const
193 {
194  return 7;
195 }
196 
197 } // namespace TmwAthena
int BeingId
Definition: beingid.h:30
#define CAST_S8
Definition: cast.h:26
#define CAST_U8
Definition: cast.h:27
Net::CharServerHandler * charServerHandler
Definition: net.cpp:85
BeingId getId() const
Definition: actorsprite.h:64
static uint8_t genderToInt(const GenderT sex) A_CONST
Definition: being.h:927
void setDefaultGender(const GenderT gender)
void setAttributes(const StringVect &labels, int available, const int min, const int max)
bool connect(const ServerInfo &server)
Definition: network.cpp:101
void skip(const int len)
Definition: network.cpp:181
void disconnect()
Definition: network.cpp:139
static Net::Character * mSelectedCharacter
static CharSelectDialog * mCharSelectDialog
static CharCreateDialog * mCharCreateDialog
void changeSlot(const int oldSlot, const int newSlot) const
void setCharCreateDialog(CharCreateDialog *const window) const
void chooseCharacter(Net::Character *const character) const
unsigned int hatSprite() const A_CONST
void renameCharacter(const BeingId id, const std::string &newName) const
void newCharacter(const std::string &name, const int slot, const GenderT gender, const int hairstyle, const int hairColor, const unsigned char race, const uint16_t look, const std::vector< int > &stats) const
void deleteCharacter(Net::Character *const character, const std::string &email) const
static Network * mInstance
Definition: network.h:54
#define CLIENT_PROTOCOL_VERSION
Definition: network.h:33
Gender ::T GenderT
Definition: gender.h:35
#define _(s)
Definition: gettext.h:35
#define A_UNUSED
Definition: localconsts.h:160
Net::LoginHandler * loginHandler
Definition: net.cpp:90
#define createOutPacket(name)
Definition: messageout.h:37
unsigned getSumStat()
Definition: chardb.cpp:162
unsigned getMinStat()
Definition: chardb.cpp:152
unsigned getMaxStat()
Definition: chardb.cpp:157
ServerInfo mapServer
ServerInfo charServer
std::vector< std::string > StringVect
Definition: stringvector.h:29
LocalPlayer * dummy
Definition: character.h:56
uint16_t slot
Definition: character.h:58
Definition: token.h:31
int session_ID2
Definition: token.h:43
GenderT sex
Definition: token.h:44
BeingId account_ID
Definition: token.h:41
int session_ID1
Definition: token.h:42