summaryrefslogtreecommitdiff
path: root/src/net/ea/charserverhandler.cpp
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/ea/charserverhandler.cpp
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/ea/charserverhandler.cpp')
-rw-r--r--src/net/ea/charserverhandler.cpp73
1 files changed, 67 insertions, 6 deletions
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index e6e7e022e..3d665af22 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -23,12 +23,15 @@
#include "net/ea/charserverhandler.h"
#include "client.h"
+#include "configuration.h"
#include "gui/charcreatedialog.h"
#include "gui/okdialog.h"
#include "net/ea/loginhandler.h"
#include "net/ea/eaprotocol.h"
+#include "net/ea/gamehandler.h"
+#include "net/ea/network.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -37,23 +40,25 @@
#include "debug.h"
-extern Net::CharHandler *charHandler;
+extern Net::CharServerHandler *charServerHandler;
namespace Ea
{
+extern ServerInfo mapServer;
+
CharServerHandler::CharServerHandler() :
- Net::CharHandler()
+ Net::CharServerHandler()
{
}
-void CharServerHandler::setCharSelectDialog(CharSelectDialog *window)
+void CharServerHandler::setCharSelectDialog(CharSelectDialog *const window)
{
mCharSelectDialog = window;
updateCharSelectDialog();
}
-void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
+void CharServerHandler::setCharCreateDialog(CharCreateDialog *const window)
{
mCharCreateDialog = window;
@@ -105,7 +110,7 @@ unsigned int CharServerHandler::maxSprite() const
return EA_SPRITE_VECTOREND;
}
-void CharServerHandler::processCharLoginError(Net::MessageIn &msg)
+void CharServerHandler::processCharLoginError(Net::MessageIn &msg) const
{
switch (msg.readInt8())
{
@@ -123,7 +128,8 @@ void CharServerHandler::processCharLoginError(Net::MessageIn &msg)
Client::setState(STATE_ERROR);
}
-void CharServerHandler::processCharCreate(Net::MessageIn &msg, bool withColors)
+void CharServerHandler::processCharCreate(Net::MessageIn &msg,
+ const bool withColors)
{
Net::Character *const character = new Net::Character;
readPlayerData(msg, character, withColors);
@@ -192,4 +198,59 @@ void CharServerHandler::clear()
mCharacters.clear();
}
+void CharServerHandler::processCharMapInfo(Net::MessageIn &msg,
+ Network *const network,
+ ServerInfo &server)
+{
+// 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();
+ server.hostname = Client::getServerName();
+ }
+ else
+ {
+ server.hostname = ipToString(msg.readInt32());
+ }
+ server.port = msg.readInt16();
+
+ // Prevent the selected local player from being deleted
+ player_node = mSelectedCharacter->dummy;
+ PlayerInfo::setBackend(mSelectedCharacter->data);
+
+ mSelectedCharacter->dummy = nullptr;
+
+ Net::getCharServerHandler()->clear();
+ updateCharSelectDialog();
+
+ if (network)
+ network->disconnect();
+ Client::setState(STATE_CONNECT_GAME);
+}
+
+void CharServerHandler::processChangeMapServer(Net::MessageIn &msg,
+ Network *const network,
+ ServerInfo &server) const
+{
+ GameHandler *const gh = static_cast<GameHandler*>(Net::getGameHandler());
+ if (!gh || !network)
+ return;
+ gh->setMap(msg.readString(16));
+ const int x = msg.readInt16();
+ const int y = msg.readInt16();
+ server.hostname = ipToString(msg.readInt32());
+ server.port = msg.readInt16();
+
+ network->disconnect();
+ Client::setState(STATE_CHANGE_MAP);
+ if (player_node)
+ {
+ player_node->setTileCoords(x, y);
+ player_node->setMap(nullptr);
+ }
+}
+
} // namespace Ea