removed event controller, and added status to api controller

get time passed returns weeks after 90 days
and months after 365
This commit is contained in:
RaidMax 2018-08-02 20:52:35 -05:00
parent 396e5c9215
commit 9d00d5a16a
13 changed files with 139 additions and 80 deletions

View File

@ -114,11 +114,11 @@
"COMMANDS_WARNCLEAR_DESC": "remove all warnings for a client",
"COMMANDS_WARNCLEAR_SUCCESS": "All warning cleared for",
"COMMANDS_WHO_DESC": "give information about yourself",
"GLOBAL_DAYS": "days",
"GLOBAL_TIME_DAYS": "days",
"GLOBAL_ERROR": "Error",
"GLOBAL_HOURS": "hours",
"GLOBAL_TIME_HOURS": "hours",
"GLOBAL_INFO": "Info",
"GLOBAL_MINUTES": "minutes",
"GLOBAL_TIME_MINUTES": "minutes",
"GLOBAL_REPORT": "If you suspect someone of ^5CHEATING ^7use the ^5!report ^7command",
"GLOBAL_VERBOSE": "Verbose",
"GLOBAL_WARNING": "Warning",

View File

@ -114,11 +114,11 @@
"COMMANDS_WARNCLEAR_DESC": "eliminar todas las advertencias de un cliente",
"COMMANDS_WARNCLEAR_SUCCESS": "Todas las advertencias borradas para",
"COMMANDS_WHO_DESC": "da información sobre ti",
"GLOBAL_DAYS": "días",
"GLOBAL_TIME_DAYS": "días",
"GLOBAL_ERROR": "Error",
"GLOBAL_HOURS": "horas",
"GLOBAL_TIME_HOURS": "horas",
"GLOBAL_INFO": "Información",
"GLOBAL_MINUTES": "minutos",
"GLOBAL_TIME_MINUTES": "minutos",
"GLOBAL_REPORT": "Si sospechas que alguien ^5usa cheats ^7usa el comando ^5!report",
"GLOBAL_VERBOSE": "Detallado",
"GLOBAL_WARNING": "Advertencia",

View File

@ -114,11 +114,11 @@
"COMMANDS_WARNCLEAR_DESC": "remove todos os avisos para um cliente",
"COMMANDS_WARNCLEAR_SUCCESS": "Todos as advertências foram apagados para",
"COMMANDS_WHO_DESC": "dá informações sobre você",
"GLOBAL_DAYS": "dias",
"GLOBAL_TIME_DAYS": "dias",
"GLOBAL_ERROR": "Erro",
"GLOBAL_HOURS": "horas",
"GLOBAL_TIME_HOURS": "horas",
"GLOBAL_INFO": "Informação",
"GLOBAL_MINUTES": "minutos",
"GLOBAL_TIME_MINUTES": "minutos",
"GLOBAL_REPORT": "Se você está suspeitando alguém de alguma ^5TRAPAÇA ^7use o comando ^5!report",
"GLOBAL_VERBOSE": "Detalhe",
"GLOBAL_WARNING": "AVISO",

View File

@ -114,11 +114,11 @@
"COMMANDS_WARNCLEAR_DESC": "удалить все предупреждения у игрока",
"COMMANDS_WARNCLEAR_SUCCESS": "Все предупреждения очищены у",
"COMMANDS_WHO_DESC": "предоставить информацию о себе",
"GLOBAL_DAYS": "дней",
"GLOBAL_TIME_DAYS": "дней",
"GLOBAL_ERROR": "Ошибка",
"GLOBAL_HOURS": "часов",
"GLOBAL_TIME_HOURS": "часов",
"GLOBAL_INFO": "Информация",
"GLOBAL_MINUTES": "минут",
"GLOBAL_TIME_MINUTES": "минут",
"GLOBAL_REPORT": "Если вы подозреваете кого-то в ^5ЧИТЕРСТВЕ^7, используйте команду ^5!report",
"GLOBAL_VERBOSE": "Подробно",
"GLOBAL_WARNING": "Предупреждение",

View File

@ -125,7 +125,7 @@
<Architecture>X64</Architecture>
</Interpreter>
</ItemGroup>
<!--<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Web.targets" />-->
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Web.targets" />
<!-- Specify pre- and post-build commands in the BeforeBuild and
AfterBuild targets below. -->
<Target Name="BeforeBuild">

