Skip to content

Commit

Permalink
Merge pull request #44 from UncomplicatedCustomServer/dev-main
Browse files Browse the repository at this point in the history
UCR v4.1.1 for EXILED 8.12
  • Loading branch information
FoxWorn3365 authored Nov 14, 2024
2 parents b575c78 + 8974828 commit 9e3b181
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 41 deletions.
22 changes: 15 additions & 7 deletions UncomplicatedCustomRoles/Commands/LogShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,25 @@ protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSe
}

long Start = DateTimeOffset.Now.ToUnixTimeMilliseconds();
response = "Loading the JSON content to share with the developers...";
response = $"Loading the JSON content to share with the developers...";

Task.Run(() =>
{
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"))
Log.Info($"[ShareTheLog] Successfully shared the UCR logs with the developers!\nSend this Id to the developers: {Data["id"]}\n\nTook {DateTimeOffset.Now.ToUnixTimeMilliseconds() - Start}ms");
else
Log.Info($"Failed to share the UCR logs with the developers: Server says: {Response}");
try
{
if (Response is HttpStatusCode.OK)
{
Dictionary<string, string> Data = JsonConvert.DeserializeObject<Dictionary<string, string>>(Plugin.HttpManager.RetriveString(Content));
Log.Info($"[ShareTheLog] Successfully shared the UCR logs with the developers!\nSend this Id to the developers: {Data["id"]}\n\nTook {DateTimeOffset.Now.ToUnixTimeMilliseconds() - Start}ms");
}
else
Log.Info($"Failed to share the UCR logs with the developers: Server says: {Response}");
}
catch (Exception e)
{
Log.Error(e.ToString());
}
});


