Skip to content

Commit

Permalink
Merge pull request #30 from UncomplicatedCustomServer/dev-main
Browse files Browse the repository at this point in the history
Update for version v2.2.0 for EXILED v8.9.4 - Candidate I
  • Loading branch information
FoxWorn3365 authored Jun 7, 2024
2 parents 0816aac + e1380f4 commit 2447e99
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Localization/README-FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<br><br>
</div>

**EXILED** >= `v8.8.1`
**EXILED** >= `v8.9.4`
<br><br>

## README Traduis
Expand Down Expand Up @@ -48,4 +48,4 @@ Lisez le [WIKI](https://github.com/UncomplicatedCustomServer/UncomplicatedCustom
**Discord:** `@foxworn`\
**Email:** `foxworn3365@gmail.com`
### Dr.Agenda
**Discord:** `dr.agenda`
**Discord:** `dr.agenda`
2 changes: 1 addition & 1 deletion Localization/README-IT.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<br><br>
</div>

**EXILED** >= `v8.8.1`
**EXILED** >= `v8.9.4`
<br><br>

## README tradotti
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<br><br>
</div>

**EXILED** >= `v8.8.1`
**EXILED** >= `v8.9.4`
<br><br>

## Localized READMEs
Expand Down
1 change: 1 addition & 0 deletions UncomplicatedCustomRoles/Commands/CommandParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public override void LoadGeneratedCommands()
RegisteredCommands.Add(new UCROwner());
RegisteredCommands.Add(new UCRRole());
RegisteredCommands.Add(new UCRSpawn());
RegisteredCommands.Add(new UCRReload());
}

public List<IUCRCommand> RegisteredCommands { get; } = new();
Expand Down
52 changes: 52 additions & 0 deletions UncomplicatedCustomRoles/Commands/UCRLogShare.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using CommandSystem;
using System;
using Exiled.Permissions.Extensions;
using Exiled.API.Features;
using System.Net;
using UncomplicatedCustomRoles.Manager;
using System.Net.Http;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace UncomplicatedCustomRoles.Commands
{
[CommandHandler(typeof(GameConsoleCommandHandler))]
internal class UCRLogShare : ParentCommand
{
public UCRLogShare() => LoadGeneratedCommands();

public override string Command { get; } = "ucrlogs";

public override string[] Aliases { get; } = new string[] { };

public override string Description { get; } = "Share the UCR Debug logs with the developers";

public override void LoadGeneratedCommands() { }

protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (sender.LogName is not "SERVER CONSOLE")
{
response = "Sorry but this command is reserved to the game console!";
return false;
}

long Start = DateTimeOffset.Now.ToUnixTimeMilliseconds();

HttpStatusCode Response = LogManager.SendReport(out HttpContent Content);
Dictionary<string, string> Data = JsonConvert.DeserializeObject<Dictionary<string, string>>(Plugin.HttpManager.RetriveString(Content));

if (Response is HttpStatusCode.OK && Data.ContainsKey("id"))
{
response = $"Successfully shared the UCR logs with the developers!\nSend this Id to the developers: {Data["id"]}\n\nTook {DateTimeOffset.Now.ToUnixTimeMilliseconds() - Start}ms";
}
else
{
response = $"Failed to share the UCR logs with the developers: Server says: {Response}";
}


return true;
}
}
}
97 changes: 97 additions & 0 deletions UncomplicatedCustomRoles/Commands/UCRReload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using CommandSystem;
using Exiled.API.Features;
using System.Collections.Generic;
using UncomplicatedCustomRoles.Elements;
using UncomplicatedCustomRoles.Interfaces;
using UncomplicatedCustomRoles.Manager;

