Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
fix: Playtime Tracker module
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Nov 11, 2023
1 parent 7747cff commit f438b2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void OnCommandCheckPlaytime(CCSPlayerController? player, CommandInfo comm

SaveClientTime(player);

MySqlQueryResult result = MySql!.Table("player_stats").Where($"steamid = '{player.SteamID}'").Select();
MySqlQueryResult result = MySql!.Table("k4times").Where($"`steam_id` = '{player.SteamID}'").Select();

if (result.Rows > 0)
{
Expand Down
14 changes: 11 additions & 3 deletions src/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@ public void LoadPlayerData(CCSPlayerController player)
RankColor = $"{ChatColors.Default}",
RankPoints = -1
};

PlayerSummaries[player] = newUser;

DateTime now = DateTime.UtcNow;

foreach (var key in new[] { "Connect", "Team", "Death" })
{
PlayerSummaries[player].Times[key] = now;
}

string escapedName = MySqlHelper.EscapeString(player.PlayerName);

MySqlQueryValue values = new MySqlQueryValue()
Expand Down Expand Up @@ -329,7 +337,7 @@ public bool IsStatsAllowed()

private void UpdatePlayerData(CCSPlayerController player, string field, double value)
{
MySql!.ExecuteNonQueryAsync($"UPDATE `player_stats` SET `{field}` = `{field}` + {(int)Math.Round(value)} WHERE `steam_id` = {player.SteamID};");
MySql!.ExecuteNonQueryAsync($"UPDATE `k4times` SET `{field}` = `{field}` + {(int)Math.Round(value)} WHERE `steam_id` = {player.SteamID};");
}

public void ResetKillStreak(int playerIndex)
Expand Down Expand Up @@ -389,7 +397,7 @@ public void SaveClientTime(CCSPlayerController player)
int allSeconds = (int)Math.Round((now - PlayerSummaries[player].Times["Connect"]).TotalSeconds);
int teamSeconds = (int)Math.Round((now - PlayerSummaries[player].Times["Team"]).TotalSeconds);

string updateQuery = $@"UPDATE `player_stats`
string updateQuery = $@"UPDATE `k4times`
SET `all` = `all` + {allSeconds}";

switch ((CsTeam)player.TeamNum)
Expand All @@ -415,7 +423,7 @@ public void SaveClientTime(CCSPlayerController player)
int deathSeconds = (int)Math.Round((now - PlayerSummaries[player].Times["Death"]).TotalSeconds);
updateQuery += $", `{field}` = `{field}` + {deathSeconds}";

updateQuery += $@" WHERE `steamid` = {player.SteamID}";
updateQuery += $@" WHERE `steam_id` = {player.SteamID}";

MySql!.ExecuteNonQueryAsync(updateQuery);

Expand Down
2 changes: 1 addition & 1 deletion src/K4-System.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace K4ryuuSystem
public partial class K4System : BasePlugin
{
public override string ModuleName => "K4-System";
public override string ModuleVersion => "v1.0.0";
public override string ModuleVersion => "v1.0.1";
public override string ModuleAuthor => "K4ryuu";

public override void Load(bool hotReload)
Expand Down

0 comments on commit f438b2a

Please sign in to comment.