summaryrefslogtreecommitdiff
path: root/src/net/ea
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 /src/net/ea
parent78e67de6f70aab502a85578264b60493a818b39f (diff)
downloadmana-ea4cfda4712ac31326b64ddf9dff61e448aeed28.tar.gz
mana-ea4cfda4712ac31326b64ddf9dff61e448aeed28.tar.bz2
mana-ea4cfda4712ac31326b64ddf9dff61e448aeed28.tar.xz
mana-ea4cfda4712ac31326b64ddf9dff61e448aeed28.zip
Implement a few more handlers for eAthena
Party, skill, and trade handlers made for eAthena.
Diffstat (limited to 'src/net/ea')
-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
10 files changed, 174 insertions, 148 deletions
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