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-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 
24 
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 
51 {
52  charServerHandler = this;
53 }
54 
56 {
57  charServerHandler = nullptr;
58 }
59 
61 {
62  if (character == nullptr)
63  return;
64 
65  mSelectedCharacter = character;
66  mCharSelectDialog = nullptr;
67 
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 {
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 
94  const std::string &email A_UNUSED)
95  const
96 {
97  if (character == nullptr)
98  return;
99 
100  mSelectedCharacter = character;
101 
103  outMsg.writeBeingId(mSelectedCharacter->dummy->getId(), "id?");
104  outMsg.writeString("[email protected]", 40, "email");
105 }
106 
108 {
109  // This is really a map-server packet
111  outMsg.writeInt8(1, "flag");
112 }
113 
115 {
116  const Token &token =
117  static_cast<LoginHandler*>(loginHandler)->getToken();
118 
119  if (Network::mInstance == nullptr)
120  return;
121 
123  Network::mInstance->connect(charServer);
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?)
136 }
137 
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);
174 }
175 
177  const std::string &newName A_UNUSED)
178  const
179 {
180 }
181 
183  const int newSlot A_UNUSED) const
184 {
185 }
186 
188 {
189 }
190 
191 unsigned int CharServerHandler::hatSprite() const
192 {
193  return 7;
194 }
195 
196 } // namespace TmwAthena
#define _(s)
Definition: gettext.h:34
int CMSG_CHAR_CREATE
Definition: protocolout.cpp:35
#define CAST_U8
Definition: cast.h:26
static Network * mInstance
Definition: network.h:53
int CMSG_CHAR_SERVER_CONNECT
Definition: protocolout.cpp:33
BeingId getId() const
Definition: actorsprite.h:63
ServerInfo mapServer
int CMSG_CHAR_SELECT
Definition: protocolout.cpp:34
int BeingId
Definition: beingid.h:29
ServerInfo charServer
unsigned int hatSprite() const A_CONST
void setAttributes(const StringVect &labels, int available, const int min, const int max)
std::vector< std::string > StringVect
Definition: stringvector.h:28
static CharCreateDialog * mCharCreateDialog
Definition: token.h:29
static CharSelectDialog * mCharSelectDialog
void chooseCharacter(Net::Character *const character) const
void renameCharacter(const BeingId id, const std::string &newName) const
GenderT sex
Definition: token.h:43
static uint8_t genderToInt(const GenderT sex) A_CONST
Definition: being.h:920
uint16_t slot
Definition: character.h:57
unsigned getMaxStat()
Definition: chardb.cpp:156
Net::LoginHandler * loginHandler
Definition: net.cpp:83
bool connect(const ServerInfo &server)
Definition: network.cpp:100
unsigned getMinStat()
Definition: chardb.cpp:151
#define CLIENT_PROTOCOL_VERSION
Definition: network.h:32
void disconnect()
Definition: network.cpp:138
unsigned getSumStat()
Definition: chardb.cpp:161
#define CAST_S8
Definition: cast.h:25
void deleteCharacter(Net::Character *const character, const std::string &email) const
BeingId account_ID
Definition: token.h:40
#define createOutPacket(name)
Definition: messageout.h:36
Gender ::T GenderT
Definition: gender.h:35
#define A_UNUSED
Definition: localconsts.h:171
void setDefaultGender(const GenderT gender)
void skip(const int len)
Definition: network.cpp:180
void changeSlot(const int oldSlot, const int newSlot) const
static Net::Character * mSelectedCharacter
int CMSG_CHAR_DELETE
Definition: protocolout.cpp:36
int CMSG_PLAYER_RESTART
Definition: protocolout.cpp:63
Net::CharServerHandler * charServerHandler
Definition: net.cpp:79
LocalPlayer * dummy
Definition: character.h:55
void setCharCreateDialog(CharCreateDialog *const window) const
int session_ID1
Definition: token.h:41
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
int session_ID2
Definition: token.h:42