-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4777c7e
Showing
9 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34616.47 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayerSettings", "PlayerSettings\PlayerSettings.csproj", "{A3C30B17-9E3D-4CA3-81E0-91B1EBFEEB6C}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayerSettingsApi", "PlayerSettingsApi\PlayerSettingsApi.csproj", "{CEFCA2C1-6552-4C3C-A348-3E3D004D5D44}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A3C30B17-9E3D-4CA3-81E0-91B1EBFEEB6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A3C30B17-9E3D-4CA3-81E0-91B1EBFEEB6C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A3C30B17-9E3D-4CA3-81E0-91B1EBFEEB6C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A3C30B17-9E3D-4CA3-81E0-91B1EBFEEB6C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{CEFCA2C1-6552-4C3C-A348-3E3D004D5D44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CEFCA2C1-6552-4C3C-A348-3E3D004D5D44}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CEFCA2C1-6552-4C3C-A348-3E3D004D5D44}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CEFCA2C1-6552-4C3C-A348-3E3D004D5D44}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {7C957E67-975E-4328-B4BD-4DD82C04E59F} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PlayerSettings | ||
{ | ||
internal class CPlayerSettings | ||
{ | ||
private int userid; | ||
private static Dictionary<string, string> cached_values; | ||
|
||
public CPlayerSettings(int _userid) | ||
{ | ||
userid = _userid; | ||
cached_values = new Dictionary<string, string>(); | ||
} | ||
|
||
public string GetValue(string param, string default_value) | ||
{ | ||
string value; | ||
if(!cached_values.TryGetValue(param, out value)) | ||
{ | ||
value = Storage.GetUserSettingValue(userid, param, default_value); | ||
cached_values[param] = value; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
public void SetValue(string param, string value) | ||
{ | ||
cached_values[param] = value; | ||
Storage.SetUserSettingValue(userid, param, value); | ||
} | ||
|
||
public int UserId() | ||
{ | ||
return userid; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Attributes.Registration; | ||
using CounterStrikeSharp.API.Core.Capabilities; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using CounterStrikeSharp.API.Modules.Menu; | ||
|
||
|
||
namespace PlayerSettings; | ||
public class PlayerSettingsCore : BasePlugin | ||
{ | ||
public override string ModuleName => "PlayerSettings [Core]"; | ||
public override string ModuleVersion => "0.1"; | ||
public override string ModuleAuthor => "Nick Fox"; | ||
public override string ModuleDescription => "One storage for player's settings (aka ClientCookies)"; | ||
|
||
private ISettingsApi? _api; | ||
private readonly PluginCapability<ISettingsApi?> _pluginCapability = new("settings:nfcore"); | ||
public override void Load(bool hotReload) | ||
{ | ||
_api = new SettingsApi(); | ||
Capabilities.RegisterPluginCapability(_pluginCapability, () => _api); | ||
Storage.Init(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.233" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\PlayerSettingsApi\PlayerSettingsApi.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="AnyBaseLib"> | ||
<HintPath>..\AnyBaseLib.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
|
||
namespace PlayerSettings | ||
{ | ||
|
||
internal class SettingsApi : ISettingsApi | ||
{ | ||
List<CPlayerSettings> settings; | ||
public SettingsApi() | ||
{ | ||
settings = new List<CPlayerSettings>(); | ||
} | ||
|
||
private CPlayerSettings FindUser(int userid) | ||
{ | ||
foreach (var item in this.settings) | ||
{ | ||
if (item.UserId() == userid) | ||
{ | ||
return item; | ||
} | ||
} | ||
var newInst = new CPlayerSettings(userid); | ||
settings.Add(newInst); | ||
return newInst; | ||
} | ||
|
||
public string GetPlayerSettingsValue(CCSPlayerController player, string param, string default_value) | ||
{ | ||
return FindUser(Storage.GetUserId(player)).GetValue(param, default_value); | ||
} | ||
|
||
public void SetPlayerSettingsValue(CCSPlayerController player, string param, string value) | ||
{ | ||
FindUser(Storage.GetUserId(player)).SetValue(param, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using AnyBaseLib; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Entities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.WebSockets; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PlayerSettings | ||
{ | ||
internal static class Storage | ||
{ | ||
private static IAnyBase db; | ||
|
||
public static void Init(BasePlugin plugin, string driver = "sqlite") | ||
{ | ||
db = CAnyBase.Base(driver); | ||
db.Set(AnyBaseLib.Bases.CommitMode.AutoCommit, Path.Combine(plugin.ModuleDirectory,"menusets")); | ||
|
||
db.Init(); | ||
db.Query("create table if not exists \"users\" (\"id\" integer primary key AUTOINCREMENT, \"steam\" varchar(255) not null)", null, true); | ||
db.Query("create table if not exists \"settings\" (\"user_id\" int, \"param\" varchar(255) not null, \"value\" varchar(255) not null)", null, true); | ||
} | ||
|
||
public static int GetUserId(CCSPlayerController player) | ||
{ | ||
var steamid = player.SteamID; | ||
var res = db.Query("select \"id\" from users where \"steam\" = \"{ARG}\"", new List<string>([steamid.ToString()])); | ||
if(res.Count == 0) | ||
{ | ||
db.Query("insert into \"users\" (\"steam\") values (\"{ARG}\")", new List<string>([steamid.ToString()]), true); | ||
res = db.Query("select \"id\" from \"users\" where \"steam\" = \"{ARG}\"", new List<string>([steamid.ToString()])); | ||
} | ||
return int.Parse(res[0][0]); | ||
} | ||
|
||
public static string GetUserSettingValue(int userid, string param, string default_value) | ||
{ | ||
var res = db.Query("select \"value\" from \"settings\" where \"user_id\" = {ARG} and \"param\" = \"{ARG}\"", new List<string>([userid.ToString(), param])); | ||
if (res.Count == 0) | ||
{ | ||
db.Query("insert into \"settings\" (\"user_id\", \"param\",\"value\") values ({ARG},\"{ARG}\", \"{ARG}\")", new List<string>([userid.ToString(), param, default_value]), true); | ||
return default_value; | ||
} | ||
return res[0][0]; | ||
} | ||
|
||
public static void SetUserSettingValue(int userid, string param, string value) | ||
{ | ||
db.Query("update \"settings\" set \"value\" = \"{ARG}\" where \"user_id\" = {ARG} and \"param\" = \"{ARG}\"", new List<string>([value, userid.ToString(), param]), true); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PlayerSettings | ||
{ | ||
public interface ISettingsApi | ||
{ | ||
public string GetPlayerSettingsValue(CCSPlayerController player, string param, string default_value); | ||
public void SetPlayerSettingsValue(CCSPlayerController player, string param, string value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.233" /> | ||
</ItemGroup> | ||
|
||
</Project> |