Skip to content

Commit

Permalink
feat: Add TestPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-wos committed May 28, 2024
1 parent 137b6df commit ec440d7
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 28 deletions.
3 changes: 3 additions & 0 deletions Sessions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Capabilities;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Timers;
using SessionsLibrary;
Expand All @@ -17,6 +18,8 @@ public void OnConfigParsed(SessionsConfig config)

public override void Load(bool hotReload)
{
Capabilities.RegisterPlayerCapability(Capability_Player, player => new SessionsPlayer(player, this));

string ip = _ip.GetPublicIp();
ushort port = (ushort)ConVar.Find("hostport")!.GetPrimitiveValue<int>();

Expand Down
10 changes: 5 additions & 5 deletions Sessions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="*" ExcludeAssets="runtime"/>
<PackageReference Include="Dapper" Version="*"/>
<PackageReference Include="Npgsql" Version="*"/>
<PackageReference Include="MySqlConnector" Version="*"/>
<PackageReference Include="CounterStrikeSharp.API" Version="*" ExcludeAssets="runtime" />
<PackageReference Include="Dapper" Version="*" />
<PackageReference Include="Npgsql" Version="*" />
<PackageReference Include="MySqlConnector" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
<Compile Remove = ".\SessionsLibrary\**" />
<Compile Remove = ".\TestPlugin\**" />
<Reference Include="SessionsLibrary">
<HintPath>SessionsLibrary\SessionsLibrary.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand Down
32 changes: 12 additions & 20 deletions SessionsLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
/*using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Capabilities;
using SessionsLibrary;

namespace Sessions;

public class SessionsPlayer : ISessions
public partial class Sessions
{
private readonly PlayerSQL? _player;
public static PlayerCapability<ISessionsPlayer> Capability_Player { get; } = new("sessions:player");
}

public SessionsPlayer(CCSPlayerController player)
{
_player = new PlayerSQL
{
Id = 1,
FirstSeen = DateTime.Now,
LastSeen = DateTime.Now,
Session = new SessionSQL
{
Id = 1
}
};
}
public class SessionsPlayer(CCSPlayerController player, Sessions plugin) : ISessionsPlayer
{
private readonly PlayerSQL? _player = plugin._players.TryGetValue(player.Slot, out PlayerSQL? value) ? value : null;

public PlayerSQL? Player => _player;
}
*/
public PlayerSQL? PlayerSQL => _player;
public SessionSQL? SessionSQL => _player?.Session;
}
5 changes: 3 additions & 2 deletions SessionsLibrary/ISessions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace SessionsLibrary;

public interface ISessions
public interface ISessionsPlayer
{
PlayerSQL? Player { get; }
PlayerSQL? PlayerSQL { get; }
SessionSQL? SessionSQL { get; }
}

public class ServerSQL
Expand Down
2 changes: 1 addition & 1 deletion SessionsLibrary/SessionsLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="*" ExcludeAssets="runtime"/>
<PackageReference Include="CounterStrikeSharp.API" Version="*" ExcludeAssets="runtime" />
</ItemGroup>

</Project>
Binary file modified SessionsLibrary/SessionsLibrary.dll
Binary file not shown.
Binary file modified SessionsLibrary/SessionsLibrary.pdb
Binary file not shown.
25 changes: 25 additions & 0 deletions TestPlugin/TestPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Capabilities;
using SessionsLibrary;

namespace TestPlugin;

public class TestPlugin : BasePlugin
{
public override string ModuleName => "TestPlugin";
public override string ModuleVersion => "1.0.0";

public static PlayerCapability<ISessionsPlayer> Capability_Player { get; } = new("sessions:player");

public override void Load(bool isReload)
{
foreach (CCSPlayerController player in Utilities.GetPlayers())
{
var temp = Capability_Player.Get(player);
var temp2 = temp.SessionSQL;

Console.WriteLine(temp2.Id);
}
}
}
21 changes: 21 additions & 0 deletions TestPlugin/TestPlugin.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="*" ExcludeAssets="runtime" />
</ItemGroup>

<ItemGroup>
<Reference Include="SessionsLibrary">
<HintPath>..\SessionsLibrary\obj\Debug\net8.0\SessionsLibrary.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>

</Project>

0 comments on commit ec440d7

Please sign in to comment.