summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--src/being.cpp6
-rw-r--r--src/game.cpp53
-rw-r--r--src/gui/buy.cpp11
-rw-r--r--src/gui/buysell.cpp12
-rw-r--r--src/gui/char_select.cpp38
-rw-r--r--src/gui/char_server.cpp14
-rw-r--r--src/gui/chat.cpp20
-rw-r--r--src/gui/npc.cpp41
-rw-r--r--src/gui/npc_text.cpp10
-rw-r--r--src/gui/popupmenu.cpp19
-rw-r--r--src/gui/requesttrade.cpp22
-rw-r--r--src/gui/sell.cpp13
-rw-r--r--src/gui/skill.cpp7
-rw-r--r--src/gui/status.cpp42
-rw-r--r--src/gui/trade.cpp27
-rw-r--r--src/inventory.cpp29
-rw-r--r--src/net/messageout.cpp8
-rw-r--r--src/net/network.cpp35
-rw-r--r--src/net/network.h5
-rw-r--r--src/net/protocol.cpp40
-rw-r--r--src/net/protocol.h23
22 files changed, 270 insertions, 213 deletions
diff --git a/ChangeLog b/ChangeLog
index 68d2de43..6550f5c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,14 @@
* The Mana World.dev, src/gui/skill.cpp: Updated to last changes, and
wrong names fixes.
+ * src/being.cpp, src/game.cpp, src/gui/buy.cpp, src/gui/buysell.cpp,
+ src/gui/char_select.cpp, src/gui/char_server, src/gui/chat.cpp,
+ src/gui/npc.cpp, src/gui/npc_text.cpp, src/gui/popupmenu.cpp,
+ src/gui/requesttrade.cpp, src/gui/sell.cpp, src/gui/skill.cpp,
+ src/gui/status.cpp, src/gui/trade.cpp, src/inventory.cpp,
+ src/net/messageout.cpp, src/net/network.cpp, src/net/network.h,
+ src/net/protocol.cpp, src/net/protocol.h: Completed transition to use
+ MessageOut.
2005-09-17 Yohann Ferreira <bertram@cegetel.net>
diff --git a/src/being.cpp b/src/being.cpp
index 4ba88a33..0a6f1043 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -36,6 +36,7 @@
#include "gui/gui.h"
+#include "net/messageout.h"
#include "net/network.h"
#include "net/protocol.h"
@@ -66,8 +67,9 @@ Being* createBeing(unsigned int id, unsigned short job, Map *map)
// If the being is a player, request the name
if (being->getType() == Being::PLAYER)
{
- writeWord(0, 0x0094);
- writeLong(2, being->getId());//readLong(2));
+ MessageOut outMsg;
+ outMsg.writeShort(0x0094);
+ outMsg.writeLong(being->getId());//readLong(2));
writeSet(6);
}
// If the being is a monster then load the monsterset
diff --git a/src/game.cpp b/src/game.cpp
index 1f725858..4616e811 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -63,6 +63,7 @@
#include "gui/trade.h"
#include "net/messagein.h"
+#include "net/messageout.h"
#include "net/network.h"
#include "net/protocol.h"
@@ -119,8 +120,9 @@ const int MAX_TIME = 10000;
class DeatchNoticeListener : public gcn::ActionListener {
public:
void action(const std::string &eventId) {
- writeWord(0, 0x00b2);
- writeByte(2, 0);
+ MessageOut outMsg;
+ outMsg.writeShort(0x00b2);
+ outMsg.writeByte(0);
writeSet(3);
deathNotice = NULL;
}
@@ -478,10 +480,6 @@ void do_input()
else if (deathNotice)
{
deathNotice->action("ok");
- writeWord(0, 0x00b2);
- writeByte(2, 0);
- writeSet(3);
- deathNotice = NULL;
}
// Close the Browser if opened
else if (helpWindow->isVisible())
@@ -528,8 +526,10 @@ void do_input()
if (id)
{
- writeWord(0, 0x009f);
- writeLong(2, id);
+ // TODO: remove duplicated code, probably add a pick up command
+ MessageOut outMsg;
+ outMsg.writeShort(0x009f);
+ outMsg.writeLong(id);
writeSet(6);
}
used = true;
@@ -628,8 +628,9 @@ void do_input()
if (emotion)
{
- writeWord(0, 0x00bf);
- writeByte(2, emotion);
+ MessageOut outMsg;
+ outMsg.writeShort(0x00bf);
+ outMsg.writeByte(emotion);
writeSet(3);
action_time = false;
used = true;
@@ -665,19 +666,23 @@ void do_input()
{
// Player default: trade
case Being::PLAYER:
- writeWord(0, 0x00e4);
- writeLong(2, target->getId());
+ {
+ MessageOut outMsg;
+ outMsg.writeShort(0x00e4);
+ outMsg.writeLong(target->getId());
writeSet(6);
tradePartnerName = target->getName();
+ }
break;
// NPC default: talk
case Being::NPC:
if (!current_npc)
{
- writeWord(0, 0x0090);
- writeLong(2, target->getId());
- writeByte(6, 0);
+ MessageOut outMsg;
+ outMsg.writeShort(0x0090);
+ outMsg.writeLong(target->getId());
+ outMsg.writeByte(0);
writeSet(7);
current_npc = target->getId();
}
@@ -719,8 +724,9 @@ void do_input()
// "sqrt(dx*dx + dy*dy) < 2" is equal to "dx*dx + dy*dy < 4"
if ((dx*dx + dy*dy) < 4)
{
- writeWord(0, 0x009f);
- writeLong(2, floorItemId);
+ MessageOut outMsg;
+ outMsg.writeShort(0x009f);
+ outMsg.writeLong(floorItemId);
writeSet(6);
}
}
@@ -912,8 +918,9 @@ void do_input()
if (id != 0)
{
- writeWord(0, 0x009f);
- writeLong(2, id);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_ITEM_PICKUP);
+ outMsg.writeLong(id);
writeSet(6);
}
}
@@ -1225,8 +1232,9 @@ void do_parse()
if (tradeWindow->isVisible() == true || requestTradeDialogOpen)
{
- writeWord(0, CMSG_TRADE_RESPONSE);
- writeByte(2, 0x04);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_TRADE_RESPONSE);
+ outMsg.writeByte(4);
writeSet(3);
break;
}
@@ -1456,7 +1464,8 @@ void do_parse()
player_node->setMap(tiledMap);
// Send "map loaded"
- writeWord(0, 0x007d);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_MAP_LOADED);
writeSet(2);
flush();
}
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 3a32824a..c825c82e 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -38,7 +38,9 @@
#include "../resources/iteminfo.h"
#include "../resources/itemmanager.h"
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
BuyDialog::BuyDialog():
@@ -235,10 +237,11 @@ void BuyDialog::action(const std::string& eventId)
// there a better way to ensure this fails in an _obivous_ way in C++?
else if (eventId == "buy" && (m_amountItems > 0 &&
m_amountItems <= m_maxItems)) {
- writeWord(0, 0x00c8);
- writeWord(2, 8);
- writeWord(4, m_amountItems);
- writeWord(6, shopInventory[selectedItem].id);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_NPC_BUY_REQUEST);
+ outMsg.writeShort(8);
+ outMsg.writeShort(m_amountItems);
+ outMsg.writeShort(shopInventory[selectedItem].id);
writeSet(8);
// update money !
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index 6a56e67f..47777ca0 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -22,9 +22,14 @@
*/
#include "buysell.h"
+
#include "button.h"
+
#include "../game.h"
+
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
BuySellDialog::BuySellDialog():
Window("Shop")
@@ -77,9 +82,10 @@ void BuySellDialog::action(const std::string& eventId)
current_npc = 0;
}
if (actionId > -1) {
- writeWord(0, 0x00c5);
- writeLong(2, current_npc);
- writeByte(6, actionId);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_NPC_BUY_SELL_REQUEST);
+ outMsg.writeLong(current_npc);
+ outMsg.writeByte(actionId);
writeSet(7);
}
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 44165707..4b52f49e 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -41,9 +41,12 @@
#include "../playerinfo.h"
#include "../net/messagein.h"
+#include "../net/messageout.h"
#include "../net/network.h"
#include "../net/protocol.h"
+
+
CharSelectDialog::CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m):
ConfirmDialog(m,
"Confirm", "Are you sure you want to delete this character?"),
@@ -192,8 +195,10 @@ void CharSelectDialog::setPlayerInfo(PLAYER_INFO *pi)
void CharSelectDialog::serverCharDelete()
{
// Request character deletion
- writeWord(0, 0x0068);
- writeLong(2, char_info[0]->id);
+ MessageOut outMsg;
+ outMsg.writeShort(0x0068);
+ outMsg.writeLong(char_info[0]->id);
+ outMsg.writeString("a@a.com", 40);
writeSet(46);
MessageIn msg = get_next_message();
@@ -221,8 +226,9 @@ void CharSelectDialog::serverCharDelete()
void CharSelectDialog::serverCharSelect()
{
// Request character selection
- writeWord(0, 0x0066);
- writeByte(2, 0);
+ MessageOut outMsg;
+ outMsg.writeShort(0x0066);
+ outMsg.writeByte(0);
writeSet(3);
MessageIn msg = get_next_message();
@@ -407,17 +413,19 @@ std::string CharCreateDialog::getName()
void CharCreateDialog::serverCharCreate()
{
- writeWord(0, 0x0067);
- strcpy(writePointer(2), getName().c_str());
- writeByte(26, 5);
- writeByte(27, 5);
- writeByte(28, 5);
- writeByte(29, 5);
- writeByte(30, 5);
- writeByte(31, 5);
- writeByte(32, 0);
- writeWord(33, playerBox->hairColor + 1);
- writeWord(35, playerBox->hairStyle + 1);
+ // Send character infos
+ MessageOut outMsg;
+ outMsg.writeShort(0x0067);
+ outMsg.writeString(getName(), 24);
+ outMsg.writeByte(5);
+ outMsg.writeByte(5);
+ outMsg.writeByte(5);
+ outMsg.writeByte(5);
+ outMsg.writeByte(5);
+ outMsg.writeByte(5);
+ outMsg.writeByte(0);
+ outMsg.writeShort(playerBox->hairColor + 1);
+ outMsg.writeShort(playerBox->hairStyle + 1);
writeSet(37);
MessageIn msg = get_next_message();
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index 4da8db84..3b6312e4 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -37,6 +37,7 @@
#include "../serverinfo.h"
#include "../net/messagein.h"
+#include "../net/messageout.h"
#include "../net/network.h"
extern SERVER_INFO **server_info;
@@ -149,12 +150,13 @@ void server_char_server(int serverIndex)
}
// Send login infos
- writeWord(0, 0x0065);
- writeLong(2, account_ID);
- writeLong(6, session_ID1);
- writeLong(10, session_ID2);
- writeWord(14, 0);
- writeByte(16, sex);
+ MessageOut outMsg;
+ outMsg.writeShort(0x0065);
+ outMsg.writeLong(account_ID);
+ outMsg.writeLong(session_ID1);
+ outMsg.writeLong(session_ID2);
+ outMsg.writeShort(0); // unknown
+ outMsg.writeByte(sex);
writeSet(17);
// Skipping a mysterious 4 bytes
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index e6dabaaa..3ef6703c 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -31,8 +31,11 @@
#include "scrollarea.h"
#include "../playerinfo.h"
+#include "../log.h"
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
ChatWindow::ChatWindow(const std::string &logfile):
Window("")
@@ -194,7 +197,7 @@ bool ChatWindow::isFocused()
char *ChatWindow::chat_send(std::string nick, std::string msg)
{
- short packid = 0x008c;
+ short packetId = CMSG_CHAT_MESSAGE;
// prepare command
if (msg.substr(0, 1) == "/") {
@@ -211,17 +214,16 @@ char *ChatWindow::chat_send(std::string nick, std::string msg)
nick += " : ";
nick += msg;
msg = nick;
- packid = 0x008c;
+ //packetId = 0x008c;
}
- msg += "\0";
-
// send processed message
- writeWord(0, packid);
- writeWord(2, (unsigned short)(msg.length() + 4));
- memcpy(writePointer(4), msg.c_str(), msg.length());
- writeSet((int)msg.length()+4);
- nick = msg = "";
+ MessageOut outMsg;
+ outMsg.writeShort(packetId);
+ outMsg.writeShort(msg.length() + 4);
+ outMsg.writeString(msg, msg.length());
+ writeSet(msg.length() + 4);
+
return "";
}
diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp
index c8d426f3..696b2825 100644
--- a/src/gui/npc.cpp
+++ b/src/gui/npc.cpp
@@ -22,11 +22,16 @@
*/
#include "npc.h"
+
#include "button.h"
#include "scrollarea.h"
#include "listbox.h"
+
#include "../game.h"
+
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
NpcListDialog::NpcListDialog():
Window("NPC")
@@ -106,27 +111,27 @@ NpcListDialog::reset()
void
NpcListDialog::action(const std::string& eventId)
{
- if (eventId == "ok") {
+ int choice = 0xff; // 0xff means cancel
+
+ if (eventId == "ok")
+ {
// Send the selected index back to the server
int selectedIndex = itemList->getSelected();
- if (selectedIndex > -1) {
- writeWord(0, 0x00b8);
- writeLong(2, current_npc);
- writeByte(6, selectedIndex + 1);
- writeSet(7);
- setVisible(false);
- current_npc = 0;
- reset();
+ if (selectedIndex > -1)
+ {
+ choice = selectedIndex + 1;
}
}
- else if (eventId == "cancel") {
- // 0xff packet means cancel
- writeWord(0, 0x00b8);
- writeLong(2, current_npc);
- writeByte(6, 0xff);
- writeSet(7);
- setVisible(false);
- reset();
- current_npc = 0;
+ else if (eventId == "cancel")
+ {
}
+
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_NPC_LIST_CHOICE);
+ outMsg.writeLong(current_npc);
+ outMsg.writeByte(choice);
+ writeSet(7);
+ setVisible(false);
+ reset();
+ current_npc = 0;
}
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 67a9e9a3..8596796f 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -22,11 +22,16 @@
*/
#include "npc_text.h"
+
#include "scrollarea.h"
#include "button.h"
#include "textbox.h"
+
#include "../game.h"
+
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
NpcTextDialog::NpcTextDialog():
Window("NPC")
@@ -76,8 +81,9 @@ NpcTextDialog::addText(const std::string &text)
void
NpcTextDialog::action(const std::string& eventId)
{
- writeWord(0, 0x00b9);
- writeLong(2, current_npc);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_NPC_NEXT_REQUEST);
+ outMsg.writeLong(current_npc);
writeSet(6);
setText("");
setVisible(false);
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 6a88cdfd..77f74f4c 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -40,7 +40,9 @@
#include "../inventory.h"
#include "../item.h"
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
#include "../resources/iteminfo.h"
#include "../resources/itemmanager.h"
@@ -130,9 +132,10 @@ void PopupMenu::handleLink(const std::string& link)
if ((link == "talk") && being && being->getType() == Being::NPC &&
(current_npc == 0))
{
- writeWord(0, 0x0090);
- writeLong(2, being->getId());
- writeByte(6, 0);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_NPC_TALK);
+ outMsg.writeLong(being->getId());
+ outMsg.writeByte(0);
writeSet(7);
current_npc = being->getId();
}
@@ -140,8 +143,9 @@ void PopupMenu::handleLink(const std::string& link)
// Trade action
else if ((link == "trade") && being && being->getType() == Being::PLAYER)
{
- writeWord(0, 0x00e4);
- writeLong(2, being->getId());
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_TRADE_REQUEST);
+ outMsg.writeLong(being->getId());
writeSet(6);
//tradePartner.flush();
//tradePartner << "Trade: You and " << being->name<< "";
@@ -166,8 +170,9 @@ void PopupMenu::handleLink(const std::string& link)
// Pick Up Floor Item action
else if ((link == "pickup") && floorItem)
{
- writeWord(0, 0x009f);
- writeLong(2, floorItem->getId());
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_ITEM_PICKUP);
+ outMsg.writeLong(floorItem->getId());
writeSet(6);
}
diff --git a/src/gui/requesttrade.cpp b/src/gui/requesttrade.cpp
index e3b70fd3..992b0c0f 100644
--- a/src/gui/requesttrade.cpp
+++ b/src/gui/requesttrade.cpp
@@ -27,7 +27,10 @@
#include <guichan/widgets/label.hpp>
#include "button.h"
+
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
bool requestTradeDialogOpen = false;
@@ -84,19 +87,18 @@ RequestTradeDialog::~RequestTradeDialog()
void RequestTradeDialog::action(const std::string& eventId)
{
+ int choice = 4; // 4 means trade canceled
+
if (eventId == "accept") {
- // Send the selected index back to the server
- writeWord(0, 0x00e6);
- writeByte(2, 3);
- writeSet(3);
- scheduleDelete();
+ choice = 3; // ok to trade
}
else if (eventId == "cancel") {
- // 0xff packet means cancel
- writeWord(0, 0x00e6);
- writeByte(2, 4);
- writeSet(3);
requestTradeDialogOpen = false;
- scheduleDelete();
}
+
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_TRADE_RESPONSE);
+ outMsg.writeByte(choice);
+ writeSet(3);
+ scheduleDelete();
}
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 7c030eb1..c3596503 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -40,7 +40,9 @@
#include "../resources/iteminfo.h"
#include "../resources/itemmanager.h"
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
SellDialog::SellDialog():
@@ -229,11 +231,12 @@ void SellDialog::action(const std::string& eventId)
else if (eventId == "sell") {
// Attempt sell
assert(m_amountItems > 0 && m_amountItems <= m_maxItems);
-
- writeWord(0, 0x00c9);
- writeWord(2, 8);
- writeWord(4, shopInventory[selectedItem].index);
- writeWord(6, m_amountItems);
+
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_NPC_SELL_REQUEST);
+ outMsg.writeShort(8);
+ outMsg.writeShort(shopInventory[selectedItem].index);
+ outMsg.writeShort(m_amountItems);
writeSet(8);
m_maxItems -= m_amountItems;
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 5b065e47..0059ec25 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -31,7 +31,9 @@
#include "../playerinfo.h"
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
char *skill_db[] = {
// 0-99
@@ -124,8 +126,9 @@ void SkillDialog::action(const std::string& eventId)
int selectedSkill = skillListBox->getSelected();
if (player_info->skillPoint > 0 && selectedSkill >= 0)
{
- writeWord(0, 0x0112);
- writeWord(2, skillList[selectedSkill]->id);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_SKILL_LEVELUP_REQUEST);
+ outMsg.writeShort(skillList[selectedSkill]->id);
writeSet(4);
}
}
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index 9bdb95a6..5a117982 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -30,7 +30,10 @@
#include "progressbar.h"
#include "../playerinfo.h"
+
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
StatusWindow::StatusWindow():
Window(player_info->name)
@@ -415,31 +418,36 @@ void StatusWindow::draw(gcn::Graphics *graphics)
void StatusWindow::action(const std::string& eventId)
{
// Stats Part
- if ( eventId.length() == 3 )
+ if (eventId.length() == 3)
{
- writeWord(0, 0x00bb);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_STAT_UPDATE_REQUEST);
- if (eventId == "STR") {
- writeWord(2, 0x000d);
+ if (eventId == "STR")
+ {
+ outMsg.writeShort(0x000d);
}
- if (eventId == "AGI") {
- writeWord(2, 0x000e);
+ if (eventId == "AGI")
+ {
+ outMsg.writeShort(0x000e);
}
- if (eventId == "VIT") {
- writeWord(2, 0x000f);
+ if (eventId == "VIT")
+ {
+ outMsg.writeShort(0x000f);
}
- if (eventId == "INT") {
- writeWord(2, 0x0010);
+ if (eventId == "INT")
+ {
+ outMsg.writeShort(0x0010);
}
- if (eventId == "DEX") {
- writeWord(2, 0x0011);
+ if (eventId == "DEX")
+ {
+ outMsg.writeShort(0x0011);
}
- if (eventId == "LUK") {
- writeWord(2, 0x0012);
+ if (eventId == "LUK")
+ {
+ outMsg.writeShort(0x0012);
}
-
- flush();
- writeByte(4, 1);
+ outMsg.writeByte(1);
writeSet(5);
}
}
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index e18dc969..6069b768 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -38,7 +38,9 @@
#include "../inventory.h"
#include "../item.h"
+#include "../net/messageout.h"
#include "../net/network.h"
+#include "../net/protocol.h"
#include "../resources/iteminfo.h"
@@ -240,9 +242,10 @@ void TradeWindow::receivedOk(bool own)
void TradeWindow::tradeItem(Item *item, int quantity)
{
- writeWord(0, 0x00e8);
- writeWord(2, item->getInvIndex());
- writeLong(4, quantity);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_TRADE_ITEM_ADD_REQUEST);
+ outMsg.writeShort(item->getInvIndex());
+ outMsg.writeLong(quantity);
writeSet(8);
flush();
}
@@ -313,7 +316,8 @@ void TradeWindow::action(const std::string &eventId)
}
else if (eventId == "cancel")
{
- writeWord(0, 0x00ed);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_TRADE_CANCEL_REQUEST);
writeSet(2);
flush();
}
@@ -326,23 +330,26 @@ void TradeWindow::action(const std::string &eventId)
{
tempMoney[1] << tempInt;
moneyField->setText(tempMoney[1].str());
-
- writeWord(0, 0x00e8);
- writeWord(2, 0);
- writeLong(4, tempInt);
+
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_TRADE_ITEM_ADD_REQUEST);
+ outMsg.writeShort(0);
+ outMsg.writeLong(tempInt);
writeSet(8);
flush();
} else {
moneyField->setText("");
}
moneyField->setEnabled(false);
- writeWord(0, 0x00eb);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_TRADE_ADD_COMPLETE);
writeSet(2);
flush();
}
else if (eventId == "trade")
{
- writeWord(0, 0x00ef);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_TRADE_OK);
writeSet(2);
flush();
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index cf39f042..d7632737 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -25,7 +25,10 @@
#include "equipment.h"
#include "item.h"
+
+#include "net/messageout.h"
#include "net/network.h"
+#include "net/protocol.h"
Inventory::Inventory()
{
@@ -90,9 +93,10 @@ bool Inventory::contains(Item *item)
int Inventory::useItem(Item *item)
{
- writeWord(0, 0x00a7);
- writeWord(2, item->getInvIndex());
- writeLong(4, item->getId());
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_PLAYER_INVENTORY_USE);
+ outMsg.writeShort(item->getInvIndex());
+ outMsg.writeLong(item->getId());
// Note: id is dest of item, usually player_node->account_ID ??
writeSet(8);
flush();
@@ -102,9 +106,10 @@ int Inventory::useItem(Item *item)
int Inventory::dropItem(Item *item, int quantity)
{
// TODO: Fix wrong coordinates of drops, serverside?
- writeWord(0, 0x00a2);
- writeWord(2, item->getInvIndex());
- writeWord(4, quantity);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_PLAYER_INVENTORY_DROP);
+ outMsg.writeShort(item->getInvIndex());
+ outMsg.writeShort(quantity);
writeSet(6);
flush();
return 0;
@@ -112,17 +117,19 @@ int Inventory::dropItem(Item *item, int quantity)
void Inventory::equipItem(Item *item)
{
- writeWord(0, 0x00a9);
- writeWord(2, item->getInvIndex());
- writeWord(4, 0);
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_PLAYER_EQUIP);
+ outMsg.writeShort(item->getInvIndex());
+ outMsg.writeShort(0);
writeSet(6);
flush();
}
void Inventory::unequipItem(Item *item)
{
- writeWord(0, 0x00ab);
- writeWord(2, item->getInvIndex());
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_PLAYER_UNEQUIP);
+ outMsg.writeShort(item->getInvIndex());
writeSet(4);
flush();
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index d25cc62b..aa7f06c4 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -37,7 +37,7 @@ MessageOut::MessageOut():
{
// TODO: data not to be already allocated, keep it this way unitl full
// conversion
- mData = out;
+ mData = out + out_size;
}
MessageOut::~MessageOut()
@@ -54,8 +54,8 @@ MessageOut::~MessageOut()
void MessageOut::expand(size_t bytes)
{
- mData = (char*)realloc(mData, bytes);
- mDataSize = bytes;
+ /*mData = (char*)realloc(mData, bytes);
+ mDataSize = bytes;*/
}
void MessageOut::writeByte(char value)
@@ -97,8 +97,6 @@ void MessageOut::writeString(const std::string &string, int length)
{
// Write the length at the start if not fixed
writeShort(string.length());
- toWrite = string;
-
expand(mPos + string.length());
}
else
diff --git a/src/net/network.cpp b/src/net/network.cpp
index 3b1d6569..4656a233 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -279,41 +279,6 @@ get_next_message()
return MessageIn(in, length);
}
-void writeByte(int pos, unsigned char value)//writeByte(unsigned char value)
-{
- (*(unsigned char *)(out + pos + out_size)) = value;
- //out_size++;
-}
-
-void writeWord(int pos, unsigned short value)//writeWord(unsigned short value)
-{
-#ifdef MACOSX
- (*(unsigned short *)(out + pos + out_size)) = DR_SwapTwoBytes(value);
-#else
- (*(unsigned short *)(out + pos + out_size)) = value;
-#endif
- //SDLNet_Write16(value, (out + (pos + out_size)));
- //out_size += 2;
-}
-
-void writeLong(int pos, unsigned int value)//writeLong(int value)
-{
-#ifdef MACOSX
- (*(unsigned int *)(out + pos + out_size)) = DR_SwapFourBytes(value);
-#else
- (*(unsigned int *)(out + pos + out_size)) = value;
-#endif
- //SDLNet_Write32((Uint32)value, (out + (pos + out_size)));
- //out_size += 4;
-}
-
-char *writePointer(int pos)//writeString(const std::string &string, int length)
-{
- return (out+(pos+out_size));
- //memcpy((out + out_size), string.c_str(), length);
- //out_size += length;
-}
-
void writeSet(unsigned int value)
{
if (out_size + value >= buffer_size) {
diff --git a/src/net/network.h b/src/net/network.h
index b6c4a520..c6a4380b 100644
--- a/src/net/network.h
+++ b/src/net/network.h
@@ -44,11 +44,6 @@ void flush();
MessageIn get_next_message();
extern char *out;
-
-void writeByte(int pos, unsigned char value);//writeByte(char value);
-void writeWord(int pos, unsigned short value);//writeWord(short value);
-void writeLong(int pos, unsigned int value);//writeLong(int value);
-char *writePointer(int pos); //writeString(const std::string &string, int length);
void writeSet(unsigned int value);
void skip(int len);
diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp
index 5a1ed9c5..2e4089d4 100644
--- a/src/net/protocol.cpp
+++ b/src/net/protocol.cpp
@@ -24,6 +24,7 @@
#include "protocol.h"
#include "messagein.h"
+#include "messageout.h"
#include "network.h"
#include "../being.h"
@@ -78,12 +79,13 @@ void map_start()
}
// Send login infos
- writeWord(0, 0x0072);
- writeLong(2, account_ID);
- writeLong(6, char_ID);
- writeLong(10, session_ID1);
- writeLong(14, session_ID2);
- writeByte(18, sex);
+ MessageOut outMsg;
+ outMsg.writeShort(0x0072);
+ outMsg.writeLong(account_ID);
+ outMsg.writeLong(char_ID);
+ outMsg.writeLong(session_ID1);
+ outMsg.writeLong(session_ID2);
+ outMsg.writeByte(sex);
writeSet(19);
// Skip a mysterious 4 bytes
@@ -113,34 +115,28 @@ void map_start()
skip(msg.getLength());
// Send "map loaded"
- writeWord(0, 0x007d);
+ // TODO: be able to reuse the same msg
+ MessageOut newMsg;
+ newMsg.writeShort(0x007d);
writeSet(2);
- flush();
}
void walk(unsigned short x, unsigned short y, unsigned char direction)
{
char temp[3];
+ MessageOut outMsg;
set_coordinates(temp, x, y, direction);
- writeWord(0, 0x0085);
- memcpy(writePointer(2), temp, 3);
+ outMsg.writeShort(0x0085);
+ outMsg.writeString(temp, 3);
writeSet(5);
}
-void speak(char *speech)
-{
- int len = (int)strlen(speech);
- writeWord(0, 0x008c);
- writeWord(2, len + 4);
- memcpy(writePointer(4), speech, len);
- writeSet(len + 4);
-}
-
void action(char type, int id)
{
- writeWord(0, 0x0089);
- writeLong(2, id);
- writeByte(6, type);
+ MessageOut outMsg;
+ outMsg.writeShort(0x0089);
+ outMsg.writeLong(id);
+ outMsg.writeByte(type);
writeSet(7);
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 69b36783..8609530a 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -84,6 +84,26 @@ class Being;
// Packets from client to server
#define CMSG_TRADE_RESPONSE 0x00e6
+#define CMSG_ITEM_PICKUP 0x009f
+#define CMSG_MAP_LOADED 0x007d
+#define CMSG_NPC_BUY_REQUEST 0x00c8
+#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5
+#define CMSG_CHAT_MESSAGE 0x008c
+#define CMSG_NPC_LIST_CHOICE 0x00b8
+#define CMSG_NPC_NEXT_REQUEST 0x00b9
+#define CMSG_NPC_SELL_REQUEST 0x00c9
+#define CMSG_SKILL_LEVELUP_REQUEST 0x0112
+#define CMSG_STAT_UPDATE_REQUEST 0x00bb
+#define CMSG_TRADE_ITEM_ADD_REQUEST 0x00e8
+#define CMSG_TRADE_CANCEL_REQUEST 0x00ed
+#define CMSG_TRADE_ADD_COMPLETE 0x00eb
+#define CMSG_TRADE_OK 0x00ef
+#define CMSG_NPC_TALK 0x0090
+#define CMSG_TRADE_REQUEST 0x00e4
+#define CMSG_PLAYER_INVENTORY_USE 0x00a7
+#define CMSG_PLAYER_INVENTORY_DROP 0x00a2
+#define CMSG_PLAYER_EQUIP 0x00a9
+#define CMSG_PLAYER_UNEQUIP 0x00ab
/** Decodes src direction */
@@ -101,9 +121,6 @@ void map_start();
/** Requests to walk */
void walk(unsigned short x, unsigned short y, unsigned char direction);
-/** Request to speak */
-void speak(char *speech);
-
/** Request to attack */
Being* attack(unsigned short x, unsigned short y, unsigned char direction);