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:
|
||||
std::string GenerateStream(uint64_t length);
|
||||
|
||||
const int state_size = 256;
|
||||
static const int state_size = 256;
|
||||
uint8_t state[state_size];
|
||||
};
|
||||
}}
|
||||
|
|
|
@ -85,6 +85,16 @@ sosc::db::Query::Query() : results(this) {
|
|||
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) {
|
||||
this->open = false;
|
||||
this->SetQuery(query, db);
|
||||
|
|
|
@ -39,7 +39,10 @@ private:
|
|||
class Query {
|
||||
public:
|
||||
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 BindDouble(double value, int i);
|
||||
|
|
|
@ -20,7 +20,6 @@ public:
|
|||
|
||||
private:
|
||||
ScapeConnection sock;
|
||||
|
||||
cgc::KeyExchange key;
|
||||
cgc::Cipher cipher;
|
||||
};
|
||||
|
|
|
@ -62,11 +62,17 @@ sosc::MasterIntraPool::MasterIntraPool() {
|
|||
"SELECT MAX(`ID`) FROM `SERVER_LIST`"
|
||||
, 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(
|
||||
"DELETE FROM `SERVER_LIST` WHERE `ID` = ?"
|
||||
, DB_USE_MEMORY));
|
||||
|
||||
}
|
||||
|
||||
void sosc::MasterIntraPool::Stop() {
|
||||
|
@ -199,11 +205,21 @@ bool sosc::MasterIntra::StatusUpdate(sosc::Packet &pck) {
|
|||
if(!this->authed)
|
||||
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))
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "../sock/pool.hpp"
|
||||
|
||||
namespace sosc {
|
||||
/** SLAVE -> CLIENT **/
|
||||
|
||||
class SlaveClient {
|
||||
public:
|
||||
SlaveClient(const ScapeConnection& client);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <list>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include "../db/database.hpp"
|
||||
|
||||
namespace sosc {
|
||||
typedef struct {
|
||||
|
@ -42,7 +43,8 @@ public:
|
|||
|
||||
virtual void Stop();
|
||||
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:
|
||||
bool IsStackFull(int stackCount) const;
|
||||
bool CanAddStack() const;
|
||||
|
@ -64,6 +66,7 @@ private:
|
|||
private:
|
||||
void StackThread();
|
||||
|
||||
std::vector<db::Query> queries;
|
||||
std::thread* thread;
|
||||
Pool<T>* pool;
|
||||
bool is_open;
|
||||
|
@ -76,6 +79,7 @@ private:
|
|||
poolinfo_t info;
|
||||
bool is_open;
|
||||
|
||||
std::vector<db::Query> queries;
|
||||
std::vector<Stack*> stacks;
|
||||
|
||||
friend class Stack;
|
||||
|
@ -97,6 +101,7 @@ void Pool<T>::Start() {
|
|||
if(this->is_open)
|
||||
return;
|
||||
|
||||
this->SetupQueries(&this->queries);
|
||||
for(int i = 0; i < this->info.initial_count; ++i) {
|
||||
this->stacks.push_back(new Stack(this));
|
||||
this->stacks.back()->Start();
|
||||
|
@ -173,6 +178,9 @@ void Pool<T>::Stop() {
|
|||
delete stack;
|
||||
}
|
||||
|
||||
for(auto& query : this->queries)
|
||||
query.Close();
|
||||
|
||||
this->stacks.clear();
|
||||
this->is_open = false;
|
||||
}
|
||||
|
@ -189,6 +197,9 @@ void Pool<T>::Stack::Start() {
|
|||
if(this->is_open || this->is_running)
|
||||
return;
|
||||
|
||||
for(auto& query : this->pool->queries)
|
||||
this->queries.push_back(db::Query(query));
|
||||
|
||||
this->is_open = true;
|
||||
this->is_running = true;
|
||||
this->thread = new std::thread([&]() {
|
||||
|
@ -220,6 +231,7 @@ int Pool<T>::Stack::ClientCount() {
|
|||
|
||||
template<class T>
|
||||
void Pool<T>::Stack::StackThread() {
|
||||
|
||||
while(this->is_running) {
|
||||
for(auto client = this->clients.begin();
|
||||
client != this->clients.end();
|
||||
|
@ -229,7 +241,7 @@ void Pool<T>::Stack::StackThread() {
|
|||
break;
|
||||
|
||||
this->clients_mtx.lock();
|
||||
if(!this->pool->ProcessClient(*client))
|
||||
if(!this->pool->ProcessClient(*client, &this->queries))
|
||||
this->clients.erase(client);
|
||||
this->clients_mtx.unlock();
|
||||
}
|
||||
|
@ -241,6 +253,9 @@ void Pool<T>::Stack::Stop() {
|
|||
if(!this->is_open || !this->is_running)
|
||||
return;
|
||||
|
||||
for(auto& query : this->queries)
|
||||
query.Close();
|
||||
|
||||
this->is_running = false;
|
||||
this->thread->join();
|
||||
|
||||
|
|
Loading…
Reference in a new issue