summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/manaserv/npchandler.cpp97
-rw-r--r--src/net/manaserv/npchandler.h20
-rw-r--r--src/net/npchandler.h15
-rw-r--r--src/net/tmwa/npchandler.cpp88
-rw-r--r--src/net/tmwa/npchandler.h21
5 files changed, 99 insertions, 142 deletions
diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp
index 09dccffe..9f63c837 100644
--- a/src/net/manaserv/npchandler.cpp
+++ b/src/net/manaserv/npchandler.cpp
@@ -51,6 +51,8 @@ NpcHandler::NpcHandler()
};
handledMessages = _messages;
npcHandler = this;
+
+ Mana::EventManager::bind(this, "NPC");
}
void NpcHandler::handleMessage(Net::MessageIn &msg)
@@ -127,58 +129,51 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
delete event;
}
-void NpcHandler::talk(int npcId)
-{
- MessageOut msg(PGMSG_NPC_TALK);
- msg.writeInt16(npcId);
- gameServerConnection->send(msg);
-}
-
-void NpcHandler::nextDialog(int npcId)
-{
- MessageOut msg(PGMSG_NPC_TALK_NEXT);
- msg.writeInt16(npcId);
- gameServerConnection->send(msg);
-}
-
-void NpcHandler::closeDialog(int npcId)
-{
- MessageOut msg(PGMSG_NPC_TALK_NEXT);
- msg.writeInt16(npcId);
- gameServerConnection->send(msg);
-}
-
-void NpcHandler::listInput(int npcId, int value)
-{
- MessageOut msg(PGMSG_NPC_SELECT);
- msg.writeInt16(npcId);
- msg.writeInt8(value);
- gameServerConnection->send(msg);
-}
-
-void NpcHandler::integerInput(int npcId, int value)
-{
- MessageOut msg(PGMSG_NPC_NUMBER);
- msg.writeInt16(npcId);
- msg.writeInt32(value);
- gameServerConnection->send(msg);
-}
-
-void NpcHandler::stringInput(int npcId, const std::string &value)
-{
- MessageOut msg(PGMSG_NPC_STRING);
- msg.writeInt16(npcId);
- msg.writeString(value);
- gameServerConnection->send(msg);
-}
-
-void NpcHandler::sendLetter(int npcId, const std::string &recipient,
- const std::string &text)
+void NpcHandler::event(const std::string &channel, const Mana::Event &event)
{
- MessageOut msg(PGMSG_NPC_POST_SEND);
- msg.writeString(recipient);
- msg.writeString(text);
- gameServerConnection->send(msg);
+ if (channel == "NPC")
+ {
+ if (event.getName() == "doTalk")
+ {
+ MessageOut msg(PGMSG_NPC_TALK);
+ msg.writeInt16(event.getInt("npcId"));
+ gameServerConnection->send(msg);
+ }
+ else if (event.getName() == "doNext" || event.getName() == "doClose")
+ {
+ MessageOut msg(PGMSG_NPC_TALK_NEXT);
+ msg.writeInt16(event.getInt("npcId"));
+ gameServerConnection->send(msg);
+ }
+ else if (event.getName() == "doMenu")
+ {
+ MessageOut msg(PGMSG_NPC_SELECT);
+ msg.writeInt16(event.getInt("npcId"));
+ msg.writeInt8(event.getInt("choice"));
+ gameServerConnection->send(msg);
+ }
+ else if (event.getName() == "doIntegerInput")
+ {
+ MessageOut msg(PGMSG_NPC_NUMBER);
+ msg.writeInt16(event.getInt("npcId"));
+ msg.writeInt32(event.getInt("value"));
+ gameServerConnection->send(msg);
+ }
+ else if (event.getName() == "doStringInput")
+ {
+ MessageOut msg(PGMSG_NPC_STRING);
+ msg.writeInt16(event.getInt("npcId"));
+ msg.writeString(event.getString("value"));
+ gameServerConnection->send(msg);
+ }
+ else if (event.getName() == "doSendLetter")
+ {
+ MessageOut msg(PGMSG_NPC_POST_SEND);
+ msg.writeString(event.getString("recipient"));
+ msg.writeString(event.getString("text"));
+ gameServerConnection->send(msg);
+ }
+ }
}
void NpcHandler::startShopping(int beingId)
diff --git a/src/net/manaserv/npchandler.h b/src/net/manaserv/npchandler.h
index d66c1a48..14e8a50a 100644
--- a/src/net/manaserv/npchandler.h
+++ b/src/net/manaserv/npchandler.h
@@ -22,6 +22,8 @@
#ifndef NET_MANASERV_NPCHANDLER_H
#define NET_MANASERV_NPCHANDLER_H
+#include "listener.h"
+
#include "net/npchandler.h"
#include "net/manaserv/messagehandler.h"
@@ -30,27 +32,15 @@
namespace ManaServ {
-class NpcHandler : public MessageHandler, public Net::NpcHandler
+class NpcHandler : public MessageHandler, public Net::NpcHandler,
+ public Mana::Listener
{
public:
NpcHandler();
void handleMessage(Net::MessageIn &msg);
- void talk(int npcId);
-
- void nextDialog(int npcId);
-
- void closeDialog(int npcId);
-
- void listInput(int npcId, int value);
-
- void integerInput(int npcId, int value);
-
- void stringInput(int npcId, const std::string &value);
-
- void sendLetter(int npcId, const std::string &recipient,
- const std::string &text);
+ void event(const std::string &channel, const Mana::Event &event);
void startShopping(int beingId);
diff --git a/src/net/npchandler.h b/src/net/npchandler.h
index 2a9cfab5..fb8ab7ec 100644
--- a/src/net/npchandler.h
+++ b/src/net/npchandler.h
@@ -31,21 +31,6 @@ class NpcHandler
public:
virtual ~NpcHandler() {}
- virtual void talk(int npcId) = 0;
-
- virtual void nextDialog(int npcId) = 0;
-
- virtual void closeDialog(int npcId) = 0;
-
- virtual void listInput(int npcId, int value) = 0;
-
- virtual void integerInput(int npcId, int value) = 0;
-
- virtual void stringInput(int npcId, const std::string &value) = 0;
-
- virtual void sendLetter(int npcId, const std::string &recipient,
- const std::string &text) = 0;
-
virtual void startShopping(int beingId) = 0;
virtual void buy(int beingId) = 0;
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp
index 485a8ff7..b61dc520 100644
--- a/src/net/tmwa/npchandler.cpp
+++ b/src/net/tmwa/npchandler.cpp
@@ -68,6 +68,8 @@ NpcHandler::NpcHandler()
};
handledMessages = _messages;
npcHandler = this;
+
+ Mana::EventManager::bind(this, "NPC");
}
void NpcHandler::handleMessage(Net::MessageIn &msg)
@@ -131,52 +133,48 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
player_node->setAction(Being::STAND);
}
-void NpcHandler::talk(int npcId)
-{
- MessageOut outMsg(CMSG_NPC_TALK);
- outMsg.writeInt32(npcId);
- outMsg.writeInt8(0); // Unused
-}
-
-void NpcHandler::nextDialog(int npcId)
-{
- MessageOut outMsg(CMSG_NPC_NEXT_REQUEST);
- outMsg.writeInt32(npcId);
-}
-
-void NpcHandler::closeDialog(int npcId)
-{
- MessageOut outMsg(CMSG_NPC_CLOSE);
- outMsg.writeInt32(npcId);
-}
-
-void NpcHandler::listInput(int npcId, int value)
-{
- MessageOut outMsg(CMSG_NPC_LIST_CHOICE);
- outMsg.writeInt32(npcId);
- outMsg.writeInt8(value);
-}
-
-void NpcHandler::integerInput(int npcId, int value)
-{
- MessageOut outMsg(CMSG_NPC_INT_RESPONSE);
- outMsg.writeInt32(npcId);
- outMsg.writeInt32(value);
-}
-
-void NpcHandler::stringInput(int npcId, const std::string &value)
+void NpcHandler::event(const std::string &channel, const Mana::Event &event)
{
- MessageOut outMsg(CMSG_NPC_STR_RESPONSE);
- outMsg.writeInt16(value.length() + 9);
- outMsg.writeInt32(npcId);
- outMsg.writeString(value, value.length());
- outMsg.writeInt8(0); // Prevent problems with string reading
-}
-
-void NpcHandler::sendLetter(int npcId, const std::string &recipient,
- const std::string &text)
-{
- // TODO
+ if (channel == "NPC")
+ {
+ if (event.getName() == "doTalk")
+ {
+ MessageOut outMsg(CMSG_NPC_TALK);
+ outMsg.writeInt32(event.getInt("npcId"));
+ outMsg.writeInt8(0); // Unused
+ }
+ else if (event.getName() == "doNext")
+ {
+ MessageOut outMsg(CMSG_NPC_NEXT_REQUEST);
+ outMsg.writeInt32(event.getInt("npcId"));
+ }
+ else if (event.getName() == "doClose")
+ {
+ MessageOut outMsg(CMSG_NPC_CLOSE);
+ outMsg.writeInt32(event.getInt("npcId"));
+ }
+ else if (event.getName() == "doMenu")
+ {
+ MessageOut outMsg(CMSG_NPC_LIST_CHOICE);
+ outMsg.writeInt32(event.getInt("npcId"));
+ outMsg.writeInt8(event.getInt("choice"));
+ }
+ else if (event.getName() == "doIntegerInput")
+ {
+ MessageOut outMsg(CMSG_NPC_INT_RESPONSE);
+ outMsg.writeInt32(event.getInt("npcId"));
+ outMsg.writeInt32(event.getInt("value"));
+ }
+ else if (event.getName() == "doStringInput")
+ {
+ const std::string &value = event.getString("value");
+ MessageOut outMsg(CMSG_NPC_STR_RESPONSE);
+ outMsg.writeInt16(value.length() + 9);
+ outMsg.writeInt32(event.getInt("npcId"));
+ outMsg.writeString(value, value.length());
+ outMsg.writeInt8(0); // Prevent problems with string reading
+ }
+ }
}
void NpcHandler::startShopping(int beingId)
diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h
index 515f62df..93c9f6ec 100644
--- a/src/net/tmwa/npchandler.h
+++ b/src/net/tmwa/npchandler.h
@@ -22,7 +22,8 @@
#ifndef NET_TA_NPCHANDLER_H
#define NET_TA_NPCHANDLER_H
-#include "net/net.h"
+#include "listener.h"
+
#include "net/npchandler.h"
#include "net/tmwa/messagehandler.h"
@@ -31,27 +32,15 @@
namespace TmwAthena {
-class NpcHandler : public MessageHandler, public Net::NpcHandler
+class NpcHandler : public MessageHandler, public Net::NpcHandler,
+ public Mana::Listener
{
public:
NpcHandler();
void handleMessage(Net::MessageIn &msg);
- void talk(int npcId);
-
- void nextDialog(int npcId);
-
- void closeDialog(int npcId);
-
- void listInput(int npcId, int value);
-
- void integerInput(int npcId, int value);
-
- void stringInput(int npcId, const std::string &value);
-
- void sendLetter(int npcId, const std::string &recipient,
- const std::string &text);
+ void event(const std::string &channel, const Mana::Event &event);
void startShopping(int beingId);