This commit is contained in:
malloc 2018-10-18 16:20:47 -05:00
parent 5bc9356f04
commit 31a8fb58ca
6 changed files with 33 additions and 16 deletions

View file

@ -1,5 +1 @@
//
// Created by alec on 10/16/2018.
//
#include "socket.hpp"

View file

@ -1,4 +1,6 @@
#ifndef SOSC_CLIENT_SOCKET_H
#define SOSC_CLIENT_SOCKET_H
#ifndef SOSC_NET_SOCKET_H
#define SOSC_NET_SOCKET_H
#endif

View file

@ -36,6 +36,7 @@ private:
};
ScapeConnection sock;
const db::Queries* queries;
bool authed;
int auth_attempts;

View file

@ -54,10 +54,28 @@ sosc::MasterClient::MasterClient(const ScapeConnection &client) {
}
bool sosc::MasterClient::Process(const db::Queries *queries) {
if(!this->sock.Handshaked())
return (this->sock.Handshake() != WS_SHAKE_ERR);
Packet pck;
int status = this->sock.Receive(&pck);
if(status == PCK_ERR)
return this->Close();
else if(status == PCK_MORE)
return true;
this->queries = queries;
switch(pck.GetId()) {
case kLoginRequest:
break;
case kRegisterRequest:
break;
case kServerListRequest:
break;
default:
return this->Close();
}
}

View file

@ -16,22 +16,22 @@ void sosc::ScapeConnection::Open(const TcpClient& client) {
int sosc::ScapeConnection::Handshake() {
if(this->handshaked)
return SOSC_SHAKE_DONE;
return WS_SHAKE_DONE;
if(!this->client_open)
return SOSC_SHAKE_ERR;
return WS_SHAKE_ERR;
if(!this->client.IsDataReady())
return SOSC_SHAKE_CONT;
return WS_SHAKE_CONT;
this->client.Receive(&this->buffer, SOSC_TCP_APPEND);
if(!str::starts(this->buffer, "GET")) {
this->Close();
return SOSC_SHAKE_ERR;
return WS_SHAKE_ERR;
}
if(!str::contains(this->buffer, "\r\n\r\n"))
return SOSC_SHAKE_CONT;
return WS_SHAKE_CONT;
std::string websocket_key = "";
auto lines = str::split(this->buffer, "\r\n");
@ -50,7 +50,7 @@ int sosc::ScapeConnection::Handshake() {
if(websocket_key.empty()) {
this->Close();
return SOSC_SHAKE_ERR;
return WS_SHAKE_ERR;
}
websocket_key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
@ -64,7 +64,7 @@ int sosc::ScapeConnection::Handshake() {
this->client.Send(stream.str());
this->handshaked = true;
return SOSC_SHAKE_DONE;
return WS_SHAKE_DONE;
}
int sosc::ScapeConnection::Receive(Packet* packet, bool block) {

View file

@ -8,9 +8,9 @@
#include "frame.hpp"
#include "tcpsock.hpp"
#define SOSC_SHAKE_ERR (-1)
#define SOSC_SHAKE_CONT 0
#define SOSC_SHAKE_DONE 1
#define WS_SHAKE_ERR (-1)
#define WS_SHAKE_CONT 0
#define WS_SHAKE_DONE 1
namespace sosc {
class ScapeConnection {