Updated the logging system

This commit is contained in:
WolverinDEV
2019-11-23 21:16:55 +01:00
parent b7d60361c0
commit fb5dc72970
28 changed files with 135 additions and 104 deletions
+29 -17
View File
@@ -57,39 +57,51 @@ CommandResult SpeakingClient::handleCommandHandshakeBegin(Command& cmd) { //If !
try {
this->handshake.identityData = make_shared<Json::Value>();
this->handshake.proof_message = cmd["data"].string();
Json::Reader reader;
std::istringstream stream(this->handshake.proof_message);
reader.parse(stream, *this->handshake.identityData);
if(!stream) return {findError("web_handshake_invalid"), "invalid json!"};
if((*this->handshake.identityData)["user_id"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
if((*this->handshake.identityData)["user_name"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
if((*this->handshake.identityData)["user_group"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
if((*this->handshake.identityData)["user_groups"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
if((*this->handshake.identityData)["data_age"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"};
std::string error{};
Json::CharReaderBuilder rbuilder{};
const std::unique_ptr<Json::CharReader> reader(rbuilder.newCharReader());
auto& json_str = this->handshake.proof_message;
if(!reader->parse(json_str.data(), json_str.data() + json_str.size(), &*this->handshake.identityData, &error)) {
debugMessage(this->getServerId(), "[{}] Failed to parse forum account data: {}", error);
return {findError("web_handshake_invalid"), "invalid json!"};
}
auto& json_data = *this->handshake.identityData;
if(json_data["user_id"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (user_id)!"};
if(json_data["user_name"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (user_name)!"};
if(json_data["user_group"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (user_group)!"};
if(json_data["user_groups"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (user_groups)!"};
if(json_data["data_age"].isNull())
return {findError("web_handshake_invalid"), "Missing json data (data_age)!"};
//Type test
(*this->handshake.identityData)["user_id"].asInt64();
json_data["user_id"].asInt64();
if((*this->handshake.identityData)["data_age"].asUInt64() < duration_cast<milliseconds>((system_clock::now() - hours(72)).time_since_epoch()).count())
if(json_data["data_age"].asUInt64() < duration_cast<milliseconds>((system_clock::now() - hours(72)).time_since_epoch()).count())
return {findError("web_handshake_invalid"), "Provided data is too old!"};
this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = base64::encode(digest::sha1("TeaSpeak-Forum#" + (*this->handshake.identityData)["user_id"].asString()));
this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = base64::encode(digest::sha1("TeaSpeak-Forum#" + json_data["user_id"].asString()));
this->properties()[property::CLIENT_TEAFORO_ID] = (*this->handshake.identityData)["user_id"].asInt64();
this->properties()[property::CLIENT_TEAFORO_NAME] = (*this->handshake.identityData)["user_name"].asString();
this->properties()[property::CLIENT_TEAFORO_ID] = json_data["user_id"].asInt64();
this->properties()[property::CLIENT_TEAFORO_NAME] = json_data["user_name"].asString();
{
///* 0x01 := Banned | 0x02 := Stuff | 0x04 := Premium */
uint64_t flags = 0;
if((*this->handshake.identityData)["is_banned"].isBool() && (*this->handshake.identityData)["is_banned"].asBool())
if(json_data["is_banned"].isBool() && json_data["is_banned"].asBool())
flags |= 0x01U;
if((*this->handshake.identityData)["is_staff"].isBool() && (*this->handshake.identityData)["is_staff"].asBool())
if(json_data["is_staff"].isBool() && json_data["is_staff"].asBool())
flags |= 0x02U;
if((*this->handshake.identityData)["is_premium"].isBool() && (*this->handshake.identityData)["is_premium"].asBool())
if(json_data["is_premium"].isBool() && json_data["is_premium"].asBool())
flags |= 0x04U;
this->properties()[property::CLIENT_TEAFORO_FLAGS] = flags;