예제 #1
0
 public Task <IReadOnlyList <RavenNest.Models.GameSession> > GetGameSessionsAsync()
 {
     return(Task.Run(() =>
     {
         var activeSessions = gameData.GetActiveSessions();
         return (IReadOnlyList <RavenNest.Models.GameSession>)activeSessions.Select(s => ModelMapper.Map(gameData, s)).ToList();
     }));
 }
예제 #2
0
        public PagedSessionCollection GetSessionsPaged(int offset, int size, string sortOrder, string query)
        {
            try
            {
                var activeSessions  = gameData.GetActiveSessions();
                var lastActiveRange = DateTime.UtcNow.AddMinutes(-30);
                activeSessions = FilterByQuery(query, activeSessions.Where(x => x.Updated >= lastActiveRange));
                activeSessions = OrderBy(sortOrder, activeSessions);

                return(new PagedSessionCollection()
                {
                    TotalSize = activeSessions.Count,
                    Items = activeSessions.Skip(offset).Take(size)
                            .Select(x => ModelMapper.Map(gameData, x))
                            .Where(x => x != null)
                            .ToList()
                });
            }
            catch (Exception exc)
            {
                logger.LogError(exc.ToString());
                return(null);
            }
        }
예제 #3
0
        public void BroadcastMessageAsync(string message, int time)
        {
            var sessions = gameData.GetActiveSessions();

            foreach (var session in sessions)
            {
                var gameEvent = gameData.CreateSessionEvent(GameEventType.ServerMessage, session, new ServerMessage()
                {
                    Message = message,
                    Time    = time
                });

                gameData.Add(gameEvent);
            }
        }
예제 #4
0
        public IReadOnlyList <TwitchStream> GetTwitchStreams()
        {
            var ran      = new Random();
            var output   = new List <TwitchStream>();
            var sessions = gameData.GetActiveSessions();

            foreach (var session in sessions)
            {
                var stream = new TwitchStream();
                var user   = gameData.GetUser(session.UserId);
                stream.TwitchUserName = user.UserName;
                stream.UserTitle      = "";
                stream.Uptime         = DateTime.UtcNow - session.Started;
                stream.PlayerCount    = gameData.GetSessionCharacters(session).Count;
                output.Add(stream);
            }
            return(output.OrderBy(x => ran.Next()).ToList());
        }
예제 #5
0
        public Task BroadcastMessageAsync(string message)
        {
            // 1. get all active sessions
            var sessions = gameData.GetActiveSessions();

            //var sessions = await db.GameSession
            //    .Include(x => x.GameEvents)
            //    .Where(x => x.Stopped != null)
            //    .ToListAsync();

            // 2. push a new event for each session
            foreach (var session in sessions)
            {
                //var revision = session.GameEvents.Count > 0
                //    ? session.GameEvents.Max(x => x.Revision) + 1 : 1;

                var gameEvent = gameData.CreateSessionEvent(GameEventType.ServerMessage, session, new ServerMessage()
                {
                    Message = message,
                });

                gameData.Add(gameEvent);

                //await db.GameEvent.AddAsync(new DataModels.GameEvent()
                //{
                //    Id = Guid.NewGuid(),
                //    GameSessionId = session.Id,
                //    GameSession = session,
                //    Data = JSON.Stringify(new ServerMessage()
                //    {
                //        Message = message,
                //    }),
                //    Type = (int)GameEventType.ServerMessage,
                //    Revision = revision
                //});
            }

            return(Task.CompletedTask);
        }