Skip to content

Commit

Permalink
feat: EULA validation for server owners.
Browse files Browse the repository at this point in the history
  • Loading branch information
Force67 committed Jan 13, 2022
1 parent c529d56 commit d5148f1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Code/base/IniSettingTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#include <gtest/gtest.h>

1 change: 1 addition & 0 deletions Code/base/Setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct SettingBase
// Doesn't show up in the help list.
kHidden = 1 << 0,
// Value is write protected
// TODO: honor the lock.
kLocked = 1 << 1,
};

Expand Down
42 changes: 41 additions & 1 deletion Code/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <TiltedCore/Filesystem.hpp>

#include <base/Check.h>
#include <base/simpleini/SimpleIni.h>
#include <base/IniSettingsProvider.h>

constexpr char kSettingsFileName[] =
Expand All @@ -27,6 +28,14 @@ constexpr char kSettingsFileName[] =
#endif
;

// Its fine for us if several potential server instances read this, since its a tilted platform thing
// and therefore not considered game specific.
constexpr char kEULAName[] = "EULA.txt";
constexpr char kEULAText[] = ";Please indicate your agreement to the Tilted platform service agreement\n"
";by setting bConfirmEULA to true\n"
"[EULA]\n"
"bConfirmEULA=false";

namespace fs = std::filesystem;

static base::StringSetting sLogLevel{"sLogLevel", "Log level to print", "info"};
Expand Down Expand Up @@ -74,12 +83,43 @@ struct SettingsScope
base::SaveSettingsToIni(m_Path);
}

private:
private:
fs::path m_Path;
};

static void ShittyFileWrite(const std::filesystem::path& aPath, const char* const acData)
{
// TODO: Get rid of this, its horrible.
std::ofstream myfile(aPath.c_str());
myfile << acData;
myfile.close();
}

static bool IsEULAAccepted()
{
auto path = fs::current_path() / kEULAName;
if (!fs::exists(path))
{
ShittyFileWrite(path, kEULAText);
return false;
}

auto data = TiltedPhoques::LoadFile(path);
CSimpleIni si;
if (si.LoadData(data.c_str()) != SI_OK)
return false;

return si.GetBoolValue("EULA", "bConfirmEULA", false);
}

int main(int argc, char** argv)
{
if (!IsEULAAccepted())
{
fmt::print("Please accept the EULA by setting bConfirmEULA to true in EULA.txt");
return 0;
}

SettingsScope sscope;
(void)sscope;

Expand Down

0 comments on commit d5148f1

Please sign in to comment.