smol changes in a lorg world

This commit is contained in:
malloc 2018-11-21 16:38:54 -06:00
parent b772a4f91f
commit 786fbfd79f
6 changed files with 14 additions and 12 deletions

View file

@ -179,8 +179,7 @@ std::string* sosc::Packet::ToString(std::string* packet) const {
for(const auto& i : this->regions) for(const auto& i : this->regions)
*packet += i; *packet += i;
packet->assign(net::htonv<uint32_t>(packet->length()), 2, 4); packet->replace(2, 4, net::htonv<uint32_t>(packet->length()));
return packet; return packet;
} }

View file

@ -131,12 +131,12 @@ bool sosc::MasterClient::ProcessLogin(Packet &pck) {
bool sosc::MasterClient::LoginError(uint16_t error_code) { bool sosc::MasterClient::LoginError(uint16_t error_code) {
if(++this->auth_attempts < MAX_AUTH_ATTEMPTS) { if(++this->auth_attempts < MAX_AUTH_ATTEMPTS) {
this->sock.Send( this->sock.Send(
Packet(kLoginResponse, {"\0", HTONUS(error_code)}) Packet(kLoginResponse, {std::string(1, '\0'), HTONUS(error_code)})
); );
return true; return true;
} else { } else {
return this->Close( return this->Close(
Packet(kLoginResponse, {"\0", HTONUS(0x100)}) Packet(kLoginResponse, {std::string(1, '\0'), HTONUS(0x100)})
); );
} }
} }
@ -171,7 +171,7 @@ bool sosc::MasterClient::ProcessRegistration(Packet &pck) {
bool sosc::MasterClient::RegistrationError(uint16_t error_code) { bool sosc::MasterClient::RegistrationError(uint16_t error_code) {
this->sock.Send( this->sock.Send(
Packet(kRegisterResponse, {"\0", HTONUS(error_code)}) Packet(kRegisterResponse, {std::string(1, '\0'), HTONUS(error_code)})
); );
return true; return true;
} }

View file

@ -7,7 +7,7 @@
#define FRAME_OK 0 #define FRAME_OK 0
#define FRAME_MORE 1 #define FRAME_MORE 1
#define FRAME_ERR -1 #define FRAME_ERR (-1)
namespace sosc { namespace sosc {
namespace ws { namespace ws {

View file

@ -237,7 +237,6 @@ int Pool<T,U>::Stack::ClientCount() {
template<class T, class U> template<class T, class U>
void Pool<T,U>::Stack::StackThread() { void Pool<T,U>::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();
@ -255,6 +254,9 @@ void Pool<T,U>::Stack::StackThread() {
} }
this->clients_mtx.unlock(); this->clients_mtx.unlock();
} }
// TODO figure out a signal based system to avoid this
std::this_thread::sleep_for(std::chrono::microseconds(5));
} }
} }

View file

@ -115,8 +115,7 @@ bool sosc::ScapeConnection::Send(const Packet& packet) {
std::string packet_raw; std::string packet_raw;
packet.ToString(&packet_raw); packet.ToString(&packet_raw);
return this->client.Send(ws::Frame(packet_raw));
return this->client.Send(packet_raw);
} }
/******************************/ /******************************/

View file

@ -131,6 +131,8 @@ function pack(id, regions) {
} }
function unpack(data) { function unpack(data) {
console.log(data);
console.log(typeof data);
if(!data.subarray(0, 2).every((v, i) => v === MAHOU[i])) if(!data.subarray(0, 2).every((v, i) => v === MAHOU[i]))
return null; return null;