Commit refactoring
This commit is contained in:
parent
f735bce4e1
commit
d33d11123d
51 changed files with 348 additions and 18 deletions
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -1,6 +1,6 @@
|
|||
[submodule "External/libremetaverse"]
|
||||
path = External/libremetaverse
|
||||
url = https://github.com/cinderblocks/libremetaverse
|
||||
[submodule "External/LibZNI"]
|
||||
path = External/LibZNI
|
||||
[submodule "External/LibAC"]
|
||||
path = External/LibAC
|
||||
url = ssh://git@git.zontreck.com:1212/zontreck/LibZNI
|
||||
|
|
|
@ -3,24 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyCompany("ZNI")]
|
||||
[assembly: AssemblyCompany("Piccari Creations")]
|
||||
[assembly: AssemblyAlgorithmId(System.Configuration.Assemblies.AssemblyHashAlgorithm.MD5)]
|
||||
[assembly: AssemblyCopyright("(C) 2020 Tara Piccari")]
|
||||
[assembly: AssemblyFileVersion("5.0.7.9200")]
|
||||
[assembly: AssemblyDescription("ForgeCore Bot Server")]
|
||||
|
||||
namespace Bot.Assemble
|
||||
namespace ForgeCore.Assemble
|
||||
{
|
||||
public class ASMInfo
|
||||
{
|
||||
public static string BotName = "ForgeCore";
|
||||
public static string BotVer = "2.0.121524.1636";
|
||||
public static string GitPassword
|
||||
{
|
||||
get
|
||||
{
|
||||
return MainConfiguration.Instance.GitPassword;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
External/LibAC
vendored
Submodule
1
External/LibAC
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit d247b843ee96c5081472b97e6cdf47ce6a238d57
|
1
External/LibZNI
vendored
1
External/LibZNI
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 0a022634c1a9e6a3ed63126cc4109c6030d054bd
|
29
ForgeCore.cs
Normal file
29
ForgeCore.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using ForgeCoreAPI;
|
||||
using LibAC.Arguments;
|
||||
|
||||
namespace ForgeCore;
|
||||
|
||||
public class ForgeCore
|
||||
{
|
||||
public static int main(string[] args)
|
||||
{
|
||||
PluginSystem.InitializeSystem();
|
||||
|
||||
Arguments arguments = ArgumentParser.Parse(args);
|
||||
if (arguments.HasArg("help") || arguments.Count == 0)
|
||||
{
|
||||
// Print the help message for the default CLI Args
|
||||
|
||||
ArgumentBuilder builder = new ArgumentBuilder();
|
||||
builder.withVersionArgument().withHelpArgument();
|
||||
|
||||
|
||||
Arguments defaults = builder.Build();
|
||||
Console.WriteLine(ArgumentHelpers.GenerateHelpMessage(defaults.GetAllArguments().ToList(), "ForgeCore"));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<StartupObject>Bot.Program</StartupObject>
|
||||
<StartupObject>ForgeCore.ForgeCore</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
|
@ -23,12 +23,22 @@
|
|||
<Content Remove="External/**/*" />
|
||||
<EmbeddedResource Remove="External/**/*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="ForgeCoreAPI/**/*" />
|
||||
<Compile Remove="ForgeCoreAPI/**/*" />
|
||||
<Content Remove="ForgeCoreAPI/**/*" />
|
||||
<EmbeddedResource Remove="ForgeCoreAPI/**/*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="OldSystem/**/*"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="External\LibZNI\LibZNI.csproj" />
|
||||
<ProjectReference Include="External\libremetaverse\LibreMetaverse.StructuredData\LibreMetaverse.StructuredData.csproj" />
|
||||
<ProjectReference Include="External\libremetaverse\LibreMetaverseTypes\LibreMetaverse.Types.csproj" />
|
||||
<ProjectReference Include="External\libremetaverse\LibreMetaverse\LibreMetaverse.csproj" />
|
||||
<ProjectReference Include="ForgeCoreAPI\ForgeCoreAPI.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -17,7 +17,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibreMetaverse.Utilities",
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ForgeCore", "ForgeCore.csproj", "{5936E1A6-1891-4EA4-B595-442750FAEF80}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibZNI", "External\LibZNI\LibZNI.csproj", "{7758FB70-E6A3-4159-A20B-9F64105A0840}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibAC", "External\LibAC\LibAC.csproj", "{7758FB70-E6A3-4159-A20B-9F64105A0840}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ForgeCoreAPI", "ForgeCoreAPI\ForgeCoreAPI.csproj", "{F3DA818D-F6AA-4286-ADDE-238B52F89838}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -52,6 +54,10 @@ Global
|
|||
{7758FB70-E6A3-4159-A20B-9F64105A0840}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7758FB70-E6A3-4159-A20B-9F64105A0840}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7758FB70-E6A3-4159-A20B-9F64105A0840}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F3DA818D-F6AA-4286-ADDE-238B52F89838}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F3DA818D-F6AA-4286-ADDE-238B52F89838}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F3DA818D-F6AA-4286-ADDE-238B52F89838}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F3DA818D-F6AA-4286-ADDE-238B52F89838}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{E5E8957B-7015-4DF0-AE67-0BEDBF9BA302} = {EC162775-3331-430A-AA32-9700375DECCA}
|
||||
|
|
67
ForgeCoreAPI/ACS/AccessToken.cs
Normal file
67
ForgeCoreAPI/ACS/AccessToken.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using ForgeCoreAPI.Utilities;
|
||||
using LibAC.NBT;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace ForgeCoreAPI.ACS;
|
||||
|
||||
/// <summary>
|
||||
/// This represents the access token which would be utilized to authenticate commands
|
||||
/// </summary>
|
||||
public class AccessToken
|
||||
{
|
||||
public string TokenName { get; set; } = "";
|
||||
public AccessTokenType TokenType { get; set; } = AccessTokenType.READ;
|
||||
private string AccessTokenSeed { get; set; } = "";
|
||||
public DateTime Expiration { get; set; } = DateTime.Now.AddDays(30);
|
||||
|
||||
public static AccessToken Create(string tokenName, AccessTokenType tokenType, bool expires = true)
|
||||
{
|
||||
AccessToken AT = new AccessToken();
|
||||
AT.TokenName = tokenName;
|
||||
AT.TokenType = tokenType;
|
||||
if (!expires)
|
||||
AT.Expiration = DateTime.MinValue;
|
||||
|
||||
var bytes = HashHelpers.EncodeMD5(HashHelpers.MakeRandomBytes(255));
|
||||
|
||||
AT.AccessTokenSeed = Convert.ToHexString(bytes);
|
||||
return AT;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Convert.ToHexString(HashHelpers.EncodeMD5(Encoding.UTF8.GetBytes($"{TokenName}:${AccessTokenSeed}")));
|
||||
}
|
||||
|
||||
public CompoundTag Save()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.Put("name", StringTag.ValueOf(TokenName));
|
||||
tag.Put("type", ByteTag.ValueOf((byte)TokenType));
|
||||
tag.Put("seed", StringTag.ValueOf(AccessTokenSeed));
|
||||
NbtUtils.WriteBoolean(tag, "expires", Expiration == DateTime.MinValue);
|
||||
tag.Put("expiration", StringTag.ValueOf(Expiration.ToString()));
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static AccessToken Load(CompoundTag tag)
|
||||
{
|
||||
AccessToken AT = new AccessToken();
|
||||
AT.TokenName = tag["name"].AsString();
|
||||
AT.TokenType = (AccessTokenType)tag["type"].AsByte();
|
||||
AT.AccessTokenSeed = tag["seed"].AsString();
|
||||
AT.Expiration = DateTime.Parse(tag["expiration"].AsString());
|
||||
|
||||
return AT;
|
||||
}
|
||||
}
|
||||
|
||||
public enum AccessTokenType : byte
|
||||
{
|
||||
FULL = 0,
|
||||
READ = 1
|
||||
}
|
1
ForgeCoreAPI/Commands.cs
Normal file
1
ForgeCoreAPI/Commands.cs
Normal file
|
@ -0,0 +1 @@
|
|||
namespace ForgeCoreAPI;
|
15
ForgeCoreAPI/ForgeCoreAPI.csproj
Normal file
15
ForgeCoreAPI/ForgeCoreAPI.csproj
Normal file
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<ProjectReference Include="..\External\LibAC\LibAC.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
23
ForgeCoreAPI/IMessage.cs
Normal file
23
ForgeCoreAPI/IMessage.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using LibAC.Arguments;
|
||||
|
||||
namespace ForgeCoreAPI;
|
||||
|
||||
/// <summary>
|
||||
/// A simple interface representing a message passed into the bot server
|
||||
/// </summary>
|
||||
public interface IMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the stored message
|
||||
/// </summary>
|
||||
/// <returns>Raw message</returns>
|
||||
public string GetMessage();
|
||||
|
||||
/// <summary>
|
||||
/// Set the stored raw message
|
||||
/// </summary>
|
||||
/// <param name="Message">Raw string message</param>
|
||||
public void SetMessage(string Message);
|
||||
|
||||
public Arguments ParseCommand();
|
||||
}
|
59
ForgeCoreAPI/IPlugin.cs
Normal file
59
ForgeCoreAPI/IPlugin.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using LibAC.NBT;
|
||||
|
||||
namespace ForgeCoreAPI;
|
||||
|
||||
public interface IPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Called on plugin load.
|
||||
/// <br/>
|
||||
/// DOES NOT INDICATE PLUGIN ENABLE / START
|
||||
/// </summary>
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is enabled by the server
|
||||
/// </summary>
|
||||
void Enable();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is disabled by the server.
|
||||
///<br/>
|
||||
/// NOTE: This action also indicates the plugin will no longer receive calls to the tick method.
|
||||
/// </summary>
|
||||
void Disable();
|
||||
|
||||
/// <summary>
|
||||
/// Called every 5 seconds by the master server
|
||||
/// </summary>
|
||||
void tick();
|
||||
|
||||
/// <summary>
|
||||
/// Provides the plugin with a copy of its saved configuration data
|
||||
/// </summary>
|
||||
/// <param name="config">A final readonly configuration object</param>
|
||||
void LoadConfig(CompoundTag config);
|
||||
|
||||
/// <summary>
|
||||
/// Requested by the master server when the state is being saved. This does not indicate shutdown of the server.
|
||||
/// </summary>
|
||||
/// <returns>A serialized copy of the plugin configuration data. This should include all settings and data.</returns>
|
||||
CompoundTag SaveConfig();
|
||||
|
||||
/// <summary>
|
||||
/// This is called when no plugin memory exists, or when a reset has been called for this plugin.
|
||||
/// </summary>
|
||||
void ResetMemory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks a class as a valid plugin. Plugin Class must also implement IPlugin
|
||||
/// </summary>
|
||||
public class ForgeCorePluginAttribute : Attribute
|
||||
{
|
||||
public string pluginName;
|
||||
public ForgeCorePluginAttribute(string PluginName)
|
||||
{
|
||||
this.pluginName = PluginName;
|
||||
}
|
||||
}
|
52
ForgeCoreAPI/PluginSystem.cs
Normal file
52
ForgeCoreAPI/PluginSystem.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System.Reflection;
|
||||
using LibAC.NBT;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace ForgeCoreAPI;
|
||||
|
||||
public class PluginSystem
|
||||
{
|
||||
public static List<IPlugin> Plugins = new List<IPlugin>();
|
||||
|
||||
public static void InitializeSystem()
|
||||
{
|
||||
CompoundTag pluginsData = NbtIo.Read("PluginStorage.dat");
|
||||
// Search the Plugins directory for DLL files
|
||||
string[] files = Directory.GetFiles("Plugins", "*.dll");
|
||||
|
||||
// Begin loading assemblies
|
||||
foreach (var file in files)
|
||||
{
|
||||
Assembly asm = Assembly.LoadFile(file);
|
||||
// Scan types for ForgeCorePlugin attribute
|
||||
|
||||
foreach (var types in asm.GetTypes())
|
||||
{
|
||||
if (types.GetCustomAttribute<ForgeCorePluginAttribute>() != null)
|
||||
{
|
||||
IPlugin plugin = Activator.CreateInstance(types) as IPlugin;
|
||||
plugin.Initialize();
|
||||
|
||||
ForgeCorePluginAttribute attrib = types.GetCustomAttribute<ForgeCorePluginAttribute>();
|
||||
|
||||
Tag? pluginStore = pluginsData.Get(attrib.pluginName);
|
||||
if (pluginStore == null)
|
||||
{
|
||||
plugin.ResetMemory();
|
||||
}
|
||||
else
|
||||
{
|
||||
CompoundTag tag = (CompoundTag) pluginStore;
|
||||
CompoundTag dataTag = tag["data"] as CompoundTag;
|
||||
|
||||
plugin.LoadConfig(dataTag);
|
||||
if(tag.Get("enabled").AsByte() == 1) plugin.Enable();
|
||||
else plugin.Disable();
|
||||
}
|
||||
|
||||
Plugins.Add(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
ForgeCoreAPI/Utilities/HashHelpers.cs
Normal file
19
ForgeCoreAPI/Utilities/HashHelpers.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Security.Cryptography;
|
||||
|
||||
namespace ForgeCoreAPI.Utilities;
|
||||
|
||||
public class HashHelpers
|
||||
{
|
||||
public static byte[] EncodeMD5(byte[] input)
|
||||
{
|
||||
MD5 md5 = MD5.Create();
|
||||
return md5.ComputeHash(input);
|
||||
}
|
||||
|
||||
public static byte[] MakeRandomBytes(int length)
|
||||
{
|
||||
ByteLayer A = new ByteLayer();
|
||||
A.InsertRandomBytes(length);
|
||||
return A.Bytes;
|
||||
}
|
||||
}
|
56
Jenkinsfile
vendored
Normal file
56
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
pipeline {
|
||||
agent any
|
||||
options {
|
||||
buildDiscarder (
|
||||
logRotator(
|
||||
numToKeepStr: '5'
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
stages {
|
||||
stage("Build on Linux") {
|
||||
agent {
|
||||
label 'linux'
|
||||
}
|
||||
|
||||
steps {
|
||||
script {
|
||||
sh '''
|
||||
dotnet restore
|
||||
|
||||
dotnet publish ForgeCore.csproj --nologo -c Release --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
archiveArtifacts artifacts: "bin/Release/net8.0/publish/ForgeCore"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage("Build on Windows") {
|
||||
agent {
|
||||
label 'windows'
|
||||
}
|
||||
|
||||
steps {
|
||||
script {
|
||||
bat '''
|
||||
dotnet restore
|
||||
|
||||
dotnet publish ForgeCore.csproj --nologo -c Release --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
archiveArtifacts artifacts:"bin\\Release\\net8.0\\publish\\ForgeCore.exe"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ using System.Text;
|
|||
using OpenMetaverse;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bot
|
||||
namespace ForgeCore
|
||||
{
|
||||
public sealed class BotSession
|
||||
{
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
|
||||
namespace Bot
|
||||
namespace ForgeCore
|
||||
{
|
||||
public class Logger
|
||||
{
|
Loading…
Add table
Add a link
Reference in a new issue