summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Marks <nymacro@gmail.com>2005-05-23 13:51:42 +0000
committerAaron Marks <nymacro@gmail.com>2005-05-23 13:51:42 +0000
commiteec7111f5cb5a3785b1e2b67bbcd96e26680f18e (patch)
tree468ddb42fffac2028ed070ff883a6424ad9074b2 /src
parent7594437a36acbdc7fb0c1a0e56b0954910c2543c (diff)
downloadmanaserv-eec7111f5cb5a3785b1e2b67bbcd96e26680f18e.tar.gz
manaserv-eec7111f5cb5a3785b1e2b67bbcd96e26680f18e.tar.bz2
manaserv-eec7111f5cb5a3785b1e2b67bbcd96e26680f18e.tar.xz
manaserv-eec7111f5cb5a3785b1e2b67bbcd96e26680f18e.zip
Updated Storage class (added extra table to database).
Misc.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/account.cpp6
-rw-r--r--src/account.h12
-rw-r--r--src/main.cpp7
-rw-r--r--src/object.h25
-rw-r--r--src/storage.cpp85
-rw-r--r--src/storage.h25
7 files changed, 139 insertions, 27 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8c3a9271..e01357c3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,7 +27,11 @@ tmwserv_SOURCES = main.cpp \
script.cpp \
script-squirrel.h \
script-squirrel.cpp \
- storage.cpp storage.h
+ storage.cpp storage.h \
+ account.h \
+ account.cpp \
+ object.h \
+ object.cpp
if BUILD_SQLITE
diff --git a/src/account.cpp b/src/account.cpp
index e2ca1c75..3ab1c701 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -23,7 +23,11 @@
#include "account.h"
-Account::Account()
+Account(const std::string &aName, const std::string aPassword,
+ const std::string &aEmail, Being aPlayer[ACC_MAX_CHARS])
+ : name(aName),
+ password(aPassword),
+ email(aEmail)
{
}
diff --git a/src/account.h b/src/account.h
index a8b8759c..87f781b4 100644
--- a/src/account.h
+++ b/src/account.h
@@ -26,7 +26,6 @@
#include <iostream>
#include "object.h"
-#include "main.h"
#define ACC_MAX_CHARS 4
@@ -41,12 +40,15 @@ class Account
std::string email;
//Player data
- Player player[ACC_MAX_CHARS];
+ Being player[ACC_MAX_CHARS];
+
+ Account() { };
public:
- Account();
- ~Account()
-;
+ Account(const std::string &aName, const std::string aPassword,
+ const std::string &email, Being aPlayer[ACC_MAX_CHARS]);
+ ~Account();
+
void setName(const std::string&);
const std::string& getName();
diff --git a/src/main.cpp b/src/main.cpp
index 38b1f29f..13d310bf 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -65,7 +65,7 @@ bool running = true; /**< Determines if server keeps running */
Skill skillTree("base"); /**< Skill tree */
-Storage *store;
+Storage store;
/**
* SDL timer callback, sends a <code>TMW_WORLD_TICK</code> event.
@@ -115,7 +115,6 @@ void initialize()
script = new ScriptSquirrel("main.nut");
#endif
- store = new Storage();
}
/**
@@ -163,8 +162,6 @@ int main(int argc, char *argv[])
delete script;
#endif
delete logger;
-
- delete store;
}
/**
@@ -199,6 +196,8 @@ int main(int argc, char *argv[])
session->startListen(connectionHandler, SERVER_PORT);
logger->log("Listening on port %d...", SERVER_PORT);
+ std::cout << "Number of accounts on server: " << store.accountCount() << std::endl;
+
SDL_Event event;
while (running)
diff --git a/src/object.h b/src/object.h
index 8a8a4d2a..88c7f515 100644
--- a/src/object.h
+++ b/src/object.h
@@ -90,24 +90,21 @@ class Being : public Object
Script *script;
#endif
+ // disable default constructor (we don't want uninitialized Being's)
+
public:
+ Being() { };
+
+ Being(const std::string &bName, unsigned int bGender,
+ unsigned int bLevel, unsigned int bMoney,
+ unsigned int bStrength, unsigned int bAgility,
+ unsigned int bVitality, unsigned int bDexterity,
+ unsigned int bLuck);
+
virtual ~Being() { } //empty definition
//update
- void update() {
- //Generate statistics
- stats.health = 20 + (20 * vitality);
- stats.attack = 10 + strength;
- stats.defense = 10 + strength;
- stats.magic = 10 + intelligence;
- stats.accuracy = 50 + dexterity;
- stats.speed = dexterity;
-
- //Update scipt
-#ifdef SCRIPT_SUPPORT
- script->update();
-#endif
- }
+ void update();
//accessors
const std::string& getName() { return name; }
diff --git a/src/storage.cpp b/src/storage.cpp
index af863d47..9d071671 100644
--- a/src/storage.cpp
+++ b/src/storage.cpp
@@ -22,6 +22,7 @@
*/
#include "storage.h"
#include <iostream>
+#include <sstream>
Storage::Storage()
{
@@ -72,13 +73,93 @@ void Storage::create_tables_if_necessary()
return;
sqlite.Begin();
- if (sqlite.DirectStatement("create table tmw_accounts(user TEXT, password TEXT, email TEXT)")) {
+ // Accounts table
+ if (sqlite.DirectStatement("create table tmw_accounts ("
+ //username
+ " user varchar(32) unique primary key not null,"
+ //password hash
+ " password varchar(32) not null,"
+ //email address
+ " email varchar(128) not null,"
+ //account type
+ " type int not null"
+ ")")) {
std::cout << "Database: table tmw_accounts created" << std::endl;
}
else {
- std::cout << "Database: table exist" << std::endl;
+ std::cout << "Database: table tmw_accounts exists" << std::endl;
}
+
+ // Characters table
+ if (sqlite.DirectStatement("create table tmw_characters ("
+ //character name
+ " name varchar(32) unique primary key not null,"
+ //user name
+ " user varchar(32) not null,"
+ //player information
+ " gender int not null,"
+ " level int not null,"
+ " money int not null,"
+ //coordinates
+ " x int not null,"
+ " y int not null,"
+ //map name
+ " map text not null,"
+ //statistics
+ " strength int not null,"
+ " agility int not null,"
+ " vitality int not null,"
+ " intelligence int not null,"
+ " dexterity int not null,"
+ " luck int not null,"
+ //player equipment
+ " inventory blob not null," // TODO: blob bad
+ " equipment blob not null," // TODO: blob bad
+ //table relationship
+ " foreign key(user) references tmw_accounts(user)"
+ ")")) {
+ std::cout << "Database: table tmw_characters created" << std::endl;
+ }
+ else {
+ std::cout << "Database: table tmw_characters exists" << std::endl;
+ }
+
+ //populate table for the hell of it ;)
+ sqlite.DirectStatement("insert into tmw_accounts values ('nym', 'tHiSiSHaShEd', 'nym@test', 0)");
+ sqlite.DirectStatement("insert into tmw_accounts values ('Bjorn', 'tHiSiSHaShEd', 'bjorn@test', 0)");
+ sqlite.DirectStatement("insert into tmw_accounts values ('Usiu', 'tHiSiSHaShEd', 'usiu@test', 0)");
+ sqlite.DirectStatement("insert into tmw_accounts values ('ElvenProgrammer', 'tHiSiSHaShEd', 'elven@test', 0)");
+
+ sqlite.Commit();
+#endif
+}
+
+void Storage::save()
+{
+#ifdef SQLITE_SUPPORT
sqlite.Commit();
#endif
}
+unsigned int Storage::accountCount()
+{
+#ifdef SQLITE_SUPPORT
+ SQLiteWrapper::ResultTable r;
+ std::stringstream s;
+ unsigned int v;
+ sqlite.SelectStmt("select count(*) from tmw_accounts", r);
+ s << r.records_[0].fields_[0];
+ s >> v;
+ return v;
+#else
+ return 0;
+#endif
+}
+
+/*
+Account& getAccount(const std::string &username)
+{
+ //give caller a initialized AccountData structure
+}
+*/
+
diff --git a/src/storage.h b/src/storage.h
index 8fd981a0..e6fec7b4 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -27,7 +27,17 @@
#include "sqlite/SQLiteWrapper.h"
#endif
+#include "object.h"
+#include "account.h"
+
+/*
+ * Storage
+ * Storage is the resource manager
+ */
class Storage {
+ private:
+ //make storage singleton
+ Storage(const Storage &n) { }
public:
/**
* Constructor.
@@ -44,6 +54,21 @@ class Storage {
*/
void create_tables_if_necessary();
+ /**
+ * Save changes to database
+ */
+ void save();
+
+ /**
+ * Account count (test function)
+ */
+ unsigned int accountCount();
+
+ /**
+ * Get account & associated data
+ */
+ //Account& getAccount(const std::string &username);
+
private:
#ifdef SQLITE_SUPPORT
SQLiteWrapper sqlite; /**< Database */