diff --git a/Refresh.GameServer/Configuration/GameServerConfig.cs b/Refresh.GameServer/Configuration/GameServerConfig.cs index 6e176b65..807e9ed6 100644 --- a/Refresh.GameServer/Configuration/GameServerConfig.cs +++ b/Refresh.GameServer/Configuration/GameServerConfig.cs @@ -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; diff --git a/Refresh.GameServer/Endpoints/Game/Handshake/WelcomeEndpoints.cs b/Refresh.GameServer/Endpoints/Game/Handshake/WelcomeEndpoints.cs index 760b803b..8f114fa9 100644 --- a/Refresh.GameServer/Endpoints/Game/Handshake/WelcomeEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/Handshake/WelcomeEndpoints.cs @@ -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 notifications = database.GetNotificationsByUser(user, 5, 0).Items.ToList(); int count = database.GetNotificationCountByUser(user); + if (count == 0) return ""; string s = count != 1 ? "s" : ""; @@ -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 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 } } \ No newline at end of file