Skip to content

Commit

Permalink
Fix bug:Permission group synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
尧杰 曾 committed Aug 4, 2022
1 parent 44121ab commit 535cb02
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion PermissionSync/Command/PermissionSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PermissionSync :IRocketCommand

public string Help => "Sync permission group between multiple servers";

public string Syntax => "<add | remove > <player> <PermiisonGroupId> [ExpireDate] ";
public string Syntax => "<add | remove > <player> <PermissionGroupId> [ExpireDate] ";

public AllowedCaller AllowedCaller => AllowedCaller.Both;

Expand Down
19 changes: 12 additions & 7 deletions PermissionSync/Database/DBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ public DBManager()
public void CheckSchama()
{
DBConnection.ExecuteQuery(true,
$"CREATE TABLE IF NOT EXISTS `{Main.Instance.Configuration.Instance.DatabaseTableName}` (`SteamID` BIGINT NOT NULL, `PermissionGroup` varchar(32) NOT NULL, `ExpireDate` datetime(6) NOT NULL DEFAULT '{DateTime.MaxValue}', `Operator` BIGINT NOT NULL)");
$"CREATE TABLE IF NOT EXISTS `{Main.Instance.Configuration.Instance.DatabaseTableName}` (`SteamID` BIGINT NOT NULL, `PermissionGroup` varchar(32) NOT NULL, `ExpireDate` datetime(6) NOT NULL DEFAULT '{DateTime.MaxValue}', `Operator`VARCHAR(32) NOT NULL)");
}

internal void PermissionSync(UnturnedPlayer player)
{
//UnturnedChat.Say(player, "[DEBUG] Sync permission");
var servergroupids = GetPlayerPermissionGroupId(player);
// Get Player's PermissionGroup
var dbgroups = GetDBPermissionGroup(player.CSteamID, EDBQueryType.ByStamID);
foreach (var dbgroup in dbgroups )
{
if( servergroupids.Contains(dbgroup.PermissionID))
if(servergroupids.Contains(dbgroup.PermissionID))
{
if(dbgroup.ExpireDate < DateTime.Now)
{
Expand All @@ -45,7 +47,7 @@ internal void PermissionSync(UnturnedPlayer player)
}
else
{
if(dbgroup.ExpireDate> DateTime.Now)
if(dbgroup.ExpireDate >= DateTime.Now)
{
R.Permissions.AddPlayerToGroup(dbgroup.PermissionID, player);
UnturnedChat.Say(player, Main.Instance.Translate("sync_permission",dbgroup.PermissionID));
Expand Down Expand Up @@ -76,24 +78,27 @@ public List<PermissionData> GetDBPermissionGroup(CSteamID steamID,EDBQueryType t
}
connection.Open();
var reader = command.ExecuteReader();
// Logger.LogWarning("[GetDB]");
while(reader.Read())
{
PermissionData permissionData = new PermissionData(new CSteamID((ulong)reader["SteamID"]), reader["PermissionGroup"].ToString(), DateTime.Parse(reader["ExpireDate"].ToString()), reader["Operator"].ToString());
PermissionData permissionData = new PermissionData(new CSteamID(Convert.ToUInt64(reader["SteamID"])), reader["PermissionGroup"].ToString(), DateTime.Parse(reader["ExpireDate"].ToString()), reader["Operator"].ToString());
permissionDatas.Add(permissionData);
//Logger.LogWarning("[DEBUG]SID:" + permissionData.SteamID + "PG:" + permissionData.PermissionID + "Date" + permissionData.ExpireDate);
}
//Logger.LogWarning("[GetDBS]");

}
catch
catch(Exception ex)
{

Logger.LogException(ex);
}
return permissionDatas;
}

private List<string> GetPlayerPermissionGroupId(UnturnedPlayer player)
{
var groupids = new List<string>();
var playergroups = R.Permissions.GetGroups(player, false);
var playergroups = R.Permissions.GetGroups(player, true);
foreach (var group in playergroups)
{
groupids.Add(group.Id);
Expand Down
2 changes: 1 addition & 1 deletion PermissionSync/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override void Unload()
public override TranslationList DefaultTranslations => new TranslationList
{
{"player_not_found","Player not found!" },
{"","" }
{"permission_expired","your permission group has been expired:{0}" }
};
}
}
4 changes: 2 additions & 2 deletions PermissionSync/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.2")]
[assembly: AssemblyFileVersion("1.0.0.2")]
[assembly: AssemblyVersion("1.0.0.3")]
[assembly: AssemblyFileVersion("1.0.0.3")]

0 comments on commit 535cb02

Please sign in to comment.