Faction Test v1.0.1.0

This commit is contained in:
Regalis11
2023-02-16 15:01:28 +02:00
parent caa5a2f762
commit 2c5a7923b0
309 changed files with 7502 additions and 4335 deletions
@@ -24,7 +24,11 @@ namespace Barotrauma
public DateTimeOffset Expiry;
}
private readonly Dictionary<Client, RateLimitInfo> rateLimits = new Dictionary<Client, RateLimitInfo>();
private readonly record struct AfflictionSubscriber(Client Subscriber, CharacterInfo Target, DateTimeOffset Expiry);
private readonly List<AfflictionSubscriber> afflictionSubscribers = new();
private readonly Dictionary<Client, RateLimitInfo> rateLimits = new();
public void ServerRead(IReadMessage inc, Client sender)
{
@@ -35,6 +39,9 @@ namespace Barotrauma
case NetworkHeader.ADD_EVERYTHING_TO_PENDING:
ProcessAddEverything(sender);
break;
case NetworkHeader.UNSUBSCRIBE_ME:
RemoveClientSubscription(sender);
break;
case NetworkHeader.REQUEST_AFFLICTIONS:
ProcessRequestedAfflictions(inc, sender);
break;
@@ -72,6 +79,17 @@ namespace Barotrauma
ServerSend(PendingHeals.ToNetCollection(), NetworkHeader.ADD_PENDING, DeliveryMethod.Reliable, reponseClient: client);
}
private void RemoveClientSubscription(Client client)
{
foreach (AfflictionSubscriber sub in afflictionSubscribers.ToList())
{
if (sub.Subscriber == client || sub.Expiry < DateTimeOffset.Now)
{
afflictionSubscribers.Remove(sub);
}
}
}
private void ProcessNewRemoval(IReadMessage inc, Client client)
{
if (CheckRateLimit(client) == RateLimitResult.LimitReached) { return; }
@@ -129,6 +147,14 @@ namespace Barotrauma
Afflictions = pendingAfflictions
};
if (foundInfo is not null)
{
RemoveClientSubscription(client);
// the client subscribes to the afflictions of the crew member for the next minute
afflictionSubscribers.Add(new AfflictionSubscriber(client, foundInfo, DateTimeOffset.Now.AddMinutes(1)));
}
ServerSend(writeCrewMember, NetworkHeader.REQUEST_AFFLICTIONS, DeliveryMethod.Unreliable, client);
}