Ejemplo n.º 1
0
        static RestRedisClient()
        {
            client = new RedisClient();

            client.SubscribeToAnswers(RedisChannels.GetNextGatewayResponse);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Game Server Key " + gameServerKey);

            client = new RedisClient();
            client.Subscribe(RedisChannels.CreateNewGameRequest, request =>
            {
                var gameId = Guid.NewGuid().ToString("N");
                var createNewGameRequest = (CreateNewGameRequest)request;
                GameManager gameManager = new GameManager(gameId) { InitialRequest = createNewGameRequest };

                games.Add(gameId, gameManager);
                //                Console.WriteLine("New Game Request " + games.Count);

                client.SendMessage("GameUpdate" + createNewGameRequest.GatewayKey, new GameUpdateRedisMessage()
                {
                    GameId = gameId,
                    UserKey = createNewGameRequest.UserKey,
                    GameServer = gameServerKey,
                    GameStatus = GameStatus.Started
                });
                startGame(gameManager);
            });

            client.Subscribe("GameServer" + gameServerKey, request =>
             {
                 var gameServerResponse = (GameServerRedisMessage)request;
                 games[gameServerResponse.GameId].DataClass.curAnswered(gameServerResponse.AnswerIndex);
             });

            timer = new Timer((e) =>
             {
                 var now = DateTime.Now;
                 var answersPerSecond = 0.0;

                 if (start != DateTime.MinValue)
                 {
                     answersPerSecond = AnswerCount / (now - start).TotalSeconds;
                 }
                 Console.WriteLine($"Games Done: {GamesDone} Answers: {AnswerCount} LiveGames: {games.Count} APS: {answersPerSecond}");
             }, null, 0, 500);

            Console.WriteLine("Press any [Enter] to close the host.");
            Console.ReadLine();
        }