View File

@ -53,7 +53,7 @@
<span class="text-primary">@stat.KDR</span><span class="text-muted"> @loc["PLUGINS_STATS_TEXT_KDR"]</span>
<span class="text-primary">@stat.Kills</span><span class="text-muted"> @loc["PLUGINS_STATS_TEXT_KILLS"]</span>
<span class="text-primary">@stat.Deaths</span><span class="text-muted"> @loc["PLUGINS_STATS_TEXT_DEATHS"]</span><br />
<span class="text-muted">@loc["WEBFRONT_PROFILE_PLAYER"]</span> <span class="text-primary"> @stat.TimePlayed </span><span class="text-muted">@loc["GLOBAL_HOURS"]</span><br />
<span class="text-muted">@loc["WEBFRONT_PROFILE_PLAYER"]</span> <span class="text-primary"> @stat.TimePlayed </span><span class="text-muted">@loc["GLOBAL_TIME_HOURS"]</span><br />
<span class="text-muted">@loc["WEBFRONT_PROFILE_LSEEN"]</span><span class="text-primary"> @stat.LastSeen </span><span class="text-muted">@loc["WEBFRONT_PENALTY_TEMPLATE_AGO"]</span>
</div>

View File

@ -521,7 +521,7 @@ namespace SharedLibraryCore.Commands
{
TimeSpan uptime = DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime;
var loc = Utilities.CurrentLocalization.LocalizationIndex;
await E.Origin.Tell($"IW4M Admin {loc["COMMANDS_UPTIME_TEXT"]} {uptime.Days} {loc["GLOBAL_DAYS"]}, {uptime.Hours} {loc["GLOBAL_HOURS"]}, {uptime.Minutes} {loc["GLOBAL_MINUTES"]}");
await E.Origin.Tell($"IW4M Admin {loc["COMMANDS_UPTIME_TEXT"]} {uptime.Days} {loc["GLOBAL_TIME_DAYS"]}, {uptime.Hours} {loc["GLOBAL_TIME_HOURS"]}, {uptime.Minutes} {loc["GLOBAL_TIME_MINUTES"]}");
}
}

View File

