Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复: Servertools 添加数据库错误 #91

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions ServerTools/DB/PlayerDeath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ServerTools.DB;

public class PlayerDeath : Dictionary<string, int>
{
public new int this[string key]
private new int this[string key]
{
get
{
Expand Down Expand Up @@ -47,9 +47,15 @@ private void ReadAll()

public void Add(string name)
{
this[name] += 1;
if (database.Query("UPDATE Death SET Count = @0 WHERE Name = @1", this[name], name) != 1)
database.Query("INSERT INTO `Death` (`Name`, `Count`) VALUES (@0, @1)", this[name], 1);

if (ContainsKey(name))
{
this[name] += 1;
database.Query("UPDATE Death SET Count = @0 WHERE Name = @1", this[name], name);
}
else
{
this[name] = 1;
database.Query("INSERT INTO `Death` (`Name`, `Count`) VALUES (@0, @1)", name, 1);
}
}
}
7 changes: 6 additions & 1 deletion ServerTools/DB/PlayerOnline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace ServerTools.DB;

public class PlayerOnline : Dictionary<string, int>
{
private HashSet<string> _players = new();
public new int this[string key]
{
get
Expand Down Expand Up @@ -42,6 +43,7 @@ public void ReadAll()
string username = reader.Get<string>("username");
int duration = reader.Get<int>("duration");
this[username] = duration;
_players.Add(username);
}
}

Expand All @@ -67,6 +69,7 @@ public bool Update(string Name, int duration)
}
public bool Insert(string Name, int duration)
{
_players.Add(Name);
return 1 == database.Query("INSERT INTO `OnlineDuration` (`username`, `duration`) VALUES (@0, @1)", Name, duration);
}

Expand All @@ -75,7 +78,9 @@ public bool Insert(string Name, int duration)

public void AddOrUpdate(string name, int duration)
{
if (!Update(name, duration))
if (_players.Contains(name))
Update(name, duration);
else
Insert(name, duration);
}

Expand Down
10 changes: 7 additions & 3 deletions ServerTools/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,17 @@ private void OnUpdate(EventArgs e)
if (TimerCount % 60 == 0)
{
Timer?.Invoke(e);
foreach (var ply in Deads)
if (Config.DeadTimer)
{
if (ply != null && ply.Active && ply.Dead)
foreach (var ply in Deads)
{
ply.SendInfoMessage(Config.DeadFormat, ply.RespawnTimer);
if (ply != null && ply.Active && ply.Dead)
{
ply.SendInfoMessage(Config.DeadFormat, ply.RespawnTimer);
}
}
}

}
}

Expand Down
Loading