Added room functionality
This commit is contained in:
38
Websockets/WebsocketManager.cs
Normal file
38
Websockets/WebsocketManager.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Net.WebSockets;
|
||||
|
||||
namespace MauMau_Server.Websockets;
|
||||
|
||||
public class WebsocketManager : IWebsocketManager
|
||||
{
|
||||
private static readonly Dictionary<string, WebSocket> Connections = new();
|
||||
|
||||
public string AddConnection(WebSocket socket)
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
Connections.Add(id, socket);
|
||||
return id;
|
||||
}
|
||||
|
||||
public WebSocket GetConnection(string id)
|
||||
{
|
||||
return Connections[id];
|
||||
}
|
||||
|
||||
public Dictionary<string, WebSocket> GetAllConnections()
|
||||
{
|
||||
return Connections;
|
||||
}
|
||||
|
||||
public void RemoveConnection(string id)
|
||||
{
|
||||
Connections.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IWebsocketManager
|
||||
{
|
||||
public string AddConnection(WebSocket socket);
|
||||
public WebSocket GetConnection(string id);
|
||||
public Dictionary<string, WebSocket> GetAllConnections();
|
||||
public void RemoveConnection(string id);
|
||||
}
|
||||
Reference in New Issue
Block a user