summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-06 02:15:54 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-06 02:15:54 +0300
commitd70cdbc7ab543988d16712a5981a54bd853620cc (patch)
tree46ecb257860ad2c12c3818abcb7c4a6c87d175ff /src
parent0d3b6da53db29cdf0ee2648fb9b0a02dd1d82dc8 (diff)
downloadmanaplus-d70cdbc7ab543988d16712a5981a54bd853620cc.tar.gz
manaplus-d70cdbc7ab543988d16712a5981a54bd853620cc.tar.bz2
manaplus-d70cdbc7ab543988d16712a5981a54bd853620cc.tar.xz
manaplus-d70cdbc7ab543988d16712a5981a54bd853620cc.zip
improve loginhandler class.
Diffstat (limited to 'src')
-rw-r--r--src/net/ea/loginhandler.cpp25
-rw-r--r--src/net/ea/loginhandler.h36
-rw-r--r--src/net/eathena/loginhandler.cpp18
-rw-r--r--src/net/eathena/loginhandler.h22
-rw-r--r--src/net/loginhandler.h20
-rw-r--r--src/net/tmwa/loginhandler.cpp18
-rw-r--r--src/net/tmwa/loginhandler.h22
7 files changed, 79 insertions, 82 deletions
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index 56538687f..ea4452528 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -50,18 +50,18 @@ LoginHandler::~LoginHandler()
delete_all(mWorlds);
}
-bool LoginHandler::isRegistrationEnabled()
+bool LoginHandler::isRegistrationEnabled() const
{
return mRegistrationEnabled;
}
-void LoginHandler::getRegistrationDetails()
+void LoginHandler::getRegistrationDetails() const
{
// Not supported, so move on
Client::setState(STATE_REGISTER);
}
-void LoginHandler::loginAccount(LoginData *loginData)
+void LoginHandler::loginAccount(LoginData *const loginData) const
{
if (loginData)
@@ -76,7 +76,7 @@ void LoginHandler::loginAccount(LoginData *loginData)
}
}
-void LoginHandler::chooseServer(unsigned int server)
+void LoginHandler::chooseServer(const unsigned int server) const
{
if (server >= mWorlds.size() || !mWorlds[server])
return;
@@ -94,7 +94,7 @@ void LoginHandler::chooseServer(unsigned int server)
Client::setState(STATE_UPDATE);
}
-void LoginHandler::registerAccount(LoginData *loginData)
+void LoginHandler::registerAccount(LoginData *const loginData) const
{
if (!loginData)
return;
@@ -130,7 +130,7 @@ void LoginHandler::clearWorlds()
mWorlds.clear();
}
-void LoginHandler::procecessCharPasswordResponse(Net::MessageIn &msg)
+void LoginHandler::procecessCharPasswordResponse(Net::MessageIn &msg) const
{
// 0: acc not found, 1: success, 2: password mismatch, 3: pass too short
const int errMsg = msg.readInt8();
@@ -164,9 +164,7 @@ void LoginHandler::procecessCharPasswordResponse(Net::MessageIn &msg)
void LoginHandler::processUpdateHost(Net::MessageIn &msg)
{
- int len;
-
- len = msg.readInt16() - 4;
+ int len = msg.readInt16() - 4;
mUpdateHost = msg.readString(len);
if (!checkPath(mUpdateHost))
@@ -221,7 +219,7 @@ void LoginHandler::processLoginData(Net::MessageIn &msg)
Client::setState(STATE_WORLD_SELECT);
}
-void LoginHandler::processLoginError(Net::MessageIn &msg)
+void LoginHandler::processLoginError(Net::MessageIn &msg) const
{
const int code = msg.readInt8();
logger->log("Login::error code: %i", code);
@@ -277,18 +275,19 @@ void LoginHandler::processLoginError(Net::MessageIn &msg)
Client::setState(STATE_ERROR);
}
-void LoginHandler::logout()
+void LoginHandler::logout() const
{
// TODO
}
-void LoginHandler::changeEmail(const std::string &email A_UNUSED)
+void LoginHandler::changeEmail(const std::string &email A_UNUSED) const
{
// TODO
}
void LoginHandler::unregisterAccount(const std::string &username A_UNUSED,
- const std::string &password A_UNUSED)
+ const std::string &password
+ A_UNUSED) const
{
// TODO
}
diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h
index b4f9d2f5c..eb81ceb6f 100644
--- a/src/net/ea/loginhandler.h
+++ b/src/net/ea/loginhandler.h
@@ -45,54 +45,56 @@ class LoginHandler : public Net::LoginHandler
~LoginHandler();
- int supportedOptionalActions() const A_WARN_UNUSED
+ int supportedOptionalActions() const override A_WARN_UNUSED
{ return SetGenderOnRegister; }
- virtual bool isRegistrationEnabled() A_WARN_UNUSED;
+ virtual bool isRegistrationEnabled() const override A_WARN_UNUSED;
- virtual void getRegistrationDetails();
+ virtual void getRegistrationDetails() const override;
- virtual unsigned int getMaxPasswordLength() const A_WARN_UNUSED
+ virtual unsigned int getMaxPasswordLength() const
+ override A_WARN_UNUSED
{ return 25; }
- virtual void loginAccount(LoginData *loginData);
+ virtual void loginAccount(LoginData *const loginData) const override;
- virtual void chooseServer(unsigned int server);
+ virtual void chooseServer(const unsigned int server) const override;
- virtual void registerAccount(LoginData *loginData);
+ virtual void registerAccount(LoginData *const loginData) const override;
- virtual Worlds getWorlds() const A_WARN_UNUSED;
+ virtual Worlds getWorlds() const override A_WARN_UNUSED;
- virtual void clearWorlds();
+ virtual void clearWorlds() override;
- virtual ServerInfo *getCharServer() A_WARN_UNUSED = 0;
+ virtual ServerInfo *getCharServer() const A_WARN_UNUSED = 0;
const Token &getToken() const A_WARN_UNUSED
{ return mToken; }
- virtual void logout();
+ virtual void logout() const override;
- virtual void changeEmail(const std::string &email);
+ virtual void changeEmail(const std::string &email) const override;
virtual void unregisterAccount(const std::string &username,
- const std::string &password);
+ const std::string &password)
+ const override;
- virtual void procecessCharPasswordResponse(Net::MessageIn &msg);
+ virtual void procecessCharPasswordResponse(Net::MessageIn &msg) const;
virtual void processUpdateHost(Net::MessageIn &msg);
- virtual void processUpdateHost2(Net::MessageIn &msg) = 0;
+ virtual void processUpdateHost2(Net::MessageIn &msg) const = 0;
virtual void processLoginData(Net::MessageIn &msg);
- virtual void processLoginError(Net::MessageIn &msg);
+ virtual void processLoginError(Net::MessageIn &msg) const;
virtual void processServerVersion(Net::MessageIn &msg) = 0;
protected:
virtual void sendLoginRegister(const std::string &username,
const std::string &password,
- const std::string &email) = 0;
+ const std::string &email) const = 0;
bool mVersionResponse;
bool mRegistrationEnabled;
diff --git a/src/net/eathena/loginhandler.cpp b/src/net/eathena/loginhandler.cpp
index eb0d1914b..d0aa9b808 100644
--- a/src/net/eathena/loginhandler.cpp
+++ b/src/net/eathena/loginhandler.cpp
@@ -105,7 +105,7 @@ void LoginHandler::connect()
MessageOut outMsg(CMSG_SERVER_VERSION_REQUEST);
}
-bool LoginHandler::isConnected()
+bool LoginHandler::isConnected() const
{
if (!mNetwork)
return false;
@@ -121,7 +121,7 @@ void LoginHandler::disconnect()
void LoginHandler::changePassword(const std::string &username A_UNUSED,
const std::string &oldPassword,
- const std::string &newPassword)
+ const std::string &newPassword) const
{
MessageOut outMsg(CMSG_CHAR_PASSWORD_CHANGE);
outMsg.writeStringNoLog(oldPassword, 24);
@@ -130,7 +130,7 @@ void LoginHandler::changePassword(const std::string &username A_UNUSED,
void LoginHandler::sendLoginRegister(const std::string &username,
const std::string &password,
- const std::string &email A_UNUSED)
+ const std::string &email A_UNUSED) const
{
MessageOut outMsg(0x0064);
outMsg.writeInt32(0); // client version
@@ -146,12 +146,12 @@ void LoginHandler::sendLoginRegister(const std::string &username,
outMsg.writeInt8(0x03);
}
-ServerInfo *LoginHandler::getCharServer()
+ServerInfo *LoginHandler::getCharServer() const
{
return &charServer;
}
-void LoginHandler::requestUpdateHosts()
+void LoginHandler::requestUpdateHosts() const
{
MessageOut outMsg(CMSG_SEND_CLIENT_INFO);
outMsg.writeInt8(CLIENT_PROTOCOL_VERSION);
@@ -174,12 +174,10 @@ void LoginHandler::processServerVersion(Net::MessageIn &msg)
mVersionResponse = true;
}
-void LoginHandler::processUpdateHost2(Net::MessageIn &msg)
+void LoginHandler::processUpdateHost2(Net::MessageIn &msg) const
{
- int len;
-
- len = msg.readInt16() - 4;
- std::string updateHost = msg.readString(len);
+ int len = msg.readInt16() - 4;
+ const std::string updateHost = msg.readString(len);
splitToStringVector(loginData.updateHosts, updateHost, '|');
FOR_EACH (StringVectIter, it, loginData.updateHosts)
diff --git a/src/net/eathena/loginhandler.h b/src/net/eathena/loginhandler.h
index a1b1095ba..d542777cd 100644
--- a/src/net/eathena/loginhandler.h
+++ b/src/net/eathena/loginhandler.h
@@ -45,36 +45,36 @@ class LoginHandler final : public MessageHandler, public Ea::LoginHandler
~LoginHandler();
- void handleMessage(Net::MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg) override;
- void connect();
+ void connect() override;
- bool isConnected() A_WARN_UNUSED;
+ bool isConnected() const override A_WARN_UNUSED;
- void disconnect();
+ void disconnect() override;
- int supportedOptionalActions() const A_WARN_UNUSED
+ int supportedOptionalActions() const override A_WARN_UNUSED
{ return SetGenderOnRegister; }
- unsigned int getMaxPasswordLength() const A_WARN_UNUSED
+ unsigned int getMaxPasswordLength() const override A_WARN_UNUSED
{ return 25; }
void changePassword(const std::string &username,
const std::string &oldPassword,
- const std::string &newPassword);
+ const std::string &newPassword) const override;
- ServerInfo *getCharServer() A_WARN_UNUSED;
+ ServerInfo *getCharServer() const override A_WARN_UNUSED;
void processServerVersion(Net::MessageIn &msg);
- void requestUpdateHosts();
+ void requestUpdateHosts() const;
- void processUpdateHost2(Net::MessageIn &msg);
+ void processUpdateHost2(Net::MessageIn &msg) const;
private:
void sendLoginRegister(const std::string &username,
const std::string &password,
- const std::string &email);
+ const std::string &email) const override;
};
} // namespace EAthena
diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h
index 49d9d20b8..fbac1ee79 100644
--- a/src/net/loginhandler.h
+++ b/src/net/loginhandler.h
@@ -57,7 +57,7 @@ class LoginHandler
virtual void connect() = 0;
- virtual bool isConnected() A_WARN_UNUSED = 0;
+ virtual bool isConnected() const A_WARN_UNUSED = 0;
virtual void disconnect() = 0;
@@ -66,9 +66,9 @@ class LoginHandler
*/
virtual int supportedOptionalActions() const A_WARN_UNUSED = 0;
- virtual bool isRegistrationEnabled() A_WARN_UNUSED = 0;
+ virtual bool isRegistrationEnabled() const A_WARN_UNUSED = 0;
- virtual void getRegistrationDetails() = 0;
+ virtual void getRegistrationDetails() const = 0;
virtual unsigned int getMinUserNameLength() const A_WARN_UNUSED
{ return 4; }
@@ -82,22 +82,22 @@ class LoginHandler
virtual unsigned int getMaxPasswordLength() const A_WARN_UNUSED
{ return 255; }
- virtual void loginAccount(LoginData *loginData) = 0;
+ virtual void loginAccount(LoginData *const loginData) const = 0;
- virtual void logout() = 0;
+ virtual void logout() const = 0;
- virtual void changeEmail(const std::string &email) = 0;
+ virtual void changeEmail(const std::string &email) const = 0;
virtual void changePassword(const std::string &username,
const std::string &oldPassword,
- const std::string &newPassword) = 0;
+ const std::string &newPassword) const = 0;
- virtual void chooseServer(unsigned int server) = 0;
+ virtual void chooseServer(unsigned int server) const = 0;
- virtual void registerAccount(LoginData *loginData) = 0;
+ virtual void registerAccount(LoginData *const loginData) const = 0;
virtual void unregisterAccount(const std::string &username,
- const std::string &password) = 0;
+ const std::string &password) const = 0;
virtual Worlds getWorlds() const A_WARN_UNUSED = 0;
diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp
index a3a9f3345..b68980969 100644
--- a/src/net/tmwa/loginhandler.cpp
+++ b/src/net/tmwa/loginhandler.cpp
@@ -107,7 +107,7 @@ void LoginHandler::connect()
MessageOut outMsg(CMSG_SERVER_VERSION_REQUEST);
}
-bool LoginHandler::isConnected()
+bool LoginHandler::isConnected() const
{
if (!mNetwork)
return false;
@@ -123,7 +123,7 @@ void LoginHandler::disconnect()
void LoginHandler::changePassword(const std::string &username A_UNUSED,
const std::string &oldPassword,
- const std::string &newPassword)
+ const std::string &newPassword) const
{
MessageOut outMsg(CMSG_CHAR_PASSWORD_CHANGE);
outMsg.writeStringNoLog(oldPassword, 24);
@@ -132,7 +132,7 @@ void LoginHandler::changePassword(const std::string &username A_UNUSED,
void LoginHandler::sendLoginRegister(const std::string &username,
const std::string &password,
- const std::string &email)
+ const std::string &email) const
{
if (email.empty())
{
@@ -167,12 +167,12 @@ void LoginHandler::sendLoginRegister(const std::string &username,
}
}
-ServerInfo *LoginHandler::getCharServer()
+ServerInfo *LoginHandler::getCharServer() const
{
return &charServer;
}
-void LoginHandler::requestUpdateHosts()
+void LoginHandler::requestUpdateHosts() const
{
MessageOut outMsg(CMSG_SEND_CLIENT_INFO);
outMsg.writeInt8(CLIENT_PROTOCOL_VERSION);
@@ -211,12 +211,10 @@ void LoginHandler::processServerVersion(Net::MessageIn &msg)
mVersionResponse = true;
}
-void LoginHandler::processUpdateHost2(Net::MessageIn &msg)
+void LoginHandler::processUpdateHost2(Net::MessageIn &msg) const
{
- int len;
-
- len = msg.readInt16() - 4;
- std::string updateHost = msg.readString(len);
+ int len = msg.readInt16() - 4;
+ const std::string updateHost = msg.readString(len);
splitToStringVector(loginData.updateHosts, updateHost, '|');
FOR_EACH (StringVectIter, it, loginData.updateHosts)
diff --git a/src/net/tmwa/loginhandler.h b/src/net/tmwa/loginhandler.h
index 4ca448108..6d8436fbd 100644
--- a/src/net/tmwa/loginhandler.h
+++ b/src/net/tmwa/loginhandler.h
@@ -45,35 +45,35 @@ class LoginHandler final : public MessageHandler, public Ea::LoginHandler
~LoginHandler();
- void handleMessage(Net::MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg) override;
- void connect();
+ void connect() override;
- bool isConnected() A_WARN_UNUSED;
+ bool isConnected() const override A_WARN_UNUSED;
- void disconnect();
+ void disconnect() override;
- int supportedOptionalActions() const A_WARN_UNUSED;
+ int supportedOptionalActions() const override A_WARN_UNUSED;
- unsigned int getMaxPasswordLength() const A_WARN_UNUSED
+ unsigned int getMaxPasswordLength() const override A_WARN_UNUSED
{ return 25; }
void changePassword(const std::string &username,
const std::string &oldPassword,
- const std::string &newPassword);
+ const std::string &newPassword) const override;
- ServerInfo *getCharServer() A_WARN_UNUSED;
+ ServerInfo *getCharServer() const override A_WARN_UNUSED;
void processServerVersion(Net::MessageIn &msg);
- void requestUpdateHosts();
+ void requestUpdateHosts() const;
- void processUpdateHost2(Net::MessageIn &msg);
+ void processUpdateHost2(Net::MessageIn &msg) const;
private:
void sendLoginRegister(const std::string &username,
const std::string &password,
- const std::string &email);
+ const std::string &email) const override;
};
} // namespace TmwAthena