From c9c09c79ef33123c52134ad44f4637f0721b50d8 Mon Sep 17 00:00:00 2001 From: malloc Date: Thu, 29 Mar 2018 17:10:39 -0500 Subject: [PATCH] flat boob theory --- client/js/scape.js | 4 +- client/src/Entrypoint.ts | 5 +- server/src/.main.cpp.kate-swp | Bin 2045 -> 0 bytes server/src/main.cpp | 93 ++++------------------------------ server/src/sock/scapesock.cpp | 67 ++++++++++++++++++++++++ server/src/sock/scapesock.hpp | 10 ++++ server/src/utils/string.cpp | 6 +++ server/src/utils/string.hpp | 2 + 8 files changed, 103 insertions(+), 84 deletions(-) delete mode 100644 server/src/.main.cpp.kate-swp diff --git a/client/js/scape.js b/client/js/scape.js index a78e31c..5444380 100644 --- a/client/js/scape.js +++ b/client/js/scape.js @@ -34,6 +34,8 @@ var Entrypoint = (function () { }; Entrypoint.start = function () { var _this = this; + var conn = new Connection("ws://127.0.0.1:8080", []); + conn.open(); Key.init(function () { _this.initStatus.keyInit = true; _this.initCheck(); @@ -50,7 +52,7 @@ var Entrypoint = (function () { }); }; Entrypoint.ready = function () { - alert("ready"); + //alert("ready"); }; return Entrypoint; }()); diff --git a/client/src/Entrypoint.ts b/client/src/Entrypoint.ts index 05ccd0d..b53a2dd 100644 --- a/client/src/Entrypoint.ts +++ b/client/src/Entrypoint.ts @@ -34,6 +34,9 @@ class Entrypoint { } public static start(): void { + var conn = new Connection("ws://127.0.0.1:8080", []); + conn.open(); + Key.init(() => { this.initStatus.keyInit = true; this.initCheck(); @@ -54,6 +57,6 @@ class Entrypoint { } private static ready(): void { - alert("ready"); + //alert("ready"); } } \ No newline at end of file diff --git a/server/src/.main.cpp.kate-swp b/server/src/.main.cpp.kate-swp deleted file mode 100644 index 59be521f20ac792936cc1190e20312419cd96a3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2045 zcmaKt*G?Nj6owbcBt#(&y_Yox493`|_s-IbVdGA!KKYxFg ze9!)Vok~1r-+cS!ubX7sToH4XWIW$1+$rTw(({ka-y?J7f(WHW-6yRWMoq})7@6X? zxQvW(RRrOQ>Cz$$6wJe|NRXaNR!H}azSCP#h7P6NUWVt}b>((lSy=b9rp&I_2;QM{HV>h22Wmahi}D zl`bT&B4yVq5t1tv7rC^P3p+Uv6Ta>pxCJ*L53a!#xC9sA{ORV&e1*+pzQPee!jn~j zaN=k=gt2J5$bocKd|OCqQ966lb({?(r!s-;sth4JDk+2qftE(Lq-*vb*;E-rHdF=> z{>ij)7I_9v!3j79N8k_~03YmwJ&*&tUifqudiVQHNGR|iv?PNkFLo#kB zV=Db5qbhyKh@A|p$UH+Ta`*@BWI$zx0r)AT#gUA39cLOztH@~mD)RKCRE8<*v&)hy zvbJ88QObJkvV@8}e%*G`r6NOj+DTkRHoike28gNDF^{WKhP10lS({1=NsBGbDh(t} zD)O}(Rb+P>R9Y#kx6A5OUXj$QbRsn>lSs9S9I+}DSzD!wOj@DRDW@H*fmN^qJg^Lw zz#>=x^I#6lf*CLkrobea0P=8-(HjLLU>FR6K`;QaAOq5%AEZDZNP=F_0}`McbOBj? yoL&cr0T;A`HqZ)MKr?6pji3S4gE~+PYCtup0+qnLIr)|3l^P4)C*j@&udaVGm8Wn3 diff --git a/server/src/main.cpp b/server/src/main.cpp index b801bc4..e2a0f18 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -14,90 +14,19 @@ #include "utils/bigint.hpp" int main(int argc, char **argv) { - //auto sock = sosc::TcpClient(); + sosc::TcpServer server; + sosc::TcpClient client; + std::string buffer; - /*std::string a = "this!!is!!a!!test"; - auto b = sosc::str::split(a, "!!"); - std::for_each(b.begin(), b.end(), [](std::string& i) { - std::cout << i << std::endl; - });*/ + server.Listen(8080); + std::cout << "Listening ..." << std::endl; + server.Accept(&client); + std::cout << "Reading ..." << std::endl; - /*sosc::TcpClient client; - client.Open("127.0.0.1", 1111); - - client.Send("test"); - std::string got = "abc"; - - while(client.IsOpen()) { - int length = client.Receive(&got); - - if(length > 0) - std::cout << got << std::endl; - }*/ - - //std::string a = sosc::cgc::sha1("test", true); - - /*sosc::cgc::Blowfish fish("TESTKEY"); - - std::string test = fish.Encrypt("imagine a test"); - std::string testd = fish.Decrypt(test); - - uint32_t teest = sosc::csprng::next(); - std::cout << std::hex << teest;*/ - - /*std::string hash = sosc::cgc::bcrypt_hash("test pwd"); - std::cout << hash << std::endl; - std::cout << sosc::cgc::bcrypt_check("test pwd", hash);*/ - - sosc::BigUInt a, b, c; - - /*a = sosc::BigUInt::GenerateRandom(128); - b = sosc::BigUInt::GenerateRandom(128); - c = sosc::BigUInt::GenerateRandom(128);*/ - - //assert(a - b == sosc::BigUInt("feff01")); - - //auto d = sosc::BigUInt::DivideWithRemainder(a, b); - - /*for(int i = a.ByteCount() * 8 - 1; i >= 0; --i) { - std::cout << a.GetBit(i); - b.SetBit(i, a.GetBit(i)); - }*/ - - //std::cout << sosc::BigUInt::GenerateRandomPrime(64).ToString(); - //std::cout << a.IsProbablePrime(); - - //for(int i = 0; i < 250; ++i) - - time_t start = time(NULL); - - /*auto d = sosc::BigUInt::DivideWithRemainder(a, b); - std::cout << d.result.ToString() << std::endl - << d.remainder.ToString() << std::endl;*/ - - std::cout //<< a.ToString() << std::endl - //<< b.ToString() << std::endl - //<< (a * b).ToString() << std::endl; - //<< c.ToString() << std::endl << std::endl - //<< sosc::BigUInt::ModPow(a, b, c).ToString() << std::endl; - - << sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl - << sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl - << sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl - << sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl; - - - - std::cout << (time(NULL) - start) << std::endl; - - //std::cout << a.ToString(); - - //std::cout << a.ToString(); - - /*std::cout << std::endl << std::endl - << d.result.ToString() - << std::endl - << d.remainder.ToString();*/ + while(true) { + client.Receive(&buffer, SOSC_TCP_BLOCK); + std::cout << buffer; + } return 0; } diff --git a/server/src/sock/scapesock.cpp b/server/src/sock/scapesock.cpp index 7715141..19f7429 100644 --- a/server/src/sock/scapesock.cpp +++ b/server/src/sock/scapesock.cpp @@ -1,2 +1,69 @@ #include "scapesock.hpp" +/**********************************/ +/* BEGIN SCAPECONNECTION CODE */ +/**********************************/ + +sosc::ScapeConnection::ScapeConnection() { + this->client_open = false; + this->handshaked = false; +} + +void sosc::ScapeConnection::Open(TcpClient client) { + this->client = client; + this->client_open = true; +} + +int sosc::ScapeConnection::Handshake() { + if(this->handshaked) + return SOSC_SHAKE_DONE; + if(!this->client_open) + return SOSC_SHAKE_ERR; + + if(!this->client.IsDataReady()) + 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(); + return SOSC_SHAKE_ERR; + } + + auto lines = str::split(this->buffer, "\r\n"); + + this->handshaked = true; + return SOSC_SHAKE_DONE; +} + +/******************************/ +/* END SCAPECONNECTION CODE */ +/******************************/ +/* BEGIN SCAPESERVER CODE */ +/******************************/ + +sosc::ScapeServer::ScapeServer() { + this->server_open = false; +} + +bool sosc::ScapeServer::Listen(uint16_t port) { + if(this->server_open) + return false; + + this->server = TcpServer(); + this->server.Listen(port); + this->server_open = true; + return true; +} + +int sosc::ScapeServer::Accept(ScapeConnection* client) { + TcpClient raw_client; + int status = this->server.Accept(&raw_client); + if(status != 0) + return status; + + + return 0; +} diff --git a/server/src/sock/scapesock.hpp b/server/src/sock/scapesock.hpp index a3accc1..2905306 100644 --- a/server/src/sock/scapesock.hpp +++ b/server/src/sock/scapesock.hpp @@ -4,11 +4,16 @@ #include "packet.hpp" #include "tcpsock.hpp" +#define SOSC_SHAKE_ERR -1 +#define SOSC_SHAKE_CONT 0 +#define SOSC_SHAKE_DONE 1 + namespace sosc { class ScapeConnection { public: ScapeConnection(); + int Handshake(); int Receive(Packet* packet, bool block = false); bool Send(const Packet& packet); @@ -16,6 +21,10 @@ public: return this->client_open; } + inline bool Handshaked() const { + return this->handshaked; + } + inline void Close() { this->client_open = false; this->client.Close(); @@ -26,6 +35,7 @@ private: void Open(TcpClient client); bool client_open; + bool handshaked; TcpClient client; std::string buffer; diff --git a/server/src/utils/string.cpp b/server/src/utils/string.cpp index 3cf199d..3af624a 100644 --- a/server/src/utils/string.cpp +++ b/server/src/utils/string.cpp @@ -114,3 +114,9 @@ bool sosc::str::ends end.begin(), end.end(), str.end() - end.length() ).first == end.end(); } + +bool sosc::str::contains + (const std::string& haystack, const std::string& needle) +{ + return haystack.find(needle) != std::string::npos; +} diff --git a/server/src/utils/string.hpp b/server/src/utils/string.hpp index 6f26dcb..266fd0c 100644 --- a/server/src/utils/string.hpp +++ b/server/src/utils/string.hpp @@ -33,6 +33,8 @@ std::string join(const std::vector& parts, bool starts(const std::string& str, const std::string& start); bool ends(const std::string& str, const std::string& end); + +bool contains(const std::string& haystack, const std::string& needle); }} #endif