summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-31 23:02:12 -0600
committerJared Adams <jaxad0127@gmail.com>2009-03-31 23:02:12 -0600
commitea4cfda4712ac31326b64ddf9dff61e448aeed28 (patch)
tree2bff17828862ebed77d44e65729a2d2944602ba9
parent78e67de6f70aab502a85578264b60493a818b39f (diff)
downloadmana-client-ea4cfda4712ac31326b64ddf9dff61e448aeed28.tar.gz
mana-client-ea4cfda4712ac31326b64ddf9dff61e448aeed28.tar.bz2
mana-client-ea4cfda4712ac31326b64ddf9dff61e448aeed28.tar.xz
mana-client-ea4cfda4712ac31326b64ddf9dff61e448aeed28.zip
Implement a few more handlers for eAthena
Party, skill, and trade handlers made for eAthena.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/commandhandler.cpp1
-rw-r--r--src/gui/partywindow.cpp9
-rw-r--r--src/gui/trade.cpp68
-rw-r--r--src/localplayer.cpp21
-rw-r--r--src/net/ea/gui/partytab.cpp27
-rw-r--r--src/net/ea/npchandler.cpp2
-rw-r--r--src/net/ea/party.cpp82
-rw-r--r--src/net/ea/party.h48
-rw-r--r--src/net/ea/partyhandler.cpp57
-rw-r--r--src/net/ea/partyhandler.h19
-rw-r--r--src/net/ea/skillhandler.cpp10
-rw-r--r--src/net/ea/skillhandler.h7
-rw-r--r--src/net/ea/tradehandler.cpp49
-rw-r--r--src/net/ea/tradehandler.h21
-rw-r--r--src/net/tradehandler.h2
16 files changed, 229 insertions, 196 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 0fe7fee7..78766e32 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -477,8 +477,6 @@ tmw_SOURCES += \
net/ea/network.h \
net/ea/npchandler.cpp \
net/ea/npchandler.h \
- net/ea/party.cpp \
- net/ea/party.h \
net/ea/partyhandler.cpp \
net/ea/partyhandler.h \
net/ea/playerhandler.cpp \
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 7b5f1ddb..63633693 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -35,7 +35,6 @@
#include "net/tmwserv/gameserver/player.h"
#else
#include "net/messageout.h"
-#include "net/ea/party.h"
#include "net/ea/protocol.h"
#endif
diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp
index d2fd7173..fde39179 100644
--- a/src/gui/partywindow.cpp
+++ b/src/gui/partywindow.cpp
@@ -23,10 +23,11 @@
#include "gui/widgets/chattab.h"
+#include "net/net.h"
#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/chatserver/party.h"
#else
-#include "net/ea/party.h"
+#include "net/ea/partyhandler.h"
#endif
#include "utils/gettext.h"
@@ -171,20 +172,22 @@ void PartyWindow::action(const gcn::ActionEvent &event)
if (eventId == "yes")
{
localChatTab->chatLog("Accepted invite from " + mPartyInviter);
+ // Net::getPartyHandler()->inviteResponse(true);
#ifdef TMWSERV_SUPPORT
Net::ChatServer::Party::acceptInvite(mPartyInviter);
#else
- eAthena::Party::respondToInvite(true);
+ partyHandler->inviteResponse(true);
#endif
mPartyInviter = "";
}
else if (eventId == "no")
{
localChatTab->chatLog("Rejected invite from " + mPartyInviter);
+ // Net::getPartyHandler()->inviteResponse(false);
#ifdef TMWSERV_SUPPORT
// TODO
#else
- eAthena::Party::respondToInvite(false);
+ partyHandler->inviteResponse(false);
#endif
mPartyInviter = "";
}
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index ce40f6ab..c94aad0a 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -19,37 +19,38 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <sstream>
-
-#include <guichan/font.hpp>
+#include "gui/trade.h"
-#include "button.h"
-#include "widgets/chattab.h"
-#include "inventorywindow.h"
-#include "item_amount.h"
-#include "itemcontainer.h"
-#include "label.h"
-#include "scrollarea.h"
-#include "textfield.h"
-#include "trade.h"
+#include "inventory.h"
+#include "item.h"
+#include "localplayer.h"
+#include "units.h"
-#include "widgets/layout.h"
+#include "gui/button.h"
+#include "gui/widgets/chattab.h"
+#include "gui/inventorywindow.h"
+#include "gui/item_amount.h"
+#include "gui/itemcontainer.h"
+#include "gui/label.h"
+#include "gui/scrollarea.h"
+#include "gui/textfield.h"
-#include "../inventory.h"
-#include "../item.h"
-#include "../localplayer.h"
-#include "../units.h"
+#include "gui/widgets/layout.h"
+#include "net/net.h"
#ifdef TMWSERV_SUPPORT
-#include "../net/tmwserv/gameserver/player.h"
+#include "net/tmwserv/gameserver/player.h"
#else
-#include "../net/messageout.h"
-#include "../net/ea/protocol.h"
+#include "net/ea/tradehandler.h"
#endif
-#include "../utils/gettext.h"
-#include "../utils/stringutils.h"
-#include "../utils/strprintf.h"
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+#include "utils/strprintf.h"
+
+#include <sstream>
+
+#include <guichan/font.hpp>
TradeWindow::TradeWindow():
Window(_("Trade: You")),
@@ -235,6 +236,7 @@ void TradeWindow::receivedOk(bool own)
void TradeWindow::tradeItem(Item *item, int quantity)
{
+ // Net::getTradeHandler()->addItem(item->getInvIndex(), quantity);
#ifdef TMWSERV_SUPPORT
Net::GameServer::Player::tradeItem(item->getInvIndex(), quantity);
addItem(item->getId(), true, quantity);
@@ -244,9 +246,7 @@ void TradeWindow::tradeItem(Item *item, int quantity)
// function. Detect the actual server version, and re-enable this
// for that version only.
//addItem(item->getId(), true, quantity, item->isEquipment());
- MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
- outMsg.writeInt32(quantity);
+ tradeHandler->addItem(item->getInvIndex(), quantity);
#endif
}
@@ -318,10 +318,12 @@ void TradeWindow::action(const gcn::ActionEvent &event)
setVisible(false);
reset();
player_node->setTrading(false);
+
+ // Net::getTradeHandler()->cancel();
#ifdef TMWSERV_SUPPORT
Net::GameServer::Player::acceptTrade(false);
#else
- MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST);
+ tradeHandler->cancel();
#endif
}
#ifdef EATHENA_SUPPORT
@@ -333,16 +335,15 @@ void TradeWindow::action(const gcn::ActionEvent &event)
{
mMoneyField->setText(toString(tempInt));
- MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeInt16(0);
- outMsg.writeInt32(tempInt);
+ // Net::getTradeHandler()->setMoney(tempInt);
+ tradeHandler->setMoney(tempInt);
}
else
{
mMoneyField->setText("");
}
mMoneyField->setEnabled(false);
- MessageOut outMsg(CMSG_TRADE_ADD_COMPLETE);
+ tradeHandler->confirm();
}
#endif
else if (event.getId() == "trade")
@@ -351,7 +352,7 @@ void TradeWindow::action(const gcn::ActionEvent &event)
Net::GameServer::Player::acceptTrade(true);
setStatus(PROPOSING);
#else
- MessageOut outMsg(CMSG_TRADE_OK);
+ tradeHandler->finish();
#endif
}
#ifdef TMWSERV_SUPPORT
@@ -367,9 +368,10 @@ void TradeWindow::action(const gcn::ActionEvent &event)
void TradeWindow::close()
{
+ // Net::getTradeHandler()->cancel();
#ifdef TMWSERV_SUPPORT
Net::GameServer::Player::acceptTrade(false);
#else
- MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST);
+ tradeHandler->cancel();
#endif
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index bf4df760..eec04a5c 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -43,6 +43,7 @@
#include "gui/storagewindow.h"
#endif
+#include "net/net.h"
#ifdef TMWSERV_SUPPORT
#include "effectmanager.h"
#include "guild.h"
@@ -52,8 +53,10 @@
#include "net/tmwserv/chatserver/party.h"
#else
#include "net/messageout.h"
-#include "net/ea/party.h"
+#include "net/ea/partyhandler.h"
#include "net/ea/protocol.h"
+#include "net/ea/skillhandler.h"
+#include "net/ea/tradehandler.h"
#endif
#include "resources/animation.h"
@@ -386,10 +389,11 @@ void LocalPlayer::inviteToParty(const std::string &name)
void LocalPlayer::inviteToParty(Player *player)
{
+ // Net::getPartyHandler()->invite(player->getId());
#ifdef TMWSERV_SUPPORT
Net::ChatServer::Party::invitePlayer(player->getName());
#else
- eAthena::Party::invite(player);
+ partyHandler->invite(player->getId());
#endif
}
@@ -776,8 +780,8 @@ void LocalPlayer::raiseSkill(Uint16 skillId)
if (mSkillPoint <= 0)
return;
- MessageOut outMsg(CMSG_SKILL_LEVELUP_REQUEST);
- outMsg.writeInt16(skillId);
+ // Net::getSkillHandler()->up(skillId);
+ skillHandler->up(skillId);
}
#endif
@@ -824,13 +828,15 @@ void LocalPlayer::tradeReply(bool accept)
if (!accept)
mTrading = false;
- MessageOut outMsg(CMSG_TRADE_RESPONSE);
- outMsg.writeInt8(accept ? 3 : 4);
+ // Net::getTradeHandler()->respond(accept);
+
+ tradeHandler->respond(accept);
}
#endif
void LocalPlayer::trade(Being *being) const
{
+ // Net::getTradeHandler()->request(being);
#ifdef TMWSERV_SUPPORT
extern std::string tradePartnerName;
extern int tradePartnerID;
@@ -838,8 +844,7 @@ void LocalPlayer::trade(Being *being) const
tradePartnerID = being->getId();
Net::GameServer::Player::requestTrade(tradePartnerID);
#else
- MessageOut outMsg(CMSG_TRADE_REQUEST);
- outMsg.writeInt32(being->getId());
+ tradeHandler->request(being);
#endif
}
diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp
index 9759962a..34b16663 100644
--- a/src/net/ea/gui/partytab.cpp
+++ b/src/net/ea/gui/partytab.cpp
@@ -23,10 +23,9 @@
#include "partytab.h"
-#include "net/messageout.h"
+#include "net/net.h"
-#include "net/ea/party.h"
-#include "net/ea/protocol.h"
+#include "net/ea/partyhandler.h"
#include "resources/iteminfo.h"
#include "resources/itemdb.h"
@@ -44,15 +43,14 @@ PartyTab::~PartyTab()
{
}
-void PartyTab::handleInput(const std::string &msg) {
- std::size_t length = msg.length() + 1;
-
- MessageOut outMsg(CMSG_PARTY_MESSAGE);
- outMsg.writeInt16(length + 4);
- outMsg.writeString(msg, length);
+void PartyTab::handleInput(const std::string &msg)
+{
+ // Net::getPartyHandler()->chat(msg);
+ partyHandler->chat(msg);
}
-void PartyTab::handleCommand(std::string msg) {
+void PartyTab::handleCommand(std::string msg)
+{
std::string::size_type pos = msg.find(' ');
std::string type(msg, 0, pos);
std::string args(msg, pos == std::string::npos ? msg.size() : pos + 1);
@@ -95,11 +93,16 @@ void PartyTab::handleCommand(std::string msg) {
}
else if (type == "create" || type == "new")
{
- eAthena::Party::create(args);
+ if (args.empty())
+ chatLog(_("Party name is missing."), BY_SERVER);
+ else
+ // Net::getPartyHandler()->create(args);
+ partyHandler->create(args);
}
else if (type == "leave")
{
- eAthena::Party::leave(args);
+ // Net::getPartyHandler()->leave();
+ partyHandler->leave();
}
else if (type == "settings")
{
diff --git a/src/net/ea/npchandler.cpp b/src/net/ea/npchandler.cpp
index 0b9a4cf6..9f9bc6a6 100644
--- a/src/net/ea/npchandler.cpp
+++ b/src/net/ea/npchandler.cpp
@@ -191,6 +191,6 @@ void NPCHandler::sellItem(int beingId, int itemId, int amount)
{
MessageOut outMsg(CMSG_NPC_SELL_REQUEST);
outMsg.writeInt16(8); // One item (length of packet)
- outMsg.writeInt16(itemId + 2);
+ outMsg.writeInt16(itemId + INVENTORY_OFFSET);
outMsg.writeInt16(amount);
}
diff --git a/src/net/ea/party.cpp b/src/net/ea/party.cpp
deleted file mode 100644
index bb7fb4c6..00000000
--- a/src/net/ea/party.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2008 Lloyd Bryant <lloyd_bryant@netzero.net>
- *
- * 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 "being.h"
-#include "localplayer.h"
-#include "party.h"
-
-#include "gui/widgets/chattab.h"
-#include "gui/chat.h"
-#include "gui/confirm_dialog.h"
-#include "gui/partywindow.h"
-
-#include "net/messageout.h"
-#include "net/ea/protocol.h"
-#include "net/ea/gui/partytab.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-#include "utils/strprintf.h"
-
-void eAthena::Party::create(const std::string &party)
-{
- if (party.empty())
- {
- partyTab->chatLog(_("Party name is missing."), BY_SERVER);
- return;
- }
- MessageOut outMsg(CMSG_PARTY_CREATE);
- outMsg.writeString(party.substr(0, 23), 24);
-}
-
-void eAthena::Party::leave(const std::string &args)
-{
- MessageOut outMsg(CMSG_PARTY_LEAVE);
- partyTab->chatLog(_("Left party."), BY_SERVER);
- player_node->setInParty(false);
-}
-
-void eAthena::Party::createResponse(bool ok)
-{
- if (ok)
- {
- partyTab->chatLog(_("Party successfully created."), BY_SERVER);
- player_node->setInParty(true);
- }
- else
- {
- partyTab->chatLog(_("Could not create party."), BY_SERVER);
- }
-}
-
-void eAthena::Party::invite(Player *player)
-{
- MessageOut outMsg(CMSG_PARTY_INVITE);
- outMsg.writeInt32(player->getId());
-}
-
-void eAthena::Party::respondToInvite(bool accept)
-{
- MessageOut outMsg(CMSG_PARTY_INVITED);
- outMsg.writeInt32(player_node->getId());
- outMsg.writeInt32(accept ? 1 : 0);
- player_node->setInParty(player_node->getInParty() || accept);
-}
diff --git a/src/net/ea/party.h b/src/net/ea/party.h
deleted file mode 100644
index f47c4956..00000000
--- a/src/net/ea/party.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2008 Lloyd Bryant <lloyd_bryant@netzero.net>
- *
- * 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 PARTY_H
-#define PARTY_H
-
-#include "being.h"
-#include "player.h"
-
-#include <string>
-
-namespace eAthena
-{
- namespace Party
- {
- void create(const std::string &party);
- void leave(const std::string &args);
-
- void createResponse(bool ok);
-
- void invite(Player *player);
-
- /**
- * Send invite response to the server
- */
- void respondToInvite(bool accept);
- }
-}
-
-#endif
diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp
index 6fdf6803..94abe0f1 100644
--- a/src/net/ea/partyhandler.cpp
+++ b/src/net/ea/partyhandler.cpp
@@ -22,13 +22,14 @@
#include "net/ea/partyhandler.h"
#include "beingmanager.h"
+#include "localplayer.h"
#include "gui/chat.h"
#include "gui/partywindow.h"
#include "net/messagein.h"
+#include "net/messageout.h"
-#include "net/ea/party.h"
#include "net/ea/protocol.h"
#include "net/ea/gui/partytab.h"
@@ -40,6 +41,8 @@ PartyTab *partyTab;
static void newPartyTab() { partyTab = new PartyTab(); }
static void deletePartyTab() { delete partyTab ; }
+PartyHandler *partyHandler;
+
PartyHandler::PartyHandler()
{
static const Uint16 _messages[] = {
@@ -56,6 +59,7 @@ PartyHandler::PartyHandler()
0
};
handledMessages = _messages;
+ partyHandler = this;
//newPartyTab();
}
@@ -70,7 +74,13 @@ void PartyHandler::handleMessage(MessageIn &msg)
switch (msg.getId())
{
case SMSG_PARTY_CREATE:
- eAthena::Party::createResponse(msg.readInt8());
+ if (msg.readInt8())
+ {
+ partyTab->chatLog(_("Party successfully created."), BY_SERVER);
+ player_node->setInParty(true);
+ }
+ else
+ partyTab->chatLog(_("Could not create party."), BY_SERVER);
break;
case SMSG_PARTY_INFO:
{
@@ -202,3 +212,46 @@ void PartyHandler::handleMessage(MessageIn &msg)
break;
}
}
+
+void PartyHandler::create(const std::string &name)
+{
+ MessageOut outMsg(CMSG_PARTY_CREATE);
+ outMsg.writeString(name.substr(0, 23), 24);
+}
+
+void PartyHandler::join(int partyId)
+{
+}
+
+void PartyHandler::invite(int playerId)
+{
+ MessageOut outMsg(CMSG_PARTY_INVITE);
+ outMsg.writeInt32(playerId);
+}
+
+void PartyHandler::inviteResponse(bool accept)
+{
+ MessageOut outMsg(CMSG_PARTY_INVITED);
+ outMsg.writeInt32(player_node->getId());
+ outMsg.writeInt32(accept ? 1 : 0);
+ player_node->setInParty(player_node->getInParty() || accept);
+}
+
+void PartyHandler::leave()
+{
+ MessageOut outMsg(CMSG_PARTY_LEAVE);
+ partyTab->chatLog(_("Left party."), BY_SERVER);
+ player_node->setInParty(false);
+}
+
+void PartyHandler::kick(int playerId)
+{
+ // TODO
+}
+
+void PartyHandler::chat(const std::string &text)
+{
+ MessageOut outMsg(CMSG_PARTY_MESSAGE);
+ outMsg.writeInt16(text.length() + 4);
+ outMsg.writeString(text, text.length());
+}
diff --git a/src/net/ea/partyhandler.h b/src/net/ea/partyhandler.h
index 34c3022e..5db4d43a 100644
--- a/src/net/ea/partyhandler.h
+++ b/src/net/ea/partyhandler.h
@@ -23,8 +23,9 @@
#define NET_EA_PARTYHANDLER_H
#include "net/messagehandler.h"
+#include "net/net.h"
-class PartyHandler : public MessageHandler
+class PartyHandler : public MessageHandler, public Net::PartyHandler
{
public:
PartyHandler();
@@ -32,6 +33,22 @@ class PartyHandler : public MessageHandler
~PartyHandler();
virtual void handleMessage(MessageIn &msg);
+
+ virtual void create(const std::string &name="");
+
+ virtual void join(int partyId);
+
+ virtual void invite(int playerId);
+
+ virtual void inviteResponse(bool accept);
+
+ virtual void leave();
+
+ virtual void kick(int playerId);
+
+ virtual void chat(const std::string &text);
};
+extern PartyHandler *partyHandler;
+
#endif // NET_EA_PARTYHANDLER_H
diff --git a/src/net/ea/skillhandler.cpp b/src/net/ea/skillhandler.cpp
index 477f96bf..0475c057 100644
--- a/src/net/ea/skillhandler.cpp
+++ b/src/net/ea/skillhandler.cpp
@@ -24,6 +24,7 @@
#include "net/ea/protocol.h"
#include "net/messagein.h"
+#include "net/messageout.h"
#include "log.h"
@@ -65,6 +66,8 @@
/** should always be zero if failed */
#define SKILL_FAILED 0x00
+SkillHandler *skillHandler;
+
SkillHandler::SkillHandler()
{
static const Uint16 _messages[] = {
@@ -73,6 +76,7 @@ SkillHandler::SkillHandler()
0
};
handledMessages = _messages;
+ skillHandler = this;
}
void SkillHandler::handleMessage(MessageIn &msg)
@@ -207,3 +211,9 @@ void SkillHandler::handleMessage(MessageIn &msg)
break;
}
}
+
+void SkillHandler::up(int skillId)
+{
+ MessageOut outMsg(CMSG_SKILL_LEVELUP_REQUEST);
+ outMsg.writeInt16(skillId);
+}
diff --git a/src/net/ea/skillhandler.h b/src/net/ea/skillhandler.h
index 8aa35c19..f3d1b9de 100644
--- a/src/net/ea/skillhandler.h
+++ b/src/net/ea/skillhandler.h
@@ -23,13 +23,18 @@
#define NET_EA_SKILLHANDLER_H
#include "net/messagehandler.h"
+#include "net/net.h"
-class SkillHandler : public MessageHandler
+class SkillHandler : public MessageHandler, public Net::SkillHandler
{
public:
SkillHandler();
virtual void handleMessage(MessageIn &msg);
+
+ virtual void up(int skillId);
};
+extern SkillHandler *skillHandler;
+
#endif // NET_EA_SKILLHANDLER_H
diff --git a/src/net/ea/tradehandler.cpp b/src/net/ea/tradehandler.cpp
index 1df02a1e..3a6ebe07 100644
--- a/src/net/ea/tradehandler.cpp
+++ b/src/net/ea/tradehandler.cpp
@@ -24,6 +24,7 @@
#include "net/ea/protocol.h"
#include "net/messagein.h"
+#include "net/messageout.h"
#include "inventory.h"
#include "item.h"
@@ -52,6 +53,8 @@ namespace {
} listener;
}
+TradeHandler *tradeHandler;
+
TradeHandler::TradeHandler()
{
static const Uint16 _messages[] = {
@@ -65,6 +68,7 @@ TradeHandler::TradeHandler()
0
};
handledMessages = _messages;
+ tradeHandler = this;
}
@@ -221,3 +225,48 @@ void TradeHandler::handleMessage(MessageIn &msg)
break;
}
}
+
+void TradeHandler::request(Being *being)
+{
+ MessageOut outMsg(CMSG_TRADE_REQUEST);
+ outMsg.writeInt32(being->getId());
+}
+
+void TradeHandler::respond(bool accept)
+{
+ MessageOut outMsg(CMSG_TRADE_RESPONSE);
+ outMsg.writeInt8(accept ? 3 : 4);
+}
+
+void TradeHandler::addItem(int slotNum, int amount)
+{
+ MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST);
+ outMsg.writeInt16(slotNum + INVENTORY_OFFSET);
+ outMsg.writeInt32(amount);
+}
+
+void TradeHandler::removeItem(int slotNum, int amount)
+{
+}
+
+void TradeHandler::setMoney(int amount)
+{
+ MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST);
+ outMsg.writeInt16(0);
+ outMsg.writeInt32(amount);
+}
+
+void TradeHandler::confirm()
+{
+ MessageOut outMsg(CMSG_TRADE_ADD_COMPLETE);
+}
+
+void TradeHandler::finish()
+{
+ MessageOut outMsg(CMSG_TRADE_OK);
+}
+
+void TradeHandler::cancel()
+{
+ MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST);
+}
diff --git a/src/net/ea/tradehandler.h b/src/net/ea/tradehandler.h
index 04a3c3e3..af7a064f 100644
--- a/src/net/ea/tradehandler.h
+++ b/src/net/ea/tradehandler.h
@@ -23,13 +23,32 @@
#define NET_EA_TRADEHANDLER_H
#include "net/messagehandler.h"
+#include "net/net.h"
-class TradeHandler : public MessageHandler
+class TradeHandler : public MessageHandler, public Net::TradeHandler
{
public:
TradeHandler();
virtual void handleMessage(MessageIn &msg);
+
+ virtual void request(Being *being);
+
+ virtual void respond(bool accept);
+
+ virtual void addItem(int slotNum, int amount);
+
+ virtual void removeItem(int slotNum, int amount);
+
+ virtual void setMoney(int amount);
+
+ virtual void confirm();
+
+ virtual void finish();
+
+ virtual void cancel();
};
+extern TradeHandler *tradeHandler;
+
#endif // NET_EA_TRADEHANDLER_H
diff --git a/src/net/tradehandler.h b/src/net/tradehandler.h
index 912e336d..671e7566 100644
--- a/src/net/tradehandler.h
+++ b/src/net/tradehandler.h
@@ -32,7 +32,7 @@ class TradeHandler
public:
virtual void request(Being *being) {}
- virtual void respond(bool accepet) {}
+ virtual void respond(bool accept) {}
virtual void addItem(int slotNum, int amount) {}