Add remaining project files
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using DeluxeBackend.Models;
|
||||
using DeluxeBackend.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Data;
|
||||
using static DeluxeBackend.Enums;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DeluxeBackend.Controllers.Matchmaking
|
||||
{
|
||||
[Route("Matchmaking/invite")]
|
||||
[ApiController]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public class InviteController(IJwtService jwt, ILiteDbService db, IMessageService message) : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Invite([FromForm(Name = "roomInstanceId")] long RoomInstanceId, [FromForm(Name = "playerId")] long PlayerId)
|
||||
{
|
||||
LoginWithInfoResult? login = await jwt.GetLoginWithInfo(User);
|
||||
|
||||
if (login == null) return Unauthorized();
|
||||
Account account = login.Account;
|
||||
Account? account1 = db.Accounts.FindById(PlayerId);
|
||||
if (account1 == null)
|
||||
{
|
||||
return Ok(new { Success = false });
|
||||
}
|
||||
|
||||
RoomInstance roomInstance = db.RoomInstances.Include(x => x.SubRoom).Include(x => x.SubRoom!.Room).Include(x => x.SubRoom!.Room!.Creator).FindById(RoomInstanceId);
|
||||
if (roomInstance == null)
|
||||
{
|
||||
return Ok(new { Success = false });
|
||||
}
|
||||
|
||||
PlayerInvite playerInvite = new()
|
||||
{
|
||||
Account = account1,
|
||||
InstanceId = roomInstance.Id,
|
||||
InvitedBy = account,
|
||||
ExpiresAt = DateTime.UtcNow.AddMinutes(10)
|
||||
};
|
||||
db.PlayerInvites.Insert(playerInvite);
|
||||
|
||||
await message.SendMessage(account, account1, MessageType.GameInviteV2, JsonSerializer.Serialize(new Dictionary<string, object>()
|
||||
{
|
||||
["inviteId"] = playerInvite.Id,
|
||||
["name"] = "meow",
|
||||
["roomInstanceId"] = roomInstance.Id
|
||||
}));
|
||||
|
||||
return Ok(new { Success = true });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user