Skip to content

Commit

Permalink
Dev (#9)
Browse files Browse the repository at this point in the history
* Normalize paths

* Update workflows

* Update workflows

* Update workflows

* Update csproj build dirs

* Update csproj build dirs

* Fix bugs

* Directories are hard

* Dont zip zip

* Rename to support CS#

* Fix nightly file name

* Debug

* Try referencing class directly

* Update dependabot

* Update gitignore and command tests

* More tests:

* Basic gang creation working
  • Loading branch information
MSWS authored Sep 3, 2024
1 parent 00f0190 commit 11ffe34
Show file tree
Hide file tree
Showing 32 changed files with 497 additions and 75 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: dev
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: main
open-pull-requests-limit: 0
52 changes: 31 additions & 21 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ name: "CodeQL"
on:
push:
branches: [ "main", "dev" ]
paths:
- 'Gangs*/**'
- '.github/workflows/nightly.yml'
- 'Core/**'
- 'Commands/**'
pull_request:
branches: [ "main" ]
paths:
- 'Gangs*/**'
- '.github/workflows/nightly.yml'
- 'Core/**'
- 'Commands/**'
schedule:
- cron: '34 12 * * 6'

Expand Down Expand Up @@ -43,8 +53,8 @@ jobs:
fail-fast: false
matrix:
include:
- language: csharp
build-mode: none
- language: csharp
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
Expand All @@ -54,23 +64,23 @@ jobs:
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
8 changes: 6 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ on:
push:
paths:
- 'Gangs*/**'
- '.github/workflows/dotnet.yml'
- '.github/workflows/nightly.yml'
- 'Core/**'
- 'Commands/**'
pull_request:
paths:
- 'Gangs*/**'
- '.github/workflows/dotnet.yml'
- '.github/workflows/nightly.yml'
- 'Core/**'
- 'Commands/**'

jobs:
build:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
paths:
- 'Gangs*/**'
- '.github/workflows/nightly.yml'
- '.github/workflows/release.yml'
- 'Core/**'
- 'Commands/**'

jobs:
build:
Expand All @@ -29,8 +32,8 @@ jobs:

- run: |
dotnet restore
dotnet build Core/Core.csproj --no-restore
dotnet publish Core/Core.csproj --no-build --no-restore
dotnet build Gangs/Gangs.csproj --no-restore
dotnet publish Gangs/Gangs.csproj --no-build --no-restore
- uses: actions/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/[email protected]
with:
name: gangs
path: build/Gangs
path: build/
# If build didn't put any artifacts in the build folder, consider it an error
if-no-files-found: error

Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
/_ReSharper.Caches/
Gangs.zip
build
.idea/
*.DotSettings.user
5 changes: 2 additions & 3 deletions Commands/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ namespace Commands;

public class CommandManager(IGangManager gangMgr)
: MockCommandManager, IPluginBehavior {
private BasePlugin plugin = null!;
private BasePlugin? plugin;

public void Start(BasePlugin? basePlugin, bool hotReload) {
ArgumentNullException.ThrowIfNull(basePlugin, nameof(basePlugin));
plugin = basePlugin;

RegisterCommand(new GangCommand(gangMgr));
}

public override bool RegisterCommand(ICommand command) {
base.RegisterCommand(command);
plugin.AddCommand(command.Name, command.Description ?? string.Empty,
plugin?.AddCommand(command.Name, command.Description ?? string.Empty,
(player, info) => {
var wrapper = player == null ? null : new PlayerWrapper(player);
var args = info.GetCommandString.Split(" ");
Expand Down
11 changes: 6 additions & 5 deletions Commands/GangCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ public class GangCommand(IGangManager gangMgr) : ICommand {

public async Task<CommandResult> Execute(PlayerWrapper? executor,
CommandInfoWrapper info) {
if (info.ArgCount == 0 || info[0] != Name) {
if (info.ArgCount == 0)
throw new InvalidOperationException(
"Attempted to execute GangCommand with no arguments");
if (info.ArgCount == 0)
throw new InvalidOperationException(
"Attempted to execute GangCommand with no arguments");
if (info[0] != Name)
throw new InvalidOperationException(
$"Attempted to execute GangCommand with invalid name: {info[0]}");
}


if (info.ArgCount == 1) return CommandResult.INVALID_ARGS;

if (!sub.TryGetValue(info[1], out var command)) {
// print usage
// info.ReplySync("Usage: /css_gang [create|help]");
return CommandResult.UNKNOWN_COMMAND;
}

Expand Down
13 changes: 11 additions & 2 deletions Commands/gang/CreateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ namespace Commands.gang;
public class CreateCommand(IGangManager gang) : ICommand {
public string Name => "create";
public string? Description => "Creates a new gang";
public string Usage => "[name]";

public async Task<CommandResult> Execute(PlayerWrapper? executor,
CommandInfoWrapper info) {
if (executor == null) { return CommandResult.PLAYER_ONLY; }

if (info.ArgCount < 2) {
info.ReplySync("Please provide a name for the gang");
return CommandResult.FAILURE;
return CommandResult.INVALID_ARGS;
}

var name = string.Join(' ', info.ArgString.Split(" ").Skip(1));
Expand All @@ -33,6 +34,14 @@ public async Task<CommandResult> Execute(PlayerWrapper? executor,
return CommandResult.FAILURE;
}

throw new NotImplementedException();
var newGang = await gang.CreateGang(name, executor.Steam);

if (newGang == null) {
info.ReplySync("Failed to create gang");
return CommandResult.FAILURE;
}

info.ReplySync($"Gang '{name}' (#{newGang.GangId}) created successfully");
return CommandResult.SUCCESS;
}
}
2 changes: 1 addition & 1 deletion Gangs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GangsAPI", "GangsAPI\GangsAPI.csproj", "{787D12D8-1310-4042-ADCE-102E517F269E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{3EA38296-9022-4874-8309-872388D884DE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gangs", "Gangs\Gangs.csproj", "{3EA38296-9022-4874-8309-872388D884DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GangsTest", "GangsTest\GangsTest.csproj", "{B1D1E7C7-BDF3-4238-9025-4FEB2B7DAB89}"
EndProject
Expand Down
3 changes: 3 additions & 0 deletions Core/CS2Gangs.cs → Gangs/CS2Gangs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public override void Load(bool hotReload) {
var extensions = scope.ServiceProvider.GetServices<IPluginBehavior>()
.ToImmutableList();

Logger.LogInformation("[Gangs] Loading {Count} extensions",
extensions.Count);

foreach (var ext in extensions) {
RegisterAllAttributes(ext);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace GangsImpl;

public class GangServiceCollection : IPluginServiceCollection<IGangPlugin> {
public class GangServiceCollection : IPluginServiceCollection<CS2Gangs> {
public void ConfigureServices(IServiceCollection serviceCollection) {
serviceCollection.AddPluginBehavior<IGangManager, MockGangManager>();
serviceCollection.AddPluginBehavior<IPlayerManager, MockPlayerManager>();
Expand Down
15 changes: 14 additions & 1 deletion Core/Core.csproj → Gangs/Gangs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@
<PackageReference Include="xunit" Version="2.9.0"/>
</ItemGroup>

<ItemGroup>
<Compile Remove="build\**" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Remove="build\**" />
</ItemGroup>

<ItemGroup>
<None Remove="build\**" />
<None Remove="Gangs.zip" />
</ItemGroup>

<PropertyGroup>
<!--Publish Configuration-->
<PublishBaseDirectory>$(MSBuildThisFileDirectory)/../../build</PublishBaseDirectory>
<PublishBaseDirectory>$(MSBuildThisFileDirectory)/../build</PublishBaseDirectory>
<PublishDir>$(PublishBaseDirectory)/Gangs</PublishDir>

<PublishRelease>false</PublishRelease>
Expand Down
28 changes: 28 additions & 0 deletions GangsAPI/Data/Command/CommandResult.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
namespace GangsAPI.Data.Command;

public enum CommandResult {
/// <summary>
/// The command completed successfully
/// </summary>
SUCCESS,

/// <summary>
/// The command encountered an error or other
/// scenario that prevented success
/// </summary>
FAILURE,

/// <summary>
/// The command was improperly formatted
/// </summary>
UNKNOWN_COMMAND,

/// <summary>
/// The command has improper arguments, or
/// no sufficient arguments
/// </summary>
INVALID_ARGS,

/// <summary>
/// The executor of the command did not have
/// the required permissions
/// </summary>
NO_PERMISSION,


/// <summary>
/// This command can only be executed by a player
/// (i.e. not from the console)
/// </summary>
PLAYER_ONLY
}
6 changes: 4 additions & 2 deletions GangsAPI/Permissions/IGangRank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ public enum Permissions {
/// <summary>
/// The member has full access to all permissions.
/// </summary>
ADMINISTRATOR = 1 << 10,
ADMINISTRATOR = 1 << 10 | INVITE_OTHERS | KICK_OTHERS | BANK_DEPOSIT
| BANK_WITHDRAW | PROMOTE_OTHERS | DEMOTE_OTHERS | PURCHASE_PERKS
| MANAGE_PERKS | MANAGE_RANKS | CREATE_RANKS,

/// <summary>
/// The member is the owner of the gang, and can not be kicked.
/// </summary>
OWNER = 1 << 11
OWNER = 1 << 11 | ADMINISTRATOR
}

string Name { get; }
Expand Down
3 changes: 2 additions & 1 deletion GangsAPI/Services/Commands/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace GangsAPI.Services.Commands;

public interface ICommand : IPluginBehavior {
string Name { get; }
string? Description { get; }
string? Description => null;
string Usage => "";
string[] RequiredFlags => [];
string[] RequiredGroups => [];

Expand Down
8 changes: 6 additions & 2 deletions GangsImpl/Mock/MockCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public async Task<CommandResult> ProcessCommand(PlayerWrapper? executor,
if (!command.CanExecute(executor)) return CommandResult.NO_PERMISSION;

var result = CommandResult.FAILURE;
var info = new CommandInfoWrapper(executor, args: args);

await Task.Run(async () => {
result = await command.Execute(executor,
new CommandInfoWrapper(executor, args: args));
result = await command.Execute(executor, info);
});

if (result == CommandResult.PLAYER_ONLY)
info.ReplySync("This command can only be executed by a player");

return result;
}
}
6 changes: 4 additions & 2 deletions GangsImpl/Mock/MockGang.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public MockGang(int id, string name, ulong owner) {
Stats = new HashSet<IStat>();
Ranks = new HashSet<IGangRank>();

Members.Add(owner,
new MockGangRank(0, "Owner", IGangRank.Permissions.OWNER));
var ownerRank = new MockGangRank(0, "Owner", IGangRank.Permissions.OWNER);

Members.Add(owner, ownerRank);
Ranks.Add(ownerRank);
}

public int GangId { get; }
Expand Down
Loading

0 comments on commit 11ffe34

Please sign in to comment.