Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32dbd4ad91 | ||
|
|
41a2f1a09d | ||
|
|
bee6b6434a |
@@ -153,6 +153,9 @@ public static class ClaimLinkChatCommand
|
|||||||
|
|
||||||
private static TextCommandResult? RequireOpOrOwner(IPlayer player, PlayerGroup group)
|
private static TextCommandResult? RequireOpOrOwner(IPlayer player, PlayerGroup group)
|
||||||
{
|
{
|
||||||
|
if (group.OwnerUID == player.PlayerUID)
|
||||||
|
return null;
|
||||||
|
|
||||||
PlayerGroupMembership? membership = player.GetGroup(group.Uid);
|
PlayerGroupMembership? membership = player.GetGroup(group.Uid);
|
||||||
return membership == null || membership.Level < EnumPlayerGroupMemberShip.Op
|
return membership == null || membership.Level < EnumPlayerGroupMemberShip.Op
|
||||||
? TextCommandResult.Error($"You must be an operator of '{group.Name}' to do that.")
|
? TextCommandResult.Error($"You must be an operator of '{group.Name}' to do that.")
|
||||||
@@ -321,7 +324,59 @@ public static class ClaimLinkChatCommand
|
|||||||
return TextCommandResult.Success($"'{groupName}' is no longer a claim link.");
|
return TextCommandResult.Success($"'{groupName}' is no longer a claim link.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public static TextCommandResult TransferOwnership(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink transferownership");
|
public static TextCommandResult TransferOwnership(TextCommandCallingArgs args)
|
||||||
|
{
|
||||||
|
string groupName = (string)args[0];
|
||||||
|
IPlayer target = (IPlayer)args[1];
|
||||||
|
IPlayer player = args.Caller.Player;
|
||||||
|
string playerUid = player.PlayerUID;
|
||||||
|
|
||||||
|
TextCommandResult? err = TryResolveGroup(groupName, out PlayerGroup group);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
err = TryResolveClaimLink(group, out _);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
err = RequireOwner(player, group);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
err = RequireMember(target, group);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
err = RequireNotAlreadyOwner(group, target);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
return Stage(playerUid, $"Ownership of '{groupName}' will be transferred to {target.PlayerName}.",
|
||||||
|
() => ExecuteTransferOwnership(group, target));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TextCommandResult? RequireNotAlreadyOwner(PlayerGroup group, IPlayer target)
|
||||||
|
{
|
||||||
|
return target.PlayerUID == group.OwnerUID
|
||||||
|
? TextCommandResult.Error($"{target.PlayerName} already owns '{group.Name}'.")
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TextCommandResult ExecuteTransferOwnership(PlayerGroup group, IPlayer target)
|
||||||
|
{
|
||||||
|
string oldOwnerUid = group.OwnerUID;
|
||||||
|
string targetUid = target.PlayerUID;
|
||||||
|
IPlayer? oldOwner = ClaimLinkModSystem.World.PlayerByUid(oldOwnerUid);
|
||||||
|
EnumPlayerGroupMemberShip? oldOwnerLevel = oldOwner?.GetGroup(group.Uid)?.Level;
|
||||||
|
EnumPlayerGroupMemberShip targetLevel = target.GetGroup(group.Uid)!.Level;
|
||||||
|
|
||||||
|
// TODO remove debug logging once transfer ownership persistence is confirmed tested
|
||||||
|
ClaimLinkModSystem.Logger.Notification(
|
||||||
|
$"claimlink: transferownership '{group.Name}' (uid {group.Uid}) BEFORE OwnerUID={oldOwnerUid} " +
|
||||||
|
$"(old owner {oldOwner?.PlayerName ?? oldOwnerUid} level={oldOwnerLevel}, new owner {target.PlayerName}/{targetUid} level={targetLevel})");
|
||||||
|
|
||||||
|
group.OwnerUID = targetUid;
|
||||||
|
|
||||||
|
ClaimLinkModSystem.Logger.Notification(
|
||||||
|
$"claimlink: transferownership '{group.Name}' (uid {group.Uid}) AFTER OwnerUID={group.OwnerUID}");
|
||||||
|
|
||||||
|
return TextCommandResult.Success($"'{group.Name}' is now owned by {target.PlayerName}.");
|
||||||
|
}
|
||||||
|
|
||||||
public static TextCommandResult Info(TextCommandCallingArgs args)
|
public static TextCommandResult Info(TextCommandCallingArgs args)
|
||||||
{
|
{
|
||||||
@@ -383,6 +438,24 @@ public static class ClaimLinkChatCommand
|
|||||||
public static TextCommandResult AdminDelete(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin delete");
|
public static TextCommandResult AdminDelete(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin delete");
|
||||||
public static TextCommandResult AdminUnlink(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin unlink");
|
public static TextCommandResult AdminUnlink(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin unlink");
|
||||||
public static TextCommandResult AdminKick(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin kick");
|
public static TextCommandResult AdminKick(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin kick");
|
||||||
public static TextCommandResult AdminTransferOwnership(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin transferownership");
|
public static TextCommandResult AdminTransferOwnership(TextCommandCallingArgs args)
|
||||||
|
{
|
||||||
|
string groupName = (string)args[0];
|
||||||
|
IPlayer target = (IPlayer)args[1];
|
||||||
|
|
||||||
|
TextCommandResult? err = TryResolveGroup(groupName, out PlayerGroup group);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
err = TryResolveClaimLink(group, out _);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
err = RequireMember(target, group);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
err = RequireNotAlreadyOwner(group, target);
|
||||||
|
if (err != null) return err;
|
||||||
|
|
||||||
|
return ExecuteTransferOwnership(group, target);
|
||||||
|
}
|
||||||
public static TextCommandResult AdminInfo(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin info");
|
public static TextCommandResult AdminInfo(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin info");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,13 @@ public class ClaimLinkModSystem : ModSystem
|
|||||||
ClaimLinkChatCommand.Register(api);
|
ClaimLinkChatCommand.Register(api);
|
||||||
|
|
||||||
api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect;
|
api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect;
|
||||||
|
|
||||||
|
// TODO remove debug logging once transfer ownership persistence is confirmed tested
|
||||||
|
foreach (ClaimLink link in Registry.All)
|
||||||
|
{
|
||||||
|
PlayerGroup group = Groups.PlayerGroupsById[link.GroupId];
|
||||||
|
Logger.Notification($"claimlink: startup state '{group.Name}' (uid {group.Uid}) OwnerUID={group.OwnerUID}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user