@ -20,6 +20,9 @@ namespace SharedLibraryCore.Database
public DbSet<EFMeta> EFMeta { get; set; }
public DbSet<EFChangeHistory> EFChangeHistory { get; set; }
/// <summary>
/// this only works if there's one connection string
/// </summary>
private static string _ConnectionString;
public DatabaseContext(DbContextOptions<DatabaseContext> opt) : base(opt) { }
@ -29,10 +32,6 @@ namespace SharedLibraryCore.Database
_ConnectionString = connStr;
}
public DatabaseContext()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (string.IsNullOrEmpty(_ConnectionString))
@ -55,7 +54,6 @@ namespace SharedLibraryCore.Database
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// make network id unique
@ -96,6 +94,7 @@ namespace SharedLibraryCore.Database
modelBuilder.Entity<EFAliasLink>().ToTable("EFAliasLinks");
modelBuilder.Entity<EFPenalty>().ToTable("EFPenalties");
// adapted from
// https://aleemkhan.wordpress.com/2013/02/28/dynamically-adding-dbset-properties-in-dbcontext-for-entity-framework-code-first/
#if !DEBUG
foreach (string dllPath in Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins"))

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SharedLibraryCore.Interfaces
{
public interface IPageList
{
IDictionary<string, string> Pages { get; set; }
}
}

View File

@ -211,30 +211,38 @@ namespace SharedLibraryCore
public static String GetTimePassed(DateTime start, bool includeAgo)
{
TimeSpan Elapsed = DateTime.UtcNow - start;
string ago = includeAgo ? " " + CurrentLocalization.LocalizationIndex["WEBFRONT_PENALTY_TEMPLATE_AGO"] : "";
string ago = includeAgo ? $" {CurrentLocalization.LocalizationIndex["WEBFRONT_PENALTY_TEMPLATE_AGO"]}" : "";
if (Elapsed.TotalSeconds < 30 && includeAgo)
return "just now";
if (Elapsed.TotalSeconds < 30)
{
return CurrentLocalization.LocalizationIndex["GLOBAL_TIME_JUSTNOW"];
}
if (Elapsed.TotalMinutes < 120)
{
if (Elapsed.TotalMinutes < 1.5)
return $"1 {CurrentLocalization.LocalizationIndex["GLOBAL_MINUTES"]}{ago}";
return Math.Round(Elapsed.TotalMinutes, 0) + $" {CurrentLocalization.LocalizationIndex["GLOBAL_MINUTES"]}{ago}";
return $"1 {CurrentLocalization.LocalizationIndex["GLOBAL_TIME_MINUTES"]}{ago}";
return Math.Round(Elapsed.TotalMinutes, 0) + $" {CurrentLocalization.LocalizationIndex["GLOBAL_TIME_MINUTES"]}{ago}";
}
if (Elapsed.TotalHours <= 24)
{
if (Elapsed.TotalHours < 1.5)
return $"1 {CurrentLocalization.LocalizationIndex["GLOBAL_HOURS"]}{ago}";
return Math.Round(Elapsed.TotalHours, 0) + $" { CurrentLocalization.LocalizationIndex["GLOBAL_HOURS"]}{ago}";
return $"1 {CurrentLocalization.LocalizationIndex["GLOBAL_TIME_HOURS"]}{ago}";
return Math.Round(Elapsed.TotalHours, 0) + $" { CurrentLocalization.LocalizationIndex["GLOBAL_TIME_HOURS"]}{ago}";
}
if (Elapsed.TotalDays <= 90)
{
if (Elapsed.TotalDays < 1.5)
return $"1 {CurrentLocalization.LocalizationIndex["GLOBAL_TIME_DAYS"]}{ago}";
return Math.Round(Elapsed.TotalDays, 0) + $" {CurrentLocalization.LocalizationIndex["GLOBAL_TIME_DAYS"]}{ago}";
}
if (Elapsed.TotalDays <= 365)
{
if (Elapsed.TotalDays < 1.5)
return $"1 {CurrentLocalization.LocalizationIndex["GLOBAL_DAYS"]}{ago}";
return Math.Round(Elapsed.TotalDays, 0) + $" {CurrentLocalization.LocalizationIndex["GLOBAL_DAYS"]}{ago}";
return $"{Math.Round(Elapsed.TotalDays / 7)} {CurrentLocalization.LocalizationIndex["GLOBAL_TIME_WEEKS"]}{ago}";
}
else
return $"a very long time{ago}";
{
return $"{Math.Round(Elapsed.TotalDays / 30, 0)} {CurrentLocalization.LocalizationIndex["GLOBAL_TIME_MONTHS"]}{ago}";
}
}
public static Game GetGame(string gameName)
@ -269,42 +277,59 @@ namespace SharedLibraryCore
if (!expressionMatch.Success) // fallback to default tempban length of 1 hour
return new TimeSpan(1, 0, 0);
char lengthDenote = expressionMatch.Value[expressionMatch.Value.Length - 1];
char lengthDenote = expressionMatch.Value.ToLower()[expressionMatch.Value.Length - 1];
int length = Int32.Parse(expressionMatch.Value.Substring(0, expressionMatch.Value.Length - 1));
switch (lengthDenote)
var loc = CurrentLocalization.LocalizationIndex;
if (lengthDenote == char.ToLower(loc["GLOBAL_TIME_MINUTES"][0]))
{
case 'm':
return new TimeSpan(0, length, 0);
case 'h':
return new TimeSpan(length, 0, 0);
case 'd':
return new TimeSpan(length, 0, 0, 0);
case 'w':
return new TimeSpan(length * 7, 0, 0, 0);
case 'y':
return new TimeSpan(length * 365, 0, 0, 0);
default:
return new TimeSpan(1, 0, 0);
return new TimeSpan(0, length, 0);
}
if (lengthDenote == char.ToLower(loc["GLOBAL_TIME_HOURS"].First()))
{
return new TimeSpan(length, 0, 0);
}
if (lengthDenote == char.ToLower(loc["GLOBAL_TIME_DAYS"].First()))
{
return new TimeSpan(length, 0, 0, 0);
}
if (lengthDenote == char.ToLower(loc["GLOBAL_TIME_WEEKS"].First()))
{
return new TimeSpan(length * 7, 0, 0, 0);
}
if (lengthDenote == char.ToLower(loc["GLOBAL_TIME_YEARS"].First()))
{
return new TimeSpan(length * 365, 0, 0, 0);
}
return new TimeSpan(1, 0, 0);
}
public static string TimeSpanText(this TimeSpan span)
{
if (span.TotalMinutes < 60)
return $"{span.Minutes} minute(s)";
else if (span.Hours >= 1 && span.TotalHours < 24)
return $"{span.Hours} hour(s)";
else if (span.TotalDays >= 1 && span.TotalDays < 7)
return $"{span.Days} day(s)";
else if (span.TotalDays >= 7 && span.TotalDays < 365)
return $"{Math.Ceiling(span.Days / 7.0)} week(s)";
else if (span.TotalDays >= 365 && span.TotalDays < 36500)
return $"{Math.Ceiling(span.Days / 365.0)} year(s)";
else if (span.TotalDays >= 36500)
return "Forever";
var loc = CurrentLocalization.LocalizationIndex;
return "1 hour";
if (span.TotalMinutes < 60)
return $"{span.Minutes} {loc["GLOBAL_TIME_MINUTES"]}";
else if (span.Hours >= 1 && span.TotalHours < 24)
return $"{span.Hours} {loc["GLOBAL_TIME_HOURS"]}";
else if (span.TotalDays >= 1 && span.TotalDays < 7)
return $"{span.Days} {loc["GLOBAL_TIME_DAYS"]}";
else if (span.TotalDays >= 7 && span.TotalDays < 90)
return $"{Math.Round(span.Days / 7.0, 0)} {loc["GLOBAL_TIME_WEEKS"]}";
else if (span.TotalDays >= 90 && span.TotalDays < 365)
return $"{Math.Round(span.Days / 30.0, 0)} {loc["GLOBAL_TIME_MONTHS"]}";
else if (span.TotalDays >= 365 && span.TotalDays < 36500)
return $"{Math.Round(span.Days / 365.0, 0)} {loc["GLOBAL_TIME_YEARS"]}";
else if (span.TotalDays >= 36500)
return loc["GLOBAL_TIME_FOREVER"];
return "unknown";
}
public static Player AsPlayer(this Database.Models.EFClient client)

