Skip to content

Commit 81c9f97

Browse files
authored
0.5
1 parent 9919102 commit 81c9f97

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

PlayerSettings/CPlayerSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class CPlayerSettings
1616
public CPlayerSettings(CCSPlayerController _player)
1717
{
1818
player = _player;
19-
userid = Storage.GetUserId(player);
19+
Storage.GetUserIdAsync(player, (userid) => this.userid = userid);
2020
cached_values = new Dictionary<string, string>();
2121
}
2222

@@ -45,7 +45,7 @@ public int UserId()
4545

4646
public bool EqualPlayer(CCSPlayerController _player)
4747
{
48-
return (player == _player);
48+
return player == _player;
4949
}
5050

5151
internal void ParseLoadedSettings(List<List<string>> rows)

PlayerSettings/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace PlayerSettings;
1212
public class PlayerSettingsCore : BasePlugin
1313
{
1414
public override string ModuleName => "PlayerSettings [Core]";
15-
public override string ModuleVersion => "0.4";
15+
public override string ModuleVersion => "0.5";
1616
public override string ModuleAuthor => "Nick Fox";
1717
public override string ModuleDescription => "One storage for player's settings (aka ClientCookies)";
1818

PlayerSettings/Storage.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void Init(BasePlugin plugin, string driver = "sqlite")
2424
db.QueryAsync("create table if not exists \"settings_users\" (\"id\" integer primary key AUTOINCREMENT, \"steam\" varchar(255) not null)", null, null, true);
2525
db.QueryAsync("create table if not exists \"settings_values\" (\"user_id\" int, \"param\" varchar(255) not null, \"value\" varchar(255) not null)", null, null, true);
2626
}
27-
27+
/*
2828
public static int GetUserId(CCSPlayerController player)
2929
{
3030
var steamid = player.SteamID;
@@ -35,6 +35,21 @@ public static int GetUserId(CCSPlayerController player)
3535
res = db.Query("select \"id\" from \"settings_users\" where \"steam\" = \"{ARG}\"", new List<string>([steamid.ToString()]));
3636
}
3737
return int.Parse(res[0][0]);
38+
}*/
39+
40+
public static void GetUserIdAsync(CCSPlayerController player, Action<int> callback)
41+
{
42+
var steamid = player.SteamID;
43+
db.QueryAsync("select \"id\" from \"settings_users\" where \"steam\" = \"{ARG}\"", new List<string>([steamid.ToString()]), (data) => {
44+
if (data.Count > 0)
45+
{
46+
callback(int.Parse(data[0][0]));
47+
}
48+
else
49+
db.QueryAsync("insert into \"settings_users\" (\"steam\") values (\"{ARG}\")", new List<string>([steamid.ToString()]), (data) => GetUserIdAsync(player, callback), true);
50+
});
51+
52+
3853
}
3954

4055
internal static void LoadSettings(int userid, Action<List<List<string>>> action)

0 commit comments

Comments
 (0)