Remove http scheme variables

The separation from the server variables doesn't really serve any purpose other than making it require very conscious effort to accidentally start connecting over plain http, but we already have enforce_https for this purpose. Beyond that, it just makes prototyping with a local server really annoying.
This commit is contained in:
Tamás Bálint Misius
2024-06-19 11:44:39 +02:00
parent 72fd55fafe
commit a24e1dbee8
37 changed files with 57 additions and 42 deletions

View File

@@ -60,8 +60,6 @@ constexpr auto DISPLAY_VERSION = APP_VERSION.displayVersion;
constexpr char IDENT_RELTYPE = SNAPSHOT ? 'S' : (BETA ? 'B' : 'R');
constexpr char SCHEME[] = "https://";
constexpr char STATICSCHEME[] = "https://";
constexpr char LOCAL_SAVE_DIR[] = "Saves";
constexpr char STAMPS_DIR[] = "stamps";
constexpr char BRUSH_DIR[] = "Brushes";

View File

@@ -113,7 +113,7 @@ static void BlueScreen(String detailMessage, std::optional<std::vector<String>>
StringBuilder crashInfo;
crashInfo << "ERROR - Details: " << detailMessage << "\n";
crashInfo << "An unrecoverable fault has occurred, please report it by visiting the website below\n\n " << SCHEME << SERVER << "\n\n";
crashInfo << "An unrecoverable fault has occurred, please report it by visiting the website below\n\n " << SERVER << "\n\n";
crashInfo << "An attempt will be made to save all of this information to " << crashLogPath.FromUtf8() << " in your data folder.\n";
crashInfo << "Please attach this file to your report.\n\n";
crashInfo << "Version: " << VersionInfo().FromUtf8() << "\n";

View File

@@ -117,7 +117,7 @@ void Client::Tick()
{
if (versionCheckRequest->StatusCode() == 618)
{
AddServerNotification({ "Failed to load SSL certificates", ByteString::Build(SCHEME, SERVER, "/FAQ.html") });
AddServerNotification({ "Failed to load SSL certificates", ByteString::Build(SERVER, "/FAQ.html") });
}
try
{

View File

@@ -5,7 +5,7 @@
namespace http
{
AddCommentRequest::AddCommentRequest(int saveID, String comment) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Browse/Comments.json?ID=", saveID), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Browse/Comments.json?ID=", saveID), authRequire, true)
{
auto user = Client::Ref().GetAuthUser();
AddPostData(FormData{

View File

@@ -5,7 +5,7 @@
namespace http
{
AddTagRequest::AddTagRequest(int saveID, ByteString tag) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Browse/EditTag.json?Op=add&ID=", saveID, "&Tag=", tag, "&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Browse/EditTag.json?Op=add&ID=", saveID, "&Tag=", tag, "&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
{
}

View File

@@ -5,7 +5,7 @@
namespace http
{
DeleteSaveRequest::DeleteSaveRequest(int saveID) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Browse/Delete.json?ID=", saveID, "&Mode=Delete&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Browse/Delete.json?ID=", saveID, "&Mode=Delete&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
{
}

View File

@@ -5,7 +5,7 @@
namespace http
{
ExecVoteRequest::ExecVoteRequest(int saveID, int newDirection) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Vote.api"), authRequire, false),
APIRequest(ByteString::Build(SERVER, "/Vote.api"), authRequire, false),
direction(newDirection)
{
AddPostData(FormData{

View File

@@ -7,7 +7,7 @@ namespace http
static ByteString Url(int saveID, bool favourite)
{
ByteStringBuilder builder;
builder << SCHEME << SERVER << "/Browse/Favourite.json?ID=" << saveID << "&Key=" << Client::Ref().GetAuthUser().SessionKey;
builder << SERVER << "/Browse/Favourite.json?ID=" << saveID << "&Key=" << Client::Ref().GetAuthUser().SessionKey;
if (!favourite)
{
builder << "&Mode=Remove";

View File

@@ -5,7 +5,7 @@
namespace http
{
GetCommentsRequest::GetCommentsRequest(int saveID, int start, int count) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Browse/Comments.json?ID=", saveID, "&Start=", start, "&Count=", count), authOmit, false)
APIRequest(ByteString::Build(SERVER, "/Browse/Comments.json?ID=", saveID, "&Start=", start, "&Count=", count), authOmit, false)
{
}

View File

@@ -6,7 +6,7 @@ namespace http
static ByteString Url(int saveID, int saveDate)
{
ByteStringBuilder builder;
builder << STATICSCHEME << STATICSERVER << "/" << saveID;
builder << STATICSERVER << "/" << saveID;
if (saveDate)
{
builder << "_" << saveDate;

View File

@@ -9,7 +9,7 @@ namespace http
static ByteString Url(int saveID, int saveDate)
{
ByteStringBuilder builder;
builder << SCHEME << SERVER << "/Browse/View.json?ID=" << saveID;
builder << SERVER << "/Browse/View.json?ID=" << saveID;
if (saveDate)
{
builder << "&Date=" << saveDate;

View File

@@ -5,7 +5,7 @@
namespace http
{
GetUserInfoRequest::GetUserInfoRequest(ByteString username) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/User.json?Name=", username), authOmit, false)
APIRequest(ByteString::Build(SERVER, "/User.json?Name=", username), authOmit, false)
{
}

View File

@@ -5,7 +5,7 @@
namespace http
{
LoginRequest::LoginRequest(ByteString username, ByteString password) : Request(ByteString::Build("https://", SERVER, "/Login.json"))
LoginRequest::LoginRequest(ByteString username, ByteString password) : Request(ByteString::Build(SERVER, "/Login.json"))
{
AddPostData(FormData{
{ "name", username },

View File

@@ -5,7 +5,7 @@
namespace http
{
LogoutRequest::LogoutRequest() :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Logout.json?Key=" + Client::Ref().GetAuthUser().SessionKey), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Logout.json?Key=" + Client::Ref().GetAuthUser().SessionKey), authRequire, true)
{
}

View File

@@ -5,7 +5,7 @@
namespace http
{
PublishSaveRequest::PublishSaveRequest(int saveID) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Browse/View.json?ID=", saveID, "&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Browse/View.json?ID=", saveID, "&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
{
AddPostData(FormData{
{ "ActionPublish", "bagels" },

View File

@@ -5,7 +5,7 @@
namespace http
{
RemoveTagRequest::RemoveTagRequest(int saveID, ByteString tag) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Browse/EditTag.json?Op=delete&ID=", saveID, "&Tag=", tag, "&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Browse/EditTag.json?Op=delete&ID=", saveID, "&Tag=", tag, "&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
{
}

View File

@@ -5,7 +5,7 @@
namespace http
{
ReportSaveRequest::ReportSaveRequest(int saveID, String message) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Browse/Report.json?ID=", saveID, "&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Browse/Report.json?ID=", saveID, "&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
{
AddPostData(FormData{
{ "Reason", message.ToUtf8() },

View File

@@ -4,7 +4,7 @@
namespace http
{
SaveUserInfoRequest::SaveUserInfoRequest(UserInfo info) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Profile.json"), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Profile.json"), authRequire, true)
{
AddPostData(FormData{
{ "Location", info.location.ToUtf8() },

View File

@@ -10,7 +10,7 @@ namespace http
static ByteString Url(int start, int count, ByteString query, Period period, Sort sort, Category category)
{
ByteStringBuilder builder;
builder << SCHEME << SERVER << "/Browse.json?Start=" << start << "&Count=" << count;
builder << SERVER << "/Browse.json?Start=" << start << "&Count=" << count;
auto appendToQuery = [&query](ByteString str) {
if (query.size())
{

View File

@@ -7,7 +7,7 @@ namespace http
static ByteString Url(int start, int count, ByteString query)
{
ByteStringBuilder builder;
builder << SCHEME << SERVER << "/Browse/Tags.json?Start=" << start << "&Count=" << count;
builder << SERVER << "/Browse/Tags.json?Start=" << start << "&Count=" << count;
if (query.size())
{
builder << "&Search_Query=" << format::URLEncode(query);

View File

@@ -6,7 +6,7 @@ namespace http
{
// TODO: update Client::messageOfTheDay
StartupRequest::StartupRequest(bool newAlternate) :
Request(ByteString::Build(SCHEME, newAlternate ? UPDATESERVER : SERVER, "/Startup.json")),
Request(ByteString::Build(newAlternate ? UPDATESERVER : SERVER, "/Startup.json")),
alternate(newAlternate)
{
auto user = Client::Ref().GetAuthUser();
@@ -70,7 +70,7 @@ namespace http
}
startupInfo.updateInfo = UpdateInfo{
channel,
ByteString::Build(SCHEME, alternate ? UPDATESERVER : SERVER, info["File"].asString()),
ByteString::Build(alternate ? UPDATESERVER : SERVER, info["File"].asString()),
ByteString(info["Changelog"].asString()).FromUtf8(),
getOr("Major", 0),
getOr("Minor", 0),

View File

@@ -6,8 +6,8 @@ namespace http
ThumbnailRequest::ThumbnailRequest(int saveID, int saveDate, Vec2<int> size) :
ImageRequest((
saveDate
? ByteString::Build(STATICSCHEME, STATICSERVER, "/", saveID, "_", saveDate, "_small.png")
: ByteString::Build(STATICSCHEME, STATICSERVER, "/", saveID, "_small.png")
? ByteString::Build(STATICSERVER, "/", saveID, "_", saveDate, "_small.png")
: ByteString::Build(STATICSERVER, "/", saveID, "_small.png")
), size)
{
}

View File

@@ -5,7 +5,7 @@
namespace http
{
UnpublishSaveRequest::UnpublishSaveRequest(int saveID) :
APIRequest(ByteString::Build(SCHEME, SERVER, "/Browse/Delete.json?ID=", saveID, "&Mode=Unpublish&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
APIRequest(ByteString::Build(SERVER, "/Browse/Delete.json?ID=", saveID, "&Mode=Unpublish&Key=", Client::Ref().GetAuthUser().SessionKey), authRequire, true)
{
}

View File

@@ -6,7 +6,7 @@
namespace http
{
UploadSaveRequest::UploadSaveRequest(const SaveInfo &saveInfo) : Request(ByteString::Build(SCHEME, SERVER, "/Save.api"))
UploadSaveRequest::UploadSaveRequest(const SaveInfo &saveInfo) : Request(ByteString::Build(SERVER, "/Save.api"))
{
auto [ fromNewerVersion, gameData ] = saveInfo.GetGameSave()->Serialise();
if (!gameData.size())

View File

@@ -552,7 +552,7 @@ bool GameController::MouseUp(int x, int y, unsigned button, MouseupReason reason
}
break;
case sign::Type::Thread:
Platform::OpenURI(ByteString::Build(SCHEME, SERVER, "/Discussions/Thread/View.html?Thread=", str.Substr(3, si.first - 3).ToUtf8()));
Platform::OpenURI(ByteString::Build(SERVER, "/Discussions/Thread/View.html?Thread=", str.Substr(3, si.first - 3).ToUtf8()));
break;
case sign::Type::Search:
OpenSearch(str.Substr(3, si.first - 3));

View File

@@ -76,7 +76,7 @@ inline ByteString IntroText()
}
else
{
sb << "\bgTo use online features such as saving, you need to register at: \brhttps://" << SERVER << "/Register.html\n";
sb << "\bgTo use online features such as saving, you need to register at: \br" << SERVER << "/Register.html\n";
}
sb << "\n\bt" << VersionInfo();
return sb.Build();

View File

@@ -22,7 +22,7 @@ void AvatarButton::Tick(float dt)
if (!avatar && !tried && name.size() > 0)
{
tried = true;
imageRequest = std::make_unique<http::ImageRequest>(ByteString::Build(SCHEME, STATICSERVER, "/avatars/", name, ".png"), Size);
imageRequest = std::make_unique<http::ImageRequest>(ByteString::Build(STATICSERVER, "/avatars/", name, ".png"), Size);
imageRequest->Start();
}

View File

@@ -9,7 +9,7 @@ void LoginModel::Login(ByteString username, ByteString password)
{
if (username.Contains("@"))
{
statusText = String::Build("Use your Powder Toy account to log in, not your email. If you don't have a Powder Toy account, you can create one at https://", SERVER, "/Register.html");
statusText = String::Build("Use your Powder Toy account to log in, not your email. If you don't have a Powder Toy account, you can create one at ", SERVER, "/Register.html");
loginStatus = loginIdle;
notifyStatusChanged();
return;

View File

@@ -88,7 +88,7 @@ void LoginView::NotifyStatusChanged(LoginModel * sender)
auto userID = Client::Ref().GetAuthUser().UserID;
if (!statusText.size() && !userID && notWorking)
{
statusText = String::Build("Don't have an account? {a:https://", SERVER, "/Register.html", "|\btRegister here\x0E}.");
statusText = String::Build("Don't have an account? {a:", SERVER, "/Register.html", "|\btRegister here\x0E}.");
}
infoLabel->Visible = statusText.size();
infoLabel->SetText(statusText);

View File

@@ -102,7 +102,7 @@ void PreviewController::FavouriteSave()
void PreviewController::OpenInBrowser()
{
ByteString uri = ByteString::Build(SCHEME, SERVER, "/Browse/View.html?ID=", saveId);
ByteString uri = ByteString::Build(SERVER, "/Browse/View.html?ID=", saveId);
Platform::OpenURI(uri);
}

View File

@@ -147,7 +147,7 @@ void PreviewModel::OnSaveReady()
{
auto gameSave = std::make_unique<GameSave>(*saveData);
if (gameSave->fromNewerVersion)
new ErrorMessage("This save is from a newer version", String::Build("Please update TPT in game or at https://", SERVER));
new ErrorMessage("This save is from a newer version", String::Build("Please update TPT in game or at ", SERVER));
saveInfo->SetGameSave(std::move(gameSave));
}
catch(ParseException &e)

View File

@@ -83,7 +83,7 @@ void ProfileActivity::setUserInfo(UserInfo newInfo)
{
ui::Button * editAvatar = new ui::Button(ui::Point(Size.X - (40 + 16 + 75), currentY), ui::Point(75, 15), "Edit Avatar");
editAvatar->SetActionCallback({ [] {
Platform::OpenURI(ByteString::Build(SCHEME, SERVER, "/Profile/Avatar.html"));
Platform::OpenURI(ByteString::Build(SERVER, "/Profile/Avatar.html"));
} });
scrollPanel->AddChild(editAvatar);
}

View File

@@ -58,7 +58,7 @@ void SearchModel::BeginGetTags(int start, int count, String query)
{
lastError = "";
ByteStringBuilder urlStream;
urlStream << SCHEME << SERVER << "/Browse/Tags.json?Start=" << start << "&Count=" << count;
urlStream << SERVER << "/Browse/Tags.json?Start=" << start << "&Count=" << count;
if(query.length())
{
urlStream << "&Search_Query=";

View File

@@ -151,7 +151,7 @@ void UpdateActivity::NotifyError(Task * sender)
new ConfirmPrompt("Autoupdate failed", sb.Build(), { [this] {
if constexpr (!USE_UPDATESERVER)
{
Platform::OpenURI(ByteString::Build(SCHEME, SERVER, "/Download.html"));
Platform::OpenURI(ByteString::Build(SERVER, "/Download.html"));
}
Exit();
}, [this] { Exit(); } });

View File

@@ -352,7 +352,7 @@ static int request(lua_State *L, bool isPost)
static int getAuthToken(lua_State *L)
{
return RequestHandle::Make(L, ByteString::Build(SCHEME, SERVER, "/ExternalAuth.api?Action=Get&Audience=", format::URLEncode(tpt_lua_checkByteString(L, 1))), false, {}, RequestHandle::getAuthToken, {}, {});
return RequestHandle::Make(L, ByteString::Build(SERVER, "/ExternalAuth.api?Action=Get&Audience=", format::URLEncode(tpt_lua_checkByteString(L, 1))), false, {}, RequestHandle::getAuthToken, {}, {});
}
static int get(lua_State *L)

View File

@@ -36,7 +36,7 @@ static int installScriptManager(lua_State *L)
new ErrorMessage("Script download", "You must run this function from the console");
return 0;
}
lsi->scriptManagerDownload = std::make_unique<http::Request>(ByteString::Build(SCHEME, "starcatcher.us/scripts/main.lua?get=1"));
lsi->scriptManagerDownload = std::make_unique<http::Request>(ByteString::Build("https://starcatcher.us/scripts/main.lua?get=1"));
lsi->scriptManagerDownload->Start();
return 0;
}

View File

@@ -24,9 +24,26 @@ conf_data.set('ALLOW_FAKE_NEWER_VERSION', (is_snapshot or is_beta or is_debug or
conf_data.set('IDENT_PLATFORM', ident_platform)
conf_data.set('IDENT', '@0@-@1@-@2@'.format(host_arch, host_platform, host_libc).to_upper())
server = get_option('server')
static_server = get_option('static_server')
update_server = get_option('update_server')
if not (server.startswith('http://') or server.startswith('https://'))
server = 'https://' + server
endif
if not (static_server.startswith('http://') or static_server.startswith('https://'))
static_server = 'https://' + static_server
endif
use_update_server = false
if update_server != ''
use_update_server = true
if not (update_server.startswith('http://') or update_server.startswith('https://'))
update_server = 'https://' + update_server
endif
endif
conf_data.set('USE_UPDATESERVER', use_update_server.to_string())
conf_data.set('UPDATESERVER', update_server)
conf_data.set('USE_UPDATESERVER', (update_server != '').to_string())
platform_clipboard = get_option('platform_clipboard')
enforce_https = get_option('enforce_https')
@@ -56,8 +73,8 @@ conf_data.set('SECURE_CIPHERS_ONLY', secure_ciphers_only.to_string())
conf_data.set('PLATFORM_CLIPBOARD', platform_clipboard.to_string())
conf_data.set('IGNORE_UPDATES', get_option('ignore_updates').to_string())
conf_data.set('SERVER', get_option('server'))
conf_data.set('STATICSERVER', get_option('static_server'))
conf_data.set('SERVER', server)
conf_data.set('STATICSERVER', static_server)
conf_data.set('APPNAME', get_option('app_name'))
conf_data.set('APPCOMMENT', get_option('app_comment'))
conf_data.set('APPEXE', app_exe)