Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

141 finish motd #222

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/EvoSC.Common/Config/Models/ThemeOptions/IUIThemeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public interface IUIThemeConfig
public string PlayerRowBackgroundColor { get; }

[Description("Colored logo to be displayed on UI elements like headers.")]
[Option(Alias = "logoUrl", DefaultValue = "https://liquipedia.net/commons/images/thumb/c/cb/XPEvo_allmode.png/600px-XPEvo_allmode.png")]
[Option(Alias = "logoUrl", DefaultValue = "")]
public string LogoUrl { get; }

[Description("White logo to be displayed on UI elements like headers.")]
[Option(Alias = "logoWhiteUrl", DefaultValue = "https://cdn.discordapp.com/attachments/764035004048080916/1150113831331307540/XPEvoW100px.png")]
[Option(Alias = "logoWhiteUrl", DefaultValue = "")]
public string LogoWhiteUrl { get; }

public IUIScoreboardThemeConfig Scoreboard { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/EvoSC.Common/Database/MigrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void MigrateFromAssembly(Assembly asm)
.AddEvoScLogging(_config.Logging)
.Configure<RunnerOptions>(opt =>
{
opt.Tags = new[] { "Production", "XPEvo" };
opt.Tags = new[] { "Production" };
})
.BuildServiceProvider(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Tags("Production")]
[Migration(1665390396)]
public class AddPlayersTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Tags("Production")]
[Migration(1666859869)]
public class AddConfigOptionsTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Tags("Production")]
[Migration(1668338922)]
public class AddMapsTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Tags("Production")]
[Migration(1668492589)]
public class AddUserPermissionTables : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Tags("Production")]
[Migration(1675849925)]
public class AddAuditLogTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Tags("Production")]
[Migration(1687252035)]
public class AddPlayerSettingsTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Tags("Production")]
[Migration(1689575375)]
public class UpdateAuditLogTableDataTypes : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Tags("Production")]
[Migration(1694073143)]
public class UpdateConfigOptionsTable : Migration
{
Expand Down
1 change: 0 additions & 1 deletion src/EvoSC/EvoSC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
<Folder Include="bin\Debug\net7.0\config\" />
<ProjectReference Include="..\Modules\ASayModule\ASayModule.csproj" />
<ProjectReference Include="..\Modules\WorldRecordModule\WorldRecordModule.csproj" />
<ProjectReference Include="..\Modules\XPEvoAdminControl\XPEvoAdminControl.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void SetMotdLocal(string local)
}
}

[ChatCommand("motdedit", "[Command.EditMotd]", MotdPermissions.OpenMotdEdit)]
[ChatCommand("motdedit", "[Command.EditMotd]", MotdPermissions.EditMotd)]
public async Task OpenEditMotdAsync()
=> await _motdService.ShowEditAsync(Context.Player);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using EvoSC.Common.Controllers.Attributes;
using EvoSC.Manialinks;
using EvoSC.Manialinks.Attributes;
using EvoSC.Modules.Official.MotdModule.Interfaces;
using EvoSC.Modules.Official.MotdModule.Models;

namespace EvoSC.Modules.Official.MotdModule.Controllers;

Expand All @@ -14,9 +16,10 @@ public MotdEditManialinkController(IMotdService motdService)
_motdService = motdService;
}

public async Task SaveAsync(string text)
[ManialinkRoute(Permission = MotdPermissions.EditMotd)]
public async Task SaveAsync(EditMotdEntryModel input)
{
_motdService.SetLocalMotd(text, Context.Player);
_motdService.SetLocalMotd(input.Text, Context.Player);
await HideAsync(Context.Player, "MotdModule.MotdEdit");
}
}
9 changes: 9 additions & 0 deletions src/Modules/MotdModule/Models/EditMotdEntryModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using EvoSC.Manialinks.Attributes;

namespace EvoSC.Modules.Official.MotdModule.Models;

[FormEntryModel]
public class EditMotdEntryModel
{
public string Text { get; set; }
}
5 changes: 4 additions & 1 deletion src/Modules/MotdModule/MotdPermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ public enum MotdPermissions
{
[Description("Set Url to fetch Motd from.")]
SetUrl,

[Description("Interval of the timer to fetch Motd.")]
SetFetchInterval,

[Description("Changes motd to be fetched from local.")]
SetLocal,

[Description("Opens the Motd editor for local motd.")]
OpenMotdEdit
EditMotd
}
23 changes: 15 additions & 8 deletions src/Modules/MotdModule/Services/MotdService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Timers;
using System.Security;
using System.Timers;
using EvoSC.Common.Interfaces.Controllers;
using EvoSC.Common.Interfaces.Models;
using EvoSC.Common.Interfaces.Services;
Expand Down Expand Up @@ -57,7 +58,7 @@ public MotdService(IManialinkManager manialink, IHttpService httpService,
};
if (_isMotdLocal)
{
MotdText = _settings.MotdLocalText;
MotdText = SecurityElement.Escape(_settings.MotdLocalText);
}

