diff --git a/src/server/MagCore.Core/Game.cs b/src/server/MagCore.Core/Game.cs index a88b1b9..dd44fee 100644 --- a/src/server/MagCore.Core/Game.cs +++ b/src/server/MagCore.Core/Game.cs @@ -101,7 +101,7 @@ public Game(IMap map) }).ContinueWith((task) => { //Recycling _state = GameState.Recycling; - Thread.Sleep(10000); + Thread.Sleep(10000); Server.RemoveGame(Id); }); } diff --git a/src/server/MagCore.Server/Controllers/GameController.cs b/src/server/MagCore.Server/Controllers/GameController.cs index 775cfc9..b23186e 100644 --- a/src/server/MagCore.Server/Controllers/GameController.cs +++ b/src/server/MagCore.Server/Controllers/GameController.cs @@ -35,24 +35,38 @@ public string Get(string id) [HttpPost] public ContentResult Post([FromBody]dynamic json) { - var map = json.Map.ToString(); - var game = Core.Server.NewGame(map); - if (!string.IsNullOrEmpty(game)) - return new ContentResult() { StatusCode = (int)HttpStatusCode.OK, Content = game }; - else + try + { + var map = json.Map.ToString(); + var game = Core.Server.NewGame(map); + if (!string.IsNullOrEmpty(game)) + return new ContentResult() { StatusCode = (int)HttpStatusCode.OK, Content = game }; + else + return new ContentResult() { StatusCode = (int)HttpStatusCode.BadRequest }; + } + catch + { return new ContentResult() { StatusCode = (int)HttpStatusCode.BadRequest }; + } } // PATCH api/game - Join game [HttpPatch] public ContentResult Patch([FromBody]dynamic json) { - var game = json.Game.ToString(); - var player = json.Player.ToString(); - if (Core.Server.Join(game, player)) - return new ContentResult() { StatusCode = (int)HttpStatusCode.OK }; - else - return new ContentResult() { StatusCode = (int)HttpStatusCode.Forbidden }; + try + { + var game = json.Game.ToString(); + var player = json.Player.ToString(); + if (Core.Server.Join(game, player)) + return new ContentResult() { StatusCode = (int)HttpStatusCode.OK }; + else + return new ContentResult() { StatusCode = (int)HttpStatusCode.Forbidden }; + } + catch + { + return new ContentResult() { StatusCode = (int)HttpStatusCode.BadRequest }; + } } // Put api/game/5b4512fb673f4a638fe2907b7483c0ab - Start game diff --git a/src/server/MagCore.Server/Controllers/PlayerController.cs b/src/server/MagCore.Server/Controllers/PlayerController.cs index 0fc96f5..0cc5559 100644 --- a/src/server/MagCore.Server/Controllers/PlayerController.cs +++ b/src/server/MagCore.Server/Controllers/PlayerController.cs @@ -16,13 +16,20 @@ public class PlayerController : Controller [HttpPost] public ContentResult Post([FromBody]dynamic json) { - var name = json.Name.ToString().Trim(); - PlayerColor color = (PlayerColor)json.Color; - var player = Core.Players.NewPlayer(name, color); - if (player != null) - return new ContentResult() { StatusCode = (int)HttpStatusCode.OK, Content = player }; - else - return new ContentResult() { StatusCode = (int)HttpStatusCode.Conflict }; + try + { + var name = json.Name.ToString().Trim(); + PlayerColor color = (PlayerColor)json.Color; + var player = Core.Players.NewPlayer(name, color); + if (player != null) + return new ContentResult() { StatusCode = (int)HttpStatusCode.OK, Content = player }; + else + return new ContentResult() { StatusCode = (int)HttpStatusCode.Conflict }; + } + catch + { + return new ContentResult() { StatusCode = (int)HttpStatusCode.BadRequest }; + } } // GET api/player/5b4512fb673f4a638fe2907b8483c0ab