public object GetUpdateFor(string clientId) { var client = _connectedClients.Find(clientId); var clients = _connectedClients.FindInGroups(client !.Groups); var progresses = _state.GetProgressesForSession(client.Group) .Where(c => c.Key != clientId && clients.Select(x => x.ClientId).Contains(c.Key)) .Select(x => new Typed { ClientId = x.Key, TypedCharactersCount = x.Value }); return(new Update { Progresses = progresses.ToList() }); }
public Player FromState(PlayerState state) { var playerId = state.PlayerId; void updateMessagingGroup(string group) { var client = _connectedClientStore.Find(playerId); if (client == null) { return; } //throw new InvalidOperationException($"Client {playerId} is not connected currently. Cannot update their messaging group."); // Do not throw when client is not connected, we can get Players from repositories even if they are offline - to perform actions on them on behalf of other players. client.Group = group; } return(Player.FromState(state, _locationStore, _roadStore, updateMessagingGroup)); }
public object GetUpdateFor(string clientId) { var contest = _contestStore.FindActiveByContestantId(clientId); if (contest == null) { // This is a bit of a hack. Either pass ConnectedClient to this method, // or have a domain-specific ISpectatorsStore that will be filled by ConnectHook. var client = _connectedClients.Find(clientId); if (client == null) { throw new InvalidOperationException("Client is not connected already."); } var contestId = client.Group; contest = _contestStore.Find(contestId); if (contest == null) { return(new ContestUpdate()); // Not started yet. } } var data = contest.GetData(); return(new ContestUpdate { Progress = data.Progress, Contestants = data.Contestants.SelectMany( x => x.Value.Select( contestantId => new ContestantUpdate { ContestantId = contestantId, Side = x.Key })).ToList(), HasStarted = data.HasStarted, HasEnded = data.HasEnded }); }
/// <summary> /// Gets a value indicating whether given client is present in the store /// (if it's connected - it will be present in the store). /// </summary> /// <param name="store">ConnectedClientStore instance.</param> /// <param name="clientId">Connected client identity.</param> /// <returns>A value indicating whether given client is present in the store.</returns> public static bool IsClientConnected(this IConnectedClientStore store, string clientId) => store.Find(clientId) != null;