From 47134fece3dd0db32da0349888d992a65a651131 Mon Sep 17 00:00:00 2001 From: malloc Date: Mon, 2 Apr 2018 15:33:01 -0500 Subject: [PATCH] DEHUMANIZE YOURSELF AND FACE TO BLOODSHED DEHUMANIZE YOURSELF AND FACE TO BLOODSHED DEHUMANIZE YOURSELF AND FACE TO BLOODSHED DEHUMANIZE YOURSELF AND FACE TO BLOODSHED DEHUMANIZE YOURSELF AND FACE TO BLOODSHED DEHUMANIZE YOURSELF AND FACE TO BLOODSHED DEHUMANIZE YOURSELF AND FACE TO BLOODSHED --- client/build.sh | 0 client/deploy.bat | 7 ----- client/index.html | 2 +- client/js/scape.js | 49 ++++++++++++++++++--------------- client/src/ui/Loading.ts | 5 ++++ server/src/main.cpp | 27 ++++++++++++------ server/src/sock/intrasock.cpp | 8 +++--- server/src/sock/intrasock.hpp | 2 +- server/src/sock/scapesock.cpp | 21 ++++++++------ server/src/sock/scapesock.hpp | 2 +- server/src/sock/tcpsock.hpp | 2 +- server/src/sock/tcpsock_bsd.cpp | 8 +++--- 12 files changed, 76 insertions(+), 57 deletions(-) create mode 100644 client/build.sh delete mode 100644 client/deploy.bat create mode 100644 client/src/ui/Loading.ts diff --git a/client/build.sh b/client/build.sh new file mode 100644 index 0000000..e69de29 diff --git a/client/deploy.bat b/client/deploy.bat deleted file mode 100644 index 5492ef4..0000000 --- a/client/deploy.bat +++ /dev/null @@ -1,7 +0,0 @@ -mkdir \\aroltd.com\aroltd\scape -mkdir \\aroltd.com\aroltd\scape\bin -copy /y /b index.html \\aroltd.com\aroltd\scape -copy /y /b error.html \\aroltd.com\aroltd\scape -copy /y /b style.css \\aroltd.com\aroltd\scape -copy /y /b bin\scape.js \\aroltd.com\aroltd\scape\bin -copy /y /b bin\lib.js \\aroltd.com\aroltd\scape\bin \ No newline at end of file diff --git a/client/index.html b/client/index.html index ca7b554..f2de955 100644 --- a/client/index.html +++ b/client/index.html @@ -59,7 +59,7 @@

LOADING

1%

