summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am1
-rw-r--r--src/account.h1
-rw-r--r--src/main.cpp18
-rw-r--r--src/main.h31
-rw-r--r--src/sqlite/SQLiteWrapper.cpp8
-rw-r--r--src/sqlite/SQLiteWrapper.h2
6 files changed, 61 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d986279..f821495 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 a57f8c7..f33bee7 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 db9b6ae..afcfe23 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 0000000..6a61476
--- /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 6c7c45a..eef2498 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 343baff..324fdb6 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: