Skip to content

Commit

Permalink
Update docs, improve provisioning and command plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooshua committed Aug 29, 2023
1 parent 74156ca commit 3ceadf8
Show file tree
Hide file tree
Showing 29 changed files with 379 additions and 174 deletions.
7 changes: 0 additions & 7 deletions BitMod.sln
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitMod.Provision", "builtin
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "plugins", "plugins", "{40317A0E-F34B-4367-BF2C-C2540A521B28}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitMod.Gamemode.GunGame", "plugins\BitMod.Gamemode.GunGame\BitMod.Gamemode.GunGame.csproj", "{93EE784F-49A4-4BF4-90CF-D1C605404458}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -106,10 +104,6 @@ Global
{2FCD0D1B-C58A-406C-83F9-FD2EB3598F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FCD0D1B-C58A-406C-83F9-FD2EB3598F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FCD0D1B-C58A-406C-83F9-FD2EB3598F9F}.Release|Any CPU.Build.0 = Release|Any CPU
{93EE784F-49A4-4BF4-90CF-D1C605404458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93EE784F-49A4-4BF4-90CF-D1C605404458}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93EE784F-49A4-4BF4-90CF-D1C605404458}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93EE784F-49A4-4BF4-90CF-D1C605404458}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{20CD73A1-A74C-4205-AD74-9B48EEEFB3EC} = {621F6C25-527F-4BA1-BF59-1D19021A9B88}
Expand All @@ -126,6 +120,5 @@ Global
{0DF78B4C-26A7-4FF7-BD07-036981815125} = {CCEA8B6B-5212-4C12-BB31-A70501DE31D0}
{3FB356E0-587B-42EA-A1A0-C10AE6ADA621} = {CCEA8B6B-5212-4C12-BB31-A70501DE31D0}
{2FCD0D1B-C58A-406C-83F9-FD2EB3598F9F} = {CCEA8B6B-5212-4C12-BB31-A70501DE31D0}
{93EE784F-49A4-4BF4-90CF-D1C605404458} = {40317A0E-F34B-4367-BF2C-C2540A521B28}
EndGlobalSection
EndGlobal
5 changes: 0 additions & 5 deletions api/BitMod/BitMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ public void Start()

Logger.Information("[BitMod] Starting server on {@IP}:{@Port}", ip.ToString(), port);
_server.Start(ip, port);

while (true)
{

}
}

public void Stop()
Expand Down
1 change: 0 additions & 1 deletion api/BitMod/Compatibility/BitServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class BitServer : GameServer<BitPlayer>, IBitObject
public override string ToString()
=> $"{this.GameIP}:{this.GamePort}";


public static implicit operator string(BitServer value)
=> value.ToString();
}
13 changes: 13 additions & 0 deletions api/BitMod/Events/Core/StandardInputEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using BitMod.Events.Base;

namespace BitMod.Events.Core;

public class StandardInputEventArgs : IEventArgs
{
public StandardInputEventArgs(string contents)
{
Contents = contents;
}

public string Contents { get; }
}
2 changes: 1 addition & 1 deletion api/BitMod/Internal/Registries/SimpleEventRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Invoke(EventInput input)
}
catch (Exception ex)
{
_logger.Warning(ex, "Event handler failed during execution!");
_logger.Warning(ex, "Event handler for {@Type} failed during execution!", input.Type?.FullName);
if (Environment.DoNotCatchEventExceptions)
throw;
}
Expand Down
13 changes: 13 additions & 0 deletions builtin/BitMod.Commands/Builtin/HelloCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using BitMod.Commands.Attributes;
using BitMod.Commands.Sources;

namespace BitMod.Commands.Builtin;

public class HelloCommand
{

[BitCommand("hello", "Say Hello")]
public async Task OnHello(ICommandSource source)
=> source.Reply("[BitMod] Hello, there!");

}
8 changes: 4 additions & 4 deletions builtin/BitMod.Commands/Handlers/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ internal class CommandHandler
public CommandHandler(LilikoiContainer container)
{
Container = container;
Compiled = container.Compile<EventInput, Task<Directive>>();
Compiled = container.Compile<EventInput, Task>();
}

public LilikoiContainer Container { get; }

public Func<EventInput, Task<Directive>> Compiled { get; }
public Func<EventInput, Task> Compiled { get; }

