Custom names and time in chat
All checks were successful
Build Mau & Deploy Mau / build (push) Successful in 1m13s
Build Mau & Deploy Mau / deploy (push) Has been skipped

This commit is contained in:
DTieman
2024-04-20 23:43:07 +02:00
parent b97eb309c0
commit 1e51defad5
5 changed files with 52 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
using System.Text.Json;
using System.Text;
using System.Text.Json;
using MauMau_Server.Websockets;
using Microsoft.AspNetCore.Mvc;
@@ -24,24 +25,27 @@ public class RoomController : ControllerBase
return Ok(rooms);
}
[HttpGet("{id}")]
public async Task ConnectToRoom(string id)
[HttpGet("{id}/{name}")]
public async Task ConnectToRoom(string id, string name)
{
var response = HttpContext.Response;
if (!HttpContext.WebSockets.IsWebSocketRequest)
{
HttpContext.Response.StatusCode = 400;
response.StatusCode = 400;
await response.BodyWriter.WriteAsync("Request is not a websocket request"u8.ToArray());
return;
}
if (!_roomManager.RoomExists(id))
{
HttpContext.Response.StatusCode = 404;
response.StatusCode = 404;
await response.BodyWriter.WriteAsync("Room could not be found"u8.ToArray());
return;
}
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
var room = _roomManager.GetRoom(id);
await room.InstantiateConnection(webSocket);
await room.InstantiateConnection(webSocket, name);
}
[HttpPost]