summaryrefslogtreecommitdiff
path: root/src/net/eathena
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-03-27 19:05:24 +0300
committerAndrei Karas <akaras@inbox.ru>2013-03-27 21:01:39 +0300
commit8150191686759b13a239c25970924c3c186140ff (patch)
tree6004551128df40dcf178ca639fe42490f80d2c01 /src/net/eathena
parent18d8872333e2e433ce7b9e7be71706de37933097 (diff)
downloadmv-8150191686759b13a239c25970924c3c186140ff.tar.gz
mv-8150191686759b13a239c25970924c3c186140ff.tar.bz2
mv-8150191686759b13a239c25970924c3c186140ff.tar.xz
mv-8150191686759b13a239c25970924c3c186140ff.zip
improve charserverhandler class.
Diffstat (limited to 'src/net/eathena')
-rw-r--r--src/net/eathena/charserverhandler.cpp78
-rw-r--r--src/net/eathena/charserverhandler.h25
-rw-r--r--src/net/eathena/generalhandler.cpp8
-rw-r--r--src/net/eathena/generalhandler.h2
4 files changed, 34 insertions, 79 deletions
diff --git a/src/net/eathena/charserverhandler.cpp b/src/net/eathena/charserverhandler.cpp
index 474874483..2fee39a03 100644
--- a/src/net/eathena/charserverhandler.cpp
+++ b/src/net/eathena/charserverhandler.cpp
@@ -42,7 +42,7 @@
#include "debug.h"
-extern Net::CharHandler *charHandler;
+extern Net::CharServerHandler *charServerHandler;
namespace EAthena
{
@@ -68,7 +68,7 @@ CharServerHandler::CharServerHandler() :
0
};
handledMessages = _messages;
- charHandler = this;
+ charServerHandler = this;
}
void CharServerHandler::handleMessage(Net::MessageIn &msg)
@@ -104,59 +104,12 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg)
break;
case SMSG_CHAR_MAP_INFO:
- {
-// msg.skip(4); // CharID, must be the same as player_node->charID
- PlayerInfo::setCharId(msg.readInt32());
- GameHandler *const gh = static_cast<GameHandler*>(
- Net::getGameHandler());
- gh->setMap(msg.readString(16));
- if (config.getBoolValue("usePersistentIP"))
- {
- msg.readInt32();
- mapServer.hostname = Client::getServerName();
- }
- else
- {
- mapServer.hostname = ipToString(msg.readInt32());
- }
- mapServer.port = msg.readInt16();
-
- // Prevent the selected local player from being deleted
- player_node = mSelectedCharacter->dummy;
- PlayerInfo::setBackend(mSelectedCharacter->data);
-
- mSelectedCharacter->dummy = nullptr;
-
- Net::getCharHandler()->clear();
- updateCharSelectDialog();
-
- if (mNetwork)
- mNetwork->disconnect();
- Client::setState(STATE_CONNECT_GAME);
- }
- break;
+ processCharMapInfo(msg, mNetwork, mapServer);
+ break;
case SMSG_CHANGE_MAP_SERVER:
- {
- GameHandler *const gh = static_cast<GameHandler*>(
- Net::getGameHandler());
- if (!gh || !mNetwork)
- return;
- gh->setMap(msg.readString(16));
- const int x = msg.readInt16();
- const int y = msg.readInt16();
- mapServer.hostname = ipToString(msg.readInt32());
- mapServer.port = msg.readInt16();
-
- mNetwork->disconnect();
- Client::setState(STATE_CHANGE_MAP);
- if (player_node)
- {
- player_node->setTileCoords(x, y);
- player_node->setMap(nullptr);
- }
- }
- break;
+ processChangeMapServer(msg, mNetwork, mapServer);
+ break;
default:
break;
@@ -164,7 +117,8 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg)
}
void CharServerHandler::readPlayerData(Net::MessageIn &msg,
- Net::Character *character, bool)
+ Net::Character *const character,
+ const bool) const
{
if (!character)
return;
@@ -244,7 +198,7 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg,
msg.readInt8(); // unknown
}
-void CharServerHandler::chooseCharacter(Net::Character *character)
+void CharServerHandler::chooseCharacter(Net::Character *const character)
{
if (!character)
return;
@@ -256,11 +210,11 @@ void CharServerHandler::chooseCharacter(Net::Character *character)
outMsg.writeInt8(static_cast<unsigned char>(mSelectedCharacter->slot));
}
-void CharServerHandler::newCharacter(const std::string &name, int slot,
- bool gender A_UNUSED, int hairstyle,
- int hairColor,
- unsigned char race A_UNUSED,
- const std::vector<int> &stats)
+void CharServerHandler::newCharacter(const std::string &name, const int slot,
+ const bool gender A_UNUSED,
+ const int hairstyle, const int hairColor,
+ const unsigned char race A_UNUSED,
+ const std::vector<int> &stats) const
{
MessageOut outMsg(CMSG_CHAR_CREATE);
outMsg.writeString(name, 24);
@@ -272,7 +226,7 @@ void CharServerHandler::newCharacter(const std::string &name, int slot,
outMsg.writeInt16(static_cast<short>(hairstyle));
}
-void CharServerHandler::deleteCharacter(Net::Character *character)
+void CharServerHandler::deleteCharacter(Net::Character *const character)
{
if (!character)
return;
@@ -284,7 +238,7 @@ void CharServerHandler::deleteCharacter(Net::Character *character)
outMsg.writeString("a@a.com", 40);
}
-void CharServerHandler::switchCharacter()
+void CharServerHandler::switchCharacter() const
{
// This is really a map-server packet
MessageOut outMsg(CMSG_PLAYER_RESTART);
diff --git a/src/net/eathena/charserverhandler.h b/src/net/eathena/charserverhandler.h
index 4c4d3f511..3a49dbb9a 100644
--- a/src/net/eathena/charserverhandler.h
+++ b/src/net/eathena/charserverhandler.h
@@ -23,7 +23,7 @@
#ifndef NET_EATHENA_CHARSERVERHANDLER_H
#define NET_EATHENA_CHARSERVERHANDLER_H
-#include "net/charhandler.h"
+#include "net/charserverhandler.h"
#include "net/ea/charserverhandler.h"
@@ -47,26 +47,27 @@ class CharServerHandler final : public MessageHandler,
A_DELETE_COPY(CharServerHandler)
- virtual void handleMessage(Net::MessageIn &msg);
+ virtual void handleMessage(Net::MessageIn &msg) override;
- void chooseCharacter(Net::Character *character);
+ void chooseCharacter(Net::Character *const character) override;
- void newCharacter(const std::string &name, int slot,
- bool gender, int hairstyle, int hairColor,
- unsigned char race,
- const std::vector<int> &stats);
+ void newCharacter(const std::string &name, const int slot,
+ const bool gender, const int hairstyle,
+ const int hairColor, const unsigned char race,
+ const std::vector<int> &stats) const override;
- void deleteCharacter(Net::Character *character);
+ void deleteCharacter(Net::Character *const character) override;
- void switchCharacter();
+ void switchCharacter() const override;
- void connect();
+ void connect() override;
void processCharLogin(Net::MessageIn &msg);
protected:
- void readPlayerData(Net::MessageIn &msg, Net::Character *character,
- bool);
+ void readPlayerData(Net::MessageIn &msg,
+ Net::Character *const character,
+ const bool) const override;
};
} // namespace EAthena
diff --git a/src/net/eathena/generalhandler.cpp b/src/net/eathena/generalhandler.cpp
index c656b944d..d34edff7c 100644
--- a/src/net/eathena/generalhandler.cpp
+++ b/src/net/eathena/generalhandler.cpp
@@ -77,7 +77,7 @@ GeneralHandler::GeneralHandler() :
mAdminHandler(new AdminHandler),
mBeingHandler(new BeingHandler(config.getBoolValue("EnableSync"))),
mBuySellHandler(new BuySellHandler),
- mCharHandler(new CharServerHandler),
+ mCharServerHandler(new CharServerHandler),
mChatHandler(new ChatHandler),
mGameHandler(new GameHandler),
mGuildHandler(new GuildHandler),
@@ -175,7 +175,7 @@ void GeneralHandler::load()
mNetwork->registerHandler(mBeingHandler.get());
mNetwork->registerHandler(mBuySellHandler.get());
mNetwork->registerHandler(mChatHandler.get());
- mNetwork->registerHandler(mCharHandler.get());
+ mNetwork->registerHandler(mCharServerHandler.get());
mNetwork->registerHandler(mGameHandler.get());
mNetwork->registerHandler(mGuildHandler.get());
mNetwork->registerHandler(mInventoryHandler.get());
@@ -195,9 +195,9 @@ void GeneralHandler::reload()
static_cast<LoginHandler*>(mLoginHandler.get())->clearWorlds();
static_cast<CharServerHandler*>(
- mCharHandler.get())->setCharCreateDialog(nullptr);
+ mCharServerHandler.get())->setCharCreateDialog(nullptr);
static_cast<CharServerHandler*>(
- mCharHandler.get())->setCharSelectDialog(nullptr);
+ mCharServerHandler.get())->setCharSelectDialog(nullptr);
static_cast<PartyHandler*>(mPartyHandler.get())->reload();
}
diff --git a/src/net/eathena/generalhandler.h b/src/net/eathena/generalhandler.h
index 58c0d1e2e..184f30bdc 100644
--- a/src/net/eathena/generalhandler.h
+++ b/src/net/eathena/generalhandler.h
@@ -67,7 +67,7 @@ class GeneralHandler final : public MessageHandler,
MessageHandlerPtr mAdminHandler;
MessageHandlerPtr mBeingHandler;
MessageHandlerPtr mBuySellHandler;
- MessageHandlerPtr mCharHandler;
+ MessageHandlerPtr mCharServerHandler;
MessageHandlerPtr mChatHandler;
MessageHandlerPtr mGameHandler;
MessageHandlerPtr mGuildHandler;