Custom names and time in chat
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user