From 14b6d91b845fee6da759819b3eb5eef2a3fae4b8 Mon Sep 17 00:00:00 2001 From: malloc Date: Wed, 28 Nov 2018 16:22:36 -0600 Subject: [PATCH] wow i might actually get to render the game soon --- PROTOCOL.md | 8 ++++-- src/common/utils/string.cpp | 40 ++++++++++++++++++++++++++++++ src/common/utils/string.hpp | 2 ++ src/server/hosts/master_client.cpp | 10 ++++++-- src/web/index.html | 6 ++--- src/web/script.js | 40 ++++++++++++++++++++++++++++-- src/web/style.css | 8 +++--- 7 files changed, 101 insertions(+), 13 deletions(-) diff --git a/PROTOCOL.md b/PROTOCOL.md index 91f798b..3238b6c 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -379,8 +379,12 @@ TODO: MAKE THIS SECTION NOT LOOK LIKE SHIT 0x100: USERNAME TAKEN -0x101: EMAIL TAKEN +0x101: USERNAME ILLEGAL -0x102: PASSWORD TOO WEAK +0x110: EMAIL TAKEN + +0x111: EMAIL ILLEGAL + +0x120: PASSWORD TOO WEAK ### Slave / Client \ No newline at end of file diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp index f73b7d5..2b1bac9 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -136,3 +136,43 @@ std::string* sosc::str::tolower(std::string* str) { std::transform(str->begin(), str->end(), str->begin(), ::tolower); return str; } + +bool sosc::str::verify_email(const std::string& email) { + if(email.length() > 320) + return false; + + std::string::size_type at_loc; + if((at_loc = email.find('@')) == std::string::npos) + return false; + if(at_loc > 64) + return false; + if(email.find('.', at_loc) == std::string::npos) + return false; + + for(std::string::size_type i = 0; i < at_loc; ++i) { + if(!( + (email[i] >= 'A' && email[i] <= 'Z') || + (email[i] >= 'a' && email[i] <= 'z') || + (email[i] >= '0' && email[i] <= '9') || + (email[i] >= '!' && email[i] <= '/' && + email[i] != '"' && email[i] != ',' && + email[i] != '(' && email[i] != ')') || + (email[i] >= '^' && email[i] <= '`') || + (email[i] >= '{' && email[i] <= '~') || + email[i] == '=' || email[i] == '?' + )) + return false; + } + + for(std::string::size_type i = at_loc + 1; i < email.length(); ++i) { + if(!( + (email[i] >= 'A' && email[i] <= 'Z') || + (email[i] >= 'a' && email[i] <= 'z') || + (email[i] >= '0' && email[i] <= '9') || + email[i] == '-' || email[i] == '.' + )) + return false; + } + + return true; +} \ No newline at end of file diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp index bf16591..a109d70 100644 --- a/src/common/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -44,6 +44,8 @@ bool contains(const std::string& haystack, const std::string& needle); std::string tolower(std::string str); std::string* tolower(std::string* str); + +bool verify_email(const std::string& email); }} #endif diff --git a/src/server/hosts/master_client.cpp b/src/server/hosts/master_client.cpp index 2589f80..91f8651 100644 --- a/src/server/hosts/master_client.cpp +++ b/src/server/hosts/master_client.cpp @@ -101,7 +101,7 @@ bool sosc::MasterClient::ProcessLogin(Packet &pck) { query->Reset(); query->BindText(pck[0], 1); if(query->ScalarInt32() == 0) - return LoginError(0x105); + return LoginError(0x101); query = this->queries->at(QRY_USER_GET_PWD_HASH); query->Reset(); @@ -146,18 +146,24 @@ bool sosc::MasterClient::ProcessRegistration(Packet &pck) { return false; pck.TrimRegions(); + if(pck[0].length() == 0) + return RegistrationError(0x101); db::Query* query = this->queries->at(QRY_USER_NAME_REG_CHECK); query->Reset(); query->BindText(pck[0], 1); if(query->ScalarInt32() > 0) return RegistrationError(0x100); + if(pck[2].length() == 0 || !str::verify_email(pck[2])) + return RegistrationError(0x111); query = this->queries->at(QRY_USER_MAIL_REG_CHECK); query->Reset(); query->BindText(pck[2], 1); if(query->ScalarInt32() > 0) - return RegistrationError(0x101); + return RegistrationError(0x110); + if(pck[1].length() == 0) + return RegistrationError(0x120); query = this->queries->at(QRY_USER_REGISTER); query->Reset(); query->BindText(pck[0], 1); diff --git a/src/web/index.html b/src/web/index.html index 6e08ffe..e706606 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -33,7 +33,7 @@ - - + +