The server runs the setup scripts on startup
This commit is contained in:
@@ -71,12 +71,3 @@ CREATE TABLE IF NOT EXISTS PlayerInventoryItems (
|
|||||||
characterID INTEGER REFERENCES PlayerCharacters(characterID),
|
characterID INTEGER REFERENCES PlayerCharacters(characterID),
|
||||||
globalItemListID INTEGER REFERENCES GlobalItemList(globalItemListID)
|
globalItemListID INTEGER REFERENCES GlobalItemList(globalItemListID)
|
||||||
);
|
);
|
||||||
|
|
||||||
--cleanup
|
|
||||||
DROP TABLE UserAccounts;
|
|
||||||
DROP TABLE GlobalItemList;
|
|
||||||
DROP TABLE MundaneItems;
|
|
||||||
DROP TABLE Consumables;
|
|
||||||
DROP TABLE Equipment;
|
|
||||||
DROP TABLE PlayerCharacters;
|
|
||||||
DROP TABLE PlayerInventoryItems;
|
|
||||||
@@ -22,9 +22,9 @@
|
|||||||
#include "server_application.hpp"
|
#include "server_application.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
ServerApplication ServerApplication::instance;
|
ServerApplication ServerApplication::instance;
|
||||||
|
|
||||||
@@ -71,6 +71,22 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
else {
|
else {
|
||||||
std::cout << "Database filename: \"" << dbname << ".db\"" << std::endl;
|
std::cout << "Database filename: \"" << dbname << ".db\"" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Run setup scripts
|
||||||
|
luaL_dofile(luaState, "rsc/setup_server.lua");
|
||||||
|
|
||||||
|
std::ifstream is("rsc/setup_server.sql");
|
||||||
|
if (!is.is_open()) {
|
||||||
|
throw(std::runtime_error("Failed to run database setup script"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "Running the database script" << std::endl;
|
||||||
|
}
|
||||||
|
std::string script;
|
||||||
|
getline(is, script, '\0');
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
sqlite3_exec(database, script.c_str(), nullptr, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::Loop() {
|
void ServerApplication::Loop() {
|
||||||
@@ -78,7 +94,7 @@ void ServerApplication::Loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::Quit() {
|
void ServerApplication::Quit() {
|
||||||
sqlite3_close(database);
|
sqlite3_close_v2(database);
|
||||||
lua_close(luaState);
|
lua_close(luaState);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user