Worked these changes into the client & server (read more)
The changes were fairly easy, and I was actually able to find and fix an out-of-sequence bug: The destructors for the AccountManager and the CharacterManager were using SQL code after the call to SQLite3_close_v2(), so I added and called UnloadAll() for both of them.
This commit is contained in:
@@ -36,16 +36,6 @@ static const char* DELETE_USER_ACCOUNT = "DELETE FROM Accounts WHERE uid = ?;";
|
||||
//Define the public methods
|
||||
//-------------------------
|
||||
|
||||
AccountManager::AccountManager() {
|
||||
//
|
||||
}
|
||||
|
||||
AccountManager::~AccountManager() {
|
||||
for (auto& it : accountMap) {
|
||||
SaveAccount(it.first);
|
||||
}
|
||||
}
|
||||
|
||||
int AccountManager::CreateAccount(std::string username, int clientIndex) {
|
||||
//create this user account, failing if it exists, leave this account in memory
|
||||
sqlite3_stmt* statement = nullptr;
|
||||
@@ -202,6 +192,13 @@ void AccountManager::DeleteAccount(int uid) {
|
||||
accountMap.erase(uid);
|
||||
}
|
||||
|
||||
void AccountManager::UnloadAll() {
|
||||
for (auto& it : accountMap) {
|
||||
SaveAccount(it.first);
|
||||
}
|
||||
accountMap.clear();
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Define the accessors and mutators
|
||||
//-------------------------
|
||||
@@ -226,4 +223,4 @@ sqlite3* AccountManager::SetDatabase(sqlite3* db) {
|
||||
|
||||
sqlite3* AccountManager::GetDatabase() {
|
||||
return database;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
|
||||
class AccountManager {
|
||||
public:
|
||||
AccountManager();
|
||||
~AccountManager();
|
||||
AccountManager() = default;
|
||||
~AccountManager() { UnloadAll(); };
|
||||
|
||||
//public access methods
|
||||
int CreateAccount(std::string username, int clientIndex);
|
||||
@@ -40,6 +40,8 @@ public:
|
||||
void UnloadAccount(int uid);
|
||||
void DeleteAccount(int uid);
|
||||
|
||||
void UnloadAll();
|
||||
|
||||
//accessors and mutators
|
||||
AccountData* GetAccount(int uid);
|
||||
std::map<int, AccountData>* GetContainer();
|
||||
|
||||
@@ -58,16 +58,6 @@ static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
|
||||
//Define the methods
|
||||
//-------------------------
|
||||
|
||||
CharacterManager::CharacterManager() {
|
||||
//
|
||||
}
|
||||
|
||||
CharacterManager::~CharacterManager() {
|
||||
for (auto& it : characterMap) {
|
||||
SaveCharacter(it.first);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: default stats as a parameter? This would be good for differing beggining states or multiple classes
|
||||
int CharacterManager::CreateCharacter(int owner, std::string handle, std::string avatar) {
|
||||
//Create the character, failing if it exists
|
||||
@@ -294,6 +284,13 @@ void CharacterManager::UnloadCharacterIf(std::function<bool(std::map<int, Charac
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterManager::UnloadAll() {
|
||||
for (auto& it : characterMap) {
|
||||
SaveCharacter(it.first);
|
||||
}
|
||||
characterMap.clear();
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Define the accessors and mutators
|
||||
//-------------------------
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
|
||||
class CharacterManager {
|
||||
public:
|
||||
CharacterManager();
|
||||
~CharacterManager();
|
||||
CharacterManager() = default;
|
||||
~CharacterManager() { UnloadAll(); };
|
||||
|
||||
//public access methods
|
||||
int CreateCharacter(int owner, std::string handle, std::string avatar);
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
|
||||
void UnloadCharacterIf(std::function<bool(std::map<int, CharacterData>::iterator)> f);
|
||||
|
||||
void UnloadAll();
|
||||
|
||||
//accessors and mutators
|
||||
CharacterData* GetCharacter(int uid);
|
||||
std::map<int, CharacterData>* GetContainer();
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#define ROOMDATA_HPP_
|
||||
|
||||
//map system
|
||||
#include "region_pager.hpp"
|
||||
#include "region_pager_lua.hpp"
|
||||
|
||||
struct RoomData {
|
||||
enum class RoomType {
|
||||
@@ -35,7 +35,7 @@ struct RoomData {
|
||||
};
|
||||
|
||||
//members
|
||||
RegionPager pager;
|
||||
RegionPagerLua pager;
|
||||
RoomType type;
|
||||
|
||||
//TODO: collision map
|
||||
|
||||
@@ -151,6 +151,14 @@ void ServerApplication::Proc() {
|
||||
void ServerApplication::Quit() {
|
||||
std::cout << "Shutting down" << std::endl;
|
||||
|
||||
//close the managers
|
||||
clientMap.clear();
|
||||
accountMgr.UnloadAll();
|
||||
characterMgr.UnloadAll();
|
||||
//TODO: unload combats
|
||||
//TODO: unload enemies
|
||||
//TODO: unload rooms
|
||||
|
||||
//APIs
|
||||
lua_close(luaState);
|
||||
sqlite3_close_v2(database);
|
||||
|
||||
Reference in New Issue
Block a user