_motdUpdateTimer.Elapsed += MotdUpdateTimerOnElapsed;
Expand All @@ -73,7 +74,7 @@ private void MotdUpdateTimerOnElapsed(object? sender, ElapsedEventArgs e)
}

timer.Interval = _timerInterval;
MotdText = GetMotdAsync().Result;
MotdText = SecurityElement.Escape(GetMotdAsync().Result);
_logger.LogDebug($"Fetching Motd");
}

Expand All @@ -92,7 +93,7 @@ public void SetLocalMotd(string text, IPlayer player)
{
var old = _settings.MotdLocalText;
_settings.MotdLocalText = text;
MotdText = text;
MotdText = SecurityElement.Escape(text);

_context.Audit().Success()
.WithEventName(AuditEvents.LocalTextSet)
Expand All @@ -107,7 +108,7 @@ public void SetMotdSource(bool local, IPlayer player)
_isMotdLocal = local;
if (local)
{
MotdText = _settings.MotdLocalText;
MotdText = SecurityElement.Escape(_settings.MotdLocalText);
}
else
{
Expand All @@ -125,7 +126,7 @@ public void SetUrl(string url, IPlayer player)
{
var oldUri = _motdUrl;
_motdUrl = url;
MotdText = GetMotdAsync().Result;
MotdText = SecurityElement.Escape(GetMotdAsync().Result);
if (!_motdUpdateTimer.Enabled)
{
_motdUpdateTimer.Enabled = true; // re-enable the timer when the url updates.
Expand All @@ -144,7 +145,7 @@ public async Task ShowEditAsync(IPlayer player)
.HavingProperties(new {Player = player})
.Comment("Local Motd editor shown.");

await _manialink.SendManialinkAsync(player, "MotdModule.MotdEdit", new { text = _settings.MotdLocalText });
await _manialink.SendManialinkAsync(player, "MotdModule.MotdEdit", new { text = MotdText });
}

public async Task ShowAsync(string login, bool explicitly)
Expand All @@ -169,8 +170,14 @@ public async Task ShowAsync(IPlayer? player, bool explicitly)
hidden = playerEntry.Hidden;
}
}

var isCheckboxChecked = hidden ?? false;
await _manialink.SendManialinkAsync(player, "MotdModule.MotdTemplate", new { isChecked = isCheckboxChecked, text = MotdText });
await _manialink.SendManialinkAsync(player, "MotdModule.MotdTemplate",
new
{
isChecked = isCheckboxChecked,
text = MotdText
});
}

public async Task<string> GetMotdAsync()
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/MotdModule/Templates/MotdEdit.mt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<template>
<Theme />
<Window width="{{ w }}" height="{{ h }}" x="{{ -w/2 }}" y="{{ h/2 }}" title="Edit Message of the Day">
<textedit class="text" id="textedit_text" default="{{ text }}" autonewline="1" z-index="{{ zIndex + 1 }}" pos="0 0" size="{{ w }} {{ h - (buttonBarHeight + titleBarHeight*2) }}" />
<textedit class="text" name="Text" default="{{ text }}" autonewline="1" z-index="{{ zIndex + 1 }}" pos="0 0" size="{{ w }} {{ h - (buttonBarHeight + titleBarHeight*2) }}" />

<frame pos="0 {{ -h + buttonBarHeight*2 + 2 }}" size="{{ w }} {{ buttonBarHeight+2 }}" z-index="{{ zIndex + 1 }}">
<Button text="Save" id="button_save" x="{{ w/2-19 }}" width="18" />
<Button text="Close" id="button_close" width="18" x="{{ w/2+1 }}" type="secondary" />
<Button text="Save" id="btnSave" action="MotdEditManialinkController/Save" x="{{ w/2-19 }}" width="18" />
<Button text="Close" id="btnClose" width="18" x="{{ w/2+1 }}" type="secondary" />
</frame>
</Window>
</template>
Expand All @@ -38,7 +38,7 @@
if (Event.Control.ControlId == "button_save") {
TriggerPageAction("MotdEditManialinkController/Save/"^(Page.GetFirstChild("textedit_text") as CMlTextEdit).Value);
CloseWindow("evosc-window");
} else if (Event.Control.ControlId == "button_close") {
} else if (Event.Control.ControlId == "btnClose") {
CloseWindow("evosc-window");
}
***
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EvoSC.Manialinks.Interfaces.Models;
using EvoSC.Modules.Official.MotdModule.Controllers;
using EvoSC.Modules.Official.MotdModule.Interfaces;
using EvoSC.Modules.Official.MotdModule.Models;
using EvoSC.Testing.Controllers;
using Moq;

Expand All @@ -21,7 +22,7 @@ public MotdEditManialinkControllerTests()
[Fact]
public async Task SaveAsync_Closes_Manialink_And_Sets_LocalMotd()
{
await Controller.SaveAsync("testing stuff");
await Controller.SaveAsync(new EditMotdEntryModel { Text = "testing stuff" });

ManialinkManager.Verify(m => m.HideManialinkAsync(_actor.Object, "MotdModule.MotdEdit"));
_motdService.Verify(r => r.SetLocalMotd("testing stuff", It.IsAny<IPlayer>()));
Expand Down
Loading