View File

@ -6,8 +6,50 @@ using System.Threading.Tasks;
namespace WebfrontCore.Controllers.API
{
[Route("api")]
public class APIController : BaseController
public class ApiController : BaseController
{
public IActionResult Index() => Ok($"IW4MAdmin API");
[HttpGet]
public IActionResult Event(bool shouldConsume = true)
{
var events = Manager.GetEventApi().GetEvents(shouldConsume);
return Json(events);
}
[HttpGet]
public IActionResult Status(int id)
{
var serverInfo = Manager.GetServers()
.Select(server => new
{
Id = server.GetHashCode(),
Name = server.Hostname,
MaxPlayers = server.MaxClients,
CurrentPlayers = server.GetPlayersAsList().Count,
Map = server.CurrentMap,
GameMode = server.Gametype,
Port = server.GetPort(),
Game = server.GameName.ToString(),
Players = server.GetPlayersAsList()
.Select(player => new
{
player.Name,
player.Score,
player.Ping,
player.State,
player.ClientNumber,
player.ConnectionTime,
player.Level,
})
});
if (id != 0)
{
serverInfo = serverInfo.Where(server => server.Id == id);
}
return Json(serverInfo);
}
}
}

View File

@ -1,18 +0,0 @@
using SharedLibraryCore.Dtos;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
namespace WebfrontCore.Controllers.API
{
public class EventController : APIController
{
[HttpGet]
[Route("event")]
public ActionResult Index(bool shouldConsume = true)
{
var events = Manager.GetEventApi().GetEvents(shouldConsume);
return Json(events);
}
}
}

View File

@ -74,7 +74,7 @@
<h5><span class="level-color-@Model.Level.ToLower()"><strong>@Model.Level</strong></span></h5>
</div>
<div id="profile_time_played" class="text-muted">
@loc["WEBFRONT_PROFILE_PLAYER"] <span class="text-primary">@Model.TimePlayed</span> @loc["GLOBAL_HOURS"]
@loc["WEBFRONT_PROFILE_PLAYER"] <span class="text-primary">@Model.TimePlayed</span> @loc["GLOBAL_TIME_HOURS"]
</div>
<div id="profile_first_seen" class="text-muted">
@loc["WEBFRONT_PROFILE_FSEEN"] <span class="text-primary">@Model.FirstSeen</span> @loc["WEBFRONT_PENALTY_TEMPLATE_AGO"]