コード例 #1
0
ファイル: Room.cs プロジェクト: swedendry/RandomCube
        public void Release()
        {
            _context.Clients(_users).SendCoreAsync("DeleteRoom", PayloadPack.Success(new SC_DeleteRoom()
            {
            }));

            _state = RoomState.End;
            _timer.Stop();
            _users.Clear();
        }
コード例 #2
0
 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));
     }
 }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
ファイル: MainService.cs プロジェクト: swedendry/RandomCube
        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));
            }
        }
コード例 #5
0
        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()));
        }
コード例 #6
0
        public static IClientProxy Clients(this IHubContext <GameHub> context, List <GameUser> users)
        {
            var connectionIds = users.Select(x => x.ConnectionId);

            return(context.Clients(connectionIds.ToArray()));
        }