sqwoobed
This commit is contained in:
parent
5bc9356f04
commit
31a8fb58ca
6 changed files with 33 additions and 16 deletions
|
@ -1,5 +1 @@
|
||||||
//
|
|
||||||
// Created by alec on 10/16/2018.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "socket.hpp"
|
#include "socket.hpp"
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#ifndef SOSC_CLIENT_SOCKET_H
|
#ifndef SOSC_NET_SOCKET_H
|
||||||
#define SOSC_CLIENT_SOCKET_H
|
#define SOSC_NET_SOCKET_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,6 +36,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
ScapeConnection sock;
|
ScapeConnection sock;
|
||||||
|
const db::Queries* queries;
|
||||||
|
|
||||||
bool authed;
|
bool authed;
|
||||||
int auth_attempts;
|
int auth_attempts;
|
||||||
|
|
|
@ -54,10 +54,28 @@ sosc::MasterClient::MasterClient(const ScapeConnection &client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sosc::MasterClient::Process(const db::Queries *queries) {
|
bool sosc::MasterClient::Process(const db::Queries *queries) {
|
||||||
|
if(!this->sock.Handshaked())
|
||||||
|
return (this->sock.Handshake() != WS_SHAKE_ERR);
|
||||||
|
|
||||||
Packet pck;
|
Packet pck;
|
||||||
int status = this->sock.Receive(&pck);
|
int status = this->sock.Receive(&pck);
|
||||||
if(status == PCK_ERR)
|
if(status == PCK_ERR)
|
||||||
return this->Close();
|
return this->Close();
|
||||||
else if(status == PCK_MORE)
|
else if(status == PCK_MORE)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
this->queries = queries;
|
||||||
|
switch(pck.GetId()) {
|
||||||
|
case kLoginRequest:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case kRegisterRequest:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case kServerListRequest:
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return this->Close();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,22 +16,22 @@ void sosc::ScapeConnection::Open(const TcpClient& client) {
|
||||||
|
|
||||||
int sosc::ScapeConnection::Handshake() {
|
int sosc::ScapeConnection::Handshake() {
|
||||||
if(this->handshaked)
|
if(this->handshaked)
|
||||||
return SOSC_SHAKE_DONE;
|
return WS_SHAKE_DONE;
|
||||||
if(!this->client_open)
|
if(!this->client_open)
|
||||||
return SOSC_SHAKE_ERR;
|
return WS_SHAKE_ERR;
|
||||||
|
|
||||||
if(!this->client.IsDataReady())
|
if(!this->client.IsDataReady())
|
||||||
return SOSC_SHAKE_CONT;
|
return WS_SHAKE_CONT;
|
||||||
|
|
||||||
this->client.Receive(&this->buffer, SOSC_TCP_APPEND);
|
this->client.Receive(&this->buffer, SOSC_TCP_APPEND);
|
||||||
|
|
||||||
if(!str::starts(this->buffer, "GET")) {
|
if(!str::starts(this->buffer, "GET")) {
|
||||||
this->Close();
|
this->Close();
|
||||||
return SOSC_SHAKE_ERR;
|
return WS_SHAKE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!str::contains(this->buffer, "\r\n\r\n"))
|
if(!str::contains(this->buffer, "\r\n\r\n"))
|
||||||
return SOSC_SHAKE_CONT;
|
return WS_SHAKE_CONT;
|
||||||
|
|
||||||
std::string websocket_key = "";
|
std::string websocket_key = "";
|
||||||
auto lines = str::split(this->buffer, "\r\n");
|
auto lines = str::split(this->buffer, "\r\n");
|
||||||
|
@ -50,7 +50,7 @@ int sosc::ScapeConnection::Handshake() {
|
||||||
|
|
||||||
if(websocket_key.empty()) {
|
if(websocket_key.empty()) {
|
||||||
this->Close();
|
this->Close();
|
||||||
return SOSC_SHAKE_ERR;
|
return WS_SHAKE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
websocket_key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
websocket_key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||||
|
@ -64,7 +64,7 @@ int sosc::ScapeConnection::Handshake() {
|
||||||
this->client.Send(stream.str());
|
this->client.Send(stream.str());
|
||||||
|
|
||||||
this->handshaked = true;
|
this->handshaked = true;
|
||||||
return SOSC_SHAKE_DONE;
|
return WS_SHAKE_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sosc::ScapeConnection::Receive(Packet* packet, bool block) {
|
int sosc::ScapeConnection::Receive(Packet* packet, bool block) {
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
#include "frame.hpp"
|
#include "frame.hpp"
|
||||||
#include "tcpsock.hpp"
|
#include "tcpsock.hpp"
|
||||||
|
|
||||||
#define SOSC_SHAKE_ERR (-1)
|
#define WS_SHAKE_ERR (-1)
|
||||||
#define SOSC_SHAKE_CONT 0
|
#define WS_SHAKE_CONT 0
|
||||||
#define SOSC_SHAKE_DONE 1
|
#define WS_SHAKE_DONE 1
|
||||||
|
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
class ScapeConnection {
|
class ScapeConnection {
|
||||||
|
|
Loading…
Reference in a new issue