Optimize GameServer /announce and add website announcements (#810)

* Improve game server announce by using StringBuilder

* Implement web announcements (condensed commit)

* Implement discord webhook support

* Display a separate message if there are no announcements

* Fix announcement string unit tests

* Fix header admin button unit test

* Clarify announcement id variable name

* Increase webhook truncation limit to 250 chars

* Convert announce text to string when returning 200

* Fix announcement unit tests ... again

* Make announcement text input a textarea rather than a simple input

* Fix styling discrepancy

* Clarify submission button

* Improve announcement webhook & set default textarea row amount
This commit is contained in:
koko 2023-06-22 23:49:22 -04:00 committed by GitHub
parent 0fd8759f3f
commit 689ebd3791
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 256 additions and 20 deletions

View file

@ -1,4 +1,5 @@
#nullable enable
using System.Text;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
@ -51,25 +52,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.";
string username = await this.database.UsernameFromGameToken(token);
string announceText = ServerConfiguration.Instance.AnnounceText;
StringBuilder announceText = new(ServerConfiguration.Instance.AnnounceText);
announceText = announceText.Replace("%user", username);
announceText = announceText.Replace("%id", token.UserId.ToString());
announceText.Replace("%user", username);
announceText.Replace("%id", token.UserId.ToString());
return this.Ok
(
announceText +
#if DEBUG
"\n\n---DEBUG INFO---\n" +
$"user.UserId: {token.UserId}\n" +
$"token.UserLocation: {token.UserLocation}\n" +
$"token.GameVersion: {token.GameVersion}\n" +
$"token.TicketHash: {token.TicketHash}\n" +
$"token.ExpiresAt: {token.ExpiresAt.ToString()}\n" +
"---DEBUG INFO---" +
#endif
(string.IsNullOrWhiteSpace(announceText) ? "" : "\n")
);
#if DEBUG
announceText.Append("\n\n---DEBUG INFO---\n" +
$"user.UserId: {token.UserId}\n" +
$"token.UserLocation: {token.UserLocation}\n" +
$"token.GameVersion: {token.GameVersion}\n" +
$"token.TicketHash: {token.TicketHash}\n" +
$"token.ExpiresAt: {token.ExpiresAt.ToString()}\n" +
"---DEBUG INFO---");
#endif
return this.Ok(announceText.ToString());
}
[HttpGet("notification")]