diff options
author | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-05-22 05:48:22 +0000 |
---|---|---|
committer | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-05-22 05:48:22 +0000 |
commit | 198d4aac190c28ab245fb979336c06cb0c51776c (patch) | |
tree | 95638b542c6aba1384c15e5a7e5b6da2bf2b65f3 | |
parent | c816b6cdf4d8e7eb9e16b8b5db80c72376461e46 (diff) | |
download | manaserv-198d4aac190c28ab245fb979336c06cb0c51776c.tar.gz manaserv-198d4aac190c28ab245fb979336c06cb0c51776c.tar.bz2 manaserv-198d4aac190c28ab245fb979336c06cb0c51776c.tar.xz manaserv-198d4aac190c28ab245fb979336c06cb0c51776c.zip |
Added main.h with database reference, opening and closing database
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/account.h | 1 | ||||
-rw-r--r-- | src/main.cpp | 18 | ||||
-rw-r--r-- | src/main.h | 31 | ||||
-rw-r--r-- | src/sqlite/SQLiteWrapper.cpp | 8 | ||||
-rw-r--r-- | src/sqlite/SQLiteWrapper.h | 2 |
6 files changed, 61 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d9862799..f821495f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,6 @@ bin_PROGRAMS = tmwserv tmwserv_SOURCES = main.cpp \ + main.h \ accounthandler.h \ accounthandler.cpp \ connectionhandler.h \ diff --git a/src/account.h b/src/account.h index a57f8c78..f33bee75 100644 --- a/src/account.h +++ b/src/account.h @@ -26,6 +26,7 @@ #include <iostream> #include "object.h" +#include "sqlite/SQLiteWrapper.h" #define ACC_MAX_CHARS 4 diff --git a/src/main.cpp b/src/main.cpp index db9b6ae7..afcfe239 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,7 @@ #define TMWSERV_VERSION "0.0.1" #include <iostream> +#include "main.h" #include "netsession.h" #include "connectionhandler.h" #include "accounthandler.h" @@ -63,6 +64,7 @@ int worldTime = 0; /**< Current world time in 100ms ticks */ bool running = true; /**< Determines if server keeps running */ Skill skillTree("base"); /**< Skill tree */ +SQLiteWrapper sqlite; /**< Database */ /** * SDL timer callback, sends a <code>TMW_WORLD_TICK</code> event. @@ -111,6 +113,14 @@ void initialize() if (scriptLanguage == "squirrel") script = new ScriptSquirrel("main.nut"); #endif + + // Open database + if (sqlite.Open("tmw.db")) { + std::cout << "tmw.db created or opened" << std::endl; + } + else { + std::cout << "couldn't open tmw.db" << std::endl; + } } /** @@ -129,6 +139,14 @@ void deinitialize() delete script; #endif delete logger; + + // Close database + if (sqlite.Close()) { + std::cout << "tmw.db closed" << std::endl; + } + else { + std::cout << "couldn't close tmw.db" << std::endl; + } } diff --git a/src/main.h b/src/main.h new file mode 100644 index 00000000..6a61476c --- /dev/null +++ b/src/main.h @@ -0,0 +1,31 @@ +/* + * The Mana World + * 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_MAIN_H +#define _TMW_MAIN_H + +#include "sqlite/SQLiteWrapper.h" + +extern SQLiteWrapper sqlite; + +#endif diff --git a/src/sqlite/SQLiteWrapper.cpp b/src/sqlite/SQLiteWrapper.cpp index 6c7c45ad..eef2498f 100644 --- a/src/sqlite/SQLiteWrapper.cpp +++ b/src/sqlite/SQLiteWrapper.cpp @@ -22,6 +22,7 @@ 3. This notice may not be removed or altered from any source distribution. Ren� Nyffenegger rene.nyffenegger@adp-gmbh.ch + Modified by Mateusz Kaduk mateusz.kaduk@gmail.com */ @@ -37,6 +38,13 @@ bool SQLiteWrapper::Open(std::string const& db_file) { return true; } +bool SQLiteWrapper::Close() { + if (sqlite3_close(db_) != SQLITE_OK) { + return false; + } + return true; +} + bool SQLiteWrapper::SelectStmt(std::string const& stmt, ResultTable& res) { char *errmsg; int ret; diff --git a/src/sqlite/SQLiteWrapper.h b/src/sqlite/SQLiteWrapper.h index 343baff2..324fdb66 100644 --- a/src/sqlite/SQLiteWrapper.h +++ b/src/sqlite/SQLiteWrapper.h @@ -22,6 +22,7 @@ 3. This notice may not be removed or altered from any source distribution. Ren� Nyffenegger rene.nyffenegger@adp-gmbh.ch + Modified by Mateusz Kaduk mateusz.kaduk@gmail.com */ #ifndef SQLITE_WRAPPER_H__ @@ -86,6 +87,7 @@ class SQLiteWrapper { SQLiteWrapper(); bool Open(std::string const& db_file); + bool Close(); class ResultRecord { public: |