Skip to content

Commit

Permalink
Revamp in-game announcements screen
Browse files Browse the repository at this point in the history
This allows the announcements screen to be empty incase there are no notifications, and brings in server announcements
  • Loading branch information
jvyden committed Sep 16, 2023
1 parent b024b76 commit 4448eb4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
4 changes: 1 addition & 3 deletions Refresh.GameServer/Configuration/GameServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ namespace Refresh.GameServer.Configuration;
[SuppressMessage("ReSharper", "RedundantDefaultMemberInitializer")]
public class GameServerConfig : Config
{
public override int CurrentConfigVersion => 9;
public override int CurrentConfigVersion => 10;
public override int Version { get; set; } = 0;

protected override void Migrate(int oldVer, dynamic oldConfig) {}

public string AnnounceText { get; set; } = "This is the announce text. You can change the value in the configuration file!";

public string LicenseText { get; set; } = "Welcome to Refresh!";

public AssetSafetyLevel MaximumAssetSafetyLevel { get; set; } = AssetSafetyLevel.Safe;
Expand Down
34 changes: 30 additions & 4 deletions Refresh.GameServer/Endpoints/Game/Handshake/WelcomeEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ public string License(RequestContext context, GameServerConfig config)
return config.LicenseText + "\n\n" + AGPLLicense + "\n";
}

[GameEndpoint("announce")]
[MinimumRole(GameUserRole.Restricted)]
public string Announce(RequestContext context, GameServerConfig config, GameUser user, GameDatabaseContext database)
private static string AnnounceGetNotifications(GameDatabaseContext database, GameUser user, GameServerConfig config)
{
List<GameNotification> notifications = database.GetNotificationsByUser(user, 5, 0).Items.ToList();
int count = database.GetNotificationCountByUser(user);
if (count == 0) return "";

string s = count != 1 ? "s" : "";

Expand All @@ -54,6 +53,33 @@ public string Announce(RequestContext context, GameServerConfig config, GameUser

notificationText += $"To view more, or clear these notifications, you can visit the website at {config.WebExternalUrl}!\n";

return config.AnnounceText.TrimEnd() + "\n\n" + notificationText;
return notificationText;
}

private static string AnnounceGetAnnouncements(GameDatabaseContext database)
{
IEnumerable<GameAnnouncement> announcements = database.GetAnnouncements();
// it's time to allocate
return announcements.Aggregate("", (current, announcement) => current + $"{announcement.Title}: {announcement.Text}\n");
}

[GameEndpoint("announce")]
[MinimumRole(GameUserRole.Restricted)]
public string Announce(RequestContext context, GameServerConfig config, GameUser user, GameDatabaseContext database)
{
if (user.Role == GameUserRole.Restricted)
{
return "Your account is currently in restricted mode.\n\n" +
"You can still play, but you won't be able to publish levels, post comments," +
"or otherwise interact with the community." +
"For more information, please contact an administrator.";
}

string announcements = AnnounceGetAnnouncements(database);
string notifications = AnnounceGetNotifications(database, user, config);

if (announcements.Length == 0) return notifications;
if (notifications.Length == 0) return announcements;
return announcements + "\n" + notifications; // I HATE IT WHYYYYYYYYYYYY
}
}

0 comments on commit 4448eb4

Please sign in to comment.