diff --git a/PROTOCOL.md b/PROTOCOL.md
index 56c74ee..91f798b 100644
--- a/PROTOCOL.md
+++ b/PROTOCOL.md
@@ -181,8 +181,8 @@ Communication between the master server and clients will be done over a WebSocke
2 |
- Message |
- String |
+ Error Code |
+ Packed Unsigned Short |
¬R1 |
@@ -213,8 +213,8 @@ Communication between the master server and clients will be done over a WebSocke
2 |
- Message |
- String |
+ Error Code |
+ Packed Unsigned Short |
@@ -354,12 +354,7 @@ TODO: MAKE THIS SECTION NOT LOOK LIKE SHIT
### Master / Slave
-#### M -> S (ID 2)
-0x100: KEY SIZE WAS INCORRECT
-
-0x101: COULD NOT PARSE KEY
-
-#### M -> S (ID 4)
+#### M -> S (ID 1)
0x100: MAX AUTH ATTEMPTS REACHED
0x101: LICENSE DATA INCORRECT
@@ -370,4 +365,22 @@ TODO: MAKE THIS SECTION NOT LOOK LIKE SHIT
### Master / Client
+#### M -> C (ID 0)
+
+0x100: MAX AUTH ATTEMPTS REACHED
+
+0x101: USERNAME DOES NOT EXIST
+
+0x102: PASSWORD INCORRECT
+
+#### M -> C (ID 1)
+
+0x000: OK
+
+0x100: USERNAME TAKEN
+
+0x101: EMAIL TAKEN
+
+0x102: PASSWORD TOO WEAK
+
### Slave / Client
\ No newline at end of file
diff --git a/src/common/sock/packet.cpp b/src/common/sock/packet.cpp
index 7cdfad8..d261693 100644
--- a/src/common/sock/packet.cpp
+++ b/src/common/sock/packet.cpp
@@ -148,6 +148,15 @@ bool sosc::Packet::Check(int region_count, ...) const {
return true;
}
+void sosc::Packet::TrimRegions(const std::vector& ids) {
+ if(ids.size() == 0)
+ for(uint32_t id = 0; id < this->regions.size(); ++id)
+ str::trim(&this->regions[id]);
+ else
+ for(auto id : ids)
+ str::trim(&this->regions[id]);
+}
+
std::string* sosc::Packet::ToString(std::string* packet) const {
*packet = std::string(8, 0);
(*packet)[0] = 0xB0;
diff --git a/src/common/sock/packet.hpp b/src/common/sock/packet.hpp
index 0552c62..583cc61 100644
--- a/src/common/sock/packet.hpp
+++ b/src/common/sock/packet.hpp
@@ -35,6 +35,7 @@ public:
int Parse(const std::string& data, std::string* extra = nullptr);
bool Check(int region_count, ...) const;
+ void TrimRegions(const std::vector& ids = {});
inline void SetId(uint8_t id) {
this->id = id;
diff --git a/src/common/utils/ini.cpp b/src/common/utils/ini.cpp
index 03606c0..26273c6 100644
--- a/src/common/utils/ini.cpp
+++ b/src/common/utils/ini.cpp
@@ -1,20 +1,20 @@
#include "ini.hpp"
using namespace sosc::ini;
-bool Field::Test() const {
+bool Field::Test(const std::string& value) const {
try {
switch(type) {
case INT32:
- (int32_t)File::Proxy(name);
+ (int32_t)File::Proxy(value);
break;
case UINT32:
- (uint32_t)File::Proxy(name);
+ (uint32_t)File::Proxy(value);
break;
case DOUBLE:
- (double)File::Proxy(name);
+ (double)File::Proxy(value);
break;
case BOOL:
- (bool)File::Proxy(name);
+ (bool)File::Proxy(value);
break;
}
@@ -100,13 +100,14 @@ File* File::Open
for(auto& section : (*ini)[rule.name].sections) {
for(auto &field : rule.required_fields) {
- if(section.values.count(str::tolower(field.name)) == 0)
+ std::string field_name = str::tolower(field.name);
+ if(section.values.count(field_name) == 0)
throw LoadError(ini, -1, str::join({
"Required field '", field.name, "' in section '",
rule.name, "' not found."
}));
- if(!field.Test())
+ if(!field.Test(section.values.at(field_name)))
throw LoadError(ini, -1, str::join({
"Field '", field.name, "' in section '",rule.name, "' "
"cannot be casted to requested type."
@@ -121,15 +122,16 @@ File* File::Open
std::runtime_error File::LoadError
(File* file, int line, const std::string &error)
{
- delete file;
+ std::string msg;
if(line > 0)
- return std::runtime_error(str::join(
+ msg = str::join(
{"LOAD ERROR IN '", file->filename, "' L", TOSTR(line), ": ", error}
- ));
+ );
else
- return std::runtime_error(str::join(
- {"LOAD ERROR IN '", file->filename, "': ", error}
- ));
+ msg = str::join({"LOAD ERROR IN '", file->filename, "': ", error});
+
+ delete file;
+ throw std::runtime_error(msg);
}
bool File::HasSection(std::string name) const {
diff --git a/src/common/utils/ini.hpp b/src/common/utils/ini.hpp
index 7ad6efb..a06f385 100644
--- a/src/common/utils/ini.hpp
+++ b/src/common/utils/ini.hpp
@@ -7,6 +7,8 @@
#include
#include