Compare commits
1 Commits
cd32786115
...
342c6dfcb2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
342c6dfcb2 |
@@ -41,38 +41,38 @@ public class DefaultDataManager : IDataManager
|
||||
|
||||
protected virtual bool HandleGet(OnActionEventArgs e)
|
||||
{
|
||||
if (e.Action != DataManagerActions.Get)
|
||||
if (!e.Is(DataManagerActions.Get))
|
||||
return false;
|
||||
|
||||
// Character
|
||||
if (e.Action == DataManagerActions.Getter.Character)
|
||||
if (e.Is(DataManagerActions.Getter.Character))
|
||||
{
|
||||
// Get
|
||||
if (e.ActionType == DataManagerActionType.Set)
|
||||
if (e.Is(DataManagerActionType.Set))
|
||||
{
|
||||
if (e.Object is Group group && e.Parameters.GetAt(0, out string? name))
|
||||
if (e.Object is Group group && e.GetParam(0, out string? name))
|
||||
return e.SetResult(CreateCharacter(e.CurrentUser, name, group));
|
||||
}
|
||||
}
|
||||
|
||||
// Group
|
||||
if (e.Action == DataManagerActions.Getter.Group)
|
||||
if (e.Is(DataManagerActions.Getter.Group))
|
||||
{
|
||||
// Get
|
||||
if (e.ActionType == DataManagerActionType.Get)
|
||||
if (e.Is(DataManagerActionType.Get))
|
||||
{
|
||||
if (e.Parameters.GetAt(0, out string? name))
|
||||
if (e.GetParam(0, out string? name))
|
||||
return e.SetResult(CreateGroup(e.CurrentUser, name));
|
||||
}
|
||||
}
|
||||
|
||||
// User
|
||||
if (e.Action == DataManagerActions.Getter.UserAccount)
|
||||
if (e.Is(DataManagerActions.Getter.UserAccount))
|
||||
{
|
||||
// Get
|
||||
if (e.ActionType == DataManagerActionType.Get)
|
||||
if (e.Is(DataManagerActionType.Get))
|
||||
{
|
||||
if (e.Parameters.GetAt(0, out string? username) && e.Parameters.GetAt(1, out string? password))
|
||||
if (e.GetParam(0, out string? username) && e.GetParam(1, out string? password))
|
||||
return e.SetResult(CreateUserAccount(username, password));
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class DefaultDataManager : IDataManager
|
||||
|
||||
protected virtual bool HandleSave(OnActionEventArgs e)
|
||||
{
|
||||
if (e.Action != DataManagerActions.Save)
|
||||
if (!e.Is(DataManagerActions.Save))
|
||||
return false;
|
||||
|
||||
// ...
|
||||
@@ -96,7 +96,7 @@ public class DefaultDataManager : IDataManager
|
||||
|
||||
protected virtual bool HandleDelete(OnActionEventArgs e)
|
||||
{
|
||||
if (e.Action != DataManagerActions.Delete)
|
||||
if (!e.Is(DataManagerActions.Delete))
|
||||
return false;
|
||||
|
||||
// Character
|
||||
@@ -116,10 +116,10 @@ public class DefaultDataManager : IDataManager
|
||||
|
||||
protected virtual bool HandleAssociation(OnActionEventArgs e)
|
||||
{
|
||||
if (e.Action != DataManagerActions.Associate)
|
||||
if (!e.Is(DataManagerActions.Associate))
|
||||
return false;
|
||||
|
||||
if (e.Action == DataManagerActions.Association.Owner)
|
||||
if (e.Is(DataManagerActions.Association.Owner))
|
||||
{
|
||||
if (e.Object is Group group)
|
||||
{
|
||||
@@ -128,7 +128,7 @@ public class DefaultDataManager : IDataManager
|
||||
case DataManagerActionType.Get:
|
||||
return e.SetResultT(DataProvider.GetOwner(group));
|
||||
case DataManagerActionType.Set:
|
||||
if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile)
|
||||
if (e.GetParam(0, out UserProfile? profile))
|
||||
return DataProvider.SetOwner(group, profile);
|
||||
break;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public class DefaultDataManager : IDataManager
|
||||
case DataManagerActionType.Get:
|
||||
return e.SetResultT(DataProvider.GetOwner(character));
|
||||
case DataManagerActionType.Set:
|
||||
if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile)
|
||||
if (e.GetParam(0, out UserProfile? profile))
|
||||
return DataProvider.SetOwner(character, profile);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public static class Extensions
|
||||
return account.Type >= permissions;
|
||||
}
|
||||
|
||||
#region OnActionEventArgs
|
||||
|
||||
public static bool SetResult(this OnActionEventArgs @this, object? data)
|
||||
{
|
||||
@this.Result = data;
|
||||
@@ -33,4 +35,26 @@ public static class Extensions
|
||||
@this.Result = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool GetParam<T>(this OnActionEventArgs @this, int index, [NotNullWhen(true)] out T? result)
|
||||
{
|
||||
return @this.Parameters.GetAt(index, out result);
|
||||
}
|
||||
|
||||
public static bool Is(this OnActionEventArgs @this, UserType minLevel)
|
||||
{
|
||||
return @this.CurrentUser.HasPermission(minLevel);
|
||||
}
|
||||
|
||||
public static bool Is(this OnActionEventArgs @this, DataManagerActionType actionType)
|
||||
{
|
||||
return @this.ActionType == actionType;
|
||||
}
|
||||
|
||||
public static bool Is(this OnActionEventArgs @this, DataManagerAction action)
|
||||
{
|
||||
return @this.Action == action;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user