mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
migrated to ASP.Net Core
This commit is contained in:
2
SharedLibrary/App.config
Normal file
2
SharedLibrary/App.config
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration />
|
@ -8,9 +8,12 @@ using SharedLibrary.Database.Models;
|
||||
using System.Data.SqlServerCe;
|
||||
using System.Data.Entity.ModelConfiguration.Conventions;
|
||||
using System.Reflection;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
using System.Data.Entity.SqlServerCompact;
|
||||
|
||||
namespace SharedLibrary.Database
|
||||
{
|
||||
|
||||
public class DatabaseContext : DbContext
|
||||
{
|
||||
public DbSet<EFClient> Clients { get; set; }
|
||||
@ -47,7 +50,7 @@ namespace SharedLibrary.Database
|
||||
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
|
||||
|
||||
// https://aleemkhan.wordpress.com/2013/02/28/dynamically-adding-dbset-properties-in-dbcontext-for-entity-framework-code-first/
|
||||
foreach (string dllPath in System.IO.Directory.GetFiles($"{Environment.CurrentDirectory}{System.IO.Path.DirectorySeparatorChar}Plugins"))
|
||||
foreach (string dllPath in System.IO.Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins"))
|
||||
{
|
||||
Assembly library;
|
||||
try
|
||||
|
14
SharedLibrary/Dtos/ClientInfo.cs
Normal file
14
SharedLibrary/Dtos/ClientInfo.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Dtos
|
||||
{
|
||||
public class ClientInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Dtos
|
||||
{
|
||||
public class ProfilePenalty
|
||||
public class PenaltyInfo
|
||||
{
|
||||
public string OffenderName { get; set; }
|
||||
public int OffenderId { get; set; }
|
||||
@ -14,5 +14,7 @@ namespace SharedLibrary.Dtos
|
||||
public int PunisherId { get; set; }
|
||||
public string Offense { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string TimePunished { get; set; }
|
||||
public string TimeRemaining { get; set; }
|
||||
}
|
||||
}
|
25
SharedLibrary/Dtos/PlayerInfo.cs
Normal file
25
SharedLibrary/Dtos/PlayerInfo.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Dtos
|
||||
{
|
||||
public class PlayerInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public string Level { get; set; }
|
||||
public string IPAddress { get; set; }
|
||||
public long NetworkId { get; set; }
|
||||
public List<string> Aliases { get; set; }
|
||||
public List<string> IPs { get; set; }
|
||||
public int ConnectionCount { get; set; }
|
||||
public string LastSeen { get; set; }
|
||||
public string FirstSeen { get; set; }
|
||||
public string TimePlayed { get; set; }
|
||||
public bool Authenticated { get; set; }
|
||||
public List<ProfileMeta> Meta { get; set; }
|
||||
}
|
||||
}
|
22
SharedLibrary/Dtos/ServerInfo.cs
Normal file
22
SharedLibrary/Dtos/ServerInfo.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Dtos
|
||||
{
|
||||
public class ServerInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Map { get; set; }
|
||||
public string GameType { get; set; }
|
||||
public int ClientCount { get; set; }
|
||||
public int MaxClients { get; set; }
|
||||
public List<Chat> ChatHistory { get; set; }
|
||||
public List<PlayerInfo> Players { get; set; }
|
||||
public Helpers.PlayerHistory[] PlayerHistory { get; set; }
|
||||
public int ID { get; set; }
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace SharedLibrary.Helpers
|
||||
{
|
||||
try
|
||||
{
|
||||
ConfigSet = Interfaces.Serialize<ConcurrentDictionary<string, dynamic>>.Read($"config/plugins_{S.ToString()}.cfg");
|
||||
ConfigSet = Interfaces.Serialize<ConcurrentDictionary<string, dynamic>>.Read($"{Utilities.OperatingDirectory}config/plugins_{S.ToString()}.cfg");
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
@ -29,7 +29,7 @@ namespace SharedLibrary.Helpers
|
||||
|
||||
private void SaveChanges()
|
||||
{
|
||||
Interfaces.Serialize<ConcurrentDictionary<string, dynamic>>.Write($"config/plugins_{ServerInstance.ToString()}.cfg", ConfigSet);
|
||||
Interfaces.Serialize<ConcurrentDictionary<string, dynamic>>.Write($"{Utilities.OperatingDirectory}config/plugins_{ServerInstance.ToString()}.cfg", ConfigSet);
|
||||
}
|
||||
|
||||
public void AddProperty(KeyValuePair<string, dynamic> prop)
|
||||
|
@ -254,7 +254,7 @@ namespace SharedLibrary
|
||||
{
|
||||
Maps = new List<Map>();
|
||||
|
||||
IFile mapfile = new IFile("config/maps.cfg");
|
||||
IFile mapfile = new IFile($"{Utilities.OperatingDirectory}config/maps.cfg");
|
||||
String[] _maps = mapfile.ReadAllLines();
|
||||
mapfile.Close();
|
||||
if (_maps.Length > 2) // readAll returns minimum one empty string
|
||||
@ -281,7 +281,7 @@ namespace SharedLibrary
|
||||
{
|
||||
BroadcastMessages = new List<String>();
|
||||
|
||||
IFile messageCFG = new IFile("config/messages.cfg");
|
||||
IFile messageCFG = new IFile($"{Utilities.OperatingDirectory}config/messages.cfg");
|
||||
String[] lines = messageCFG.ReadAllLines();
|
||||
messageCFG.Close();
|
||||
|
||||
@ -319,7 +319,7 @@ namespace SharedLibrary
|
||||
{
|
||||
Rules = new List<String>();
|
||||
|
||||
IFile ruleFile = new IFile("config/rules.cfg");
|
||||
IFile ruleFile = new IFile($"{Utilities.OperatingDirectory}config/rules.cfg");
|
||||
String[] _rules = ruleFile.ReadAllLines();
|
||||
ruleFile.Close();
|
||||
if (_rules.Length > 2) // readAll returns minimum one empty string
|
||||
|
@ -13,7 +13,7 @@ namespace SharedLibrary
|
||||
|
||||
public override string Filename()
|
||||
{
|
||||
return $"config/servers/{IP}_{Port}.cfg";
|
||||
return $"{Utilities.OperatingDirectory}config/servers/{IP}_{Port}.cfg";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +55,9 @@ namespace SharedLibrary.Services
|
||||
{
|
||||
Active = true,
|
||||
// set the level to the level of the existing client if they have the same IP + Name but new NetworkId
|
||||
// fixme: issues?
|
||||
Level = hasExistingAlias ?
|
||||
context.Clients.First(c => c.CurrentAliasId == existingAlias.AliasId).Level :
|
||||
context.Clients.First(c => c.AliasLinkId== existingAlias.LinkId).Level :
|
||||
Player.Permission.User,
|
||||
FirstConnection = DateTime.UtcNow,
|
||||
Connections = 1,
|
||||
|
@ -144,7 +144,7 @@ namespace SharedLibrary.Services
|
||||
select new ProfileMeta()
|
||||
{
|
||||
Key = "Event.Penalty",
|
||||
Value = new ProfilePenalty
|
||||
Value = new PenaltyInfo
|
||||
{
|
||||
OffenderName = victimAlias.Name,
|
||||
OffenderId = victimClient.ClientId,
|
||||
@ -175,7 +175,7 @@ namespace SharedLibrary.Services
|
||||
select new ProfileMeta()
|
||||
{
|
||||
Key = "Event.Penalty",
|
||||
Value = new ProfilePenalty
|
||||
Value = new PenaltyInfo
|
||||
{
|
||||
OffenderName = victimAlias.Name,
|
||||
OffenderId = victimClient.ClientId,
|
||||
|
@ -2,6 +2,7 @@
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D51EECEB-438A-47DA-870F-7D7B41BC24D6}</ProjectGuid>
|
||||
@ -9,7 +10,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SharedLibrary</RootNamespace>
|
||||
<AssemblyName>SharedLibrary</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
@ -65,6 +66,33 @@
|
||||
<OutputPath>bin\x86\Release-Stable\</OutputPath>
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>..\..\..\RuleSet1.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release-Nightly|x64'">
|
||||
<OutputPath>bin\x64\Release-Nightly\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release-Stable|x64'">
|
||||
<OutputPath>bin\x64\Release-Stable\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
@ -75,10 +103,6 @@
|
||||
<Reference Include="EntityFramework.SqlServerCompact, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.SqlServerCompact.6.2.0\lib\net45\EntityFramework.SqlServerCompact.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
@ -103,8 +127,11 @@
|
||||
<Compile Include="Database\Models\EFClient.cs" />
|
||||
<Compile Include="Database\Models\EFPenalty.cs" />
|
||||
<Compile Include="Database\Models\SharedEntity.cs" />
|
||||
<Compile Include="Dtos\PlayerInfo.cs" />
|
||||
<Compile Include="Dtos\ClientInfo.cs" />
|
||||
<Compile Include="Dtos\ProfileMeta.cs" />
|
||||
<Compile Include="Dtos\ProfilePenalty.cs" />
|
||||
<Compile Include="Dtos\PenaltyInfo.cs" />
|
||||
<Compile Include="Dtos\ServerInfo.cs" />
|
||||
<Compile Include="Exceptions\DatabaseException.cs" />
|
||||
<Compile Include="Helpers\AsyncStatus.cs" />
|
||||
<Compile Include="Commands\NativeCommands.cs" />
|
||||
@ -144,11 +171,15 @@
|
||||
<Compile Include="Services\MetaService.cs" />
|
||||
<Compile Include="Services\PenaltyService.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
<Compile Include="WebService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json">
|
||||
<Version>11.0.1</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>move "$(TargetDir)Newtonsoft.Json.dll" "$(TargetDir)lib\Newtonsoft.Json.dll"
|
||||
|
@ -7,11 +7,15 @@ using System.Collections.Generic;
|
||||
|
||||
using SharedLibrary.Objects;
|
||||
using static SharedLibrary.Server;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
public static class Utilities
|
||||
{
|
||||
public static string OperatingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
|
||||
|
||||
//Get string with specified number of spaces -- really only for visual output
|
||||
public static String GetSpaces(int Num)
|
||||
{
|
||||
|
@ -1,104 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
public class WebService
|
||||
{
|
||||
public static List<IPage> PageList { get; set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
PageList = new List<IPage>();
|
||||
}
|
||||
}
|
||||
|
||||
public struct HttpResponse
|
||||
{
|
||||
public string contentType;
|
||||
public object content;
|
||||
public byte[] BinaryContent;
|
||||
public Dictionary<string, string> additionalHeaders;
|
||||
}
|
||||
|
||||
public interface IPage
|
||||
{
|
||||
string GetPath();
|
||||
string GetName();
|
||||
Task<HttpResponse> GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers);
|
||||
bool Visible();
|
||||
}
|
||||
|
||||
public abstract class HTMLPage : IPage
|
||||
{
|
||||
private bool visible;
|
||||
|
||||
public HTMLPage()
|
||||
{
|
||||
visible = true;
|
||||
}
|
||||
|
||||
public HTMLPage(bool visible)
|
||||
{
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
protected string GetContentType()
|
||||
{
|
||||
return "text/html";
|
||||
}
|
||||
|
||||
protected string LoadFile(string filename)
|
||||
{
|
||||
string s;
|
||||
|
||||
IFile HTML = new IFile(filename);
|
||||
s = HTML.GetText();
|
||||
HTML.Close();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
protected string LoadHeader()
|
||||
{
|
||||
return LoadFile("webfront\\header.html");
|
||||
}
|
||||
|
||||
protected string LoadFooter()
|
||||
{
|
||||
return LoadFile("webfront\\footer.html");
|
||||
}
|
||||
|
||||
public bool Visible()
|
||||
{
|
||||
return visible;
|
||||
}
|
||||
|
||||
virtual public string GetPath()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
abstract public string GetName();
|
||||
virtual public Dictionary<string, string> GetHeaders(IDictionary<string, string> requestHeaders)
|
||||
{
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
abstract public string GetContent(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers);
|
||||
|
||||
public async Task<HttpResponse> GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
||||
{
|
||||
HttpResponse resp = new HttpResponse()
|
||||
{
|
||||
content = GetContent(querySet, headers),
|
||||
contentType = GetContentType(),
|
||||
additionalHeaders = GetHeaders(headers)
|
||||
};
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user