Add remaining project files
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
using DeluxeBackend.Models;
|
||||
using DeluxeBackend.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using static DeluxeBackend.Enums;
|
||||
|
||||
namespace DeluxeBackend.Controllers.Matchmaking
|
||||
{
|
||||
[Route("Matchmaking/roominstance")]
|
||||
[ApiController]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public class RoomInstanceController(IJwtService jwt, ILiteDbService db, INotificationService ws) : ControllerBase
|
||||
{
|
||||
[HttpPut("{roominstanceId}/markprivate")]
|
||||
public async Task<IActionResult> MakePrivate(long roominstanceId)
|
||||
{
|
||||
LoginWithInfoResult? login = await jwt.GetLoginWithInfo(User);
|
||||
if (login == null) return Unauthorized();
|
||||
|
||||
Account account = login.Account;
|
||||
AccountPresence presence = GetOrCreatePresence(account);
|
||||
if (presence.Instance == null)
|
||||
{
|
||||
return BadRequest("Not in a Instance");
|
||||
}
|
||||
|
||||
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 NotFound();
|
||||
if (roomInstance.Id != presence.Instance!.Id)
|
||||
{
|
||||
return StatusCode(403);
|
||||
}
|
||||
if (roomInstance.InstanceType == RoomInstanceType.Public)
|
||||
{
|
||||
roomInstance.InstanceType = RoomInstanceType.Private;
|
||||
}
|
||||
roomInstance.Private= true;
|
||||
db.RoomInstances.Update(roomInstance);
|
||||
await ws.SendToPlayerSubs(account.Id, "RoomInstanceUpdate", roomInstance.ToDictionary());
|
||||
|
||||
return Ok(new { Success = true });
|
||||
}
|
||||
[HttpPut("{roominstanceId}/inprogress")]
|
||||
public async Task<IActionResult> SetInProgress(long roominstanceId, [FromForm] bool inprogress)
|
||||
{
|
||||
LoginWithInfoResult? login = await jwt.GetLoginWithInfo(User);
|
||||
if (login == null) return Unauthorized();
|
||||
|
||||
Account account = login.Account;
|
||||
AccountPresence presence = GetOrCreatePresence(account);
|
||||
if (presence.Instance == null)
|
||||
{
|
||||
return BadRequest("Not in a Instance");
|
||||
}
|
||||
|
||||
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 NotFound();
|
||||
if (roomInstance.Id != presence.Instance!.Id)
|
||||
{
|
||||
return StatusCode(403);
|
||||
}
|
||||
if (roomInstance.GameInProgress == inprogress)
|
||||
{
|
||||
return Ok(new { Success = true });
|
||||
}
|
||||
roomInstance.GameInProgress= inprogress;
|
||||
db.RoomInstances.Update(roomInstance);
|
||||
await ws.SendToPlayerSubs(account.Id, "RoomInstanceUpdate", roomInstance.ToDictionary());
|
||||
|
||||
return Ok(new { Success = true });
|
||||
}
|
||||
[HttpPut("{roominstanceId}/roomCode")]
|
||||
public async Task<IActionResult> SetRoomCode(long roominstanceId, [FromForm, Required] string roomCode, [FromForm, Required] bool forceChange)
|
||||
{
|
||||
return StatusCode(501);
|
||||
}
|
||||
[HttpPost("{roominstanceId}/reportjoinresult")]
|
||||
public async Task<IActionResult> ReportJoinResult(long roominstanceId)
|
||||
{
|
||||
return StatusCode(501);
|
||||
}
|
||||
|
||||
private AccountPresence GetOrCreatePresence(Account account)
|
||||
{
|
||||
var presence = db.Presences
|
||||
.Include(x => x.Account)
|
||||
.Include(x => x.Instance)
|
||||
.Include(x => x.Instance!.SubRoom)
|
||||
.Include(x => x.Instance!.SubRoom!.Room)
|
||||
.Include(x => x.Instance!.SubRoom!.Room!.Creator)
|
||||
.FindOne(x => x.Account.Id == account.Id);
|
||||
|
||||
return presence ?? new AccountPresence { Account = account };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user