﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Game;
using GnomeServer.Extensions;
using GnomeServer.Routing;

namespace GnomeServer.Controllers
{
    [Route("Game")]
    public sealed class GameController : ConventionRoutingController
    {
        [HttpGet]
        [Route("")]
        public IResponseFormatter Get(int speed)
        {
            GnomanEmpire.Instance.World.GameSpeed.Value = speed;
            String content = String.Format("Game Speed set to '{0}'", speed);
            return JsonResponse(content);
        }

        public IResponseFormatter Test()
        {
            BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;

            var fields = typeof(Character).GetFields(bindFlags);
            var behaviorTypeFields = fields.Where(obj => obj.FieldType == typeof(BehaviorType)).ToList();

            List<TestResponse> testResponses = new List<TestResponse>();

            var members = GnomanEmpire.Instance.GetGnomes();
            foreach (var characterKey in members)
            {
                var character = characterKey.Value;
                var name = character.NameAndTitle();

                foreach (var fieldInfo in behaviorTypeFields)
                {
                    var val = (BehaviorType)(fieldInfo.GetValue(character));
                    testResponses.Add(new TestResponse
                    {
                        Name = name,
                        Value = val.ToString(),
                    });
                }
            }
            return JsonResponse(testResponses);
        }

        private class TestResponse
        {
            public String Name { get; set; }
            public String Value { get; set; }
        }
    }
}

﻿using System.Globalization;
using System.Net;
using Game;
using GnomeServer.Routing;

namespace GnomeServer.Controllers
{
    [Route("Game")]
    public sealed class GameController : ConventionRoutingController
    {
        [HttpGet]
        [Route("Speed")]
        public IResponseFormatter GetSpeed()
        {
            var world = GnomanEmpire.Instance.World;
            var speed = new
            {
                Speed = world.GameSpeed.Value.ToString(CultureInfo.InvariantCulture),
                IsPaused = world.Paused.Value.ToString(CultureInfo.InvariantCulture)
            };
            return JsonResponse(speed);
        }

        [HttpPost]
        [Route("Speed")]
        public IResponseFormatter PostSpeed(int speed)
        {
            GnomanEmpire.Instance.World.GameSpeed.Value = speed;
            return BlankResponse(HttpStatusCode.NoContent);
        }

        [HttpPost]
        [Route("Pause")]
        public IResponseFormatter PostPause()
        {
            GnomanEmpire.Instance.World.Paused.Value = true;
            return BlankResponse(HttpStatusCode.NoContent);
        }

        [HttpPost]
        [Route("Play")]
        public IResponseFormatter PostPlay()
        {
            GnomanEmpire.Instance.World.Paused.Value = false;
            return BlankResponse(HttpStatusCode.NoContent);
        }
    }
}

Add endpoints for controlling game speed.
Add endpoints for controlling game speed.
