Skip to content

Commit

Permalink
Rewrite to pgsql #minor
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-wos committed May 15, 2024
1 parent 7f12a0f commit d593bcb
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 275 deletions.
File renamed without changes.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bin/
obj/
compiled/
*.sln
.vs/
DataBaseService.cs
SqlExample.cs
2 changes: 1 addition & 1 deletion Core/.vscode/tasks.json → .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build",
"${workspaceFolder}/Core.csproj",
"--output",
"compiled/Core",
"//wsl.localhost/Debian/root/cs2/game/csgo/addons/counterstrikesharp/plugins/Core"
],
"problemMatcher": "$msCompile",
"group": {
Expand Down
7 changes: 6 additions & 1 deletion Core/Config.cs → Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ public class CoreConfig : BasePluginConfig
{
public override int Version { get; set; } = 1;

[JsonPropertyName("DatabaseType")]
public string DatabaseType { get; set; } = "postgres";

[JsonPropertyName("DatabaseHost")]
public string DatabaseHost { get; set; } = "";

[JsonPropertyName("DatabasePort")]
public int DatabasePort { get; set; } = 3036;
public int DatabasePort { get; set; } = 5432;

[JsonPropertyName("DatabaseUser")]
public string DatabaseUser { get; set; } = "";
Expand All @@ -22,5 +25,7 @@ public class CoreConfig : BasePluginConfig
[JsonPropertyName("DatabaseName")]
public string DatabaseName { get; set; } = "";

[JsonPropertyName("DatabaseKeepAlive")]
public int DatabaseKeepAlive { get; set; } = 30;
}
}
24 changes: 18 additions & 6 deletions Core/Core.cs → Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,35 @@ namespace Core;
public partial class Core : BasePlugin, IPluginConfig<CoreConfig>
{
public CoreConfig Config { get; set; } = new();
//internal static DataBase? _dataBase;
internal static DataBaseService? _dataBaseService;

Check failure on line 16 in Core.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'DataBaseService' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 16 in Core.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'DataBaseService' could not be found (are you missing a using directive or an assembly reference?)
internal static PostgresService? _postgresService;

public override string ModuleName => "Core";
public override string ModuleDescription => "";
public override string ModuleAuthor => "Oscar Wos-Szlaga";
public override string ModuleVersion => "0.0.1";


public void OnConfigParsed(CoreConfig config)
public async void OnConfigParsed(CoreConfig config)
{
_postgresService = new PostgresService(config);
await _postgresService.InitConnectAsync();
/*
var con = new NpgsqlConnection(
connectionString: "Server=127.0.0.1;Port=5432;User Id=cs2;Password=lol;Database=cs2db;");
con.Open();
using var cmd = new NpgsqlCommand();
cmd.Connection = con;
cmd.CommandText = $"DROP TABLE IF EXISTS teachers";
await cmd.ExecuteNonQueryAsync();
/*s
_dataBaseService = new DataBaseService(config);
_dataBaseService.TestAndCheckDataBaseTableAsync().GetAwaiter().GetResult();
Config = config;
_dataBaseService.TestAndCheckDataBaseTableAsync().GetAwaiter().GetResult(); 1
*/
Config = config;
}


Expand All @@ -38,7 +51,6 @@ public override void Load(bool hotReload)
[ConsoleCommand("css_hello", "Say hello in the player language")]
public void OnCommandHello(CCSPlayerController? player, CommandInfo command)
{
/*
if (player != null)
{
string playerName = player.PlayerName;
Expand All @@ -50,7 +62,7 @@ public void OnCommandHello(CCSPlayerController? player, CommandInfo command)


}
*/

if (player != null)
command.ReplyToCommand($"{Localizer["hello.player", player.PlayerName, player.GetLanguage()]}");
}
Expand Down
1 change: 1 addition & 0 deletions Core/Core.csproj → Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
<PackageReference Include="Dapper" Version="*" />
<PackageReference Include="MySqlConnector" Version="*" />
<PackageReference Include="Npgsql" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 0 additions & 5 deletions Core/.gitignore

This file was deleted.

169 changes: 0 additions & 169 deletions Core/DataBaseService.cs

This file was deleted.

93 changes: 0 additions & 93 deletions Core/SqlExample.cs

This file was deleted.

7 changes: 7 additions & 0 deletions Database.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Core
{
public class Database
{

}
}
Loading

0 comments on commit d593bcb

Please sign in to comment.