49 lines
1.8 KiB
C#
49 lines
1.8 KiB
C#
using Microsoft.AspNetCore.RateLimiting;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using QuestShare.Server.Managers;
|
|
|
|
namespace QuestShare.Server.Hubs
|
|
{
|
|
public partial class ShareHub : Hub
|
|
{
|
|
[HubMethodName(nameof(GroupLeave))]
|
|
[EnableRateLimiting("ClientPolicy")]
|
|
public async Task Server_GroupLeave(GroupLeave.Request request)
|
|
{
|
|
if (BanManager.IsBanned(Context))
|
|
{
|
|
Context.Abort();
|
|
return;
|
|
}
|
|
var error = Error.None;
|
|
if (request.Token == "") error = Error.InvalidToken;
|
|
else if (request.Version != Common.Constants.Version) error = Error.InvalidVersion;
|
|
var client = ClientManager.GetClient(Context.ConnectionId);
|
|
if (client == null) error = Error.Unauthorized;
|
|
var share = ShareManager.GetShare(request.ShareCode);
|
|
if (share == null) error = Error.ShareNotFound;
|
|
if (error != Error.None)
|
|
{
|
|
await Clients.Caller.SendAsync(nameof(GroupLeave), new GroupLeave.Response
|
|
{
|
|
Success = false,
|
|
Error = error,
|
|
});
|
|
return;
|
|
}
|
|
await ShareManager.RemoveGroupMember(share!, client!);
|
|
await Clients.Caller.SendAsync(nameof(GroupLeave), new GroupLeave.Response
|
|
{
|
|
Success = true,
|
|
});
|
|
// broadcast to party
|
|
await Clients.GroupExcept(share!.ShareCode, Context.ConnectionId).SendAsync(nameof(GroupNotify), new GroupNotify.GroupNotifyBroadcast
|
|
{
|
|
ShareCode = share.ShareCode,
|
|
CharacterId = client!.CharacterId,
|
|
NotifyType = NotifyType.Leave,
|
|
});
|
|
}
|
|
}
|
|
}
|