summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-23 17:00:11 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-23 17:00:11 +0000
commit919bcd64912d88993b56e931b0eea880b466947b (patch)
tree23686fa6d5a0b5beccb536d9108358221b07f09d /src
parent091a57aca17453b08e2a912a6ed19c09131e2123 (diff)
downloadmanaserv-919bcd64912d88993b56e931b0eea880b466947b.tar.gz
manaserv-919bcd64912d88993b56e931b0eea880b466947b.tar.bz2
manaserv-919bcd64912d88993b56e931b0eea880b466947b.tar.xz
manaserv-919bcd64912d88993b56e931b0eea880b466947b.zip
Commented out code unavailable from client side. Added support for NPCs.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/account-server/serverhandler.cpp2
-rw-r--r--src/defines.h13
-rw-r--r--src/game-server/accountconnection.cpp7
-rw-r--r--src/game-server/accountconnection.hpp2
-rw-r--r--src/game-server/gamehandler.cpp38
-rw-r--r--src/game-server/gamehandler.hpp2
-rw-r--r--src/game-server/mapcomposite.hpp5
-rw-r--r--src/game-server/npc.hpp60
-rw-r--r--src/game-server/state.cpp7
-rw-r--r--src/game-server/testing.cpp50
-rw-r--r--src/resourcemanager.cpp1
12 files changed, 176 insertions, 12 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2d2ae0c0..00efc9dc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -111,6 +111,7 @@ tmwserv_game_SOURCES = \
game-server/monstermanager.cpp \
game-server/movingobject.hpp \
game-server/movingobject.cpp \
+ game-server/npc.hpp \
game-server/object.hpp \
game-server/spawnarea.hpp \
game-server/spawnarea.cpp \
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index d9995f5b..ad6bb446 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -189,6 +189,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
} break;
+#if 0
case GAMSG_GUILD_CREATE:
{
LOG_DEBUG("GAMSG_GUILD_CREATE");
@@ -349,6 +350,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
result.writeLong(playerId);
result.writeShort(guildId);
} break;
+#endif
default:
LOG_WARN("ServerHandler::processMessage, Invalid message type: "
diff --git a/src/defines.h b/src/defines.h
index 595760da..56d79797 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -151,6 +151,7 @@ enum {
GPMSG_BEING_ENTER = 0x0200, // B type, W being id, B action, W*2 position
// character: S name, B hair style, B hair color, B gender, B item bitmask, { W item id }*
// monster: W type id
+ // npc: W type id
GPMSG_BEING_LEAVE = 0x0201, // W being id
GPMSG_ITEM_APPEAR = 0x0202, // W item id, W*2 position
GPMSG_BEING_LOOKS_CHANGE = 0x0210, // W weapon, W hat, W top clothes, W bottom clothes
@@ -163,10 +164,16 @@ enum {
GPMSG_BEING_ATTACK = 0x0291, // W being id, B direction
PGMSG_SAY = 0x02A0, // S text
GPMSG_SAY = 0x02A1, // W being id, S text
+ GPMSG_NPC_CHOICE = 0x02B0, // W being id, B* text
+ GPMSG_NPC_MESSAGE = 0x02B1, // W being id, B* text
+ PGMSG_NPC_TALK = 0x02B2, // W being id
+ PGMSG_NPC_TALK_NEXT = 0x02B3, // W being id
+ PGMSG_NPC_SELECT = 0x02B4, // W being id, B choice
PGMSG_USE_ITEM = 0x0300, // L item id
GPMSG_USE_RESPONSE = 0x0301, // B error
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
-
+
+#if 0
// Guild
PGMSG_GUILD_CREATE = 0x0350, // S name
GPMSG_GUILD_CREATE_RESPONSE = 0x0351, // B error, W id
@@ -180,6 +187,7 @@ enum {
GPMSG_GUILD_LEFT = 0x0359, // W id
PGMSG_GUILD_QUIT = 0x0360, // W id
GPMSG_GUILD_QUIT_RESPONSE = 0x0361, // B error, W id
+#endif
CPMSG_GUILD_INVITED = 0x0370, // S name, S name
CPMSG_GUILD_REJOIN = 0x0371, // S name, W id, W rights
@@ -217,6 +225,8 @@ enum {
GAMSG_REDIRECT = 0x0530, // L id
AGMSG_REDIRECT_RESPONSE = 0x0531, // L id, B*32 token, S game address, W game port
GAMSG_PLAYER_RECONNECT = 0x0532, // L id, B*32 token
+
+#if 0
GAMSG_GUILD_CREATE = 0x0550, // S name
AGMSG_GUILD_CREATE_RESPONSE = 0x0551, // B error, W id
GAMSG_GUILD_INVITE = 0x0552, // W id, S name
@@ -227,6 +237,7 @@ enum {
AGMSG_GUILD_GET_MEMBERS_RESPONSE = 0x0557, // S names
GAMSG_GUILD_QUIT = 0x0558, // W id
AGMSG_GUILD_QUIT_RESPONSE = 0x0559, // B error
+#endif
XXMSG_INVALID = 0x7FFF
};
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index 3bdd971c..89d19187 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -92,7 +92,9 @@ void AccountConnection::processMessage(MessageIn &msg)
int port = msg.readShort();
gameHandler->completeServerChange(id, token, address, port);
} break;
-
+
+// The client should directly talk with the chat server and not go through the game server.
+#if 0
case AGMSG_GUILD_CREATE_RESPONSE:
{
if(msg.readByte() == ERRMSG_OK)
@@ -205,6 +207,7 @@ void AccountConnection::processMessage(MessageIn &msg)
gameHandler->sendTo(player, result);
}
} break;
+#endif
default:
LOG_WARN("Invalid message type");
@@ -221,6 +224,7 @@ void AccountConnection::playerReconnectAccount(int id, const std::string magic_t
send(msg);
}
+#if 0
void AccountConnection::playerCreateGuild(int id, const std::string &guildName)
{
LOG_INFO("Send GAMSG_GUILD_CREATE");
@@ -266,3 +270,4 @@ void AccountConnection::quitGuild(int id, short guildId)
msg.writeShort(guildId);
send(msg);
}
+#endif
diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp
index e06966df..ba9abe06 100644
--- a/src/game-server/accountconnection.hpp
+++ b/src/game-server/accountconnection.hpp
@@ -50,6 +50,7 @@ class AccountConnection : public Connection
*/
void playerReconnectAccount(int id, const std::string magic_token);
+#if 0
/**
* Sends create guild message
*/
@@ -74,6 +75,7 @@ class AccountConnection : public Connection
* Sends quit guild message.
*/
void quitGuild(int id, short guildId);
+#endif
protected:
/**
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index e1257e71..8010374b 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -32,6 +32,7 @@
#include "game-server/itemmanager.hpp"
#include "game-server/map.hpp"
#include "game-server/mapcomposite.hpp"
+#include "game-server/npc.hpp"
#include "game-server/state.hpp"
#include "net/messagein.hpp"
#include "net/messageout.hpp"
@@ -142,6 +143,36 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
GameState::sayAround(computer.character, say);
} break;
+ case PGMSG_NPC_TALK:
+ case PGMSG_NPC_TALK_NEXT:
+ case PGMSG_NPC_SELECT:
+ {
+ int id = message.readShort();
+ MapComposite *map = computer.character->getMap();
+ MovingObject *o = NULL;
+ Point ppos = computer.character->getPosition();
+ // TODO: use a less arbitrary value.
+ for (MovingObjectIterator i(map->getAroundPointIterator(ppos, 48)); i; ++i)
+ {
+ if ((*i)->getPublicID() == id)
+ {
+ o = *i;
+ break;
+ }
+ }
+ if (!o || o->getType() != OBJECT_NPC) break;
+
+ NPC *q = static_cast< NPC * >(o);
+ if (message.getId() == PGMSG_NPC_SELECT)
+ {
+ q->select(computer.character, message.readByte());
+ }
+ else
+ {
+ q->prompt(computer.character, message.getId() == PGMSG_NPC_TALK);
+ }
+ } break;
+
case PGMSG_PICKUP:
{
int x = message.readShort();
@@ -258,7 +289,11 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
computer.character = NULL;
computer.status = CLIENT_LOGIN;
} break;
-
+
+
+// The following messages should be handled by the chat server, not the game server.
+#if 0
+
case PGMSG_GUILD_CREATE:
{
std::string name = message.readString();
@@ -299,6 +334,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
messageMap[characterId] = computer.character;
accountHandler->quitGuild(characterId, guildId);
} break;
+#endif
default:
LOG_WARN("Invalid message type");
diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp
index 85a38674..f07e1ac9 100644
--- a/src/game-server/gamehandler.hpp
+++ b/src/game-server/gamehandler.hpp
@@ -90,7 +90,7 @@ class GameHandler: public ConnectionHandler
* Map of character's and their id used for getting which character to
* forward account server messages back to.
*/
- std::map<int, Character*> messageMap;
+ // std::map<int, Character*> messageMap;
/**
* Combines a client with it's character.
diff --git a/src/game-server/mapcomposite.hpp b/src/game-server/mapcomposite.hpp
index 880f4c12..00d52173 100644
--- a/src/game-server/mapcomposite.hpp
+++ b/src/game-server/mapcomposite.hpp
@@ -183,11 +183,6 @@ class MapComposite
void update();
/**
- * Gets an object given its ID.
- */
- MovingObject *getObjectByID(int) const;
-
- /**
* Gets an iterator on the objects of the whole map.
*/
ZoneIterator getWholeMapIterator() const
diff --git a/src/game-server/npc.hpp b/src/game-server/npc.hpp
new file mode 100644
index 00000000..44bbf4b8
--- /dev/null
+++ b/src/game-server/npc.hpp
@@ -0,0 +1,60 @@
+/*
+ * The Mana World Server
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMWSERV_GAMESERVER_NPC_HPP_
+#define _TMWSERV_GAMESERVER_NPC_HPP_
+
+#include "game-server/being.hpp"
+
+/**
+ * Class describing a non-player character.
+ */
+class NPC : public Being
+{
+ public:
+ NPC(int id): Being(OBJECT_NPC, 65535), mID(id) {}
+
+ void update() {}
+
+ /**
+ * Prompts NPC.
+ * TODO: should not be virtual, should invoke a scripting engine instead.
+ */
+ virtual void prompt(Character *, bool restart) = 0;
+
+ /**
+ * Selects an NPC proposition.
+ * TODO: should not be virtual, should invoke a scripting engine instead.
+ */
+ virtual void select(Character *, int) = 0;
+
+ /**
+ * Gets NPC ID.
+ */
+ int getNPC() const
+ { return mID; }
+
+ private:
+ unsigned short mID; /**< ID of the NPC. */
+};
+
+#endif
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index d9922df7..bcb93962 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -36,6 +36,7 @@
#include "game-server/mapcomposite.hpp"
#include "game-server/mapmanager.hpp"
#include "game-server/monster.hpp"
+#include "game-server/npc.hpp"
#include "net/messageout.hpp"
#include "utils/logger.h"
@@ -271,6 +272,12 @@ static void informPlayer(MapComposite *map, Character *p)
enterMsg.writeShort(q->getSpecy()->getType());
} break;
+ case OBJECT_NPC:
+ {
+ NPC *q = static_cast< NPC * >(o);
+ enterMsg.writeShort(q->getNPC());
+ } break;
+
default:
assert(false); // TODO
}
diff --git a/src/game-server/testing.cpp b/src/game-server/testing.cpp
index 01cb4e4f..7b875eaf 100644
--- a/src/game-server/testing.cpp
+++ b/src/game-server/testing.cpp
@@ -5,14 +5,52 @@
#include <cassert>
#include "defines.h"
+#include "game-server/gamehandler.hpp"
#include "game-server/item.hpp"
#include "game-server/itemmanager.hpp"
#include "game-server/mapcomposite.hpp"
#include "game-server/mapmanager.hpp"
-#include "game-server/monstermanager.hpp"
-#include "game-server/spawnarea.hpp"
+#include "game-server/npc.hpp"
#include "game-server/state.hpp"
-#include "game-server/trigger.hpp"
+#include "net/messageout.hpp"
+
+// For testing purpose only, the NPC class is not meant to be inherited!!
+struct DummyNPC: NPC
+{
+ DummyNPC(): NPC(110) {}
+
+ void prompt(Character *q, bool restart)
+ {
+ if (restart)
+ {
+ MessageOut msg(GPMSG_NPC_MESSAGE);
+ msg.writeShort(getPublicID());
+ std::string text = "What do you want?";
+ msg.writeString(text, text.length());
+ gameHandler->sendTo(q, msg);
+ }
+ else
+ {
+ MessageOut msg(GPMSG_NPC_CHOICE);
+ msg.writeShort(getPublicID());
+ std::string text = "Guns! Lots of guns!:Nothing";
+ msg.writeString(text, text.length());
+ gameHandler->sendTo(q, msg);
+ }
+ }
+
+ void select(Character *q, int c)
+ {
+ if (c == 1)
+ {
+ MessageOut msg(GPMSG_NPC_MESSAGE);
+ msg.writeShort(getPublicID());
+ std::string text = "Sorry, this is a heroic-fantasy game, I do not have any gun.";
+ msg.writeString(text, text.length());
+ gameHandler->sendTo(q, msg);
+ }
+ }
+};
static void dropItem(MapComposite *map, int x, int y, int type)
{
@@ -34,6 +72,12 @@ void testingMap(MapComposite *map)
// Drop some items
dropItem(map, 58 * 32 + 16, 20 * 32 + 16, 508);
dropItem(map, 58 * 32 + 16, 21 * 32 + 16, 524);
+
+ // Add an NPC
+ NPC *q = new DummyNPC;
+ q->setMap(map);
+ q->setPosition(Point(50 * 32 + 16, 19 * 32 + 16));
+ GameState::insert(q);
} break;
}
}
diff --git a/src/resourcemanager.cpp b/src/resourcemanager.cpp
index fc62299a..41039ab1 100644
--- a/src/resourcemanager.cpp
+++ b/src/resourcemanager.cpp
@@ -69,6 +69,7 @@ ResourceManager::deleteInstance()
void
ResourceManager::searchAndAddZipFiles()
{
+ PHYSFS_permitSymbolicLinks(1);
// Add the main data directory to our PhysicsFS search path
PHYSFS_addToSearchPath("data", 1);
PHYSFS_addToSearchPath(TMWSERV_DATADIR "data", 1);