Files
Shogi/Gameboard.ShogiUI.Sockets/Models/Session.cs
2021-09-03 22:43:06 -05:00

38 lines
1.0 KiB
C#

using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
using Newtonsoft.Json;
using System.Collections.Concurrent;
using System.Net.WebSockets;
namespace Gameboard.ShogiUI.Sockets.Models
{
public class Session
{
// TODO: Separate subscriptions to the Session from the Session.
[JsonIgnore] public ConcurrentDictionary<string, WebSocket> Subscriptions { get; }
public string Name { get; }
public string Player1 { get; }
public string? Player2 { get; private set; }
public bool IsPrivate { get; }
public Shogi Shogi { get; }
public Session(string name, bool isPrivate, Shogi shogi, string player1, string? player2 = null)
{
Subscriptions = new ConcurrentDictionary<string, WebSocket>();
Name = name;
Player1 = player1;
Player2 = player2;
IsPrivate = isPrivate;
Shogi = shogi;
}
public void SetPlayer2(string userName)
{
Player2 = userName;
}
public Game ToServiceModel() => new() { GameName = Name, Player1 = Player1, Player2 = Player2 };
}
}