DROP A TRAIN ON IT
This commit is contained in:
parent
9b3487d567
commit
fff2db63b6
5 changed files with 91 additions and 32 deletions
|
@ -25,7 +25,8 @@ bool sosc::db::init_databases(std::string* error) {
|
||||||
|
|
||||||
int32_t lastMig = db::Query::ScalarInt32("SELECT MAX(ID) FROM MIGRATIONS");
|
int32_t lastMig = db::Query::ScalarInt32("SELECT MAX(ID) FROM MIGRATIONS");
|
||||||
if(lastMig > _hard_db_sql.size()) {
|
if(lastMig > _hard_db_sql.size()) {
|
||||||
*error = "HARD DB: RECORDED MIGRATION COUNT TOO HIGH";
|
if(error != nullptr)
|
||||||
|
*error = "HARD DB: RECORDED MIGRATION COUNT TOO HIGH";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +42,8 @@ bool sosc::db::init_databases(std::string* error) {
|
||||||
std::string hash = getMigration.ScalarText();
|
std::string hash = getMigration.ScalarText();
|
||||||
if(hash.empty()) {
|
if(hash.empty()) {
|
||||||
if(id < lastMig) {
|
if(id < lastMig) {
|
||||||
*error = "HARD DB: MIGRATION RECORDS NOT CONTINUOUS";
|
if(error != nullptr)
|
||||||
|
*error = "HARD DB: MIGRATION RECORDS NOT CONTINUOUS";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +54,8 @@ bool sosc::db::init_databases(std::string* error) {
|
||||||
insertMigration.NonQuery();
|
insertMigration.NonQuery();
|
||||||
} else {
|
} else {
|
||||||
if(hash != cgc::sha1(_hard_db_sql[id])) {
|
if(hash != cgc::sha1(_hard_db_sql[id])) {
|
||||||
*error = "HARD DB: MIGRATION SQL HASH MISMATCH";
|
if(error != nullptr)
|
||||||
|
*error = "HARD DB: MIGRATION SQL HASH MISMATCH";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,6 @@ public:
|
||||||
|
|
||||||
~MasterClient() { this->Close(); };
|
~MasterClient() { this->Close(); };
|
||||||
private:
|
private:
|
||||||
bool IsAuthed();
|
|
||||||
|
|
||||||
bool ProcessLogin(Packet& pck);
|
bool ProcessLogin(Packet& pck);
|
||||||
bool ProcessRegistration(Packet& pck);
|
bool ProcessRegistration(Packet& pck);
|
||||||
bool ListServers(Packet& pck);
|
bool ListServers(Packet& pck);
|
||||||
|
|
|
@ -83,8 +83,9 @@ bool sosc::MasterClient::Process(const db::Queries *queries) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sosc::MasterClient::IsAuthed() {
|
bool sosc::MasterClient::ProcessLogin(Packet &pck) {
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sosc::MasterClient::Close() {
|
bool sosc::MasterClient::Close() {
|
||||||
|
|
|
@ -2,37 +2,75 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "sock/tcpsock.hpp"
|
|
||||||
#include "utils/string.hpp"
|
|
||||||
#include "utils/net.hpp"
|
|
||||||
#include "utils/time.hpp"
|
|
||||||
#include "sock/tcpsock.hpp"
|
|
||||||
#include "crypto/sha1.hpp"
|
|
||||||
#include "crypto/base64.hpp"
|
|
||||||
#include "crypto/bfish.hpp"
|
|
||||||
#include "utils/csprng.hpp"
|
|
||||||
#include "crypto/bcrypt.hpp"
|
|
||||||
#include "utils/bigint.hpp"
|
|
||||||
#include "sock/scapesock.hpp"
|
|
||||||
#include "sock/pool.hpp"
|
|
||||||
|
|
||||||
|
#include "utils/string.hpp"
|
||||||
|
#include "db/database.hpp"
|
||||||
#include "hosts/master.hpp"
|
#include "hosts/master.hpp"
|
||||||
#include "hosts/slave.hpp"
|
#include "hosts/slave.hpp"
|
||||||
|
|
||||||
|
static struct _slave_ctx {
|
||||||
|
sosc::ScapeServer server;
|
||||||
|
sosc::SlaveClientPool pool;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct {
|
||||||
|
sosc::IntraServer server;
|
||||||
|
sosc::MasterIntraPool pool;
|
||||||
|
} master_intra;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
sosc::ScapeServer server;
|
||||||
|
sosc::MasterIntraPool pool;
|
||||||
|
} master_client;
|
||||||
|
|
||||||
|
_slave_ctx* slaves;
|
||||||
|
bool running;
|
||||||
|
} _ctx;
|
||||||
|
|
||||||
bool master_intra(uint16_t port, const sosc::poolinfo_t& info);
|
bool master_intra(uint16_t port, const sosc::poolinfo_t& info);
|
||||||
bool master_client(uint16_t port, const sosc::poolinfo_t& info);
|
bool master_client(uint16_t port, const sosc::poolinfo_t& info);
|
||||||
bool slave(uint16_t port, const sosc::poolinfo_t& info);
|
bool slave(uint16_t port, const sosc::poolinfo_t& info);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
using namespace sosc;
|
||||||
if(argc < 2)
|
if(argc < 2)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(argv[1][0] == 'm') {
|
_ctx.running = true;
|
||||||
|
std::vector<std::thread*> threads;
|
||||||
|
|
||||||
master_client(8008, sosc::poolinfo_t());
|
if(argv[1][0] == 'm') {
|
||||||
//master_intra(1234, sosc::poolinfo_t());
|
if(!db::init_databases(nullptr))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
threads.push_back(new std::thread([&] {
|
||||||
|
master_client(8008, poolinfo_t());
|
||||||
|
}));
|
||||||
|
threads.push_back(new std::thread([&] {
|
||||||
|
master_intra(1234, poolinfo_t());
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
slave(1234, sosc::poolinfo_t());
|
threads.push_back(new std::thread([&] {
|
||||||
|
slave(1234, poolinfo_t());
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Server threads started. Type STOP to cancel." << std::endl;
|
||||||
|
|
||||||
|
std::string input;
|
||||||
|
while(true) {
|
||||||
|
std::cin >> input;
|
||||||
|
str::tolower(str::trim(&input));
|
||||||
|
|
||||||
|
if(input == "stop")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ctx.running = false;
|
||||||
|
for(const auto& thread : threads) {
|
||||||
|
thread->join();
|
||||||
|
delete thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -50,10 +88,17 @@ bool master_intra(uint16_t port, const sosc::poolinfo_t& info) {
|
||||||
pool.Configure(info);
|
pool.Configure(info);
|
||||||
pool.Start();
|
pool.Start();
|
||||||
|
|
||||||
while(server.Accept(&client))
|
auto listenThread = std::thread([&] {
|
||||||
pool.AddClient(new MasterIntra(client));
|
while (server.Accept(&client))
|
||||||
|
pool.AddClient(new MasterIntra(client));
|
||||||
|
});
|
||||||
|
|
||||||
|
while(_ctx.running);
|
||||||
|
|
||||||
|
server.Close();
|
||||||
|
listenThread.join();
|
||||||
pool.Stop();
|
pool.Stop();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,10 +114,17 @@ bool master_client(uint16_t port, const sosc::poolinfo_t& info) {
|
||||||
pool.Configure(info);
|
pool.Configure(info);
|
||||||
pool.Start();
|
pool.Start();
|
||||||
|
|
||||||
while(server.Accept(&client))
|
auto listenThread = std::thread([&] {
|
||||||
pool.AddClient(new MasterClient(client));
|
while(server.Accept(&client))
|
||||||
|
pool.AddClient(new MasterClient(client));
|
||||||
|
});
|
||||||
|
|
||||||
|
while(_ctx.running);
|
||||||
|
|
||||||
|
server.Close();
|
||||||
|
listenThread.join();
|
||||||
pool.Stop();
|
pool.Stop();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +140,16 @@ bool slave(uint16_t port, const sosc::poolinfo_t& info) {
|
||||||
pool.Configure(info);
|
pool.Configure(info);
|
||||||
pool.Start();
|
pool.Start();
|
||||||
|
|
||||||
while(server.Accept(&client))
|
auto listenThread = std::thread([&] {
|
||||||
pool.AddClient(new SlaveClient(client));
|
while (server.Accept(&client))
|
||||||
|
pool.AddClient(new SlaveClient(client));
|
||||||
|
});
|
||||||
|
|
||||||
|
while(_ctx.running);
|
||||||
|
|
||||||
|
server.Close();
|
||||||
|
listenThread.join();
|
||||||
pool.Stop();
|
pool.Stop();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,8 +127,6 @@ function pack(id, regions) {
|
||||||
body_ptr += length;
|
body_ptr += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(regions);
|
|
||||||
console.log(pck);
|
|
||||||
return pck;
|
return pck;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue