Began marking changes for monsters
These changes include storing monsters on shutdown, storing dead characters and monsters, etc. Also fleshed out the MonsterManager's internals a bit. (cherry picked from commit af982710f6de050c09ef503cf2f8e1c9fdd34979)
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
//Define the queries
|
||||
//-------------------------
|
||||
|
||||
static const char* CREATE_USER_ACCOUNT = "INSERT INTO Accounts (username) VALUES (?);";
|
||||
static const char* CREATE_USER_ACCOUNT = "INSERT INTO UserAccounts (username) VALUES (?);";
|
||||
|
||||
static const char* LOAD_USER_ACCOUNT = "SELECT "
|
||||
"uid, "
|
||||
@@ -35,18 +35,18 @@ static const char* LOAD_USER_ACCOUNT = "SELECT "
|
||||
"whitelisted, "
|
||||
"mod, "
|
||||
"admin "
|
||||
" FROM Accounts WHERE username = ?;";
|
||||
" FROM UserAccounts WHERE username = ?;";
|
||||
|
||||
static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL Accounts SET "
|
||||
static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL UserAccounts SET "
|
||||
"blacklisted = ?2, "
|
||||
"whitelisted = ?3, "
|
||||
"mod = ?4, "
|
||||
"admin = ?5 "
|
||||
"WHERE uid = ?1;";
|
||||
|
||||
static const char* DELETE_USER_ACCOUNT = "DELETE FROM Accounts WHERE uid = ?;";
|
||||
static const char* DELETE_USER_ACCOUNT = "DELETE FROM UserAccounts WHERE uid = ?;";
|
||||
|
||||
static const char* COUNT_USER_ACCOUNT_RECORDS = "SELECT COUNT(*) FROM Accounts;";
|
||||
static const char* COUNT_USER_ACCOUNT_RECORDS = "SELECT COUNT(*) FROM UserAccounts;";
|
||||
|
||||
//-------------------------
|
||||
//Define the public methods
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
//NOTE: Programmer set variables are NOT zero-indexed
|
||||
//NOTE: SQLite3 returned variables (i.e. loading) ARE zero-indexed
|
||||
|
||||
static const char* CREATE_CHARACTER = "INSERT INTO Characters ("
|
||||
static const char* CREATE_CHARACTER = "INSERT INTO LiveCharacters ("
|
||||
"owner, "
|
||||
"handle, "
|
||||
"avatar, "
|
||||
@@ -57,9 +57,9 @@ static const char* LOAD_CHARACTER = "SELECT "
|
||||
"boundsY, "
|
||||
"boundsW, "
|
||||
"boundsH "
|
||||
"FROM Characters WHERE handle = ?;";
|
||||
"FROM LiveCharacters WHERE handle = ?;";
|
||||
|
||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET "
|
||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL LiveCharacters SET "
|
||||
"roomIndex = ?2, "
|
||||
"originX = ?3, "
|
||||
"originY = ?4, "
|
||||
@@ -69,9 +69,9 @@ static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET "
|
||||
"boundsH = ?8 "
|
||||
"WHERE uid = ?1;";
|
||||
|
||||
static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
|
||||
static const char* DELETE_CHARACTER = "DELETE FROM LiveCharacters WHERE uid = ?;";
|
||||
|
||||
static const char* COUNT_CHARACTER_RECORDS = "SELECT COUNT(*) FROM Characters;";
|
||||
static const char* COUNT_CHARACTER_RECORDS = "SELECT COUNT(*) FROM LiveCharacters;";
|
||||
|
||||
//-------------------------
|
||||
//Define the methods
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
static int setAvatar(lua_State* L) {
|
||||
MonsterData* monster = static_cast<MonsterData*>(lua_touserdata(L, 1));
|
||||
monster->SetAvatar(lua_tostring(L, 2));
|
||||
//TODO: send an update to the clients?
|
||||
//TODO: (1) send an update to the clients?
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,46 +29,60 @@ MonsterManager::~MonsterManager() {
|
||||
UnloadAll();
|
||||
}
|
||||
|
||||
int MonsterManager::Create(std::string) {
|
||||
//TODO: (9) MonsterManager::Create()
|
||||
int MonsterManager::Create(std::string s) {
|
||||
//TODO: (1) MonsterManager::Create()
|
||||
}
|
||||
|
||||
void MonsterManager::Unload(int uid) {
|
||||
//TODO: (9) MonsterManager::Unload()
|
||||
elementMap.erase(uid);
|
||||
}
|
||||
|
||||
void MonsterManager::UnloadAll() {
|
||||
//TODO: (9) MonsterManager::UnloadAll()
|
||||
elementMap.clear();
|
||||
}
|
||||
|
||||
void MonsterManager::UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn) {
|
||||
//TODO: (9) MonsterManager::UnloadIf()
|
||||
std::map<int, MonsterData>::iterator it = elementMap.begin();
|
||||
while (it != elementMap.end()) {
|
||||
if (fn(*it)) {
|
||||
it = elementMap.erase(it);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MonsterData* MonsterManager::Get(int uid) {
|
||||
//TODO: (9) MonsterManager::Get()
|
||||
std::map<int, MonsterData>::iterator it = elementMap.find(uid);
|
||||
|
||||
if (it == elementMap.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
int MonsterManager::GetLoadedCount() {
|
||||
//TODO: (9) MonsterManager::GetLoadedCount()
|
||||
return elementMap.size();
|
||||
}
|
||||
|
||||
std::map<int, MonsterData>* MonsterManager::GetContainer() {
|
||||
//TODO: (9) MonsterManager::GetContainer()
|
||||
return &elementMap;
|
||||
}
|
||||
|
||||
lua_State* MonsterManager::SetLuaState(lua_State* L) {
|
||||
//TODO: (9) MonsterManager::SetLuaState()
|
||||
return lua = L;
|
||||
}
|
||||
|
||||
lua_State* MonsterManager::GetLuaState() {
|
||||
//TODO: (9) MonsterManager::GetLuaState()
|
||||
return lua;
|
||||
}
|
||||
|
||||
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
|
||||
//TODO: (9) MonsterManager::SetDatabase()
|
||||
return database = db;
|
||||
}
|
||||
|
||||
sqlite3* MonsterManager::GetDatabase() {
|
||||
//TODO: (9) MonsterManager::GetDatabase()
|
||||
return database;
|
||||
}
|
||||
|
||||
@@ -62,8 +62,13 @@ static int pumpCharacterUpdate(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pumpMonsterUpdate(lua_State* L) {
|
||||
//TODO: (0) send the info about a specific monster instance
|
||||
}
|
||||
|
||||
static const luaL_Reg networkLib[] = {
|
||||
{"PumpCharacterUpdate", pumpCharacterUpdate},
|
||||
{"PumpMonsterUpdate", pumpMonsterUpdate},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user