예제 #1
0
        private UserDto InitPlayer(string playerConnectionId, MatchDto matchDto, ValilGame valilGame)
        {
            string playerSessionId = SignalRContext.GetSessionIdByConnectionId(playerConnectionId);
            string playerUsername = SignalRContext.StorageProvider.Current[playerSessionId] as string;

            UserDto player = _getUserByUserNameQueryHandler.Handle(new GetUserByUserNameQuery(playerUsername));

            player.ConnectionId = playerConnectionId;
            player.SessionId = playerSessionId;

            SignalRContext.SessionProvider[player.SessionId][NamingContract.Session_SearchingForMatch] = false;
            SignalRContext.SessionProvider[player.SessionId][NamingContract.Session_Match] = matchDto;
            SignalRContext.SessionProvider[player.SessionId][NamingContract.Session_Game] = valilGame;

            _gameHub.Groups.Add(player.ConnectionId, matchDto.MatchId).Wait();

            return player;
        }
예제 #2
0
        private void OnReportMatch(FoundGameType foundGameType)
        {
            MatchDto matchDto = new MatchDto
            {
                MatchId = Guid.NewGuid().ToString(),
                IsGameInitialized = false,
                IsDrawOffered = false,
                GameFoundTime = DateTime.Now,
                InitialTime = foundGameType.StartTime,
                AddedTimePerMove = foundGameType.AddedTimePerMove
            };

            ValilGame valilGame = InitValilGame();

            UserDto hoster = InitPlayer(foundGameType.HosterId, matchDto, valilGame);
            UserDto seeker = InitPlayer(foundGameType.SeekerId, matchDto, valilGame);

            matchDto.White = hoster;
            matchDto.Black = seeker;

            _gameHub.Clients.Group(matchDto.MatchId).reportMatch(matchDto);
        }