Skip to content

Commit

Permalink
Added ban storage events, fixed Paths, added Warhead.IsLocked, change…
Browse files Browse the repository at this point in the history
…d .editorconfig (#81)
  • Loading branch information
zabszk authored Dec 16, 2022
1 parent 16fd5bd commit 7157c14
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 37 deletions.
8 changes: 7 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[*.cs]
[*]
charset = utf-8

[*.cs]

# CS0436: Type conflicts with imported type
dotnet_diagnostic.CS0436.severity = none
Expand Down Expand Up @@ -75,3 +78,6 @@ dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
indent_style = tab

insert_final_newline = false
trim_trailing_whitespace = true
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,11 @@ public static class EventManager
new EventParameter("PluginAPI.Core.Interfaces.IPlayer", false, "player"),
new EventParameter("Interactables.Interobjects.DoorUtils.DoorVariant", false, "door"),
new EventParameter("System.Boolean", false, "canOpen")) },
{ 102, new Event(
new EventParameter("BanDetails", false, "banDetails"),
new EventParameter("BanHandler+BanType", false, "banType")) },
{ 103, new Event(
new EventParameter("System.String", false, "id"),
new EventParameter("BanHandler+BanType", false, "banType")) },
};
}
9 changes: 9 additions & 0 deletions NwPluginAPI/Core/Warhead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public static bool WarheadUnlocked
set => Server.Instance.GetComponent<AlphaWarheadOutsitePanel>(true).keycardEntered = value;
}

/// <summary>
/// Gets or sets a value indicating whether the current warhead status cannot be changed by the player.
/// </summary>
public static bool IsLocked
{
get => AlphaWarheadController.Singleton.IsLocked;
set => AlphaWarheadController.Singleton.IsLocked = value;
}

/// <summary>
/// Gets a value indicating whether or not the warhead is detonated.
/// </summary>
Expand Down
54 changes: 35 additions & 19 deletions NwPluginAPI/Enums/ServerEventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public enum ServerEventType : int
/// <remarks>
/// Parameters: <see cref="SpawnableTeamType"/> team.
/// </remarks>
///
///
TeamRespawnSelected = 70,

/// <summary>
Expand Down Expand Up @@ -665,144 +665,160 @@ public enum ServerEventType : int
/// Event executed when SCP-173 tries to start/stop brackneck speeds.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player <see cref="bool"/> activate.
/// Parameters: <see cref="IPlayer"/> player <see cref="bool"/> activate.
/// </remarks>
Scp173BreakneckSpeeds = 84,

/// <summary>
/// Event executed when SCP-173 is seen by player.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player <see cref="IPlayer"/> target.
/// Parameters: <see cref="IPlayer"/> player <see cref="IPlayer"/> target.
/// </remarks>
Scp173NewObserver = 85,

/// <summary>
/// Event executed when SCP-173 tries to snap player neck.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player <see cref="IPlayer"/> target.
/// Parameters: <see cref="IPlayer"/> player <see cref="IPlayer"/> target.
/// </remarks>
Scp173SnapPlayer = 100,

/// <summary>
/// Event executed when SCP-939 tries to create amnestic cloud.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player.
/// Parameters: <see cref="IPlayer"/> player.
/// </remarks>
Scp939CreateAmnesticCloud = 86,

/// <summary>
/// Event executed when SCP-939 tries to lunge.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="Scp939LungeState"/> state.
/// Parameters: <see cref="IPlayer"/> player, <see cref="Scp939LungeState"/> state.
/// </remarks>
Scp939Lunge = 87,

/// <summary>
/// Event executed when SCP-939 tries to attack something.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="IDestructible"/> target.
/// Parameters: <see cref="IPlayer"/> player, <see cref="IDestructible"/> target.
/// </remarks>
Scp939Attack = 88,

/// <summary>
/// Event executed when SCP-079 gains experience.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="int"/> amount, <see cref="Scp079HudTranslation"/> reason.
/// Parameters: <see cref="IPlayer"/> player, <see cref="int"/> amount, <see cref="Scp079HudTranslation"/> reason.
/// </remarks>
Scp079GainExperience = 89,

/// <summary>
/// Event executed when SCP-079 level ups to new tier.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="int"/> tier.
/// Parameters: <see cref="IPlayer"/> player, <see cref="int"/> tier.
/// </remarks>
Scp079LevelUpTier = 90,