public Directive Invoke(EventInput input)
=> Compiled(input).Result;
public void Invoke(EventInput input)
=> Compiled(input);
}
32 changes: 32 additions & 0 deletions builtin/BitMod.Commands/Hosts/StandardInputHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using BitMod.Attributes.Targets;
using BitMod.Commands.Extensions;
using BitMod.Commands.Handlers;
using BitMod.Commands.Sources.Internal;
using BitMod.Events.Core;
using BitMod.Internal.Public;

using Lilikoi.Standard;

using Serilog;

namespace BitMod.Commands.Hosts;

public class StandardInputHost
{

[Singleton]
private ILogger _logger;

[Singleton]
private PluginInvoker _invoker;

[BitEvent]
public async Task OnStandardInput(StandardInputEventArgs ev)
{
var source = new StandardInputSource(_logger);
var input = CommandInput.FromString(source, ev.Contents);

_invoker.Command(input);
}

}
32 changes: 32 additions & 0 deletions builtin/BitMod.Commands/Sources/Internal/StandardInputSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using BitMod.Compatibility;

using Serilog;

namespace BitMod.Commands.Sources.Internal;

public class StandardInputSource : ICommandSource
{
private readonly ILogger _logger;

public StandardInputSource(ILogger logger)
{
_logger = logger;
}

public bool IsRemote => true;

public bool IsAuthenticated => false;

public bool IsAssociatedWithGameServer => false;

public ulong Steam64 => ulong.MaxValue;

public BitServer? GameServer => null;

public BitPlayer? Player => null;

public void Reply(string message)
{
_logger.Information("[BitMod Commands] {@Msg}", message);
}
}
10 changes: 8 additions & 2 deletions builtin/BitMod.Flags/Public/FlagExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ public class FlagExtension : IExtension
public void Register(Mount mount)
{
var cfg = mount.Get<IConfigurationSystem>();
var logger = mount.Get<ILogger>();
var cfgObject = cfg.Get(FlagFile.NAME);
var flagFile = new FlagFile(cfgObject, mount.Get<ILogger>(), cfg);
mount.Store(flagFile);
var flagFile = new FlagFile(cfgObject, logger, cfg);

logger.Information("Registering FlagFile");
mount.Store<FlagFile>(flagFile);
}

public void Unregister(Mount mount)
{
var logger = mount.Get<ILogger>();
logger.Information("Unregistering FlagFile");

mount.Store<FlagFile>(null);
}
}
24 changes: 24 additions & 0 deletions builtin/BitMod.Provision/Config/ProvisionConfigAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using BitMod.Compatibility;
using BitMod.Configuration.Model;

namespace BitMod.Provision.Config;

public class ProvisionConfigAdapter
{
private IConfigObject _configObject;

public ProvisionConfigAdapter(IConfigObject configObject)
{
_configObject = configObject;
}

public ProvisionServerAdapter? GetServer(string server)
{
var child = _configObject.Get<IConfigObject>(server);

if (child == null)
return null;

return new ProvisionServerAdapter(child);
}
}
25 changes: 0 additions & 25 deletions builtin/BitMod.Provision/Config/ProvisionServer.cs

This file was deleted.

37 changes: 37 additions & 0 deletions builtin/BitMod.Provision/Config/ProvisionServerAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using BitMod.Configuration.Model;

namespace BitMod.Provision.Config;

public class ProvisionServerAdapter
{
private const string MAPCYCLE = "mapcycle";
private const string GAMEMODES = "gamemodes";
private IConfigObject _configObject;

public ProvisionServerAdapter(IConfigObject configObject)
{
_configObject = configObject;
}

public bool HasMapcycle()
=> _configObject.Get(MAPCYCLE) != null;

public bool HasGamemodes()
=> _configObject.Get(GAMEMODES) != null;

public string[]? GetMapcycle()
=> _configObject.Get<IConfigObject>(MAPCYCLE)?.AsList()
?.Select(model => model as IConfigSymbol)
?.Where(symbol => symbol != null)
?.Select(symbol => symbol.Symbol)
?.ToArray();

public string[]? GetGamemodes()
=> _configObject.Get<IConfigObject>(GAMEMODES)?.AsList()
?.Select(model => model as IConfigSymbol)
?.Where(symbol => symbol != null)
?.Select(symbol => symbol.Symbol)
?.ToArray();


}
68 changes: 22 additions & 46 deletions builtin/BitMod.Provision/Host/ProvisionHost.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using BattleBitAPI.Common;

