Updates for the new token system

This commit is contained in:
WolverinDEV
2021-02-25 11:13:30 +01:00
parent 22d366edc7
commit 7325caa7e8
23 changed files with 1463 additions and 323 deletions
+23 -2
View File
@@ -401,6 +401,7 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
void SpeakingClient::processJoin() {
TIMING_START(timings);
auto ref_server = this->server;
assert(ref_server);
this->resetIdleTime();
threads::MutexLock lock(this->command_lock); //Don't process any commands!
@@ -445,10 +446,10 @@ void SpeakingClient::processJoin() {
if(geoloc::provider) {
auto loc = this->isAddressV4() ? geoloc::provider->resolveInfoV4(this->getPeerIp(), false) : geoloc::provider->resolveInfoV6(this->getPeerIp(), false);
if(loc) {
debugMessage(this->getServerId(), "Client " + this->getDisplayName() + "|" + this->getLoggingPeerIp() + " comes from " + loc->name + "|" + loc->identifier);
debugMessage(this->getServerId(), "{} Resolved ip address to {}/{}", this->getLoggingPrefix(), loc->name, loc->identifier);
this->properties()[property::CLIENT_COUNTRY] = loc->identifier;
} else {
logError(ref_server ? ref_server->getServerId() : 0, "Could not resolve country for ip " + this->getLoggingPeerIp() + "|" + this->getDisplayName());
debugMessage(this->getServerId(), "{} Could not resolve IP info for {}", this->getLoggingPrefix(), this->getLoggingPeerIp());
}
}
//this->updateChannelClientProperties(false); /* will be already updated via assignChannel */
@@ -468,6 +469,25 @@ void SpeakingClient::processJoin() {
debugMessage(this->getServerId(), "Client id: " + to_string(this->getClientId()));
TIMING_STEP(timings, "notify sini");
if(auto token{this->properties()[property::CLIENT_DEFAULT_TOKEN].value()}; !token.empty()){
auto token_info = ref_server->getTokenManager().load_token(token, true);
if(token_info) {
if(token_info->is_expired()) {
debugMessage(this->getServerId(), "{} Client tried to use an expired token {}", this->getLoginName(), token);
} else if(token_info->use_limit_reached()) {
debugMessage(this->getServerId(), "{} Client tried to use an token which reached the use limit {}", this->getLoginName(), token);
} else {
debugMessage(this->getServerId(), "{} Client used token {}", this->getLoginName(), token);
ref_server->getTokenManager().log_token_use(token_info->id);
this->useToken(token_info->id);
}
} else {
debugMessage(this->getServerId(), "{} Client tried to use an unknown token {}", token);
}
}
TIMING_STEP(timings, "token use ");
if(!ref_server->assignDefaultChannel(this->ref(), false)) {
auto result = command_result{error::vs_critical, "Could not assign default channel!"};
this->notifyError(result);
@@ -533,6 +553,7 @@ void SpeakingClient::processJoin() {
}
debugMessage(this->getServerId(), "{} Client join timings: {}", CLIENT_STR_LOG_PREFIX, TIMING_FINISH(timings));
this->join_whitelisted_channel.clear();
serverInstance->action_logger()->client_channel_logger.log_client_join(this->getServerId(), this->ref(), this->getChannelId(), this->currentChannel->name());
}