-
+
diff --git a/client/js/scape.js b/client/js/scape.js index 5444380..63bedfc 100644 --- a/client/js/scape.js +++ b/client/js/scape.js @@ -1,4 +1,4 @@ -var SockContext = (function () { +var SockContext = /** @class */ (function () { function SockContext() { } Object.defineProperty(SockContext, "masterSock", { @@ -19,10 +19,10 @@ var SockContext = (function () { if (this.didInit) return; }; + SockContext.didInit = false; return SockContext; }()); -SockContext.didInit = false; -var Entrypoint = (function () { +var Entrypoint = /** @class */ (function () { function Entrypoint() { } Entrypoint.initCheck = function () { @@ -54,13 +54,13 @@ var Entrypoint = (function () { Entrypoint.ready = function () { //alert("ready"); }; + Entrypoint.initStatus = { + keyInit: false, + fileCache: false + }; return Entrypoint; }()); -Entrypoint.initStatus = { - keyInit: false, - fileCache: false -}; -var FileCache = (function () { +var FileCache = /** @class */ (function () { function FileCache() { } FileCache.initCache = function (success, error) { @@ -125,15 +125,15 @@ var FileCache = (function () { store = query.objectStore("metadata"); store.delete(fileName); }; + FileCache.dbHandle = null; return FileCache; }()); -FileCache.dbHandle = null; -var FileMeta = (function () { +var FileMeta = /** @class */ (function () { function FileMeta() { } return FileMeta; }()); -var MasterProtocol = (function () { +var MasterProtocol = /** @class */ (function () { function MasterProtocol() { } Object.defineProperty(MasterProtocol, "packetHandlers", { @@ -158,7 +158,7 @@ var MasterProtocol = (function () { }; return MasterProtocol; }()); -var SlaveProtocol = (function () { +var SlaveProtocol = /** @class */ (function () { function SlaveProtocol() { } Object.defineProperty(SlaveProtocol, "packetHandlers", { @@ -175,12 +175,12 @@ var SlaveProtocol = (function () { }; return SlaveProtocol; }()); -var Rendering = (function () { +var Rendering = /** @class */ (function () { function Rendering() { } return Rendering; }()); -var Connection = (function () { +var Connection = /** @class */ (function () { function Connection(address, handles, useCipher, onOpen, onClose, onError) { if (useCipher === void 0) { useCipher = false; } if (onOpen === void 0) { onOpen = null; } @@ -272,7 +272,7 @@ var Connection = (function () { }; return Connection; }()); -var Key = (function () { +var Key = /** @class */ (function () { function Key() { } Object.defineProperty(Key, "privateKey", { @@ -303,10 +303,10 @@ var Key = (function () { Key._privateKey = serverKey.modPow(Key.secret, modulus); return Packet.create(1 /* KeyExchange */, [clientKey.toString(16)]); }; + Key._privateKey = new bigInt(0); return Key; }()); -Key._privateKey = new bigInt(0); -var Cipher = (function () { +var Cipher = /** @class */ (function () { function Cipher() { } Object.defineProperty(Cipher, "ready", { @@ -355,10 +355,10 @@ var Cipher = (function () { Cipher.close = function () { Cipher._ready = false; }; + Cipher._ready = false; return Cipher; }()); -Cipher._ready = false; -var Packet = (function () { +var Packet = /** @class */ (function () { function Packet() { this._regions = []; } @@ -467,9 +467,14 @@ var Packet = (function () { }); return buffer; }; + Packet.magicNumber = new Uint8Array([0xB0, 0x0B]); return Packet; }()); -Packet.magicNumber = new Uint8Array([0xB0, 0x0B]); +var LoadingBar = /** @class */ (function () { + function LoadingBar() { + } + return LoadingBar; +}()); // ** STRING EXTENSIONS ** \\ String.prototype.replaceAll = function (needle, replace, ignoreCase) { if (ignoreCase === void 0) { ignoreCase = false; } @@ -619,7 +624,7 @@ bigInt.prototype.toByteArray = function (byteCount) { } return byteArray; }; -var CriticalStop = (function () { +var CriticalStop = /** @class */ (function () { function CriticalStop() { } CriticalStop.redirect = function (message) { @@ -627,7 +632,7 @@ var CriticalStop = (function () { }; return CriticalStop; }()); -var Random = (function () { +var Random = /** @class */ (function () { function Random() { } Random.generatePrime = function (bitCount) { diff --git a/client/src/ui/Loading.ts b/client/src/ui/Loading.ts new file mode 100644 index 0000000..dc673f6 --- /dev/null +++ b/client/src/ui/Loading.ts @@ -0,0 +1,5 @@ +class LoadingBar { + private static bar: HTMLElement; + private static barPercent: HTMLElement; + private static barWrapper: HTMLElement; +} \ No newline at end of file diff --git a/server/src/main.cpp b/server/src/main.cpp index e2a0f18..d333778 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -12,21 +12,32 @@ #include "utils/csprng.hpp" #include "crypto/bcrypt.hpp" #include "utils/bigint.hpp" +#include "sock/scapesock.hpp" int main(int argc, char **argv) { - sosc::TcpServer server; - sosc::TcpClient client; + sosc::ScapeServer server; + sosc::ScapeConnection client; std::string buffer; - server.Listen(8080); + if(!server.Listen(8080)) { + std::cout << "Listening failed." << std::endl; + return -1; + } std::cout << "Listening ..." << std::endl; - server.Accept(&client); - std::cout << "Reading ..." << std::endl; - while(true) { - client.Receive(&buffer, SOSC_TCP_BLOCK); - std::cout << buffer; + server.Accept(&client); + std::cout << "Shaking ..." << std::endl; + + bool loop = true; + while(loop) { + if(!client.Handshaked()) + client.Handshake(); + else + break; + //client.Receive(&buffer, SOSC_TCP_BLOCK); + //std::cout << buffer; } + server.Close(); return 0; } diff --git a/server/src/sock/intrasock.cpp b/server/src/sock/intrasock.cpp index 2369711..f82e829 100644 --- a/server/src/sock/intrasock.cpp +++ b/server/src/sock/intrasock.cpp @@ -72,16 +72,16 @@ bool sosc::IntraServer::Listen(uint16_t port) { return this->server.Listen(port); } -int sosc::IntraServer::Accept(IntraClient* client) { +bool sosc::IntraServer::Accept(IntraClient* client) { if(!this->server_open) - return -1; + return false; TcpClient new_client; if(this->server.Accept(&new_client) == 0) { client->Open(new_client); - return 0; + return true; } else - return -1; + return false; } sosc::IntraServer::~IntraServer() { diff --git a/server/src/sock/intrasock.hpp b/server/src/sock/intrasock.hpp index 3e79342..0b9cb54 100644 --- a/server/src/sock/intrasock.hpp +++ b/server/src/sock/intrasock.hpp @@ -38,7 +38,7 @@ public: IntraServer(); bool Listen(uint16_t port); - int Accept(IntraClient* client); + bool Accept(IntraClient* client); inline bool IsOpen() const { return this->server_open; diff --git a/server/src/sock/scapesock.cpp b/server/src/sock/scapesock.cpp index 19f7429..5e7afaf 100644 --- a/server/src/sock/scapesock.cpp +++ b/server/src/sock/scapesock.cpp @@ -24,8 +24,6 @@ int sosc::ScapeConnection::Handshake() { return SOSC_SHAKE_CONT; this->client.Receive(&this->buffer, SOSC_TCP_APPEND); - if(!str::contains(this->buffer, "\r\n\r\n")) - return SOSC_SHAKE_CONT; if(!str::starts(this->buffer, "GET")) { this->Close(); @@ -34,6 +32,10 @@ int sosc::ScapeConnection::Handshake() { auto lines = str::split(this->buffer, "\r\n"); + + if(!str::contains(this->buffer, "\r\n\r\n")) + return SOSC_SHAKE_CONT; + this->handshaked = true; return SOSC_SHAKE_DONE; } @@ -58,12 +60,15 @@ bool sosc::ScapeServer::Listen(uint16_t port) { return true; } -int sosc::ScapeServer::Accept(ScapeConnection* client) { +bool sosc::ScapeServer::Accept(ScapeConnection* client) { TcpClient raw_client; - int status = this->server.Accept(&raw_client); - if(status != 0) - return status; + if(!this->server.Accept(&raw_client)) + return false; - - return 0; + client->Open(raw_client); + return true; +} + +sosc::ScapeServer::~ScapeServer() { + this->Close(); } diff --git a/server/src/sock/scapesock.hpp b/server/src/sock/scapesock.hpp index 2905306..9e6321a 100644 --- a/server/src/sock/scapesock.hpp +++ b/server/src/sock/scapesock.hpp @@ -47,7 +47,7 @@ public: ScapeServer(); bool Listen(uint16_t port); - int Accept(ScapeConnection* client); + bool Accept(ScapeConnection* client); inline bool IsOpen() const { return this->server_open; diff --git a/server/src/sock/tcpsock.hpp b/server/src/sock/tcpsock.hpp index 31ca44c..1b4307a 100644 --- a/server/src/sock/tcpsock.hpp +++ b/server/src/sock/tcpsock.hpp @@ -81,7 +81,7 @@ public: TcpServer(); bool Listen(uint16_t port); - int Accept(TcpClient* client); + bool Accept(TcpClient* client); void Close(); ~TcpServer(); diff --git a/server/src/sock/tcpsock_bsd.cpp b/server/src/sock/tcpsock_bsd.cpp index 8bd0e50..05e1f42 100644 --- a/server/src/sock/tcpsock_bsd.cpp +++ b/server/src/sock/tcpsock_bsd.cpp @@ -206,9 +206,9 @@ bool sosc::TcpServer::Listen(uint16_t port) { return true; } -int sosc::TcpServer::Accept(TcpClient* client) { +bool sosc::TcpServer::Accept(TcpClient* client) { if(!this->sock_open) - return -1; + return false; SOSC_SOCK_T sock; SOSC_ADDR_T addr; @@ -217,12 +217,12 @@ int sosc::TcpServer::Accept(TcpClient* client) { sock = accept(this->sock, (struct sockaddr*)&addr, &addr_len); if(sock < 0) { this->Close(); - return -1; + return false; } client->Close(); client->Open(sock, addr, addr_len); - return 0; + return true; } void sosc::TcpServer::Close() {