Netplay: Sync codes

Adds a tickbox to the server's window to syncronize codes. Codes
are temporarily sent to each client and are used for the duration of the
session.

Saves the "sync codes" tickbox as per PR Netplay: Properly save hosting
settings #7483
This commit is contained in:
Vin Bertinelli
2018-10-04 18:49:41 -04:00
committed by Pierre Bourdon
parent 0140009114
commit 469f29350f
17 changed files with 545 additions and 7 deletions

View File

@ -83,6 +83,7 @@ enum
// General lock. Protects codes list and internal log.
static std::mutex s_lock;
static std::vector<ARCode> s_active_codes;
static std::vector<ARCode> s_synced_codes;
static std::vector<std::string> s_internal_log;
static std::atomic<bool> s_use_internal_log{false};
// pointer to the code currently being run, (used by log messages that include the code name)
@ -123,6 +124,37 @@ void ApplyCodes(const std::vector<ARCode>& codes)
s_active_codes.shrink_to_fit();
}
void SetSyncedCodesAsActive()
{
s_active_codes.clear();
s_active_codes.reserve(s_synced_codes.size());
s_active_codes = s_synced_codes;
}
void UpdateSyncedCodes(const std::vector<ARCode>& codes)
{
s_synced_codes.clear();
s_synced_codes.reserve(codes.size());
std::copy_if(codes.begin(), codes.end(), std::back_inserter(s_synced_codes),
[](const ARCode& code) { return code.active; });
s_synced_codes.shrink_to_fit();
}
std::vector<ARCode> ApplyAndReturnCodes(const std::vector<ARCode>& codes)
{
if (SConfig::GetInstance().bEnableCheats)
{
std::lock_guard<std::mutex> guard(s_lock);
s_disable_logging = false;
s_active_codes.clear();
std::copy_if(codes.begin(), codes.end(), std::back_inserter(s_active_codes),
[](const ARCode& code) { return code.active; });
}
s_active_codes.shrink_to_fit();
return s_active_codes;
}
void AddCode(ARCode code)
{
if (!SConfig::GetInstance().bEnableCheats)