/// <summary>
/// Event executed when SCP-079 tries to use tesla.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="TeslaGate"/> tesla.
/// Parameters: <see cref="IPlayer"/> player, <see cref="TeslaGate"/> tesla.
/// </remarks>
Scp079UseTesla = 91,

/// <summary>
/// Event executed when SCP-079 lockdowns room.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="RoomIdentifier"/> room.
/// Parameters: <see cref="IPlayer"/> player, <see cref="RoomIdentifier"/> room.
/// </remarks>
Scp079LockdownRoom = 92,

/// <summary>
/// Event executed when SCP-079 cancels room lockdown.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="RoomIdentifier"/> room.
/// Parameters: <see cref="IPlayer"/> player, <see cref="RoomIdentifier"/> room.
/// </remarks>
Scp079CancelRoomLockdown = 101,

/// <summary>
/// Event executed when SCP-079 locks door.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="DoorVariant"/> door.
/// Parameters: <see cref="IPlayer"/> player, <see cref="DoorVariant"/> door.
/// </remarks>
Scp079LockDoor = 93,

/// <summary>
/// Event executed when SCP-079 unlocks door.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="DoorVariant"/> door.
/// Parameters: <see cref="IPlayer"/> player, <see cref="DoorVariant"/> door.
/// </remarks>
Scp079UnlockDoor = 94,

/// <summary>
/// Event executed when SCP-079 blackouts zone.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="FacilityZone"/> zone.
/// Parameters: <see cref="IPlayer"/> player, <see cref="FacilityZone"/> zone.
/// </remarks>
Scp079BlackoutZone = 95,

/// <summary>
/// Event executed when SCP-079 blackouts room.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="RoomIdentifier"/> room.
/// Parameters: <see cref="IPlayer"/> player, <see cref="RoomIdentifier"/> room.
/// </remarks>
Scp079BlackoutRoom = 96,

/// <summary>
/// Event executed when SCP-049 resurrects body.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="IPlayer"/> target, <see cref="Ragdoll"/> body.
/// Parameters: <see cref="IPlayer"/> player, <see cref="IPlayer"/> target, <see cref="Ragdoll"/> body.
/// </remarks>
Scp049ResurrectBody = 97,

/// <summary>
/// Event executed when SCP-049 starts resurrecting body.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="IPlayer"/> target, <see cref="Ragdoll"/> body, <see cref="bool"/> canResurrect.
/// Parameters: <see cref="IPlayer"/> player, <see cref="IPlayer"/> target, <see cref="Ragdoll"/> body, <see cref="bool"/> canResurrect.
/// </remarks>
Scp049StartResurrectingBody = 98,

/// <summary>
/// Event executed when player tries to interact with door.
/// </summary>
/// <remarks>
/// Parameters: <see cref="IPlayer"/> player, <see cref="DoorVariant"/> door, <see cref="bool"/> canOpen.
/// Parameters: <see cref="IPlayer"/> player, <see cref="DoorVariant"/> door, <see cref="bool"/> canOpen.
/// </remarks>
PlayerInteractDoor = 99,

/// <summary>
/// Event executed when a new ban issued and saved in the files.
/// </summary>
/// <remarks>
/// Parameters: <see cref="BanDetails"/> banDetails, <see cref="BanType"/> banType.
/// </remarks>
BanIssued = 102,

/// <summary>
/// Event executed when an existing ban is revoked and removed from the files.
/// </summary>
/// <remarks>
/// Parameters: <see cref="string"/> userId, <see cref="BanType"/> banType.
/// </remarks>
BanRevoked = 103,
}
}
16 changes: 11 additions & 5 deletions NwPluginAPI/Events/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ public static class EventManager
new EventParameter(typeof(IPlayer), "player"),
new EventParameter(typeof(DoorVariant), "door"),
new EventParameter(typeof(bool), "canOpen")) },
{ ServerEventType.BanIssued, new Event(
new EventParameter(typeof(BanDetails), "banDetails"),
new EventParameter(typeof(BanHandler.BanType), "banType")) },
{ ServerEventType.BanRevoked, new Event(
new EventParameter(typeof(string), "id"),
new EventParameter(typeof(BanHandler.BanType), "banType")) },
};

private static bool ValidateEvent(Type[] parameters, Type[] requiredParameters)
Expand Down Expand Up @@ -384,7 +390,7 @@ public static void RegisterAllEvents(object plugin)
Type pluginType = plugin.GetType();

if (!AssemblyLoader.PluginToAssembly.TryGetValue(plugin, out Assembly assembly)) return;

