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

View file

@ -1,7 +1,6 @@
using SharpChat.Misuzu; using SharpChat.Misuzu;
using SharpChat.Packet; using SharpChat.Packet;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -9,7 +8,6 @@ namespace SharpChat.PacketHandlers {
public class PingHandler : IChatPacketHandler { public class PingHandler : IChatPacketHandler {
private readonly MisuzuClient Misuzu; private readonly MisuzuClient Misuzu;
private readonly object BumpAccess = new();
private readonly TimeSpan BumpInterval = TimeSpan.FromMinutes(1); private readonly TimeSpan BumpInterval = TimeSpan.FromMinutes(1);
private DateTimeOffset LastBump = DateTimeOffset.MinValue; private DateTimeOffset LastBump = DateTimeOffset.MinValue;
@ -30,7 +28,8 @@ namespace SharpChat.PacketHandlers {
ctx.Connection.BumpPing(); ctx.Connection.BumpPing();
ctx.Connection.Send(new PongPacket(ctx.Connection.LastPing)); ctx.Connection.Send(new PongPacket(ctx.Connection.LastPing));
lock(BumpAccess) { ctx.Chat.ContextAccess.Wait();
try {
if(LastBump < DateTimeOffset.UtcNow - BumpInterval) { if(LastBump < DateTimeOffset.UtcNow - BumpInterval) {
(string, string)[] bumpList = ctx.Chat.Users (string, string)[] bumpList = ctx.Chat.Users
.Where(u => u.Status == ChatUserStatus.Online && ctx.Chat.Connections.Any(c => c.User == u)) .Where(u => u.Status == ChatUserStatus.Online && ctx.Chat.Connections.Any(c => c.User == u))
@ -44,6 +43,8 @@ namespace SharpChat.PacketHandlers {
LastBump = DateTimeOffset.UtcNow; 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. // Extra validation step, not necessary at all but enforces proper formatting in SCv1.
if(!long.TryParse(args[1], out long mUserId) || user.UserId != mUserId) if(!long.TryParse(args[1], out long mUserId) || user.UserId != mUserId)
return; return;
ctx.Chat.ContextAccess.Wait();
try {
ChatChannel channel = user.CurrentChannel; ChatChannel channel = user.CurrentChannel;
if(channel == null if(channel == null
@ -96,6 +99,9 @@ namespace SharpChat.PacketHandlers {
ctx.Chat.Events.AddEvent(message); ctx.Chat.Events.AddEvent(message);
ctx.Chat.SendTo(channel, new ChatMessageAddPacket(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)) ? GuestHandlers.FirstOrDefault(h => h.IsMatch(context))
: AuthedHandlers.FirstOrDefault(h => h.IsMatch(context)); : AuthedHandlers.FirstOrDefault(h => h.IsMatch(context));
if(handler is not null) { handler?.Handle(context);
Context.ContextAccess.Wait();
try {
handler.Handle(context);
} finally {
Context.ContextAccess.Release();
}
}
} }
private bool IsDisposed; private bool IsDisposed;