Expand Down
45 changes: 32 additions & 13 deletions UncomplicatedCustomRoles/Events/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,35 @@ internal class EventHandler
{
private static List<int> RagdollAppearanceQueue { get; } = new();

private static List<int> FirstRoundPlayers { get; } = new();

private static bool Initialized { get; set; } = false;

public void OnWaitingForPlayers()
{
Plugin.Instance.OnFinishedLoadingPlugins();

}

public void OnRoundStarted()
{
Initialized = true;
FirstRoundPlayers.Clear();

// Starts the infinite effect thing
InfiniteEffect.Stop();
InfiniteEffect.EffectAssociationAllowed = true;
InfiniteEffect.Start();
}

public void OnVerified(VerifiedEventArgs ev)
{
if (Initialized)
return;

FirstRoundPlayers.Add(ev.Player.Id);
}

public void OnInteractingScp330(InteractingScp330EventArgs ev)
{
if (!ev.IsAllowed)
Expand Down Expand Up @@ -137,31 +158,29 @@ public void OnChangingRole(ChangingRoleEventArgs ev)
if (ev.NewRole is RoleTypeId.Spectator || ev.NewRole is RoleTypeId.None || ev.NewRole is RoleTypeId.Filmmaker)
return;

LogManager.Debug("Called CHANGINGROLE event");

if (Spawn.Spawning.Contains(ev.Player.Id))
return;

if (ev.Player.HasCustomRole())
return;


if (ev.Player.IsNPC)
return;

string LogReason = string.Empty;
if (Plugin.Instance.Config.AllowOnlyNaturalSpawns && !Spawn.SpawnQueue.Contains(ev.Player.Id))
{
LogManager.Debug("The player is not in the queue for respawning!");
return;
}
else if (Spawn.SpawnQueue.Contains(ev.Player.Id))
if (!FirstRoundPlayers.Contains(ev.Player.Id))
{
Spawn.SpawnQueue.Remove(ev.Player.Id);
LogReason = " [WITH a respawn wave - VANILLA]";
if (Plugin.Instance.Config.AllowOnlyNaturalSpawns && !Spawn.SpawnQueue.Contains(ev.Player.Id))
{
LogManager.Debug("The player is not in the queue for respawning!");
return;
}
else if (Spawn.SpawnQueue.Contains(ev.Player.Id))
{
Spawn.SpawnQueue.Remove(ev.Player.Id);
}
}

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

ICustomRole Role = SpawnManager.DoEvaluateSpawnForPlayer(ev.Player, ev.NewRole);

if (Role is not null)
Expand Down
10 changes: 5 additions & 5 deletions UncomplicatedCustomRoles/Manager/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ internal static HttpStatusCode SendReport(out HttpContent content)
if (History.Count < 1)
return HttpStatusCode.Forbidden;

string Content = string.Empty;
string stringContent = string.Empty;

foreach (LogEntry Element in History)
Content += $"{Element}\n";
stringContent += $"{Element}\n";

// Now let's add the separator
Content += "\n======== BEGIN CUSTOM ROLES ========\n";
stringContent += "\n======== BEGIN CUSTOM ROLES ========\n";

foreach (ICustomRole Role in CustomRole.CustomRoles.Values)
{
Content += $"{Loader.Serializer.Serialize(Role)}\n\n---\n\n";
stringContent += $"{Loader.Serializer.Serialize(Role)}\n\n---\n\n";
}

HttpStatusCode Response = Plugin.HttpManager.ShareLogs(Content, out _);
HttpStatusCode Response = Plugin.HttpManager.ShareLogs(stringContent, out content);

if (Response is HttpStatusCode.OK)
{
Expand Down
4 changes: 2 additions & 2 deletions UncomplicatedCustomRoles/Manager/NET/HttpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class HttpManager
/// <summary>
/// Gets the UCS APIs endpoint
/// </summary>
public string Endpoint { get; } = "https://api.ucserver.it";
public string Endpoint { get; } = "https://api.ucserver.it/v2";

/// <summary>
/// Gets the CreditTag storage for the plugin, downloaded from our central server
Expand Down Expand Up @@ -171,7 +171,7 @@ public void LoadCreditTags()
Credits = new();
try
{
Dictionary<string, Dictionary<string, string>> Data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(RetriveString(HttpGetRequest("https://ucs.fcosma.it/api/credits.json")));
Dictionary<string, Dictionary<string, string>> Data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(RetriveString(HttpGetRequest("https://api.ucserver.it/credits.json")));

if (Data is null)
{
Expand Down
3 changes: 3 additions & 0 deletions UncomplicatedCustomRoles/Manager/SpawnManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ public static void SummonSubclassApplier(Player Player, ICustomRole Role)
if (Spawn.Spawning.Contains(Player.Id))
Spawn.Spawning.Remove(Player.Id);

if (API.Features.Escape.Bucket.Contains(Player.Id))
API.Features.Escape.Bucket.Remove(Player.Id);

LogManager.Debug($"{Player} successfully spawned as {Role.Name} ({Role.Id})! [2VDS]");
}

Expand Down
10 changes: 0 additions & 10 deletions UncomplicatedCustomRoles/Patches/PluginsLoaded.cs

This file was deleted.

2 changes: 1 addition & 1 deletion UncomplicatedCustomRoles/Patches/ServerNamePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace UncomplicatedCustomRoles.Patches
[HarmonyPatch(typeof(ServerConsole), nameof(ServerConsole.ReloadServerName))]
internal class ServerNamePatch
{
private static void Postfix() => ServerConsole._serverName += $"<color=#000000><size=1>UCR {Plugin.Instance.Version.ToString(3)}</size></color>";
private static void Postfix() => ServerConsole._serverName += $"<color=#00000000><size=1>UCR {Plugin.Instance.Version.ToString(3)}</size></color>";
}
}
7 changes: 5 additions & 2 deletions UncomplicatedCustomRoles/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class Plugin : Plugin<Config>

public override string Author => "FoxWorn3365, Dr.Agenda";

public override Version Version { get; } = new(4, 1, 0);
public override Version Version { get; } = new(4, 1, 1);

public override Version RequiredExiledVersion { get; } = new(8, 11, 0);

Expand Down Expand Up @@ -60,8 +60,8 @@ public override void OnEnabled()
ServerHandler.RespawningTeam += Handler.OnRespawningWave;
ServerHandler.RoundStarted += Handler.OnRoundStarted;
ServerHandler.RoundEnded += Handler.OnRoundEnded;
ServerHandler.WaitingForPlayers += Handler.OnWaitingForPlayers;

// PlayerHandler.Verified += Handler.OnVerified;
PlayerHandler.ActivatingGenerator += Handler.OnGenerator;
PlayerHandler.Dying += Handler.OnDying;
PlayerHandler.Died += Handler.OnDied;
Expand All @@ -77,6 +77,7 @@ public override void OnEnabled()
PlayerHandler.TriggeringTesla += Handler.OnTriggeringTeslaGate;
PlayerHandler.MakingNoise += Handler.OnMakingNoise;
PlayerHandler.PickingUpItem += Handler.OnPickingUp;
PlayerHandler.Verified += Handler.OnVerified;

Scp049Handler.FinishingRecall += Handler.OnFinishingRecall;

Expand Down Expand Up @@ -147,6 +148,7 @@ public override void OnDisabled()
ServerHandler.RespawningTeam -= Handler.OnRespawningWave;
ServerHandler.RoundEnded -= Handler.OnRoundEnded;
ServerHandler.RoundStarted -= Handler.OnRoundStarted;
ServerHandler.WaitingForPlayers -= Handler.OnWaitingForPlayers;

// PlayerHandler.Verified -= Handler.OnVerified;
PlayerHandler.ActivatingGenerator -= Handler.OnGenerator;
Expand All @@ -164,6 +166,7 @@ public override void OnDisabled()
PlayerHandler.TriggeringTesla -= Handler.OnTriggeringTeslaGate;
PlayerHandler.MakingNoise -= Handler.OnMakingNoise;
PlayerHandler.PickingUpItem -= Handler.OnPickingUp;
PlayerHandler.Verified -= Handler.OnVerified;

Scp049Handler.FinishingRecall -= Handler.OnFinishingRecall;

Expand Down
1 change: 0 additions & 1 deletion UncomplicatedCustomRoles/UncomplicatedCustomRoles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
<Compile Include="Patches\InventoryLimitsPrefix.cs" />
<Compile Include="Patches\DisabledEventPatch.cs" />
<Compile Include="Patches\PlayerInfoPatch.cs" />
<Compile Include="Patches\PluginsLoaded.cs" />
<Compile Include="Patches\Scp3114StranglePrefix.cs" />
<Compile Include="Patches\ServerNamePatch.cs" />
<Compile Include="Patches\SetRolePatch.cs" />
Expand Down

0 comments on commit 9e3b181

Please sign in to comment.