foreach(var type in assembly.GetTypes().Where(x => x.IsClass))
{
bool foundEvents = false;
Expand Down Expand Up @@ -423,9 +429,9 @@ public static void UnregisterAllEvents(object plugin)
Type pluginType = plugin.GetType();

foreach(var handler in Events
.SelectMany(x =>
.SelectMany(x =>
x.Value.Invokers.Where(y => y.Key == pluginType))
.SelectMany(x =>
.SelectMany(x =>
x.Value.Select(y => y.Target))
.Distinct())
{
Expand Down Expand Up @@ -528,7 +534,7 @@ static void RegisterEvents(Type plugin, object eventHandler)
Log.Debug($"Registered event &6{method.Name}&r (&6{pluginEvent.EventType}&r) in plugin &6{plugin.FullName}&r!", Log.DebugMode);
break;
}
}
}
}
}

Expand Down Expand Up @@ -611,7 +617,7 @@ public static T ExecuteEvent<T>(ServerEventType type, params object[] args) wher
Log.Error($"Failed executing event &6{invoker.Method.Name}&r (&6{type}&r) in plugin &6{invoker.Plugin.FullName}&r\n{ex}");
continue;
}

if (cancelled || result is null)
continue;

Expand Down
24 changes: 18 additions & 6 deletions NwPluginAPI/Events/IEventCancellation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static PreauthCancellationData RejectBanned(string banReason, long expira
{
if (banReason.Length > 400)
throw new ArgumentOutOfRangeException(nameof(banReason), "Reason can't be longer than 400 characters.");

return new PreauthCancellationData(RejectionReason.Banned, isForced, banReason, expiration: expiration);
}

Expand All @@ -90,7 +90,7 @@ public static PreauthCancellationData Reject(string customReason, bool isForced)
{
if (string.IsNullOrEmpty(customReason) || customReason.Length > 400)
throw new ArgumentOutOfRangeException(nameof(customReason), "Reason can't be null, empty or longer than 400 characters.");

return new PreauthCancellationData(RejectionReason.Custom, isForced, customReason: customReason);
}

Expand All @@ -109,7 +109,7 @@ public static PreauthCancellationData Reject(RejectionReason reason, bool isForc
case RejectionReason.Redirect:
case RejectionReason.Custom:
throw new Exception("Specified reason requires extra parameters. Please use the appropriate method.");

default:
return new PreauthCancellationData(reason, isForced);
}
Expand Down Expand Up @@ -202,28 +202,40 @@ public NetDataWriter GenerateWriter(out bool forced)
/// <inheritdoc />
public bool IsCancelled { get; }

/// <summary>
/// Determines whether the player should be allowed to join unconditionally.
/// </summary>
public bool BypassReservedSlotsLimit { get; }

// ReSharper disable once MemberCanBePrivate.Global
public readonly bool HasReservedSlot;

private PlayerCheckReservedSlotCancellationData(bool isCancelled, bool hasReservedSlot)
private PlayerCheckReservedSlotCancellationData(bool isCancelled, bool hasReservedSlot, bool bypassReservedSlotsLimit)
{
IsCancelled = isCancelled;
HasReservedSlot = hasReservedSlot;
BypassReservedSlotsLimit = bypassReservedSlotsLimit;
}

/// <summary>
/// Doesn't override the reserved slot check.
/// </summary>
/// <returns>The <see cref="PlayerCheckReservedSlotCancellationData"/>.</returns>
public static PlayerCheckReservedSlotCancellationData LeaveUnchanged() =>
new PlayerCheckReservedSlotCancellationData(false, false);
new PlayerCheckReservedSlotCancellationData(false, false, false);

/// <summary>
/// Overrides a reserved slot check.
/// </summary>
/// <param name="hasReservedSlot">Indicating whether or not the player has a reserved slot.</param>
/// <returns>The <see cref="PlayerCheckReservedSlotCancellationData"/>.</returns>
public static PlayerCheckReservedSlotCancellationData Override(bool hasReservedSlot) =>
new PlayerCheckReservedSlotCancellationData(true, hasReservedSlot);
new PlayerCheckReservedSlotCancellationData(true, hasReservedSlot, false);

/// <summary>
/// Bypasses the check of free reserved slots on the server and allows the connection unconditionally.
/// </summary>
/// <returns></returns>
public static PlayerCheckReservedSlotCancellationData BypassCheck() => new PlayerCheckReservedSlotCancellationData(true, true, true);
}
}
Loading

0 comments on commit 7157c14

Please sign in to comment.