summaryrefslogtreecommitdiff
path: root/src/net/ea
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/ea')
-rw-r--r--src/net/ea/adminhandler.cpp11
-rw-r--r--src/net/ea/adminhandler.h5
-rw-r--r--src/net/ea/beinghandler.cpp5
-rw-r--r--src/net/ea/beinghandler.h4
-rw-r--r--src/net/ea/buysellhandler.cpp2
-rw-r--r--src/net/ea/buysellhandler.h4
-rw-r--r--src/net/ea/charserverhandler.cpp4
-rw-r--r--src/net/ea/charserverhandler.h6
-rw-r--r--src/net/ea/chathandler.cpp2
-rw-r--r--src/net/ea/chathandler.h5
-rw-r--r--src/net/ea/equipmenthandler.cpp2
-rw-r--r--src/net/ea/equipmenthandler.h4
-rw-r--r--src/net/ea/gamehandler.cpp2
-rw-r--r--src/net/ea/gamehandler.h4
-rw-r--r--src/net/ea/generalhandler.cpp2
-rw-r--r--src/net/ea/generalhandler.h5
-rw-r--r--src/net/ea/inventoryhandler.cpp12
-rw-r--r--src/net/ea/inventoryhandler.h9
-rw-r--r--src/net/ea/itemhandler.cpp2
-rw-r--r--src/net/ea/itemhandler.h4
-rw-r--r--src/net/ea/loginhandler.cpp2
-rw-r--r--src/net/ea/loginhandler.h4
-rw-r--r--src/net/ea/messagehandler.cpp47
-rw-r--r--src/net/ea/messagehandler.h58
-rw-r--r--src/net/ea/messagein.cpp70
-rw-r--r--src/net/ea/messagein.h51
-rw-r--r--src/net/ea/messageout.cpp126
-rw-r--r--src/net/ea/messageout.h64
-rw-r--r--src/net/ea/network.cpp10
-rw-r--r--src/net/ea/network.h23
-rw-r--r--src/net/ea/npchandler.cpp2
-rw-r--r--src/net/ea/npchandler.h5
-rw-r--r--src/net/ea/partyhandler.cpp2
-rw-r--r--src/net/ea/partyhandler.h5
-rw-r--r--src/net/ea/playerhandler.cpp12
-rw-r--r--src/net/ea/playerhandler.h9
-rw-r--r--src/net/ea/specialhandler.cpp2
-rw-r--r--src/net/ea/specialhandler.h5
-rw-r--r--src/net/ea/tradehandler.cpp2
-rw-r--r--src/net/ea/tradehandler.h5
40 files changed, 530 insertions, 68 deletions
diff --git a/src/net/ea/adminhandler.cpp b/src/net/ea/adminhandler.cpp
index e1099a4d..62fe9ea8 100644
--- a/src/net/ea/adminhandler.cpp
+++ b/src/net/ea/adminhandler.cpp
@@ -21,11 +21,10 @@
#include "net/ea/adminhandler.h"
-#include "net/ea/chathandler.h"
-#include "net/ea/protocol.h"
+#include "net/chathandler.h"
+#include "net/net.h"
-#include "net/messagein.h"
-#include "net/messageout.h"
+#include "net/ea/protocol.h"
#include "being.h"
#include "beingmanager.h"
@@ -55,7 +54,7 @@ AdminHandler::AdminHandler()
adminHandler = this;
}
-void AdminHandler::handleMessage(MessageIn &msg)
+void AdminHandler::handleMessage(Net::MessageIn &msg)
{
int id;
switch (msg.getId())
@@ -118,7 +117,7 @@ void AdminHandler::unban(int playerId)
void AdminHandler::unban(const std::string &name)
{
- chatHandler->talk("@unban " + name);
+ Net::getChatHandler()->talk("@unban " + name);
}
void AdminHandler::mute(int playerId, int type, int limit)
diff --git a/src/net/ea/adminhandler.h b/src/net/ea/adminhandler.h
index 6ef4f76a..83d732cc 100644
--- a/src/net/ea/adminhandler.h
+++ b/src/net/ea/adminhandler.h
@@ -23,9 +23,10 @@
#define NET_EA_ADMINHANDLER_H
#include "net/adminhandler.h"
-#include "net/messagehandler.h"
#include "net/net.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class AdminHandler : public MessageHandler, public Net::AdminHandler
@@ -33,7 +34,7 @@ class AdminHandler : public MessageHandler, public Net::AdminHandler
public:
AdminHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void announce(const std::string &text);
diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp
index 2cc93f6e..8a958845 100644
--- a/src/net/ea/beinghandler.cpp
+++ b/src/net/ea/beinghandler.cpp
@@ -23,9 +23,6 @@
#include "net/ea/protocol.h"
-#include "net/messagein.h"
-#include "net/messageout.h"
-
#include "being.h"
#include "beingmanager.h"
#include "effectmanager.h"
@@ -97,7 +94,7 @@ Being *createBeing(int id, short job)
return being;
}
-void BeingHandler::handleMessage(MessageIn &msg)
+void BeingHandler::handleMessage(Net::MessageIn &msg)
{
int id;
short job, speed, gender;
diff --git a/src/net/ea/beinghandler.h b/src/net/ea/beinghandler.h
index 97001579..d1cafc93 100644
--- a/src/net/ea/beinghandler.h
+++ b/src/net/ea/beinghandler.h
@@ -22,7 +22,7 @@
#ifndef NET_EA_BEINGHANDLER_H
#define NET_EA_BEINGHANDLER_H
-#include "net/messagehandler.h"
+#include "net/ea/messagehandler.h"
namespace EAthena {
@@ -31,7 +31,7 @@ class BeingHandler : public MessageHandler
public:
BeingHandler(bool enableSync);
- virtual void handleMessage(MessageIn &msg);
+ virtual void handleMessage(Net::MessageIn &msg);
private:
// Should we honor server "Stop Walking" packets
diff --git a/src/net/ea/buysellhandler.cpp b/src/net/ea/buysellhandler.cpp
index 48e856e4..8dba566d 100644
--- a/src/net/ea/buysellhandler.cpp
+++ b/src/net/ea/buysellhandler.cpp
@@ -54,7 +54,7 @@ BuySellHandler::BuySellHandler()
handledMessages = _messages;
}
-void BuySellHandler::handleMessage(MessageIn &msg)
+void BuySellHandler::handleMessage(Net::MessageIn &msg)
{
int n_items;
switch (msg.getId())
diff --git a/src/net/ea/buysellhandler.h b/src/net/ea/buysellhandler.h
index cddace55..8277c5c9 100644
--- a/src/net/ea/buysellhandler.h
+++ b/src/net/ea/buysellhandler.h
@@ -22,7 +22,7 @@
#ifndef NET_EA_BUYSELLHANDLER_H
#define NET_EA_BUYSELLHANDLER_H
-#include "net/messagehandler.h"
+#include "net/ea/messagehandler.h"
namespace EAthena {
@@ -31,7 +31,7 @@ class BuySellHandler : public MessageHandler
public:
BuySellHandler();
- virtual void handleMessage(MessageIn &msg);
+ virtual void handleMessage(Net::MessageIn &msg);
};
} // namespace EAthena
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index f4b82aee..47eddc12 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -67,7 +67,7 @@ CharServerHandler::CharServerHandler():
charHandler = this;
}
-void CharServerHandler::handleMessage(MessageIn &msg)
+void CharServerHandler::handleMessage(Net::MessageIn &msg)
{
int count, slot;
LocalPlayer *tempPlayer;
@@ -176,7 +176,7 @@ void CharServerHandler::handleMessage(MessageIn &msg)
}
}
-LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
+LocalPlayer *CharServerHandler::readPlayerData(Net::MessageIn &msg, int &slot)
{
const Token &token =
static_cast<LoginHandler*>(Net::getLoginHandler())->getToken();
diff --git a/src/net/ea/charserverhandler.h b/src/net/ea/charserverhandler.h
index 393ec15c..b1e2b797 100644
--- a/src/net/ea/charserverhandler.h
+++ b/src/net/ea/charserverhandler.h
@@ -22,10 +22,10 @@
#ifndef NET_EA_CHARSERVERHANDLER_H
#define NET_EA_CHARSERVERHANDLER_H
-#include "net/messagehandler.h"
#include "net/charhandler.h"
#include "net/serverinfo.h"
+#include "net/ea/messagehandler.h"
#include "net/ea/token.h"
class LoginData;
@@ -40,7 +40,7 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler
public:
CharServerHandler();
- virtual void handleMessage(MessageIn &msg);
+ virtual void handleMessage(Net::MessageIn &msg);
void setCharInfo(LockedArray<LocalPlayer*> *charInfo)
{ mCharInfo = charInfo; }
@@ -72,7 +72,7 @@ class CharServerHandler : public MessageHandler, public Net::CharHandler
CharSelectDialog *mCharSelectDialog;
CharCreateDialog *mCharCreateDialog;
- LocalPlayer *readPlayerData(MessageIn &msg, int &slot);
+ LocalPlayer *readPlayerData(Net::MessageIn &msg, int &slot);
};
} // namespace EAthena
diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp
index 65f1db3c..913cfacf 100644
--- a/src/net/ea/chathandler.cpp
+++ b/src/net/ea/chathandler.cpp
@@ -58,7 +58,7 @@ ChatHandler::ChatHandler()
chatHandler = this;
}
-void ChatHandler::handleMessage(MessageIn &msg)
+void ChatHandler::handleMessage(Net::MessageIn &msg)
{
Being *being;
std::string chatMsg;
diff --git a/src/net/ea/chathandler.h b/src/net/ea/chathandler.h
index f77b7b80..3396a88b 100644
--- a/src/net/ea/chathandler.h
+++ b/src/net/ea/chathandler.h
@@ -23,9 +23,10 @@
#define NET_EA_CHATHANDLER_H
#include "net/chathandler.h"
-#include "net/messagehandler.h"
#include "net/net.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class ChatHandler : public MessageHandler, public Net::ChatHandler
@@ -33,7 +34,7 @@ class ChatHandler : public MessageHandler, public Net::ChatHandler
public:
ChatHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void talk(const std::string &text);
diff --git a/src/net/ea/equipmenthandler.cpp b/src/net/ea/equipmenthandler.cpp
index 3520bca5..28a2940c 100644
--- a/src/net/ea/equipmenthandler.cpp
+++ b/src/net/ea/equipmenthandler.cpp
@@ -155,7 +155,7 @@ EquipmentHandler::EquipmentHandler()
memset(equips, 0, sizeof(equips));
}
-void EquipmentHandler::handleMessage(MessageIn &msg)
+void EquipmentHandler::handleMessage(Net::MessageIn &msg)
{
int itemCount;
int index, equipPoint, itemId;
diff --git a/src/net/ea/equipmenthandler.h b/src/net/ea/equipmenthandler.h
index 47c2f803..32ea83c4 100644
--- a/src/net/ea/equipmenthandler.h
+++ b/src/net/ea/equipmenthandler.h
@@ -22,7 +22,7 @@
#ifndef NET_EA_EQUIPMENTHANDLER_H
#define NET_EA_EQUIPMENTHANDLER_H
-#include "net/messagehandler.h"
+#include "net/ea/messagehandler.h"
class Item;
@@ -37,7 +37,7 @@ class EquipmentHandler : public MessageHandler
public:
EquipmentHandler();
- virtual void handleMessage(MessageIn &msg);
+ virtual void handleMessage(Net::MessageIn &msg);
};
} // namespace EAthena
diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp
index 97862883..5becfe1b 100644
--- a/src/net/ea/gamehandler.cpp
+++ b/src/net/ea/gamehandler.cpp
@@ -61,7 +61,7 @@ GameHandler::GameHandler()
gameHandler = this;
}
-void GameHandler::handleMessage(MessageIn &msg)
+void GameHandler::handleMessage(Net::MessageIn &msg)
{
switch (msg.getId())
{
diff --git a/src/net/ea/gamehandler.h b/src/net/ea/gamehandler.h
index d8adeeaf..0095ada3 100644
--- a/src/net/ea/gamehandler.h
+++ b/src/net/ea/gamehandler.h
@@ -23,10 +23,10 @@
#define NET_EA_MAPHANDLER_H
#include "net/gamehandler.h"
-#include "net/messagehandler.h"
#include "net/net.h"
#include "net/serverinfo.h"
+#include "net/ea/messagehandler.h"
#include "net/ea/token.h"
namespace EAthena {
@@ -36,7 +36,7 @@ class GameHandler : public MessageHandler, public Net::GameHandler
public:
GameHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void connect();
diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp
index 62a7c1aa..4ef2f9e2 100644
--- a/src/net/ea/generalhandler.cpp
+++ b/src/net/ea/generalhandler.cpp
@@ -110,7 +110,7 @@ GeneralHandler::~GeneralHandler()
delete mNetwork;
}
-void GeneralHandler::handleMessage(MessageIn &msg)
+void GeneralHandler::handleMessage(Net::MessageIn &msg)
{
int code;
diff --git a/src/net/ea/generalhandler.h b/src/net/ea/generalhandler.h
index b8ea8049..8bbf4f61 100644
--- a/src/net/ea/generalhandler.h
+++ b/src/net/ea/generalhandler.h
@@ -23,10 +23,11 @@
#define NET_EA_GENERALHANDLER_H
#include "net/generalhandler.h"
-#include "net/messagehandler.h"
#include "net/net.h"
#include "net/serverinfo.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class GeneralHandler : public MessageHandler, public Net::GeneralHandler
@@ -36,7 +37,7 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler
~GeneralHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void load();
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 55714a70..8f2b4453 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -72,7 +72,7 @@ InventoryHandler::InventoryHandler()
inventoryHandler = this;
}
-void InventoryHandler::handleMessage(MessageIn &msg)
+void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
int number;
int index, amount, itemId, equipType, arrow;
@@ -374,4 +374,14 @@ void InventoryHandler::moveItem(StorageType source, int slot, int amount,
}
}
+size_t InventoryHandler::getInventorySize() const
+{
+ return 100;
+}
+
+size_t InventoryHandler::getStorageSize() const
+{
+ return 300;
+}
+
} // namespace EAthena
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index 30408dad..e61ee14b 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -23,9 +23,10 @@
#define NET_EA_INVENTORYHANDLER_H
#include "net/inventoryhandler.h"
-#include "net/messagehandler.h"
#include "net/net.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class InventoryHandler : public MessageHandler, public Net::InventoryHandler
@@ -33,7 +34,7 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler
public:
InventoryHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void equipItem(const Item *item);
@@ -55,6 +56,10 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler
void moveItem(StorageType source, int slot, int amount,
StorageType destination);
+
+ size_t getInventorySize() const;
+
+ size_t getStorageSize() const;
};
} // namespace EAthena
diff --git a/src/net/ea/itemhandler.cpp b/src/net/ea/itemhandler.cpp
index 95d480f9..f926f8e8 100644
--- a/src/net/ea/itemhandler.cpp
+++ b/src/net/ea/itemhandler.cpp
@@ -41,7 +41,7 @@ ItemHandler::ItemHandler()
handledMessages = _messages;
}
-void ItemHandler::handleMessage(MessageIn &msg)
+void ItemHandler::handleMessage(Net::MessageIn &msg)
{
Uint32 id;
Uint16 x, y;
diff --git a/src/net/ea/itemhandler.h b/src/net/ea/itemhandler.h
index f72e4779..53362190 100644
--- a/src/net/ea/itemhandler.h
+++ b/src/net/ea/itemhandler.h
@@ -22,7 +22,7 @@
#ifndef NET_EA_ITEMHANDLER_H
#define NET_EA_ITEMHANDLER_H
-#include "net/messagehandler.h"
+#include "net/ea/messagehandler.h"
namespace EAthena {
@@ -31,7 +31,7 @@ class ItemHandler : public MessageHandler
public:
ItemHandler();
- virtual void handleMessage(MessageIn &msg);
+ virtual void handleMessage(Net::MessageIn &msg);
};
} // namespace EAthena
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index c48e596e..a57eee8a 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -55,7 +55,7 @@ LoginHandler::LoginHandler()
loginHandler = this;
}
-void LoginHandler::handleMessage(MessageIn &msg)
+void LoginHandler::handleMessage(Net::MessageIn &msg)
{
int code, worldCount;
diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h
index 0d0ef1eb..ac3bf4f4 100644
--- a/src/net/ea/loginhandler.h
+++ b/src/net/ea/loginhandler.h
@@ -23,8 +23,8 @@
#define NET_EA_LOGINHANDLER_H
#include "net/loginhandler.h"
-#include "net/messagehandler.h"
+#include "net/ea/messagehandler.h"
#include "net/ea/token.h"
#include <string>
@@ -38,7 +38,7 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
public:
LoginHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void connect();
diff --git a/src/net/ea/messagehandler.cpp b/src/net/ea/messagehandler.cpp
new file mode 100644
index 00000000..fde65d55
--- /dev/null
+++ b/src/net/ea/messagehandler.cpp
@@ -0,0 +1,47 @@
+/*
+ * The Mana World
+ * Copyright (C) 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "net/ea/messagehandler.h"
+
+#include "net/ea/network.h"
+
+#include <cassert>
+
+namespace EAthena {
+
+MessageHandler::MessageHandler()
+ : mNetwork(NULL)
+{
+}
+
+MessageHandler::~MessageHandler()
+{
+ if (mNetwork)
+ mNetwork->unregisterHandler(this);
+}
+
+void MessageHandler::setNetwork(Network *network)
+{
+ assert(!(network && mNetwork));
+ mNetwork = network;
+}
+
+}
diff --git a/src/net/ea/messagehandler.h b/src/net/ea/messagehandler.h
new file mode 100644
index 00000000..3f006671
--- /dev/null
+++ b/src/net/ea/messagehandler.h
@@ -0,0 +1,58 @@
+/*
+ * The Mana World
+ * Copyright (C) 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef NET_EA_MESSAGEHANDLER_H
+#define NET_EA_MESSAGEHANDLER_H
+
+#include "net/messagehandler.h"
+#include "net/messagein.h"
+
+#include "net/ea/messageout.h"
+
+#include <SDL_types.h>
+
+#include <memory>
+
+namespace EAthena {
+
+class Network;
+
+/**
+ * \ingroup Network
+ */
+class MessageHandler : public Net::MessageHandler
+{
+ public:
+ MessageHandler();
+
+ ~MessageHandler();
+
+ void setNetwork(Network *network);
+
+ protected:
+ Network *mNetwork;
+};
+
+typedef const std::auto_ptr<MessageHandler> MessageHandlerPtr;
+
+}
+
+#endif // NET_EA_MESSAGEHANDLER_H
diff --git a/src/net/ea/messagein.cpp b/src/net/ea/messagein.cpp
new file mode 100644
index 00000000..0b1ab70a
--- /dev/null
+++ b/src/net/ea/messagein.cpp
@@ -0,0 +1,70 @@
+/*
+ * The Mana World
+ * Copyright (C) 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "net/ea/messagein.h"
+
+#include <SDL.h>
+#include <SDL_endian.h>
+
+#define MAKEWORD(low,high) \
+ ((unsigned short)(((unsigned char)(low)) | \
+ ((unsigned short)((unsigned char)(high))) << 8))
+
+namespace EAthena {
+
+MessageIn::MessageIn(const char *data, unsigned int length):
+ Net::MessageIn(data, length)
+{
+ // Read the message ID
+ mId = readInt16();
+}
+
+int MessageIn::readInt16()
+{
+ int value = -1;
+ if (mPos + 2 <= mLength)
+ {
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ value = SDL_Swap16(*(Sint16*)(mData + mPos));
+#else
+ value = (*(Sint16*)(mData + mPos));
+#endif
+ }
+ mPos += 2;
+ return value;
+}
+
+int MessageIn::readInt32()
+{
+ int value = -1;
+ if (mPos + 4 <= mLength)
+ {
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ value = SDL_Swap32(*(Sint32*)(mData + mPos));
+#else
+ value = (*(Sint32*)(mData + mPos));
+#endif
+ }
+ mPos += 4;
+ return value;
+}
+
+}
diff --git a/src/net/ea/messagein.h b/src/net/ea/messagein.h
new file mode 100644
index 00000000..89a9839f
--- /dev/null
+++ b/src/net/ea/messagein.h
@@ -0,0 +1,51 @@
+/*
+ * The Mana World
+ * Copyright (C) 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef NET_EA_MESSAGEIN_H
+#define NET_EA_MESSAGEIN_H
+
+#include "net/messagein.h"
+
+#include <SDL_types.h>
+#include <string>
+
+namespace EAthena {
+
+/**
+ * Used for parsing an incoming message.
+ *
+ * \ingroup Network
+ */
+ class MessageIn : public Net::MessageIn
+{
+ public:
+ /**
+ * Constructor.
+ */
+ MessageIn(const char *data, unsigned int length);
+
+ int readInt16(); /**< Reads a short. */
+ int readInt32(); /**< Reads a long. */
+};
+
+}
+
+#endif // NET_EA_MESSAGEIN_H
diff --git a/src/net/ea/messageout.cpp b/src/net/ea/messageout.cpp
new file mode 100644
index 00000000..f75dcf7e
--- /dev/null
+++ b/src/net/ea/messageout.cpp
@@ -0,0 +1,126 @@
+/*
+ * The Mana World
+ * Copyright (C) 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "net/ea/messageout.h"
+
+#include "net/ea/network.h"
+
+#include <SDL.h>
+#include <SDL_endian.h>
+
+#include <cstring>
+#include <string>
+
+namespace EAthena {
+
+MessageOut::MessageOut(short id):
+ Net::MessageOut(id)
+{
+ mNetwork = EAthena::Network::instance();
+ mData = mNetwork->mOutBuffer + mNetwork->mOutSize;
+ writeInt16(id);
+}
+
+void MessageOut::expand(size_t bytes)
+{
+ mNetwork->mOutSize += bytes;
+}
+
+void MessageOut::writeInt16(Sint16 value)
+{
+ expand(2);
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ (*(Sint16 *)(mData + mPos)) = SDL_Swap16(value);
+#else
+ (*(Sint16 *)(mData + mPos)) = value;
+#endif
+ mPos += 2;
+}
+
+void MessageOut::writeInt32(Sint32 value)
+{
+ expand(4);
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ (*(Sint32 *)(mData + mPos)) = SDL_Swap32(value);
+#else
+ (*(Sint32 *)(mData + mPos)) = value;
+#endif
+ mPos += 4;
+}
+
+#define LOBYTE(w) ((unsigned char)(w))
+#define HIBYTE(w) ((unsigned char)(((unsigned short)(w)) >> 8))
+
+void MessageOut::writeCoordinates(unsigned short x, unsigned short y,
+ unsigned char direction)
+{
+ char *data = mData + mPos;
+ mNetwork->mOutSize += 3;
+ mPos += 3;
+
+ short temp;
+ temp = x;
+ temp <<= 6;
+ data[0] = 0;
+ data[1] = 1;
+ data[2] = 2;
+ data[0] = HIBYTE(temp);
+ data[1] = (unsigned char) temp;
+ temp = y;
+ temp <<= 4;
+ data[1] |= HIBYTE(temp);
+ data[2] = LOBYTE(temp);
+
+ // Translate direction to eAthena format
+ switch (direction)
+ {
+ case 1:
+ direction = 0;
+ break;
+ case 3:
+ direction = 1;
+ break;
+ case 2:
+ direction = 2;
+ break;
+ case 6:
+ direction = 3;
+ break;
+ case 4:
+ direction = 4;
+ break;
+ case 12:
+ direction = 5;
+ break;
+ case 8:
+ direction = 6;
+ break;
+ case 9:
+ direction = 7;
+ break;
+ default:
+ // OOPSIE! Impossible or unknown
+ direction = (unsigned char) -1;
+ }
+ data[2] |= direction;
+}
+
+}
diff --git a/src/net/ea/messageout.h b/src/net/ea/messageout.h
new file mode 100644
index 00000000..47cd7bd9
--- /dev/null
+++ b/src/net/ea/messageout.h
@@ -0,0 +1,64 @@
+/*
+ * The Mana World
+ * Copyright (C) 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef NET_EA_MESSAGEOUT_H
+#define NET_EA_MESSAGEOUT_H
+
+#include "net/messageout.h"
+
+#include <iosfwd>
+#include <SDL_types.h>
+
+namespace EAthena {
+
+class Network;
+
+/**
+ * Used for building an outgoing message.
+ *
+ * \ingroup Network
+ */
+class MessageOut : public Net::MessageOut
+{
+ public:
+ /**
+ * Constructor.
+ */
+ MessageOut(short id);
+
+ void writeInt16(Sint16 value); /**< Writes a short. */
+ void writeInt32(Sint32 value); /**< Writes a long. */
+
+ /**
+ * Encodes coordinates and direction in 3 bytes.
+ */
+ void writeCoordinates(unsigned short x, unsigned short y,
+ unsigned char direction);
+
+ private:
+ void expand(size_t size);
+
+ Network *mNetwork;
+};
+
+}
+
+#endif // NET_EA_MESSAGEOUT_H
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index d8d27577..c12e1bb9 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -84,6 +84,8 @@ short packet_lengths[] = {
const unsigned int BUFFER_SIZE = 65536;
+namespace EAthena {
+
int networkThread(void *data)
{
Network *network = static_cast<Network*>(data);
@@ -222,9 +224,13 @@ void Network::dispatchMessages()
MessageHandlerIterator iter = mMessageHandlers.find(msg.getId());
if (iter != mMessageHandlers.end())
+ {
iter->second->handleMessage(msg);
+ }
else
+ {
logger->log("Unhandled packet: %x", msg.getId());
+ }
skip(msg.getLength());
}
@@ -317,7 +323,7 @@ MessageIn Network::getNextMessage()
len = readWord(2);
#ifdef DEBUG
- logger->log("Received packet 0x%x of length %d", msgId, len);
+ logger->log("Received packet 0x%x of length %d\n", msgId, len);
#endif
MessageIn msg(mInBuffer, len);
@@ -464,3 +470,5 @@ Uint16 Network::readWord(int pos)
return (*(Uint16*)(mInBuffer+(pos)));
#endif
}
+
+}
diff --git a/src/net/ea/network.h b/src/net/ea/network.h
index 3b8d09f9..0bbcae0e 100644
--- a/src/net/ea/network.h
+++ b/src/net/ea/network.h
@@ -19,11 +19,15 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef EA_NETWORK_H
-#define EA_NETWORK_H
+#ifndef NET_EA_NETWORK_H
+#define NET_EA_NETWORK_H
#include "net/serverinfo.h"
+#include "net/ea/messagehandler.h"
+#include "net/ea/messagein.h"
+#include "net/ea/messageout.h"
+
#include <SDL_net.h>
#include <SDL_thread.h>
@@ -36,15 +40,11 @@
*/
#define CLIENT_PROTOCOL_VERSION 1
-class MessageHandler;
-class MessageIn;
+namespace EAthena {
class Network
{
public:
- friend int networkThread(void *data);
- friend class MessageOut;
-
Network();
~Network();
@@ -89,7 +89,10 @@ class Network
NET_ERROR
};
- private:
+ protected:
+ friend int networkThread(void *data);
+ friend class MessageOut;
+
static Network *instance();
void setError(const std::string &error);
@@ -122,4 +125,6 @@ class Network
static Network *mInstance;
};
-#endif
+}
+
+#endif // NET_EA_NETWORK_H
diff --git a/src/net/ea/npchandler.cpp b/src/net/ea/npchandler.cpp
index 41caf226..24d8fb64 100644
--- a/src/net/ea/npchandler.cpp
+++ b/src/net/ea/npchandler.cpp
@@ -55,7 +55,7 @@ NpcHandler::NpcHandler()
npcHandler = this;
}
-void NpcHandler::handleMessage(MessageIn &msg)
+void NpcHandler::handleMessage(Net::MessageIn &msg)
{
int id;
bool resetPlayer = false;
diff --git a/src/net/ea/npchandler.h b/src/net/ea/npchandler.h
index 557b97d9..56802d03 100644
--- a/src/net/ea/npchandler.h
+++ b/src/net/ea/npchandler.h
@@ -22,10 +22,11 @@
#ifndef NET_EA_NPCHANDLER_H
#define NET_EA_NPCHANDLER_H
-#include "net/messagehandler.h"
#include "net/net.h"
#include "net/npchandler.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class NpcHandler : public MessageHandler, public Net::NpcHandler
@@ -33,7 +34,7 @@ class NpcHandler : public MessageHandler, public Net::NpcHandler
public:
NpcHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void talk(int npcId);
diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp
index 27e19392..0865f71c 100644
--- a/src/net/ea/partyhandler.cpp
+++ b/src/net/ea/partyhandler.cpp
@@ -69,7 +69,7 @@ PartyHandler::~PartyHandler()
//deletePartyTab();
}
-void PartyHandler::handleMessage(MessageIn &msg)
+void PartyHandler::handleMessage(Net::MessageIn &msg)
{
switch (msg.getId())
{
diff --git a/src/net/ea/partyhandler.h b/src/net/ea/partyhandler.h
index a9fe843b..188df2ac 100644
--- a/src/net/ea/partyhandler.h
+++ b/src/net/ea/partyhandler.h
@@ -22,10 +22,11 @@
#ifndef NET_EA_PARTYHANDLER_H
#define NET_EA_PARTYHANDLER_H
-#include "net/messagehandler.h"
#include "net/net.h"
#include "net/partyhandler.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class PartyHandler : public MessageHandler, public Net::PartyHandler
@@ -35,7 +36,7 @@ class PartyHandler : public MessageHandler, public Net::PartyHandler
~PartyHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void create(const std::string &name = "");
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index ca308bb2..454d6210 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -162,7 +162,7 @@ PlayerHandler::PlayerHandler()
playerHandler = this;
}
-void PlayerHandler::handleMessage(MessageIn &msg)
+void PlayerHandler::handleMessage(Net::MessageIn &msg)
{
switch (msg.getId())
{
@@ -570,4 +570,14 @@ bool PlayerHandler::canUseMagic()
return player_node->getAttributeEffective(MATK) > 0;
}
+bool PlayerHandler::canCorrectAttributes()
+{
+ return false;
+}
+
+int PlayerHandler::getJobLocation()
+{
+ return JOB;
+}
+
} // namespace EAthena
diff --git a/src/net/ea/playerhandler.h b/src/net/ea/playerhandler.h
index 78e64a88..61f3b705 100644
--- a/src/net/ea/playerhandler.h
+++ b/src/net/ea/playerhandler.h
@@ -22,10 +22,11 @@
#ifndef NET_EA_PLAYERHANDLER_H
#define NET_EA_PLAYERHANDLER_H
-#include "net/messagehandler.h"
#include "net/net.h"
#include "net/playerhandler.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class PlayerHandler : public MessageHandler, public Net::PlayerHandler
@@ -33,7 +34,7 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler
public:
PlayerHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void attack(int id);
@@ -60,6 +61,10 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler
void ignoreAll(bool ignore);
bool canUseMagic();
+
+ bool canCorrectAttributes();
+
+ int getJobLocation();
};
} // namespace EAthena
diff --git a/src/net/ea/specialhandler.cpp b/src/net/ea/specialhandler.cpp
index 528f531e..5def63b7 100644
--- a/src/net/ea/specialhandler.cpp
+++ b/src/net/ea/specialhandler.cpp
@@ -83,7 +83,7 @@ SpecialHandler::SpecialHandler()
specialHandler = this;
}
-void SpecialHandler::handleMessage(MessageIn &msg)
+void SpecialHandler::handleMessage(Net::MessageIn &msg)
{
int skillCount;
int skillId;
diff --git a/src/net/ea/specialhandler.h b/src/net/ea/specialhandler.h
index eac53569..501ea74d 100644
--- a/src/net/ea/specialhandler.h
+++ b/src/net/ea/specialhandler.h
@@ -22,10 +22,11 @@
#ifndef NET_EA_SKILLHANDLER_H
#define NET_EA_SKILLHANDLER_H
-#include "net/messagehandler.h"
#include "net/net.h"
#include "net/specialhandler.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class SpecialHandler : public MessageHandler, public Net::SpecialHandler
@@ -33,7 +34,7 @@ class SpecialHandler : public MessageHandler, public Net::SpecialHandler
public:
SpecialHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void use(int id);
diff --git a/src/net/ea/tradehandler.cpp b/src/net/ea/tradehandler.cpp
index 4f045573..bfd01f89 100644
--- a/src/net/ea/tradehandler.cpp
+++ b/src/net/ea/tradehandler.cpp
@@ -76,7 +76,7 @@ TradeHandler::TradeHandler()
}
-void TradeHandler::handleMessage(MessageIn &msg)
+void TradeHandler::handleMessage(Net::MessageIn &msg)
{
switch (msg.getId())
{
diff --git a/src/net/ea/tradehandler.h b/src/net/ea/tradehandler.h
index 1d94b849..b8a99421 100644
--- a/src/net/ea/tradehandler.h
+++ b/src/net/ea/tradehandler.h
@@ -22,10 +22,11 @@
#ifndef NET_EA_TRADEHANDLER_H
#define NET_EA_TRADEHANDLER_H
-#include "net/messagehandler.h"
#include "net/net.h"
#include "net/tradehandler.h"
+#include "net/ea/messagehandler.h"
+
namespace EAthena {
class TradeHandler : public MessageHandler, public Net::TradeHandler
@@ -33,7 +34,7 @@ class TradeHandler : public MessageHandler, public Net::TradeHandler
public:
TradeHandler();
- void handleMessage(MessageIn &msg);
+ void handleMessage(Net::MessageIn &msg);
void request(Being *being);