From 6d98bab0007b9d9515a74f511657dd650947f4de Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 13 Aug 2014 09:45:54 +1000 Subject: [PATCH] Began refactoring the server (read more) * deleted the enemy and combat stubs * encapsulated the character and account stubs TODO: * The remaining managers should be singletons --- server/accounts/account_data.hpp | 26 +++++++++-- server/characters/character_data.hpp | 42 ++++++++++++------ server/characters/character_manager.cpp | 58 ++++++++++++------------- server/combat/combat_data.hpp | 52 ---------------------- server/combat/combat_manager.cpp | 54 ----------------------- server/combat/combat_manager.hpp | 51 ---------------------- server/combat/makefile | 37 ---------------- server/enemies/enemy_data.hpp | 47 -------------------- server/enemies/enemy_manager.cpp | 54 ----------------------- server/enemies/enemy_manager.hpp | 51 ---------------------- server/enemies/makefile | 37 ---------------- 11 files changed, 80 insertions(+), 429 deletions(-) delete mode 100644 server/combat/combat_data.hpp delete mode 100644 server/combat/combat_manager.cpp delete mode 100644 server/combat/combat_manager.hpp delete mode 100644 server/combat/makefile delete mode 100644 server/enemies/enemy_data.hpp delete mode 100644 server/enemies/enemy_manager.cpp delete mode 100644 server/enemies/enemy_manager.hpp delete mode 100644 server/enemies/makefile diff --git a/server/accounts/account_data.hpp b/server/accounts/account_data.hpp index 9c3d735..d7fb022 100644 --- a/server/accounts/account_data.hpp +++ b/server/accounts/account_data.hpp @@ -24,15 +24,35 @@ #include -struct AccountData { +class AccountData { +public: + AccountData() = default; + ~AccountData() = default; + + //accessors and mutators + int SetClientIndex(int i) { return clientIndex = i; } + int GetClientIndex() { return clientIndex; } + + std::string SetUsername(std::string s) { return username = s; } + std::string GetUsername() { return username; } + + //database stuff + bool GetBlackListed() { return blackListed; } + bool GetWhiteListed() { return whiteListed; } + bool GetModerator() { return mod; } + bool GetAdministrator() { return admin; } + +private: + friend class AccountManager; + + int clientIndex; std::string username; //TODO: password + bool blackListed = false; bool whiteListed = true; bool mod = false; bool admin = false; - - int clientIndex; }; #endif diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp index 5650e36..bbcc759 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -31,27 +31,41 @@ #include #include -struct CharacterData { - //metadata - int owner; - std::string handle; - std::string avatar; +class CharacterData { +public: + CharacterData(); + ~CharacterData(); + + //location and movement + int SetRoomIndex(int i) { return roomIndex = i; } + Vector2 SetOrigin(Vector2 v) { return origin = v; } + Vector2 SetMotion(Vector2 v) { return motion = v; } + + int GetRoomIndex() { return roomIndex; } + Vector2 GetOrigin() { return origin; } + Vector2 GetMotion() { return motion; } + + //accessors and mutators + Statistics* GetBaseStats() { return &baseStats; } + + //database stuff + int GetOwner() { return owner; } + std::string GetHandle() { return handle; } + std::string GetAvatar() { return avatar; } + +private: + friend class CharacterManager; //world position int roomIndex = 0; Vector2 origin = {0.0,0.0}; Vector2 motion = {0.0,0.0}; - //base statistics - Statistics stats; + Statistics baseStats; - //TODO: gameplay components: equipment, items, buffs, debuffs - - //active gameplay members - //NOTE: these are lost when unloaded - bool inCombat = false; - int atbGauge = 0; - //TODO: stored command + int owner; + std::string handle; + std::string avatar; }; #endif diff --git a/server/characters/character_manager.cpp b/server/characters/character_manager.cpp index bfc070c..baabac1 100644 --- a/server/characters/character_manager.cpp +++ b/server/characters/character_manager.cpp @@ -58,7 +58,7 @@ static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;"; //Define the methods //------------------------- -//NOTE: default stats as a parameter would be good for different beggining states or multiple classes +//NOTE: default baseStats as a parameter would be good for different beggining states or multiple classes int CharacterManager::CreateCharacter(int owner, std::string handle, std::string avatar) { //Create the character, failing if it exists sqlite3_stmt* statement = nullptr; @@ -142,20 +142,20 @@ int CharacterManager::LoadCharacter(int owner, std::string handle, std::string a newChar.origin.y = (double)sqlite3_column_int(statement, 7); //statistics - newChar.stats.level = sqlite3_column_int(statement, 8); - newChar.stats.exp = sqlite3_column_int(statement, 9); - newChar.stats.maxHP = sqlite3_column_int(statement, 10); - newChar.stats.health = sqlite3_column_int(statement, 11); - newChar.stats.maxMP = sqlite3_column_int(statement, 12); - newChar.stats.mana = sqlite3_column_int(statement, 13); - newChar.stats.attack = sqlite3_column_int(statement, 14); - newChar.stats.defence = sqlite3_column_int(statement, 15); - newChar.stats.intelligence = sqlite3_column_int(statement, 16); - newChar.stats.resistance = sqlite3_column_int(statement, 17); - newChar.stats.speed = sqlite3_column_int(statement, 18); - newChar.stats.accuracy = sqlite3_column_double(statement, 19); - newChar.stats.evasion = sqlite3_column_double(statement, 20); - newChar.stats.luck = sqlite3_column_double(statement, 21); + newChar.baseStats.level = sqlite3_column_int(statement, 8); + newChar.baseStats.exp = sqlite3_column_int(statement, 9); + newChar.baseStats.maxHP = sqlite3_column_int(statement, 10); + newChar.baseStats.health = sqlite3_column_int(statement, 11); + newChar.baseStats.maxMP = sqlite3_column_int(statement, 12); + newChar.baseStats.mana = sqlite3_column_int(statement, 13); + newChar.baseStats.attack = sqlite3_column_int(statement, 14); + newChar.baseStats.defence = sqlite3_column_int(statement, 15); + newChar.baseStats.intelligence = sqlite3_column_int(statement, 16); + newChar.baseStats.resistance = sqlite3_column_int(statement, 17); + newChar.baseStats.speed = sqlite3_column_int(statement, 18); + newChar.baseStats.accuracy = sqlite3_column_double(statement, 19); + newChar.baseStats.evasion = sqlite3_column_double(statement, 20); + newChar.baseStats.luck = sqlite3_column_double(statement, 21); //TODO: gameplay components: equipment, items, buffs, debuffs @@ -199,20 +199,20 @@ int CharacterManager::SaveCharacter(int uid) { ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK; //statistics - ret |= sqlite3_bind_int(statement, 5, character.stats.level) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 6, character.stats.exp) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 7, character.stats.maxHP) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 8, character.stats.health) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 9, character.stats.maxMP) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 10, character.stats.mana) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 11, character.stats.attack) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 12, character.stats.defence) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 13, character.stats.intelligence) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 14, character.stats.resistance) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 15, character.stats.speed) != SQLITE_OK; - ret |= sqlite3_bind_double(statement, 16, character.stats.accuracy) != SQLITE_OK; - ret |= sqlite3_bind_double(statement, 17, character.stats.evasion) != SQLITE_OK; - ret |= sqlite3_bind_double(statement, 18, character.stats.luck) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 5, character.baseStats.level) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 6, character.baseStats.exp) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 7, character.baseStats.maxHP) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 8, character.baseStats.health) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 9, character.baseStats.maxMP) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 10, character.baseStats.mana) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 11, character.baseStats.attack) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 12, character.baseStats.defence) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 13, character.baseStats.intelligence) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 14, character.baseStats.resistance) != SQLITE_OK; + ret |= sqlite3_bind_int(statement, 15, character.baseStats.speed) != SQLITE_OK; + ret |= sqlite3_bind_double(statement, 16, character.baseStats.accuracy) != SQLITE_OK; + ret |= sqlite3_bind_double(statement, 17, character.baseStats.evasion) != SQLITE_OK; + ret |= sqlite3_bind_double(statement, 18, character.baseStats.luck) != SQLITE_OK; //TODO: gameplay components: equipment, items, buffs, debuffs diff --git a/server/combat/combat_data.hpp b/server/combat/combat_data.hpp deleted file mode 100644 index 683e66f..0000000 --- a/server/combat/combat_data.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2014 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef COMBATDATA_HPP_ -#define COMBATDATA_HPP_ - -#include "vector2.hpp" -#include "combat_defines.hpp" - -//gameplay members -#include "character_data.hpp" -#include "enemy_data.hpp" - -//std namespace -#include -#include -#include - -struct CombatData { - typedef std::chrono::steady_clock Clock; - - std::array characterArray; - std::array enemyArray; - - //world interaction - int mapIndex = 0; - Vector2 origin = {0.0,0.0}; - Vector2 bounds = {0.0,0.0}; - - //time interval - Clock::time_point lastTick = Clock::now(); -}; - -#endif diff --git a/server/combat/combat_manager.cpp b/server/combat/combat_manager.cpp deleted file mode 100644 index be4f9ac..0000000 --- a/server/combat/combat_manager.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2014 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#include "combat_manager.hpp" - -//------------------------- -//public access methods -//------------------------- - -//TODO - -//------------------------- -//accessors and mutators -//------------------------- - -CombatData* CombatManager::GetCombat(int uid) { - std::map::iterator it = combatMap.find(uid); - - if (it == combatMap.end()) { - return nullptr; - } - - return &it->second; -} - -std::map* CombatManager::GetContainer() { - return &combatMap; -} - -lua_State* CombatManager::SetLuaState(lua_State* L) { - return luaState = L; -} - -lua_State* CombatManager::GetLuaState() { - return luaState; -} diff --git a/server/combat/combat_manager.hpp b/server/combat/combat_manager.hpp deleted file mode 100644 index 77573ab..0000000 --- a/server/combat/combat_manager.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2014 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef COMBATMANAGER_HPP_ -#define COMBATMANAGER_HPP_ - -#include "combat_data.hpp" - -#include "lua/lua.hpp" - -#include - -class CombatManager { -public: - CombatManager() = default; - ~CombatManager() = default; - - //public access methods - //TODO - - //accessors and mutators - CombatData* GetCombat(int uid); - std::map* GetContainer(); - - lua_State* SetLuaState(lua_State*); - lua_State* GetLuaState(); - -private: - std::map combatMap; - lua_State* luaState = nullptr; -}; - -#endif \ No newline at end of file diff --git a/server/combat/makefile b/server/combat/makefile deleted file mode 100644 index 4d71462..0000000 --- a/server/combat/makefile +++ /dev/null @@ -1,37 +0,0 @@ -#config -INCLUDES+=. ../../common/gameplay ../../common/utilities ../characters ../enemies -LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=.. -OUT=$(addprefix $(OUTDIR)/,server.a) - -#targets -all: $(OBJ) $(OUT) - ar -crs $(OUT) $(OBJ) - -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: - $(RM) *.o *.a *.exe - -rebuild: clean all diff --git a/server/enemies/enemy_data.hpp b/server/enemies/enemy_data.hpp deleted file mode 100644 index ab1ef89..0000000 --- a/server/enemies/enemy_data.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2014 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef ENEMYDATA_HPP_ -#define ENEMYDATA_HPP_ - -#include "vector2.hpp" -#include "statistics.hpp" - -//std namespace -#include - -struct EnemyData { - //metadata - std::string handle; - std::string avatar; - - //gameplay - Statistics stats; - - //TODO: gameplay components: equipment, items, buffs, debuffs, rewards - - //active gameplay members - //NOTE: these are lost when unloaded - int tableIndex; - int atbGauge = 0; -}; - -#endif diff --git a/server/enemies/enemy_manager.cpp b/server/enemies/enemy_manager.cpp deleted file mode 100644 index 2b49d3d..0000000 --- a/server/enemies/enemy_manager.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2014 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#include "enemy_manager.hpp" - -//------------------------- -//public access methods -//------------------------- - -//TODO - -//------------------------- -//accessors and mutators -//------------------------- - -EnemyData* EnemyManager::GetEnemy(int uid) { - std::map::iterator it = enemyMap.find(uid); - - if (it == enemyMap.end()) { - return nullptr; - } - - return &it->second; -} - -std::map* EnemyManager::GetContainer() { - return &enemyMap; -} - -lua_State* EnemyManager::SetLuaState(lua_State* L) { - return luaState = L; -} - -lua_State* EnemyManager::GetLuaState() { - return luaState; -} diff --git a/server/enemies/enemy_manager.hpp b/server/enemies/enemy_manager.hpp deleted file mode 100644 index dae86ad..0000000 --- a/server/enemies/enemy_manager.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2014 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef ENEMYMANAGER_HPP_ -#define ENEMYMANAGER_HPP_ - -#include "enemy_data.hpp" - -#include "lua/lua.hpp" - -#include - -class EnemyManager { -public: - EnemyManager() = default; - ~EnemyManager() = default; - - //public access methods - //TODO - - //accessors and mutators - EnemyData* GetEnemy(int uid); - std::map* GetContainer(); - - lua_State* SetLuaState(lua_State*); - lua_State* GetLuaState(); - -private: - std::map enemyMap; - lua_State* luaState = nullptr; -}; - -#endif \ No newline at end of file diff --git a/server/enemies/makefile b/server/enemies/makefile deleted file mode 100644 index 8c2156a..0000000 --- a/server/enemies/makefile +++ /dev/null @@ -1,37 +0,0 @@ -#config -INCLUDES+=. ../mapgen ../../common/gameplay ../../common/map ../../common/utilities -LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=.. -OUT=$(addprefix $(OUTDIR)/,server.a) - -#targets -all: $(OBJ) $(OUT) - ar -crs $(OUT) $(OBJ) - -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: - $(RM) *.o *.a *.exe - -rebuild: clean all