public void Release() { _context.Clients(_users).SendCoreAsync("DeleteRoom", PayloadPack.Success(new SC_DeleteRoom() { })); _state = RoomState.End; _timer.Stop(); _users.Clear(); }
private static void ForGame(Guid gameId, IHubContext ctx, Action<dynamic> actionOnValidClient) { foreach (var registration in Registry.ClientToGames.Where(x => x.Value == gameId)) { actionOnValidClient(ctx.Clients().Client(registration.Key)); } }
private void CheckMatching() { var curtime = DateTime.UtcNow; var users = _users.OrderBy(x => x.MatchTime).Take(ServerDefine.MAX_GAME_USER).ToList(); if (users.Count >= ServerDefine.MAX_GAME_USER) { //매칭 성공 var groupName = Guid.NewGuid().ToString("d"); var connectionIds = users.Select(x => x.ConnectionId).ToArray(); _context.Clients(connectionIds).SendCoreAsync("SuccessMatch", PayloadPack.Success(new SC_SuccessMatch() { GroupName = groupName, })); users.ForEach(x => _users.Remove(x)); } }
public async Task Login(string connectionId, string id, string name) { var method = "Login"; try { var duplicationUser = GetUserById(id); if (duplicationUser != null) { //중복 _users.Remove(duplicationUser); } var user = new User() { Id = id, Name = name, ConnectionId = connectionId, }; _users.Add(user); await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Success(new SC_Login() { User = user, })); } catch (Exception ex) { await _context.Clients(connectionId).SendCoreAsync(method, PayloadPack.Error(ex)); } }
public static IClientProxy ClientsExceptById(this IHubContext <GameHub> context, List <GameUser> users, params string[] excludedIds) { var connectionIds = users.Where(x => !excludedIds.Contains(x.Id)).Select(x => x.ConnectionId); return(context.Clients(connectionIds.ToArray())); }
public static IClientProxy Clients(this IHubContext <GameHub> context, List <GameUser> users) { var connectionIds = users.Select(x => x.ConnectionId); return(context.Clients(connectionIds.ToArray())); }