PS 44:15 - My confusion is continually before me, and the shame of my face hath covered me
This commit is contained in:
parent
2c32c63abb
commit
ceedfe12e2
7 changed files with 60 additions and 15 deletions
|
@ -15,7 +15,7 @@ public:
|
||||||
private:
|
private:
|
||||||
std::string GenerateStream(uint64_t length);
|
std::string GenerateStream(uint64_t length);
|
||||||
|
|
||||||
const int state_size = 256;
|
static const int state_size = 256;
|
||||||
uint8_t state[state_size];
|
uint8_t state[state_size];
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -85,6 +85,16 @@ sosc::db::Query::Query() : results(this) {
|
||||||
this->open = false;
|
this->open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sosc::db::Query::Query(const Query &query) : results(this) {
|
||||||
|
this->open = false;
|
||||||
|
if(query.open) {
|
||||||
|
this->SetQuery(
|
||||||
|
sqlite3_sql(query.statement),
|
||||||
|
query.database == _ctx.mem_db ? DB_USE_MEMORY : DB_USE_HARD
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sosc::db::Query::Query(const std::string& query, int db) : results(this) {
|
sosc::db::Query::Query(const std::string& query, int db) : results(this) {
|
||||||
this->open = false;
|
this->open = false;
|
||||||
this->SetQuery(query, db);
|
this->SetQuery(query, db);
|
||||||
|
|
|
@ -39,7 +39,10 @@ private:
|
||||||
class Query {
|
class Query {
|
||||||
public:
|
public:
|
||||||
Query();
|
Query();
|
||||||
Query(const std::string& query, int db = DB_USE_HARD);
|
Query(const Query& query);
|
||||||
|
|
||||||
|
Query& operator= (const Query&) = delete;
|
||||||
|
explicit Query(const std::string& query, int db = DB_USE_HARD);
|
||||||
void SetQuery(const std::string& query, int db = DB_USE_HARD);
|
void SetQuery(const std::string& query, int db = DB_USE_HARD);
|
||||||
|
|
||||||
void BindDouble(double value, int i);
|
void BindDouble(double value, int i);
|
||||||
|
|
|
@ -20,7 +20,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScapeConnection sock;
|
ScapeConnection sock;
|
||||||
|
|
||||||
cgc::KeyExchange key;
|
cgc::KeyExchange key;
|
||||||
cgc::Cipher cipher;
|
cgc::Cipher cipher;
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,11 +62,17 @@ sosc::MasterIntraPool::MasterIntraPool() {
|
||||||
"SELECT MAX(`ID`) FROM `SERVER_LIST`"
|
"SELECT MAX(`ID`) FROM `SERVER_LIST`"
|
||||||
, DB_USE_MEMORY));
|
, DB_USE_MEMORY));
|
||||||
|
|
||||||
#define QRY_SERVER_LIST_DELETE 9
|
#define QRY_SERVER_LIST_MODIFY 9
|
||||||
|
this->queries.push_back(new db::Query(
|
||||||
|
"UPDATE `SERVER_LIST` SET "
|
||||||
|
"`USERS` = ?, `MAX_USERS` = ? "
|
||||||
|
"WHERE ID = ?"
|
||||||
|
, DB_USE_MEMORY));
|
||||||
|
|
||||||
|
#define QRY_SERVER_LIST_DELETE 10
|
||||||
this->queries.push_back(new db::Query(
|
this->queries.push_back(new db::Query(
|
||||||
"DELETE FROM `SERVER_LIST` WHERE `ID` = ?"
|
"DELETE FROM `SERVER_LIST` WHERE `ID` = ?"
|
||||||
, DB_USE_MEMORY));
|
, DB_USE_MEMORY));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sosc::MasterIntraPool::Stop() {
|
void sosc::MasterIntraPool::Stop() {
|
||||||
|
@ -199,11 +205,21 @@ bool sosc::MasterIntra::StatusUpdate(sosc::Packet &pck) {
|
||||||
if(!this->authed)
|
if(!this->authed)
|
||||||
return this->NotAuthorized(packetId);
|
return this->NotAuthorized(packetId);
|
||||||
|
|
||||||
|
db::Query* query = this->queries->at(QRY_LICENSE_VERIFY);
|
||||||
|
query->Reset();
|
||||||
|
query->BindText(this->license, 0);
|
||||||
|
if(query->ScalarInt32() == 0)
|
||||||
|
return this->NotAuthorized(packetId);
|
||||||
|
|
||||||
if(!pck.Check(2, 2, 2))
|
if(!pck.Check(2, 2, 2))
|
||||||
return this->Close();
|
return this->Close();
|
||||||
|
|
||||||
|
query = this->queries->at(QRY_SERVER_LIST_MODIFY);
|
||||||
|
query->Reset();
|
||||||
|
query->BindInt32(net::ntohv<uint16_t>(pck[0]), 0);
|
||||||
|
query->BindInt32(net::ntohv<uint16_t>(pck[1]), 1);
|
||||||
|
query->BindInt32(this->server_id, 2);
|
||||||
|
query->NonQuery();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include "../sock/pool.hpp"
|
#include "../sock/pool.hpp"
|
||||||
|
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
|
/** SLAVE -> CLIENT **/
|
||||||
|
|
||||||
class SlaveClient {
|
class SlaveClient {
|
||||||
public:
|
public:
|
||||||
SlaveClient(const ScapeConnection& client);
|
SlaveClient(const ScapeConnection& client);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include "../db/database.hpp"
|
||||||
|
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -42,7 +43,8 @@ public:
|
||||||
|
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
protected:
|
protected:
|
||||||
virtual bool ProcessClient(T& client) = 0;
|
virtual void SetupQueries(std::vector<db::Query>* queries) {};
|
||||||
|
virtual bool ProcessClient(T& client, std::vector<db::Query>* queries) = 0;
|
||||||
private:
|
private:
|
||||||
bool IsStackFull(int stackCount) const;
|
bool IsStackFull(int stackCount) const;
|
||||||
bool CanAddStack() const;
|
bool CanAddStack() const;
|
||||||
|
@ -64,6 +66,7 @@ private:
|
||||||
private:
|
private:
|
||||||
void StackThread();
|
void StackThread();
|
||||||
|
|
||||||
|
std::vector<db::Query> queries;
|
||||||
std::thread* thread;
|
std::thread* thread;
|
||||||
Pool<T>* pool;
|
Pool<T>* pool;
|
||||||
bool is_open;
|
bool is_open;
|
||||||
|
@ -76,6 +79,7 @@ private:
|
||||||
poolinfo_t info;
|
poolinfo_t info;
|
||||||
bool is_open;
|
bool is_open;
|
||||||
|
|
||||||
|
std::vector<db::Query> queries;
|
||||||
std::vector<Stack*> stacks;
|
std::vector<Stack*> stacks;
|
||||||
|
|
||||||
friend class Stack;
|
friend class Stack;
|
||||||
|
@ -97,6 +101,7 @@ void Pool<T>::Start() {
|
||||||
if(this->is_open)
|
if(this->is_open)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
this->SetupQueries(&this->queries);
|
||||||
for(int i = 0; i < this->info.initial_count; ++i) {
|
for(int i = 0; i < this->info.initial_count; ++i) {
|
||||||
this->stacks.push_back(new Stack(this));
|
this->stacks.push_back(new Stack(this));
|
||||||
this->stacks.back()->Start();
|
this->stacks.back()->Start();
|
||||||
|
@ -173,6 +178,9 @@ void Pool<T>::Stop() {
|
||||||
delete stack;
|
delete stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(auto& query : this->queries)
|
||||||
|
query.Close();
|
||||||
|
|
||||||
this->stacks.clear();
|
this->stacks.clear();
|
||||||
this->is_open = false;
|
this->is_open = false;
|
||||||
}
|
}
|
||||||
|
@ -189,6 +197,9 @@ void Pool<T>::Stack::Start() {
|
||||||
if(this->is_open || this->is_running)
|
if(this->is_open || this->is_running)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
for(auto& query : this->pool->queries)
|
||||||
|
this->queries.push_back(db::Query(query));
|
||||||
|
|
||||||
this->is_open = true;
|
this->is_open = true;
|
||||||
this->is_running = true;
|
this->is_running = true;
|
||||||
this->thread = new std::thread([&]() {
|
this->thread = new std::thread([&]() {
|
||||||
|
@ -220,6 +231,7 @@ int Pool<T>::Stack::ClientCount() {
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Pool<T>::Stack::StackThread() {
|
void Pool<T>::Stack::StackThread() {
|
||||||
|
|
||||||
while(this->is_running) {
|
while(this->is_running) {
|
||||||
for(auto client = this->clients.begin();
|
for(auto client = this->clients.begin();
|
||||||
client != this->clients.end();
|
client != this->clients.end();
|
||||||
|
@ -229,7 +241,7 @@ void Pool<T>::Stack::StackThread() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
this->clients_mtx.lock();
|
this->clients_mtx.lock();
|
||||||
if(!this->pool->ProcessClient(*client))
|
if(!this->pool->ProcessClient(*client, &this->queries))
|
||||||
this->clients.erase(client);
|
this->clients.erase(client);
|
||||||
this->clients_mtx.unlock();
|
this->clients_mtx.unlock();
|
||||||
}
|
}
|
||||||
|
@ -241,6 +253,9 @@ void Pool<T>::Stack::Stop() {
|
||||||
if(!this->is_open || !this->is_running)
|
if(!this->is_open || !this->is_running)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
for(auto& query : this->queries)
|
||||||
|
query.Close();
|
||||||
|
|
||||||
this->is_running = false;
|
this->is_running = false;
|
||||||
this->thread->join();
|
this->thread->join();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue