summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Marks <nymacro@gmail.com>2005-07-26 13:05:08 +0000
committerAaron Marks <nymacro@gmail.com>2005-07-26 13:05:08 +0000
commit9603167e6b7c364e1a979f5a23420b6289026f46 (patch)
treee4a9c104c12057ab737ce592e64f31a25e18ae76
parent0a7f92741ee87b35d30ccc351fe892e090b1d31a (diff)
downloadmanaserv-9603167e6b7c364e1a979f5a23420b6289026f46.tar.gz
manaserv-9603167e6b7c364e1a979f5a23420b6289026f46.tar.bz2
manaserv-9603167e6b7c364e1a979f5a23420b6289026f46.tar.xz
manaserv-9603167e6b7c364e1a979f5a23420b6289026f46.zip
Added shell for GameHandler (core game message handler).
Updated PostgreSQL tables -- now another unknown error results after various operations. Updated Item class (now inherits from Object).
-rw-r--r--src/Makefile.am1
-rw-r--r--src/dalstorage.cpp13
-rw-r--r--src/dalstoragesql.h13
-rw-r--r--src/defines.h4
-rw-r--r--src/gamehandler.cpp66
-rw-r--r--src/gamehandler.h43
-rw-r--r--src/items.cpp29
-rw-r--r--src/items.h29
-rw-r--r--src/main.cpp16
9 files changed, 191 insertions, 23 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7ecc74ef..8c479b40 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,6 +18,7 @@ tmwserv_SOURCES = main.cpp \
debug.cpp \
defines.h \
items.h \
+ items.cpp \
map.cpp \
map.h \
mapreader.cpp \
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index 38e61397..938b06a9 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -410,7 +410,9 @@ DALStorage::_addAccount(const AccountPtr& account)
// insert the account.
std::ostringstream sql1;
- sql1 << "insert into " << ACCOUNTS_TBL_NAME << " values (null, '"
+ sql1 << "insert into " << ACCOUNTS_TBL_NAME
+ << " (username, password, email, level, banned)"
+ << " values ('"
<< account->getName() << "', '"
<< account->getPassword() << "', '"
<< account->getEmail() << "', "
@@ -443,7 +445,9 @@ DALStorage::_addAccount(const AccountPtr& account)
for (; it != it_end; ++it) {
RawStatistics& stats = (*it)->getRawStatistics();
std::ostringstream sql3;
- sql3 << "insert into " << CHARACTERS_TBL_NAME << " values (null, "
+ sql3 << "insert into " << CHARACTERS_TBL_NAME
+ << " (name, gender, level, money, x, y, map_id, str, agi, int, dex luck)"
+ << " values ("
<< (account_it->second).id << ", '"
<< (*it)->getName() << "', '"
<< (*it)->getGender() << "', "
@@ -527,8 +531,9 @@ DALStorage::_updAccount(const AccountPtr& account)
std::ostringstream sql3;
if (charInfo.rows() == 0) {
- sql3 << "insert into " << CHARACTERS_TBL_NAME
- << " values (null, "
+ sql3 << "inpsert into " << CHARACTERS_TBL_NAME
+ << " (name, gender, level, money, x, y, map_id, str, agi, vit, int, dex, luck)"
+ << " values ("
<< (account_it->second).id << ", '"
<< (*it)->getName() << "', "
<< (*it)->getGender() << ", "
diff --git a/src/dalstoragesql.h b/src/dalstoragesql.h
index a9cb8f82..3d1ffc05 100644
--- a/src/dalstoragesql.h
+++ b/src/dalstoragesql.h
@@ -50,7 +50,8 @@
* (http://www.sqlite.org/datatype3.html)
* - the size of TEXT cannot be set, it is just ignored by the engine.
* - IMPORTANT: foreign key constraints are not yet supported
- * (http://www.sqlite.org/omitted.html)
+ * (http://www.sqlite.org/omitted.html). Included in case of future
+ * support.
*
* Notes:
* - the SQL queries will take advantage of the most appropriate data
@@ -76,7 +77,7 @@ const std::string SQL_MAPS_TABLE(
"id INTEGER PRIMARY KEY,"
"map TEXT NOT NULL"
#elif defined (POSTGRESQL_SUPPORT)
- "id INTEGER PRIMARY KEY,"
+ "id SERIAL PRIMARY KEY,"
"map TEXT NOT NULL"
#endif
");"
@@ -112,7 +113,7 @@ const std::string SQL_ACCOUNTS_TABLE(
"level INTEGER NOT NULL,"
"banned INTEGER NOT NULL"
#elif defined (POSTGRESQL_SUPPORT)
- "id INTEGER PRIMARY KEY,"
+ "id SERIAL PRIMARY KEY,"
"username TEXT NOT NULL UNIQUE,"
"password TEXT NOT NULL,"
"email TEXT NOT NULL,"
@@ -180,7 +181,7 @@ const std::string SQL_CHARACTERS_TABLE(
"FOREIGN KEY (user_id) REFERENCES tmw_accounts(id),"
"FOREIGN KEY (map_id) REFERENCES tmw_maps(id)"
#elif defined (POSTGRESQL_SUPPORT)
- "id INTEGER PRIMARY KEY,"
+ "id SERIAL PRIMARY KEY,"
"user_id INTEGER NOT NULL,"
"name TEXT NOT NULL UNIQUE,"
// general information about the character
@@ -227,7 +228,7 @@ const std::string SQL_ITEMS_TABLE(
"type INTEGER NOT NULL,"
"state TEXT"
#elif defined (POSTGRESQL_SUPPORT)
- "id INTEGER PRIMARY KEY,"
+ "id SERIAL PRIMARY KEY,"
"amount INTEGER NOT NULL,"
"type INTEGER NOT NULL,"
"state TEXT"
@@ -298,7 +299,7 @@ const std::string SQL_INVENTORIES_TABLE(
"id INTEGER NOT NULL,"
"owner_id INTEGER NOT NULL,"
"FOREIGN KEY (id) REFERENCES tmw_items(id),"
- "FOREIGN KEY (map_id) REFERENCES tmw_maps(id)"
+ "FOREIGN KEY (owner_id) REFERENCES tmw_characters(id)"
#elif defined (POSTGRESQL_SUPPORT)
"id INTEGER NOT NULL,"
"owner_id INTEGER NOT NULL,"
diff --git a/src/defines.h b/src/defines.h
index 35c05363..12d7e0a6 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -101,7 +101,9 @@ enum {
SMSG_SYSTEM = 0x0401,
SMSG_ANNOUNCEMENT = 0x0402,
CMSG_SAY = 0x0410,
- CMSG_ANNOUNCE = 0x0411,
+ CMSG_ANNOUNCE = 0x0411
+
+ // NOTE: We will need more messages for in-game control (eg. moving a client to a new map/position etc.). Currently the protocol only caters for the bare basics.
};
// Login return values
diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp
new file mode 100644
index 00000000..340e8690
--- /dev/null
+++ b/src/gamehandler.cpp
@@ -0,0 +1,66 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 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$
+ */
+
+#include "gamehandler.h"
+#include <iostream>
+
+void GameHandler::receiveMessage(NetComputer &computer, MessageIn &message)
+{
+ if (computer.getAccount() == NULL)
+ return;
+
+ switch (message.getId())
+ {
+ case CMSG_PICKUP:
+ break;
+
+ case CMSG_USE_OBJECT:
+ break;
+
+ case CMSG_TARGET:
+ break;
+
+ case CMSG_WALK:
+ break;
+
+ case CMSG_START_TRADE:
+ break;
+
+ case CMSG_START_TALK:
+ break;
+
+ case CMSG_REQ_TRADE:
+ break;
+
+ case CMSG_USE_ITEM:
+ break;
+
+ case CMSG_EQUIP:
+ break;
+
+ default:
+ std::cerr << "Warning: GameHandler received message of unkown type"
+ << " (" << message.getId() << ")" << std::endl;
+ break;
+ }
+}
diff --git a/src/gamehandler.h b/src/gamehandler.h
new file mode 100644
index 00000000..46245bf4
--- /dev/null
+++ b/src/gamehandler.h
@@ -0,0 +1,43 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 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 _TMW_SERVER_GAMEHANDLER_
+#define _TMW_SERVER_GAMEHANDLER_
+
+#include "messagehandler.h"
+#include "netcomputer.h"
+#include "messagein.h"
+
+/**
+ * Manage main game events & server processing.
+ */
+class GameHandler : public MessageHandler
+{
+ public:
+ /**
+ * Recieve messages related to core game events
+ */
+ void receiveMessage(NetComputer &computer, MessageIn &message);
+};
+
+#endif
diff --git a/src/items.cpp b/src/items.cpp
new file mode 100644
index 00000000..e0606920
--- /dev/null
+++ b/src/items.cpp
@@ -0,0 +1,29 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 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$
+ */
+
+#include "items.h"
+
+void tmwserv::Item::use()
+{
+ //
+}
diff --git a/src/items.h b/src/items.h
index 69c44185..4d8dc94e 100644
--- a/src/items.h
+++ b/src/items.h
@@ -27,17 +27,21 @@
#include "script.h"
#include "object.h"
-//General Item Definition
-class Item
+namespace tmwserv
{
- //Statistics modifier
- Statistics stats;
+/**
+ * Class for all types of in-game items.
+ */
+class Item : public Object
+{
//Item type
unsigned int type;
public:
- //Item type definitions
+ /**
+ * Enumeration of available Item types.
+ */
static enum {
Usable,
Equipment
@@ -45,14 +49,17 @@ class Item
virtual ~Item() { }
- //Use item
- void use() { };
+ /**
+ * The function called to use an item
+ */
+ void use();
- //Accessors
+ /**
+ * Return type of item
+ */
unsigned int getType() { return type; }
-
- //Get statistics information
- const Statistics& getStatistics() { return stats; }
};
+} // namespace tmwserv
+
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 6178940f..ff939e12 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,6 +31,7 @@
#include "netsession.h"
#include "connectionhandler.h"
#include "accounthandler.h"
+#include "gamehandler.h"
#include "chathandler.h"
#include "storage.h"
#include "configuration.h"
@@ -73,7 +74,8 @@ Skill skillTree("base"); /**< Skill tree */
Configuration config; /**< XML config reader */
AccountHandler *accountHandler = new AccountHandler(); /**< Account message handler */
-ChatHandler *chatHandler = new ChatHandler();
+ChatHandler *chatHandler = new ChatHandler(); /**< Communications (chat) messaqge handler */
+GameHandler *gameHandler = new GameHandler(); /**< Core game message handler */
/**
* SDL timer callback, sends a <code>TMW_WORLD_TICK</code> event.
@@ -168,6 +170,7 @@ void deinitialize()
// destroy message handlers
delete accountHandler;
delete chatHandler;
+ delete gameHandler;
// Get rid of persistent data storage
tmwserv::Storage::destroy();
@@ -207,9 +210,20 @@ int main(int argc, char *argv[])
connectionHandler->registerHandler(CMSG_REGISTER, accountHandler);
connectionHandler->registerHandler(CMSG_CHAR_CREATE, accountHandler);
connectionHandler->registerHandler(CMSG_CHAR_SELECT, accountHandler);
+
connectionHandler->registerHandler(CMSG_SAY, chatHandler);
connectionHandler->registerHandler(CMSG_ANNOUNCE, chatHandler);
+ connectionHandler->registerHandler(CMSG_PICKUP, gameHandler);
+ connectionHandler->registerHandler(CMSG_USE_OBJECT, gameHandler);
+ connectionHandler->registerHandler(CMSG_TARGET, gameHandler);
+ connectionHandler->registerHandler(CMSG_WALK, gameHandler);
+ connectionHandler->registerHandler(CMSG_START_TRADE, gameHandler);
+ connectionHandler->registerHandler(CMSG_START_TALK, gameHandler);
+ connectionHandler->registerHandler(CMSG_REQ_TRADE, gameHandler);
+ connectionHandler->registerHandler(CMSG_USE_ITEM, gameHandler); // NOTE: this is probably redundant (CMSG_USE_OBJECT)
+ connectionHandler->registerHandler(CMSG_EQUIP, gameHandler);
+
//LOG_INFO("The Mana World Server v" << PACKAGE_VERSION) PACKAGE_VERSION undeclared
session->startListen(connectionHandler.get(), SERVER_PORT);
LOG_INFO("Listening on port " << SERVER_PORT << "...")