Files
Shogi/Gameboard.ShogiUI.Sockets/Models/Session.cs
2021-11-10 18:46:29 -06:00

39 lines
1.2 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 User Player1 { get; }
public User? Player2 { get; private set; }
public bool IsPrivate { get; }
// TODO: Don't retain the entire rules system within the Session model. It just needs the board state after rules are applied.
public Shogi Shogi { get; }
public Session(string name, bool isPrivate, Shogi shogi, User player1, User? player2 = null)
{
Subscriptions = new ConcurrentDictionary<string, WebSocket>();
Name = name;
Player1 = player1;
Player2 = player2;
IsPrivate = isPrivate;
Shogi = shogi;
}
public void SetPlayer2(User user)
{
Player2 = user;
}
public Game ToServiceModel() => new() { GameName = Name, Player1 = Player1.DisplayName, Player2 = Player2?.DisplayName };
}
}