Even slightly lesser aggressive question mark

This commit is contained in:
flash 2023-02-19 23:47:53 +01:00
parent 86a46539f2
commit 8de3ba8dbb
4 changed files with 84 additions and 79 deletions

View file

@ -98,6 +98,8 @@ namespace SharpChat.PacketHandlers {
return;
}
await ctx.Chat.ContextAccess.WaitAsync();
try {
ChatUser user = ctx.Chat.Users.FirstOrDefault(u => u.UserId == fai.UserId);
if(user == null)
@ -128,6 +130,9 @@ namespace SharpChat.PacketHandlers {
}
ctx.Chat.HandleJoin(user, DefaultChannel, ctx.Connection, MaxMessageLength);
} finally {
ctx.Chat.ContextAccess.Release();
}
}).Wait();
}
}

View file

@ -1,7 +1,6 @@
using SharpChat.Misuzu;
using SharpChat.Packet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -9,7 +8,6 @@ namespace SharpChat.PacketHandlers {
public class PingHandler : IChatPacketHandler {
private readonly MisuzuClient Misuzu;
private readonly object BumpAccess = new();
private readonly TimeSpan BumpInterval = TimeSpan.FromMinutes(1);
private DateTimeOffset LastBump = DateTimeOffset.MinValue;
@ -30,7 +28,8 @@ namespace SharpChat.PacketHandlers {
ctx.Connection.BumpPing();
ctx.Connection.Send(new PongPacket(ctx.Connection.LastPing));
lock(BumpAccess) {
ctx.Chat.ContextAccess.Wait();
try {
if(LastBump < DateTimeOffset.UtcNow - BumpInterval) {
(string, string)[] bumpList = ctx.Chat.Users
.Where(u => u.Status == ChatUserStatus.Online && ctx.Chat.Connections.Any(c => c.User == u))
@ -44,6 +43,8 @@ namespace SharpChat.PacketHandlers {
LastBump = DateTimeOffset.UtcNow;
}
} finally {
ctx.Chat.ContextAccess.Release();
}
}
}

View file

@ -42,6 +42,9 @@ namespace SharpChat.PacketHandlers {
// Extra validation step, not necessary at all but enforces proper formatting in SCv1.
if(!long.TryParse(args[1], out long mUserId) || user.UserId != mUserId)
return;
ctx.Chat.ContextAccess.Wait();
try {
ChatChannel channel = user.CurrentChannel;
if(channel == null
@ -96,6 +99,9 @@ namespace SharpChat.PacketHandlers {
ctx.Chat.Events.AddEvent(message);
ctx.Chat.SendTo(channel, new ChatMessageAddPacket(message));
} finally {
ctx.Chat.ContextAccess.Release();
}
}
}
}

View file

@ -203,14 +203,7 @@ namespace SharpChat {
? GuestHandlers.FirstOrDefault(h => h.IsMatch(context))
: AuthedHandlers.FirstOrDefault(h => h.IsMatch(context));
if(handler is not null) {
Context.ContextAccess.Wait();
try {
handler.Handle(context);
} finally {
Context.ContextAccess.Release();
}
}
handler?.Handle(context);
}
private bool IsDisposed;