namespace UncomplicatedCustomRoles.Commands
{
public class UCRReload : IUCRCommand
{
public string Name { get; } = "reload";

public string Description { get; } = "Reload every custom role loaded and search for new";

public string RequiredPermission { get; } = "ucr.reload";

public bool Executor(List<string> arguments, ICommandSender sender, out string response)
{
if (!Round.IsStarted)
{
response = "Sorry but you can't use this command if the round is not started!";
return false;
}

// Create a copy of the custom roles Dictionary
Dictionary<int, ICustomRole> Roles = new();

Plugin.FileConfigs.LoadAction((CustomRole Role) =>
{
if (!SpawnManager.SubclassValidator(Role))
{
LogManager.Warn($"[RL] Failed to register the UCR role with the ID {Role.Id} due to the validator check!");
return;
}
if (!Roles.ContainsKey(Role.Id))
{
Roles.Add(Role.Id, Role);
if (Plugin.Instance.Config.EnableBasicLogs)
{
LogManager.Info($"[RL] Successfully registered the UCR role with the ID {Role.Id} and {Role.Name} as name!");
}
return;
}
LogManager.Warn($"[RL] Failed to register the UCR role with the ID {Role.Id}: apparently there's already another role with the same Id!\nId fixer deactivated [!]");
});

Plugin.FileConfigs.LoadAction((CustomRole Role) =>
{
if (!SpawnManager.SubclassValidator(Role))
{
LogManager.Warn($"[RL] Failed to register the UCR role with the ID {Role.Id} due to the validator check!");
return;
}
if (!Roles.ContainsKey(Role.Id))
{
Roles.Add(Role.Id, Role);
if (Plugin.Instance.Config.EnableBasicLogs)
{
LogManager.Info($"[RL] Successfully registered the UCR role with the ID {Role.Id} and {Role.Name} as name!");
}
return;
}
LogManager.Warn($"[RL] Failed to register the UCR role with the ID {Role.Id}: apparently there's already another role with the same Id!\nId fixer deactivated [!]");
}, Server.Port.ToString());

if (Roles.Count < Plugin.CustomRoles.Count)
{
response = $"The reload command found a role that is loaded in the plugin but has not been loaded by the reload!\nYou can't remove custom roles without restarting the server!\nExpected {Plugin.CustomRoles.Count} roles, found {Roles.Count}";
return true;
}

foreach (ICustomRole Role in Plugin.CustomRoles.Values)
{
if (!Roles.ContainsKey(Role.Id))
{
response = $"The reload command found a role that is loaded in the plugin but has not been loaded by the reload!\nYou can't remove custom roles without restarting the server!\nMissing role: {Role.Id}";
return true;
}
}

// Ok now we can push the dictionary
Plugin.CustomRoles = Roles;

response = $"\n>> UCR Reload Report <<\nReloaded {Roles.Count} custom roles.\nFound {Plugin.CustomRoles.Count - Roles.Count} new roles.\n⚠ WARNING ⚠\nIf you have modified something like the health or the name the players that currently have this custom roles won't be affected by these changes!";
return true;
}
}
}
6 changes: 3 additions & 3 deletions UncomplicatedCustomRoles/Commands/UCRSpawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public bool Executor(List<string> arguments, ICommandSender sender, out string r
{
int Id = int.Parse(arguments[1]);

Log.Debug($"Selected role Id as Int32: {Id}");
LogManager.Debug($"Selected role Id as Int32: {Id}");
if (!Plugin.CustomRoles.ContainsKey(Id))
{
response = $"Role with the Id {Id} was not found!";
Expand All @@ -54,12 +54,12 @@ public bool Executor(List<string> arguments, ICommandSender sender, out string r

if (arguments.Count > 2 && arguments[2] is not null && arguments[2] == "sync")
{
Log.Debug("Spawning player sync");
LogManager.Debug("Spawning player sync");
SpawnManager.SummonCustomSubclass(Player, Id, true);
}
else
{
Log.Debug("Spawning player async");
LogManager.Debug("Spawning player async");
Timing.RunCoroutine(Handler.DoSpawnPlayer(Player, Id));
}
return true;
Expand Down
22 changes: 11 additions & 11 deletions UncomplicatedCustomRoles/Events/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void OnPlayerSpawned(SpawnedEventArgs Spawned)
string LogReason = string.Empty;
if (Plugin.Instance.Config.AllowOnlyNaturalSpawns && !Plugin.RoleSpawnQueue.Contains(Spawned.Player.Id))
{
Log.Debug("The player is not in the queue for respawning!");
LogManager.Debug("The player is not in the queue for respawning!");
return;
}
else if (Plugin.RoleSpawnQueue.Contains(Spawned.Player.Id))
Expand All @@ -73,7 +73,7 @@ public void OnPlayerSpawned(SpawnedEventArgs Spawned)
LogReason = " [going with a respawn wave OR 049 revival]";
}

Log.Debug($"Player {Spawned.Player.Nickname} spawned{LogReason}, going to assign a role if needed!");
LogManager.Debug($"Player {Spawned.Player.Nickname} spawned{LogReason}, going to assign a role if needed!");

Timing.CallDelayed(0.1f, () =>
{
Expand Down Expand Up @@ -109,23 +109,23 @@ public void OnHurting(HurtingEventArgs Hurting)

public void OnEscaping(EscapingEventArgs Escaping)
{
Log.Debug($"Player {Escaping.Player.Nickname} triggered the escaping event as {Escaping.Player.Role.Name}");
LogManager.Debug($"Player {Escaping.Player.Nickname} triggered the escaping event as {Escaping.Player.Role.Name}");

if (Plugin.PlayerRegistry.ContainsKey(Escaping.Player.Id))
{
Log.Debug($"Player IS a custom role: {Plugin.PlayerRegistry[Escaping.Player.Id]}");
LogManager.Debug($"Player IS a custom role: {Plugin.PlayerRegistry[Escaping.Player.Id]}");
ICustomRole Role = Plugin.CustomRoles[Plugin.PlayerRegistry[Escaping.Player.Id]];

if (!Role.CanEscape)
{
Log.Debug($"Player with the role {Role.Id} ({Role.Name}) can't escape, so nuh uh!");
LogManager.Debug($"Player with the role {Role.Id} ({Role.Name}) can't escape, so nuh uh!");
Escaping.IsAllowed = false;
return;
}

if (Role.CanEscape && (Role.RoleAfterEscape is null || Role.RoleAfterEscape.Length < 2))
{
Log.Debug($"Player with the role {Role.Id} ({Role.Name}) evaluated for a natural respawn!");
LogManager.Debug($"Player with the role {Role.Id} ({Role.Name}) evaluated for a natural respawn!");
Escaping.IsAllowed = true;
return;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ public IEnumerator<float> DoSetInfiniteEffectToPlayers()
// Here we can see and trigger role for SCPs escape event
foreach (Player Player in Player.List.Where(player => player.IsScp && Vector3.Distance(new(123.85f, 988.8f, 18.9f), player.Position) < 2.5f))
{
Log.Debug("Calling respawn event for plauer -> position");
LogManager.Debug("Calling respawn event for plauer -> position");
// Let's make this SCP escape
OnEscaping(new(Player, RoleTypeId.ChaosConscript, EscapeScenario.None));
}
Expand Down Expand Up @@ -227,7 +227,7 @@ public static void DoEvaluateSpawnForPlayer(Player Player)
{
if (Role.Value.RequiredPermission != null && Role.Value.RequiredPermission != string.Empty && !Player.CheckPermission(Role.Value.RequiredPermission))
{
Log.Debug($"[NOTICE] Ignoring the role {Role.Value.Id} [{Role.Value.Name}] while creating the list for the player {Player.Nickname} due to: cannot [permissions].");
LogManager.Debug($"[NOTICE] Ignoring the role {Role.Value.Id} [{Role.Value.Name}] while creating the list for the player {Player.Nickname} due to: cannot [permissions].");
continue;
}

Expand All @@ -243,7 +243,7 @@ public static void DoEvaluateSpawnForPlayer(Player Player)

if (Plugin.PlayerRegistry.ContainsKey(Player.Id))
{
Log.Debug("Was evalutating role select for an already custom role player, stopping");
LogManager.Debug("Was evalutating role select for an already custom role player, stopping");
return;
}

Expand All @@ -260,11 +260,11 @@ public static void DoEvaluateSpawnForPlayer(Player Player)
{
Timing.RunCoroutine(DoSpawnPlayer(Player, RoleId, false));
Plugin.RolesCount[RoleId].Add(Player.Id);
Log.Debug($"Player {Player.Nickname} spawned as CustomRole {RoleId}");
LogManager.Debug($"Player {Player.Nickname} spawned as CustomRole {RoleId}");
}
else
{
Log.Debug($"Player {Player.Nickname} won't be spawned as CustomRole {RoleId} because it has reached the maximus number");
LogManager.Debug($"Player {Player.Nickname} won't be spawned as CustomRole {RoleId} because it has reached the maximus number");
}
}
}
Expand Down
20 changes: 14 additions & 6 deletions UncomplicatedCustomRoles/Manager/FileConfigs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public string[] List(string localDir = "")
}

public void LoadAll(string localDir = "")
{
LoadAction((CustomRole Role) =>
{
SpawnManager.RegisterCustomSubclass(Role);
}, localDir);
}

public void LoadAction(Action<CustomRole> action, string localDir = "")
{
foreach (string FileName in List(localDir))
{
Expand All @@ -38,24 +46,24 @@ public void LoadAll(string localDir = "")

if (!Roles.ContainsKey("custom_roles"))
{
Log.Error($"Error during the deserialization of file {FileName}: Node name 'custom_roles' not found!");
LogManager.Error($"Error during the deserialization of file {FileName}: Node name 'custom_roles' not found!");
return;
}
foreach (CustomRole Role in Roles["custom_roles"])
{
Log.Debug($"Proposed to the registerer the external role {Role.Id} [{Role.Name}] from file:\n{FileName}");
SpawnManager.RegisterCustomSubclass(Role);
LogManager.Debug($"Proposed to the registerer the external role {Role.Id} [{Role.Name}] from file:\n{FileName}");
action(Role);
}
}
catch (Exception ex)
{
if (!Plugin.Instance.Config.Debug)
{
Log.Error($"Failed to parse {FileName}. YAML Exception: {ex.Message}.");
LogManager.Error($"Failed to parse {FileName}. YAML Exception: {ex.Message}.");
}
else
{
Log.Error($"Failed to parse {FileName}. YAML Exception: {ex.Message}.\nStack trace: {ex.StackTrace}");
LogManager.Error($"Failed to parse {FileName}. YAML Exception: {ex.Message}.\nStack trace: {ex.StackTrace}");
}
}
}
Expand All @@ -79,7 +87,7 @@ public void Welcome(string localDir = "")
}
}));

Log.Info($"Plugin does not have a role folder, generated one in {Path.Combine(Dir, localDir)}");
LogManager.Info($"Plugin does not have a role folder, generated one in {Path.Combine(Dir, localDir)}");
}
}
}
Expand Down
Loading

0 comments on commit 2447e99

Please sign in to comment.