RPCN v0.6

This commit is contained in:
RipleyTom 2022-05-18 17:44:21 +02:00 committed by kd-11
parent 67c02e3522
commit eea73deab3
39 changed files with 3461 additions and 758 deletions

View file

@ -21,6 +21,14 @@ void cfg_rpcn::load()
rpcn_log.notice("RPCN config missing. Using default settings. Path: %s", path);
from_default();
}
// Update config from old version(s)
if (version == 1)
{
password.from_string("");
version.set(2);
save();
}
}
void cfg_rpcn::save() const
@ -55,7 +63,7 @@ std::string cfg_rpcn::generate_npid()
std::string gen_npid = "RPCS3_";
const char list_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
std::srand(time(nullptr));
@ -72,6 +80,32 @@ std::string cfg_rpcn::get_host() const
return host.to_string();
}
std::vector<std::pair<std::string, std::string>> cfg_rpcn::get_hosts()
{
std::vector<std::pair<std::string, std::string>> vec_hosts;
auto hosts_list = fmt::split(hosts.to_string(), {"|||"});
for (const auto& cur_host : hosts_list)
{
auto desc_and_host = fmt::split(cur_host, {"|"});
if (desc_and_host.size() != 2)
{
rpcn_log.error("Invalid host in the list of hosts: %s", cur_host);
continue;
}
vec_hosts.push_back(std::make_pair(std::move(desc_and_host[0]), std::move(desc_and_host[1])));
}
if (vec_hosts.empty())
{
hosts.from_default();
save();
return get_hosts();
}
return vec_hosts;
}
std::string cfg_rpcn::get_npid()
{
std::string final_npid = npid.to_string();
@ -94,22 +128,80 @@ std::string cfg_rpcn::get_token() const
return token.to_string();
}
void cfg_rpcn::set_host(const std::string& host)
void cfg_rpcn::set_host(std::string_view host)
{
this->host.from_string(host);
}
void cfg_rpcn::set_npid(const std::string& npid)
void cfg_rpcn::set_npid(std::string_view npid)
{
this->npid.from_string(npid);
}
void cfg_rpcn::set_password(const std::string& password)
void cfg_rpcn::set_password(std::string_view password)
{
this->password.from_string(password);
}
void cfg_rpcn::set_token(const std::string& token)
void cfg_rpcn::set_token(std::string_view token)
{
this->token.from_string(token);
}
void cfg_rpcn::set_hosts(const std::vector<std::pair<std::string, std::string>>& vec_hosts)
{
std::string final_string;
for (const auto& [cur_desc, cur_host] : vec_hosts)
{
fmt::append(final_string, "%s|%s|||", cur_desc, cur_host);
}
if (final_string.empty())
{
hosts.from_default();
return;
}
final_string.resize(final_string.size() - 3);
hosts.from_string(final_string);
}
bool cfg_rpcn::add_host(std::string_view new_description, std::string_view new_host)
{
auto cur_hosts = get_hosts();
for (const auto& [cur_desc, cur_host] : cur_hosts)
{
if (cur_desc == new_description && cur_host == new_host)
return false;
}
cur_hosts.push_back(std::make_pair(std::string(new_description), std::string(new_host)));
set_hosts(cur_hosts);
return true;
}
bool cfg_rpcn::del_host(std::string_view del_description, std::string_view del_host)
{
// Do not delete default servers
if ((del_description == "Official RPCN Server" && del_host == "np.rpcs3.net") ||
(del_description == "RPCN Test Server" && del_host == "test-np.rpcs3.net"))
{
return true;
}
auto cur_hosts = get_hosts();
for (auto it = cur_hosts.begin(); it != cur_hosts.end(); it++)
{
if (it->first == del_description && it->second == del_host)
{
cur_hosts.erase(it);
set_hosts(cur_hosts);
return true;
}
}
return false;
}