Skip to content

Commit

Permalink
update server to v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvees committed Jul 11, 2018
1 parent 57fbf5e commit 2b1ac67
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/server/MagCore.Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Game(IMap map)
}).ContinueWith((task) => {
//Recycling
_state = GameState.Recycling;
Thread.Sleep(10000);
Thread.Sleep(10000);
Server.RemoveGame(Id);
});
}
Expand Down
36 changes: 25 additions & 11 deletions src/server/MagCore.Server/Controllers/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions src/server/MagCore.Server/Controllers/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b1ac67

Please sign in to comment.