summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-11-06 16:10:05 +0000
committerDavid Athay <ko2fan@gmail.com>2008-11-06 16:10:05 +0000
commit37a627f2e9d0de8d198f23cb363aacb1acf1f281 (patch)
treeee76e6b794b4b9bb4948b1bb1e2635e48d8ee1a0
parentb9a916704505a52633e1089215020a68168950a0 (diff)
downloadmanaserv-37a627f2e9d0de8d198f23cb363aacb1acf1f281.tar.gz
manaserv-37a627f2e9d0de8d198f23cb363aacb1acf1f281.tar.bz2
manaserv-37a627f2e9d0de8d198f23cb363aacb1acf1f281.tar.xz
manaserv-37a627f2e9d0de8d198f23cb363aacb1acf1f281.zip
Added sending post via NPC.
-rw-r--r--ChangeLog5
-rw-r--r--src/defines.h9
-rw-r--r--src/game-server/accountconnection.cpp15
-rw-r--r--src/game-server/gamehandler.cpp2
-rw-r--r--src/scripting/lua.cpp23
5 files changed, 38 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 51d96b2b..b88d1f0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-06 David Athay <ko2fan@gmail.com>
+
+ * src/scripting/lua.cpp, src/defines.h, src/game-server/gamehandler.cpp,
+ src/game-server/accountconnection.cpp: Added sending post via NPC.
+
2008-11-02 Philipp Sehmisch <tmw@crushnet.org>
* src/scripting/lua.cpp: Added convenience wrappers for converting
diff --git a/src/defines.h b/src/defines.h
index 15b51505..22b57fb3 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -178,6 +178,9 @@ enum {
GPMSG_NPC_SELL = 0x02B6, // W being id, { W item id, W amount, W cost }*
PGMSG_NPC_BUYSELL = 0x02B7, // W item id, W amount
GPMSG_NPC_ERROR = 0x02B8, // B error
+ GPMSG_NPC_POST = 0x02D0, // W being id
+ PGMSG_NPC_POST_SEND = 0x02D1, // W being id, { S name, S text, W item id }
+ GPMSG_NPC_POST_GET = 0x02D2, // W being id, S name, S text, W item id
PGMSG_TRADE_REQUEST = 0x02C0, // W being id
GPMSG_TRADE_REQUEST = 0x02C1, // W being id
GPMSG_TRADE_START = 0x02C2, // -
@@ -247,12 +250,6 @@ enum {
PCMSG_USER_MODE = 0x0465, // W channel id, S name, B mode
PCMSG_KICK_USER = 0x0466, // W channel id, S name
- // Post
- PGMSG_SEND_POST = 0x04A0, // S player, S letter, { W attachment id }
- GPMSG_SEND_POST_RESPONSE = 0x04A1, // B error
- PGMSG_GET_POST = 0x04A2, //
- GPMSG_GET_POST_RESPONSE = 0x04A3, // { S sender name, S letter, { W attachment id } }
-
// Inter-server
GAMSG_REGISTER = 0x0500, // S address, W port, L items db revision, { W map id }*
AGMSG_REGISTER_RESPONSE = 0x0501, // C item version
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index 772369ef..9efb6d82 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -173,12 +173,9 @@ void AccountConnection::processMessage(MessageIn &msg)
break;
}
- // create message and put error inside
- MessageOut out(GPMSG_SEND_POST_RESPONSE);
- out.writeByte(msg.readByte());
+ // TODO: Get NPC to tell character if the sending of post
+ // was successful or not
- // send message to character
- gameHandler->sendTo(character, out);
} break;
default:
@@ -268,13 +265,13 @@ void AccountConnection::sendStatistics()
void AccountConnection::sendPost(Character *c, MessageIn &msg)
{
// send message to account server with id of sending player,
- // the id of receiving player, the letter contents, and attachments
+ // the id of receiving player, the letter receiver and contents, and attachments
LOG_DEBUG("Sending GCMSG_STORE_POST.");
MessageOut out(GCMSG_STORE_POST);
out.writeLong(c->getDatabaseID());
- out.writeString(msg.readString());
- out.writeString(msg.readString());
- while (msg.getUnreadLength())
+ out.writeString(msg.readString()); // name of receiver
+ out.writeString(msg.readString()); // content of letter
+ while (msg.getUnreadLength()) // attachments
{
// write the item id and amount for each attachment
out.writeLong(msg.readShort());
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index 701c759a..74fa4a9e 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -462,7 +462,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
computer.character->respawn(); // plausibility check is done by character class
} break;
- case PGMSG_SEND_POST:
+ case PGMSG_NPC_POST_SEND:
{
handleSendPost(&computer, message);
} break;
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 38b044d0..c86d5778 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -314,6 +314,28 @@ static int LuaNpc_Create(lua_State *s)
}
/**
+ * Callback for sending a NPC_POST.
+ * tmw.npc_post(npc, character)
+ */
+static int LuaNPC_Post(lua_State *s)
+{
+ NPC *p = getNPC(s, 1);
+ Character *q = getCharacter(s, 2);
+
+ if (!p || !q)
+ {
+ raiseScriptError(s, "npc_Choice called with incorrect parameters.");
+ return 0;
+ }
+
+ MessageOut msg(GPMSG_NPC_POST);
+ msg.writeShort(p->getPublicID());
+ gameHandler->sendTo(q, msg);
+
+ return 0;
+}
+
+/**
* Enable a NPC if it has previously disabled
* tmw.npc_enable(npc)
*/
@@ -1126,6 +1148,7 @@ LuaScript::LuaScript():
{ "npc_message", &LuaNpc_Message },
{ "npc_choice", &LuaNpc_Choice },
{ "npc_trade", &LuaNpc_Trade },
+ { "npc_post", &LuaNPC_Post },
{ "npc_enable", &LuaNPC_Enable },
{ "npc_disable", &LuaNPC_Disable },
{ "chr_warp", &LuaChr_Warp },