wow i might actually get to render the game soon

This commit is contained in:
malloc 2018-11-28 16:22:36 -06:00
parent a9b9a78670
commit 14b6d91b84
7 changed files with 101 additions and 13 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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);

View file

@ -33,7 +33,7 @@
</label>
<label>
Email: <br/>
<input type="test" id="reg-email" />
<input type="text" id="reg-email" />
</label>
<label>
Password: <br/>
@ -43,8 +43,8 @@
Confirm Password: <br/>
<input type="password" id="reg-conf-pwd" />
</label>
<input type="button" value="Register" />
<input type="button" value="Cancel" onclick="show_section('login')" />
<input type="button" value="Register" onclick="attempt_register();" />
<input type="button" value="Cancel" onclick="show_section('login');" />
</div>
<div id="client" class="hidden section">
<iframe id="client_iframe"></iframe>

View file

@ -58,13 +58,41 @@ function attempt_login() {
error.innerHTML = error_text;
error.classList.remove("hidden");
} else {
alert("allo");
//show_section()
}
for_each(lock_fields, x => x.disabled = false);
};
}
function attempt_register() {
clear_errors();
let section = document.getElementById("register");
let error = section.getElementsByClassName("error")[0];
let lock_fields = filter(
to_array(section.getElementsByTagName("input")),
x => ["submit", "button", "text", "password"].indexOf(x.type) !== -1
);
let fields = {};
for_each(section.getElementsByTagName("input"), x => {
if(x.id.substr(0, 4) === "reg-")
fields[x.id.substr(4)] = x.value.trim();
});
if(fields["pwd"] === fields["conf-pwd"])
for_each(lock_fields, x => x.disabled = true);
ws.send(pack(
kClientToMaster.LoginRequest, [
document.getElementById("login-user").value,
document.getElementById("login-pwd").value
]
));
}
function show_section(id) {
clear_inputs();
clear_errors();
@ -82,8 +110,10 @@ function clear_inputs() {
let inputs = document.getElementsByTagName("input");
for_each(inputs, x => {
if(types.indexOf(x.type) !== -1)
if(types.indexOf(x.type) !== -1) {
x.value = "";
x.disabled = false;
}
});
}
@ -358,26 +388,32 @@ Number.prototype.packDouble = function() {
/*** UINT8ARRAY EXTENSIONS ***/
Uint8Array.prototype.unpackInt16 = function(offset = 0) {
offset += this.byteOffset;
return new DataView(this.buffer).getInt16(offset, false);
};
Uint8Array.prototype.unpackUint16 = function(offset = 0) {
offset += this.byteOffset;
return new DataView(this.buffer).getUint16(offset, false);
};
Uint8Array.prototype.unpackInt32 = function(offset = 0) {
offset += this.byteOffset;
return new DataView(this.buffer).getInt32(offset, false);
};
Uint8Array.prototype.unpackUint32 = function(offset = 0) {
offset += this.byteOffset;
return new DataView(this.buffer).getUint32(offset, false);
};
Uint8Array.prototype.unpackFloat = function(offset = 0) {
offset += this.byteOffset;
return new DataView(this.buffer).getFloat32(offset, false);
};
Uint8Array.prototype.unpackDouble = function(offset = 0) {
offset += this.byteOffset;
return new DataView(this.buffer).getFloat64(offset, false);
};

View file

@ -2,10 +2,10 @@ body {
padding-top: 36px;
font-family: monospace;
text-align: center;
background: #000;
color: #fff;
/*background: #fff;
color: #000;*/
/*background: #000;
color: #fff;*/
background: #fff;
color: #000;
}
.hidden {