Skip to content

Commit

Permalink
dont show rate limit notifications in editor or playlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Aug 15, 2024
1 parent 90d1902 commit a4a055e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/hooks/GJBaseGameLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <Geode/Geode.hpp>
#include <Geode/modify/GJBaseGameLayer.hpp>
#include "../utils.hpp"

using namespace geode::prelude;


class BI_DLL $modify(BIGJBaseGameLayer, GJBaseGameLayer) {
bool init() {
if (!GJBaseGameLayer::init()) return false;

BetterInfo::cancelUnimportantNotifications();

return true;
}
};
16 changes: 16 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,4 +885,20 @@ long long BetterInfo::strtol(std::string_view str) {
long long result = 0;
std::from_chars(str.data(), str.data() + str.size(), result);
return result;
}

static std::vector<Ref<Notification>> notifications;
void BetterInfo::showUnimportantNotification(const std::string& content, NotificationIcon icon, float time) {
if(GJBaseGameLayer::get()) return;

auto notif = Notification::create(content, icon, time);
notifications.push_back(notif);
notif->show();
}

void BetterInfo::cancelUnimportantNotifications() {
for(auto& notification : notifications) {
notification->cancel();
}
notifications.clear();
}
3 changes: 3 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@ namespace BetterInfo {
BI_DLL int stoi(std::string_view str);
BI_DLL float stof(std::string_view str);
BI_DLL long long strtol(std::string_view str);

BI_DLL void showUnimportantNotification(const std::string& content, NotificationIcon icon, float time = 5.f);
BI_DLL void cancelUnimportantNotifications();
}
4 changes: 2 additions & 2 deletions src/utils/ServerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ bool ServerUtils::showCFError(const std::string& data) {
message = fmt::format(" A server error has occurred.\n (error code: {})", error);
break;
}
Notification::create(message, NotificationIcon::Error, 5.f)->show();
BetterInfo::showUnimportantNotification(message, NotificationIcon::Error, 5.f);
return true;
}
return false;
}

bool ServerUtils::showRateLimitError(int seconds) {
Notification::create(fmt::format(" Rate limited by RobTop's server\n Try again in {}", GameToolbox::getTimeString(seconds, false)), NotificationIcon::Warning, 5.f)->show();
BetterInfo::showUnimportantNotification(fmt::format(" Rate limited by RobTop's server\n Try again in {}", GameToolbox::getTimeString(seconds, false)), NotificationIcon::Warning, 5.f);
return true;
}

0 comments on commit a4a055e

Please sign in to comment.