summaryrefslogtreecommitdiff
path: root/src/net/tmwa
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/tmwa
parent18d8872333e2e433ce7b9e7be71706de37933097 (diff)
downloadplus-8150191686759b13a239c25970924c3c186140ff.tar.gz
plus-8150191686759b13a239c25970924c3c186140ff.tar.bz2
plus-8150191686759b13a239c25970924c3c186140ff.tar.xz
plus-8150191686759b13a239c25970924c3c186140ff.zip
improve charserverhandler class.
Diffstat (limited to 'src/net/tmwa')
-rw-r--r--src/net/tmwa/charserverhandler.cpp82
-rw-r--r--src/net/tmwa/charserverhandler.h25
-rw-r--r--src/net/tmwa/generalhandler.cpp8
-rw-r--r--src/net/tmwa/generalhandler.h2
4 files changed, 37 insertions, 80 deletions
diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp
index d922f0852..0b449bff8 100644
--- a/src/net/tmwa/charserverhandler.cpp
+++ b/src/net/tmwa/charserverhandler.cpp
@@ -42,14 +42,15 @@
#include "debug.h"
-extern Net::CharHandler *charHandler;
+extern Net::CharServerHandler *charServerHandler;
namespace TmwAthena
{
-extern ServerInfo charServer;
extern ServerInfo mapServer;
+extern ServerInfo charServer;
+
CharServerHandler::CharServerHandler() :
MessageHandler(),
Ea::CharServerHandler()
@@ -68,7 +69,7 @@ CharServerHandler::CharServerHandler() :
0
};
handledMessages = _messages;
- charHandler = this;
+ charServerHandler = this;
}
void CharServerHandler::handleMessage(Net::MessageIn &msg)
@@ -105,59 +106,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;
@@ -166,8 +120,8 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg)
}
void CharServerHandler::readPlayerData(Net::MessageIn &msg,
- Net::Character *character,
- bool withColors)
+ Net::Character *const character,
+ const bool withColors) const
{
if (!character)
return;
@@ -275,7 +229,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;
@@ -287,10 +241,12 @@ 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,
- 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,
+ const std::vector<int> &stats) const
{
MessageOut outMsg(CMSG_CHAR_CREATE);
outMsg.writeString(name, 24);
@@ -304,7 +260,7 @@ void CharServerHandler::newCharacter(const std::string &name, int slot,
outMsg.writeInt8(race);
}
-void CharServerHandler::deleteCharacter(Net::Character *character)
+void CharServerHandler::deleteCharacter(Net::Character *const character)
{
if (!character)
return;
@@ -316,7 +272,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/tmwa/charserverhandler.h b/src/net/tmwa/charserverhandler.h
index b83d7acaf..9d4006a4a 100644
--- a/src/net/tmwa/charserverhandler.h
+++ b/src/net/tmwa/charserverhandler.h
@@ -23,7 +23,7 @@
#ifndef NET_TA_CHARSERVERHANDLER_H
#define NET_TA_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 withColors);
+ void readPlayerData(Net::MessageIn &msg,
+ Net::Character *const character,
+ const bool withColors) const override;
};
} // namespace TmwAthena
diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp
index c366efc9d..f6a78372e 100644
--- a/src/net/tmwa/generalhandler.cpp
+++ b/src/net/tmwa/generalhandler.cpp
@@ -78,7 +78,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),
@@ -179,7 +179,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());
@@ -200,9 +200,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/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h
index 2fcc625d1..e1254e18f 100644
--- a/src/net/tmwa/generalhandler.h
+++ b/src/net/tmwa/generalhandler.h
@@ -64,7 +64,7 @@ class GeneralHandler final : public MessageHandler, public Net::GeneralHandler,
MessageHandlerPtr mAdminHandler;
MessageHandlerPtr mBeingHandler;
MessageHandlerPtr mBuySellHandler;
- MessageHandlerPtr mCharHandler;
+ MessageHandlerPtr mCharServerHandler;
MessageHandlerPtr mChatHandler;
MessageHandlerPtr mGameHandler;
MessageHandlerPtr mGuildHandler;