using BitMod.Attributes.Injects;
using BitMod.Attributes.Targets;
using BitMod.Compatibility;
using BitMod.Configuration.Model;
using BitMod.Events.Meta;
using BitMod.Events.Server;
using BitMod.Provision.Config;
Expand All @@ -14,70 +17,43 @@ namespace BitMod.Provision.Host;

public class ProvisionHost
{

/*[Config("provisions")]
private Dictionary<string, ProvisionServer> _servers;
[Config("provisions")]
private IConfigObject _config;

[Singleton]
private ILogger _logger;

[Singleton]
private IConfigurationSystem _config;

[BitEvent]
public async Task OnPluginLoad(PluginLoadEvent ev)
public async Task OnServerConnected(GameServerConnectedEventArgs ev)
{
Provision(ev.Server);
}

[BitEvent]
public async Task OnGameServerConnected(GameServerConnectedEventArgs ev)
=> Provision(ev.Server);
[BitEvent]
public async Task OnRoundEnd(RoundEndedEventArgs ev)
=> Provision(ev.Server);
private void Provision(BitServer server)
public async Task OnServerRoundEnd(RoundEndedEventArgs ev)
{
if (_servers.TryGetValue($"{server.GameIP.ToString()}:{server.GamePort}", out var config))
Provision(server, config);
else
Provision(server, new ProvisionServer());
Provision(ev.Server);
}

private void Provision(BitServer server, ProvisionServer provision)
private void Provision(BitServer server)
{
_logger.Information("[BitMod Provision] Provisioning server {@Name} {@IP}:{@Port}", server.ServerName, server.GameIP, server.GamePort);
_logger.Information("[BitMod Provision] Current: {@Settings}; New: {@Settings}", server.ServerSettings, provision);
server.ServerSettings.BleedingEnabled = provision.BleedingEnabled;
server.ServerSettings.DamageMultiplier = provision.DamageMultiplier;
server.ServerSettings.SpectatorEnabled = provision.SpectatorsEnabled;
server.ServerSettings.HitMarkersEnabled = provision.HitMarkersEnabled;
server.ServerSettings.StamineEnabled = provision.StaminaEnabled;
server.ServerSettings.FriendlyFireEnabled = provision.FriendlyFireEnabled;
server.ServerSettings.PointLogEnabled = provision.PointLogEnabled;
server.ServerSettings.OnlyWinnerTeamCanVote = provision.OnlyWinnersCanVote;
var globalAdapter = new ProvisionConfigAdapter(_config);
var localAdapter = globalAdapter.GetServer(server);

if (provision.Gamemodes?.Count != 0 && provision.Gamemodes != null)
{
_logger.Information("[BitMod Provision] Gamemodes: {@Modes}", server.GamemodeRotation.GetGamemodeRotation().ToList());
foreach (string gamemode in server.GamemodeRotation.GetGamemodeRotation().ToList())
server.GamemodeRotation.RemoveFromRotation(gamemode);
if (localAdapter == null)
return;

foreach (string provisionGamemode in provision.Gamemodes)
server.GamemodeRotation.AddToRotation(provisionGamemode);
if (localAdapter.HasMapcycle())
{
_logger.Verbose("Provisioning {@Server}'s mapcycle to {@Mapcycle}", server.ToString(), localAdapter.GetMapcycle());
server.MapRotation.SetRotation(localAdapter.GetMapcycle());
}

if (provision.Maps?.Count != 0 && provision.Maps != null)
if (localAdapter.HasGamemodes())
{
_logger.Information("[BitMod Provision] Maps: {@Maps}", server.MapRotation.GetMapRotation().ToList());
foreach (string gamemode in server.MapRotation.GetMapRotation().ToList())
server.MapRotation.RemoveFromRotation(gamemode);
foreach (string provisionGamemode in provision.Maps)
server.MapRotation.AddToRotation(provisionGamemode);
_logger.Verbose("Provisioning {@Server}'s gamemodes to {@Gamemodes}", server.ToString(), localAdapter.GetGamemodes());
server.GamemodeRotation.SetRotation(localAdapter.GetGamemodes());
}
}*/
}
}
5 changes: 5 additions & 0 deletions builtin/Directory.Build.Targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions docs/Writerside/bd.tree
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
<toc-element topic="Plugins-Routing.topic"/>
</toc-element>

<toc-element topic="Embedding-BitMod.topic"/>

</instance-profile>
Loading

0 comments on commit 3ceadf8

Please sign in to comment.