oily woily sql

This commit is contained in:
malloc 2018-04-24 17:03:19 -05:00
parent f448d18e9e
commit 846bc6ef2f
8 changed files with 73 additions and 7 deletions

View file

@ -22,7 +22,7 @@ class Entrypoint {
private static initStatus = { private static initStatus = {
keyInit: false, keyInit: false,
fileCache: false fileCache: false
} };
private static initCheck(): void { private static initCheck(): void {
var done = true; var done = true;

View file

@ -12,7 +12,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -static")
endif() endif()
add_executable(server ${server_src}) add_executable(server ${server_src} src/db/_init_sql.cpp)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
target_link_libraries(server wsock32 ws2_32) target_link_libraries(server wsock32 ws2_32)

View file

@ -18,7 +18,7 @@ sosc::Packet sosc::cgc::KeyExchange::GenerateRequest() const {
} }
bool sosc::cgc::KeyExchange::ParseRequest bool sosc::cgc::KeyExchange::ParseRequest
(const Packet& request, Packet* response) (const Packet& request, Packet* response, uint8_t id)
{ {
if(request.GetId() != 1 || request.RegionCount() != 3) if(request.GetId() != 1 || request.RegionCount() != 3)
return false; return false;
@ -33,7 +33,7 @@ bool sosc::cgc::KeyExchange::ParseRequest
this->private_key = BigUInt::ModPow(public_key, this->secret, modulus); this->private_key = BigUInt::ModPow(public_key, this->secret, modulus);
public_key = BigUInt::ModPow(generator, this->secret, modulus); public_key = BigUInt::ModPow(generator, this->secret, modulus);
*response = Packet(1, { public_key.ToString() }); *response = Packet(id, { public_key.ToString() });
return true; return true;
} }

View file

@ -11,7 +11,7 @@ public:
KeyExchange(); KeyExchange();
Packet GenerateRequest() const; Packet GenerateRequest() const;
bool ParseRequest(const Packet& request, Packet* response); bool ParseRequest(const Packet& request, Packet* response, uint8_t id);
bool ParseResponse(const Packet& response); bool ParseResponse(const Packet& response);
inline bool Succeeded() const { inline bool Succeeded() const {

View file

@ -0,0 +1,10 @@
#include <vector>
const char* _mem_db_sql =
"CREATE TABLE ";
const std::vector<const char*> _hard_db_sql = {
/** START MIGRATION 0 **/
"CREATE TABLE ",
/** END MIGRATION 0 **/
};

View file

@ -1 +1,31 @@
#include "database.hpp" #include "database.hpp"
#include "_init_sql.cpp"
static struct {
bool ready = false;
sqlite3* mem_db;
sqlite3* hard_db;
} _ctx;
void sosc::db::init_databases() {
if(_ctx.ready)
return;
sqlite3_open(":memory:", &_ctx.mem_db);
sqlite3_exec(_ctx.mem_db, _mem_db_sql, nullptr, nullptr, nullptr);
sqlite3_open("scape.db", &_ctx.hard_db);
_ctx.ready = true;
}
void sosc::db::close_databases() {
if(!_ctx.ready)
return;
sqlite3_close(_ctx.mem_db);
sqlite3_close(_ctx.hard_db);
_ctx.ready = false;
}

View file

@ -2,10 +2,33 @@
#define SOSC_DATABASE_H #define SOSC_DATABASE_H
#include "sqlite/sqlite3.h" #include "sqlite/sqlite3.h"
#include <vector>
namespace sosc { namespace sosc {
namespace db { namespace db {
class ResultSet {
public:
private:
};
class Query {
public:
template<typename T>
static T ScalarOnce();
static void NonQueryOnce();
static ResultSet Once();
private:
};
// THE FOLLOWING ARE NOT THREAD SAFE !!
// CALL THEM ONLY WHEN MASTER POOL IS INACTIVE
void init_databases();
void close_databases();
}} }}
#endif #endif

View file

@ -18,13 +18,16 @@ bool sosc::MasterIntra::Process() {
return this->Close(Packet(EncryptionError, { "\x01" })); return this->Close(Packet(EncryptionError, { "\x01" }));
Packet response; Packet response;
if(!this->key.ParseRequest(pck, &response)) if(!this->key.ParseRequest(pck, &response, KeyExchange))
return this->Close(Packet(EncryptionError, { "\x02" })); return this->Close(Packet(EncryptionError, { "\x02" }));
this->sock.Send(response); this->sock.Send(response);
break; break;
case Authentication: case Authentication:
break;
case StatusUpdate:
break; break;
default: default:
this->Close(); this->Close();