ManaPlus
loginrecv.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 
24 #include "net/ea/loginrecv.h"
25 
26 #include "client.h"
27 
28 #include "fs/paths.h"
29 
31 
32 #include "utils/gettext.h"
33 
34 #include "net/logindata.h"
35 #include "net/messagein.h"
36 
37 #include "debug.h"
38 
39 namespace Ea
40 {
41 
42 namespace LoginRecv
43 {
44  std::string mUpdateHost;
47  bool mVersionResponse = false;
48  bool mRegistrationEnabled = true;
49 } // namespace LoginRecv
50 
52 {
53  const int len = msg.readInt16("len") - 4;
54  mUpdateHost = msg.readString(len, "update host");
55 
56  if (!checkPath(mUpdateHost))
57  {
58  mUpdateHost.clear();
59  logger->log1("Warning: incorrect update server name");
60  }
62 
63  logger->log("Received update host \"%s\" from login server.",
64  mUpdateHost.c_str());
65 }
66 
68 {
69  const uint8_t code = msg.readUInt8("error");
70  logger->log("Login::error code: %u", CAST_U32(code));
71  std::string date = msg.readString(20, "date");
72 
73  switch (code)
74  {
75  case 0:
76  // TRANSLATORS: error message
77  errorMessage = _("Unregistered ID.");
78  break;
79  case 1:
80  // TRANSLATORS: error message
81  errorMessage = _("Wrong password.");
83  break;
84  case 2:
85  // TRANSLATORS: error message
86  errorMessage = _("Account expired.");
87  break;
88  case 3:
89  // TRANSLATORS: error message
90  errorMessage = _("Rejected from server.");
91  break;
92  case 4:
93  // TRANSLATORS: error message
94  errorMessage = _("You have been permanently banned from "
95  "the game. Please contact the GM team.");
96  break;
97  case 5:
98  // TRANSLATORS: error message
99  errorMessage = _("Client too old or wrong server type.\n"
100  "Please update client on http://manaplus.org");
101  break;
102  case 6:
103  // TRANSLATORS: error message
104  errorMessage = strprintf(_("You have been temporarily "
105  "banned from the game until %s.\nPlease contact the GM "
106  "team via the forums."), date.c_str());
107  break;
108  case 7:
109  // TRANSLATORS: error message
110  errorMessage = _("Server overpopulated.");
111  break;
112  case 9:
113  // TRANSLATORS: error message
114  errorMessage = _("This user name is already taken.");
115  break;
116  case 10:
117  // TRANSLATORS: error message
118  errorMessage = _("Wrong name.");
119  break;
120  case 11:
121  // TRANSLATORS: error message
122  errorMessage = _("Incorrect email.");
123  break;
124  case 99:
125  // TRANSLATORS: error message
126  errorMessage = _("Username permanently erased.");
127  break;
128  default:
129  // TRANSLATORS: error message
130  errorMessage = _("Unknown error.");
131  break;
132  }
134 }
135 
136 } // namespace Ea
#define CAST_U32
Definition: cast.h:31
void setState(const StateT state)
Definition: client.h:66
void log(const char *const log_text,...)
Definition: logger.cpp:269
void log1(const char *const log_text)
Definition: logger.cpp:238
std::string updateHost
Definition: logindata.h:62
static std::string savedPassword
Definition: logindialog.h:80
Client * client
Definition: client.cpp:118
std::string errorMessage
Definition: client.cpp:116
#define _(s)
Definition: gettext.h:35
Logger * logger
Definition: logger.cpp:89
LoginData loginData
Definition: client.cpp:185
bool msg(InputEvent &event)
Definition: chat.cpp:39
void processLoginError(Net::MessageIn &msg)
Definition: loginrecv.cpp:67
bool mVersionResponse
Definition: loginrecv.cpp:47
bool mRegistrationEnabled
Definition: loginrecv.cpp:48
std::string mUpdateHost
Definition: loginrecv.cpp:44
Worlds mWorlds
Definition: loginrecv.cpp:45
void processUpdateHost(Net::MessageIn &msg)
Definition: loginrecv.cpp:51
@ ERROR
Definition: state.h:35
bool checkPath(const std::string &path)
Definition: paths.cpp:121
std::string strprintf(const char *const format,...)
Definition: token.h:31
std::vector< WorldInfo * > Worlds
Definition: worldinfo.h:59