Some general code cleanup
This commit is contained in:
@@ -100,7 +100,7 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
|
||||
TIMING_START(timings);
|
||||
|
||||
{
|
||||
lock_guard<threads::Mutex> lock(this->server->join_attempts_lock);
|
||||
lock_guard lock(this->server->join_attempts_lock);
|
||||
auto client_address = this->getPeerIp();
|
||||
auto& client_join_attempts = this->server->join_attempts[client_address];
|
||||
auto& general_join_attempts = this->server->join_attempts["_"];
|
||||
@@ -252,9 +252,11 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
|
||||
}
|
||||
TIMING_STEP(timings, "valid hw ip");
|
||||
|
||||
if(!permission::v2::permission_granted(1, permissions[permission::b_virtualserver_join_ignore_password]))
|
||||
if(!this->server->verifyServerPassword(cmd["client_server_password"].string(), true))
|
||||
if(!permission::v2::permission_granted(1, permissions[permission::b_virtualserver_join_ignore_password])) {
|
||||
if(!this->server->verifyServerPassword(cmd["client_server_password"].string(), true)) {
|
||||
return command_result{error::server_invalid_password};
|
||||
}
|
||||
}
|
||||
|
||||
if(!config::server::clients::ignore_max_clone_permissions) {
|
||||
size_t clones_uid = 0;
|
||||
@@ -300,7 +302,7 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
|
||||
string fullReason = string() + "You are banned " + (banEntry->serverId == 0 ? "globally" : "from this server") + ". Reason: \"" + banEntry->reason + "\". Ban expires ";
|
||||
|
||||
string time;
|
||||
if(banEntry->until.time_since_epoch().count() != 0){
|
||||
if(banEntry->until.time_since_epoch().count() != 0) {
|
||||
time += "in ";
|
||||
auto seconds = chrono::ceil<chrono::seconds>(banEntry->until - chrono::system_clock::now()).count();
|
||||
tm p{};
|
||||
@@ -310,30 +312,43 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
|
||||
p.tm_year++;
|
||||
seconds -= 365 * 24 * 60 * 60;
|
||||
}
|
||||
|
||||
while(seconds >= 24 * 60 * 60){
|
||||
p.tm_yday++;
|
||||
seconds -= 24 * 60 * 60;
|
||||
}
|
||||
|
||||
while(seconds >= 60 * 60){
|
||||
p.tm_hour++;
|
||||
seconds -= 60 * 60;
|
||||
}
|
||||
|
||||
while(seconds >= 60){
|
||||
p.tm_min++;
|
||||
seconds -= 60;
|
||||
}
|
||||
p.tm_sec = (int) seconds;
|
||||
|
||||
if(p.tm_year > 0)
|
||||
if(p.tm_year > 0) {
|
||||
time += to_string(p.tm_year) + " years, ";
|
||||
if(p.tm_yday > 0)
|
||||
}
|
||||
|
||||
if(p.tm_yday > 0) {
|
||||
time += to_string(p.tm_yday) + " days, ";
|
||||
if(p.tm_hour > 0)
|
||||
}
|
||||
|
||||
if(p.tm_hour > 0) {
|
||||
time += to_string(p.tm_hour) + " hours, ";
|
||||
if(p.tm_min > 0)
|
||||
}
|
||||
|
||||
if(p.tm_min > 0) {
|
||||
time += to_string(p.tm_min) + " minutes, ";
|
||||
if(p.tm_sec > 0)
|
||||
}
|
||||
|
||||
if(p.tm_sec > 0) {
|
||||
time += to_string(p.tm_sec) + " seconds, ";
|
||||
}
|
||||
|
||||
if(time.empty()) time = "now, ";
|
||||
time = time.substr(0, time.length() - 2);
|
||||
} else time = "never";
|
||||
@@ -344,11 +359,12 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
|
||||
TIMING_STEP(timings, "ban resolve");
|
||||
|
||||
size_t count = 0;
|
||||
{
|
||||
for(const auto &cl : this->server->getClients())
|
||||
if((cl->getType() == CLIENT_TEAMSPEAK || cl->getType() == CLIENT_WEB || cl->getType() == CLIENT_TEASPEAK || cl->getType() == CLIENT_MUSIC))
|
||||
if(cl->connectionState() <= ConnectionState::CONNECTED && cl->connectionState() >= ConnectionState::INIT_HIGH)
|
||||
count++;
|
||||
for(const auto &cl : this->server->getClients()) {
|
||||
if((cl->getType() == CLIENT_TEAMSPEAK || cl->getType() == CLIENT_WEB || cl->getType() == CLIENT_TEASPEAK || cl->getType() == CLIENT_MUSIC)) {
|
||||
if(cl->connectionState() <= ConnectionState::CONNECTED && cl->connectionState() >= ConnectionState::INIT_HIGH) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto maxClients = this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0);
|
||||
@@ -356,15 +372,17 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
|
||||
|
||||
bool allowReserved = permission::v2::permission_granted(1, permissions[permission::b_client_use_reserved_slot]);
|
||||
if(reserved > maxClients){
|
||||
if(!allowReserved)
|
||||
if(!allowReserved) {
|
||||
return command_result{error::server_maxclients_reached};
|
||||
} else if(maxClients - (allowReserved ? 0 : reserved) <= count)
|
||||
}
|
||||
} else if(maxClients - (allowReserved ? 0 : reserved) <= count) {
|
||||
return command_result{error::server_maxclients_reached};
|
||||
}
|
||||
TIMING_STEP(timings, "max clients");
|
||||
|
||||
|
||||
auto old_last_connected = this->properties()[property::CLIENT_LASTCONNECTED].as_or<int64_t>(0);
|
||||
this->properties()[property::CONNECTION_CLIENT_IP] = this->getLoggingPeerIp();
|
||||
serverInstance->databaseHelper()->updateClientIpAddress(this->getServerId(), this->getClientDatabaseId(), this->getLoggingPeerIp());
|
||||
this->properties()[property::CLIENT_LASTCONNECTED] = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
this->properties()[property::CLIENT_TOTALCONNECTIONS].increment_by<uint64_t>(1);
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user