before deleting Rules
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.WebSockets;
|
||||
@@ -9,18 +10,20 @@ namespace Gameboard.ShogiUI.Sockets.Models
|
||||
{
|
||||
public class Session
|
||||
{
|
||||
[JsonIgnore] public ConcurrentDictionary<string, WebSocket> Subscriptions { get; }
|
||||
public string Name { get; }
|
||||
public string Player1 { get; }
|
||||
public string Player2 { get; }
|
||||
public string? Player2 { get; }
|
||||
public bool IsPrivate { get; }
|
||||
|
||||
public ConcurrentDictionary<string, WebSocket> Subscriptions { get; }
|
||||
|
||||
public Session(Shogi.Api.ServiceModels.Types.Session session)
|
||||
public Session(string name, bool isPrivate, string player1, string? player2 = null)
|
||||
{
|
||||
Name = session.Name;
|
||||
Player1 = session.Player1;
|
||||
Player2 = session.Player2;
|
||||
Subscriptions = new ConcurrentDictionary<string, WebSocket>();
|
||||
|
||||
Name = name;
|
||||
Player1 = player1;
|
||||
Player2 = player2;
|
||||
IsPrivate = isPrivate;
|
||||
}
|
||||
|
||||
public bool Subscribe(string playerName, WebSocket socket) => Subscriptions.TryAdd(playerName, socket);
|
||||
@@ -47,7 +50,7 @@ namespace Gameboard.ShogiUI.Sockets.Models
|
||||
|
||||
public Task SendToPlayer2(string message)
|
||||
{
|
||||
if (Subscriptions.TryGetValue(Player2, out var socket))
|
||||
if (Player2 != null && Subscriptions.TryGetValue(Player2, out var socket))
|
||||
{
|
||||
return socket.SendTextAsync(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user