summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp7
-rw-r--r--src/gui/char_select.cpp35
-rw-r--r--src/main.cpp13
-rw-r--r--src/net/charhandler.h10
-rw-r--r--src/net/ea/charserverhandler.cpp34
-rw-r--r--src/net/ea/charserverhandler.h12
-rw-r--r--src/net/ea/maphandler.cpp16
-rw-r--r--src/net/ea/maphandler.h4
-rw-r--r--src/net/ea/network.cpp2
-rw-r--r--src/net/ea/protocol.h5
-rw-r--r--src/net/maphandler.h6
11 files changed, 93 insertions, 51 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 8c886793..ca436409 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -100,7 +100,6 @@
#include "net/tmwserv/partyhandler.h"
#else
#include "net/ea/gui/partytab.h"
-#include "net/ea/network.h"
#include "net/ea/adminhandler.h"
#include "net/ea/chathandler.h"
#include "net/ea/beinghandler.h"
@@ -110,12 +109,11 @@
#include "net/ea/itemhandler.h"
#include "net/ea/maphandler.h"
#include "net/ea/npchandler.h"
+#include "net/ea/network.h"
#include "net/ea/playerhandler.h"
#include "net/ea/partyhandler.h"
#include "net/ea/tradehandler.h"
-#include "net/ea/protocol.h"
#include "net/ea/skillhandler.h"
-#include "net/messageout.h"
#endif
#include "resources/imagewriter.h"
@@ -446,8 +444,7 @@ Game::Game(Network *network):
* packet is handled by the older version, but its response
* is ignored by the client
*/
- MessageOut msg(CMSG_CLIENT_PING);
- msg.writeInt32(tick_time);
+ mapHandler->ping(tick_time);
map_path = map_path.substr(0, map_path.rfind("."));
engine->changeMap(map_path);
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index bf885de9..595d6043 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -43,6 +43,9 @@
#include "net/ea/charserverhandler.h"
#endif
+#include "net/charhandler.h"
+#include "net/net.h"
+
#include "gui/widgets/layout.h"
#include "game.h"
@@ -342,25 +345,22 @@ void CharSelectDialog::updatePlayerInfo()
void CharSelectDialog::attemptCharDelete()
{
+ // Net::getCharHandler()->deleteCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
#ifdef TMWSERV_SUPPORT
Net::AccountServer::Account::deleteCharacter(mCharInfo->getPos());
#else
- // Request character deletion
- MessageOut outMsg(0x0068);
- outMsg.writeInt32(mCharInfo->getEntry()->mCharId);
- outMsg.writeString("a@a.com", 40);
+ charHandler->deleteCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
#endif
mCharInfo->lock();
}
void CharSelectDialog::attemptCharSelect()
{
+ // Net::getCharHandler()->chooseCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
#ifdef TMWSERV_SUPPORT
Net::AccountServer::Account::selectCharacter(mCharInfo->getPos());
#else
- // Request character selection
- MessageOut outMsg(0x0066);
- outMsg.writeInt8(mCharInfo->getPos());
+ charHandler->chooseCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
#endif
mCharInfo->lock();
}
@@ -582,7 +582,8 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
(int) mAttributeSlider[5]->getValue() // WILL
);
#else
- attemptCharCreate();
+ charHandler->newCharacter(getName(), mSlot, false,
+ mPlayer->getHairStyle(), mPlayer->getHairColor());
#endif
}
else
@@ -681,21 +682,3 @@ int CharCreateDialog::getDistributedPoints()
return points;
}
#endif
-
-#ifndef TMWSERV_SUPPORT
-void CharCreateDialog::attemptCharCreate()
-{
- // Send character infos
- MessageOut outMsg(0x0067);
- outMsg.writeString(getName(), 24);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(5);
- outMsg.writeInt8(mSlot);
- outMsg.writeInt16(mPlayer->getHairColor());
- outMsg.writeInt16(mPlayer->getHairStyle());
-}
-#endif
diff --git a/src/main.cpp b/src/main.cpp
index 05518e19..97cf39d4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -826,19 +826,14 @@ static void mapLogin(Network *network, LoginData *loginData)
logger->log("Trying to connect to map server...");
logger->log("Map: %s", map_path.c_str());
+ MapHandler *mapHandler = new MapHandler;
network->connect(loginData->hostname, loginData->port);
//network->registerHandler(mapHandler);
- network->registerHandler(new MapHandler);
+ network->registerHandler(mapHandler);
- // Send login infos
- MessageOut outMsg(0x0072);
- outMsg.writeInt32(loginData->account_ID);
- outMsg.writeInt32(player_node->mCharId);
- outMsg.writeInt32(loginData->session_ID1);
- outMsg.writeInt32(loginData->session_ID2);
- outMsg.writeInt8(loginData->sex);
+ mapHandler->connect(loginData);
- // We get 4 useless bytes before the real answer comes in
+ // We get 4 useless bytes before the real answer comes in (what are these?)
network->skip(4);
}
diff --git a/src/net/charhandler.h b/src/net/charhandler.h
index e7871aab..fa2820e9 100644
--- a/src/net/charhandler.h
+++ b/src/net/charhandler.h
@@ -22,18 +22,20 @@
#ifndef CHARHANDLER_H
#define CHARHANDLER_H
+#include "localplayer.h"
+
#include <iosfwd>
namespace Net {
class CharHandler
{
public:
- virtual void ChooseCharacter(int slot) {}
+ virtual void chooseCharacter(int slot, LocalPlayer* character) = 0;
- virtual void NewCharacter(const std::string &name, bool gender,
- int hairstyle, int hairColor) {}
+ virtual void newCharacter(const std::string &name, int slot,
+ bool gender, int hairstyle, int hairColor) = 0;
- virtual void DeleteCharacter(int slot) {}
+ virtual void deleteCharacter(int slot, LocalPlayer* character) = 0;
};
}
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index d212ebfe..822c15c4 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -24,9 +24,9 @@
#include "net/ea/protocol.h"
#include "net/messagein.h"
+#include "net/messageout.h"
#include "game.h"
-#include "localplayer.h"
#include "log.h"
#include "logindata.h"
#include "main.h"
@@ -37,6 +37,8 @@
#include "utils/gettext.h"
#include "utils/stringutils.h"
+Net::CharHandler *charHandler;
+
CharServerHandler::CharServerHandler():
mCharCreateDialog(0)
{
@@ -52,6 +54,7 @@ CharServerHandler::CharServerHandler():
0
};
handledMessages = _messages;
+ charHandler = this;
}
void CharServerHandler::handleMessage(MessageIn &msg)
@@ -235,3 +238,32 @@ LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
return tempPlayer;
}
+
+void CharServerHandler::chooseCharacter(int slot, LocalPlayer* character)
+{
+ MessageOut outMsg(CMSG_CHAR_SELECT);
+ outMsg.writeInt8(slot);
+}
+
+void CharServerHandler::newCharacter(const std::string &name, int slot,
+ bool gender, int hairstyle, int hairColor)
+{
+ MessageOut outMsg(CMSG_CHAR_CREATE);
+ outMsg.writeString(name, 24);
+ outMsg.writeInt8(5);
+ outMsg.writeInt8(5);
+ outMsg.writeInt8(5);
+ outMsg.writeInt8(5);
+ outMsg.writeInt8(5);
+ outMsg.writeInt8(5);
+ outMsg.writeInt8(slot);
+ outMsg.writeInt16(hairColor);
+ outMsg.writeInt16(hairstyle);
+}
+
+void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character)
+{
+ MessageOut outMsg(CMSG_CHAR_DELETE);
+ outMsg.writeInt32(character->mCharId);
+ outMsg.writeString("a@a.com", 40);
+}
diff --git a/src/net/ea/charserverhandler.h b/src/net/ea/charserverhandler.h
index ec21a357..e499ab74 100644
--- a/src/net/ea/charserverhandler.h
+++ b/src/net/ea/charserverhandler.h
@@ -23,6 +23,7 @@
#define NET_EA_CHARSERVERHANDLER_H
#include "net/messagehandler.h"
+#include "net/charhandler.h"
#include "lockedarray.h"
@@ -33,7 +34,7 @@ class LoginData;
/**
* Deals with incoming messages from the character server.
*/
-class CharServerHandler : public MessageHandler
+class CharServerHandler : public MessageHandler, public Net::CharHandler
{
public:
CharServerHandler();
@@ -54,6 +55,13 @@ class CharServerHandler : public MessageHandler
void setCharCreateDialog(CharCreateDialog *window)
{ mCharCreateDialog = window; }
+ void chooseCharacter(int slot, LocalPlayer* character);
+
+ void newCharacter(const std::string &name, int slot, bool gender,
+ int hairstyle, int hairColor);
+
+ void deleteCharacter(int slot, LocalPlayer* character);
+
protected:
LoginData *mLoginData;
LockedArray<LocalPlayer*> *mCharInfo;
@@ -62,4 +70,6 @@ class CharServerHandler : public MessageHandler
LocalPlayer *readPlayerData(MessageIn &msg, int &slot);
};
+extern Net::CharHandler *charHandler;
+
#endif // NET_EA_CHARSERVERHANDLER_H
diff --git a/src/net/ea/maphandler.cpp b/src/net/ea/maphandler.cpp
index fefeac86..d12106d6 100644
--- a/src/net/ea/maphandler.cpp
+++ b/src/net/ea/maphandler.cpp
@@ -96,9 +96,15 @@ void MapHandler::handleMessage(MessageIn &msg)
}
}
-void MapHandler::connect()
+void MapHandler::connect(LoginData *loginData)
{
- // TODO
+ // Send login infos
+ MessageOut outMsg(CMSG_MAP_SERVER_CONNECT);
+ outMsg.writeInt32(loginData->account_ID);
+ outMsg.writeInt32(player_node->mCharId);
+ outMsg.writeInt32(loginData->session_ID1);
+ outMsg.writeInt32(loginData->session_ID2);
+ outMsg.writeInt8(loginData->sex);
}
void MapHandler::mapLoaded(const std::string &mapName)
@@ -115,3 +121,9 @@ void MapHandler::quit()
{
MessageOut outMsg(CMSG_CLIENT_QUIT);
}
+
+void MapHandler::ping(int tick)
+{
+ MessageOut msg(CMSG_CLIENT_PING);
+ msg.writeInt32(tick);
+}
diff --git a/src/net/ea/maphandler.h b/src/net/ea/maphandler.h
index 77811b4e..d4ccdbe2 100644
--- a/src/net/ea/maphandler.h
+++ b/src/net/ea/maphandler.h
@@ -33,13 +33,15 @@ class MapHandler : public MessageHandler, public Net::MapHandler
void handleMessage(MessageIn &msg);
- void connect();
+ void connect(LoginData *loginData);
void mapLoaded(const std::string &mapName);
void who();
void quit();
+
+ void ping(int tick);
};
extern MapHandler *mapHandler;
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index 4aecb268..8f55236f 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -72,7 +72,7 @@ short packet_lengths[] = {
8, 14, 10, 35, 6, 8, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
-1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
-// #0x200
+// #0x2000
26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h
index 356b34a4..4dc7db36 100644
--- a/src/net/ea/protocol.h
+++ b/src/net/ea/protocol.h
@@ -122,6 +122,11 @@ static const int STORAGE_OFFSET = 1;
/**********************************
* Packets from client to server *
**********************************/
+#define CMSG_CHAR_SELECT 0x0066
+#define CMSG_CHAR_CREATE 0x0067
+#define CMSG_CHAR_DELETE 0x0068
+
+#define CMSG_MAP_SERVER_CONNECT 0x0072
#define CMSG_CLIENT_PING 0x007e /**< Send to server with tick */
#define CMSG_CLIENT_QUIT 0x018A
#define CMSG_TRADE_RESPONSE 0x00e6
diff --git a/src/net/maphandler.h b/src/net/maphandler.h
index 80f9183f..6c91f4ef 100644
--- a/src/net/maphandler.h
+++ b/src/net/maphandler.h
@@ -22,6 +22,8 @@
#ifndef MAPHANDLER_H
#define MAPHANDLER_H
+#include "logindata.h"
+
#include <iosfwd>
namespace Net {
@@ -29,13 +31,15 @@ namespace Net {
class MapHandler
{
public:
- virtual void connect() = 0;
+ virtual void connect(LoginData *loginData) = 0;
virtual void mapLoaded(const std::string &mapName) = 0;
virtual void who() = 0;
virtual void quit() = 0;
+
+ virtual void ping(int tick) = 0;
};
} // namespace Net