summaryrefslogtreecommitdiff
path: root/DSACore/Controllers
diff options
context:
space:
mode:
authoruzvkl <dennis.kobert@student.kit.edu>2019-06-11 23:33:41 +0200
committeruzvkl <dennis.kobert@student.kit.edu>2019-06-11 23:33:41 +0200
commitaf74efccf8d21e6151022b71f3cacd3fa83024ee (patch)
tree20f383065d5cadea36e8d11d4bb3b35eca99f691 /DSACore/Controllers
parente6181c24124d97f2fbc932b8a68311e625463156 (diff)
Seperate the Core from dsa gamelogic
Diffstat (limited to 'DSACore/Controllers')
-rw-r--r--DSACore/Controllers/CommandsController.cs56
-rw-r--r--DSACore/Controllers/LobbyController.cs32
-rw-r--r--DSACore/Controllers/TokensController.cs25
-rw-r--r--DSACore/Controllers/ValuesController.cs45
4 files changed, 158 insertions, 0 deletions
diff --git a/DSACore/Controllers/CommandsController.cs b/DSACore/Controllers/CommandsController.cs
new file mode 100644
index 0000000..b6e0be2
--- /dev/null
+++ b/DSACore/Controllers/CommandsController.cs
@@ -0,0 +1,56 @@
+using System;
+using DSACore.Models.Network;
+using DSALib.Commands;
+using DSALib.Models.Network;
+using Microsoft.AspNetCore.Mvc;
+
+// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+
+namespace DSACore.Controllers
+{
+ [Route("dsa/[controller]")]
+ public class CommandsController : Controller
+ {
+ // GET: api/<controller>
+ [HttpGet]
+ public string Get()
+ {
+ return "Usage: post the command to execute";
+ }
+
+ // GET api/<controller>/5
+ /*[HttpGet("{id}")]
+ public string Get(int id)
+ {
+ return "value";
+ }*/
+
+ // POST api/<controller>/Felis
+ [HttpPost]
+ public string Post([FromBody] Command cmd)
+ {
+ try
+ {
+ return CommandHandler.ExecuteCommand(cmd).message;
+ }
+ catch (Exception e)
+ {
+ return $"Ein Fehler ist aufgetreten: \n {e.Message}";
+ }
+ }
+
+/*
+
+ // PUT api/<controller>/5
+ [HttpPut("{id}")]
+ public void Put(int id, [FromBody]string value)
+ {
+ }
+
+ // DELETE api/<controller>/5
+ [HttpDelete("{id}")]
+ public void Delete(int id)
+ {
+ }*/
+ }
+} \ No newline at end of file
diff --git a/DSACore/Controllers/LobbyController.cs b/DSACore/Controllers/LobbyController.cs
new file mode 100644
index 0000000..7890b4f
--- /dev/null
+++ b/DSACore/Controllers/LobbyController.cs
@@ -0,0 +1,32 @@
+using System;
+using DSACore.Models.Network;
+using DSALib.Commands;
+using DSALib.Models.Network;
+using Microsoft.AspNetCore.Mvc;
+
+namespace DSACore.Controllers
+{
+ public class ScribbleController : Controller
+ {
+ [Route("[controller]")]
+ // GET: api/<controller>
+ [HttpGet]
+ public string Get()
+ {
+ return "Usage: get /tokens/{Token}";
+ }
+
+ [HttpPost]
+ public string Post([FromBody] Command cmd)
+ {
+ try
+ {
+ return CommandHandler.ExecuteCommand(cmd).message;
+ }
+ catch (Exception e)
+ {
+ return $"Ein Fehler ist aufgetreten: \n {e.Message}";
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/DSACore/Controllers/TokensController.cs b/DSACore/Controllers/TokensController.cs
new file mode 100644
index 0000000..a85cabe
--- /dev/null
+++ b/DSACore/Controllers/TokensController.cs
@@ -0,0 +1,25 @@
+using DSACore.Hubs;
+using Microsoft.AspNetCore.Mvc;
+
+namespace DSACore.Controllers
+{
+ [Route("lobby/[controller]")]
+ [ApiController]
+ public class TokensController : Controller
+ {
+ // GET
+ [HttpGet("{token}")]
+ public ActionResult<string> Get(string token)
+ {
+ if (!int.TryParse(token, out var intToken))
+ return BadRequest("The token has to be a 32 bit unsigned integer");
+
+ if (intToken == 42) return Ok("Scribble");
+
+ if (!Users.Tokens.Exists(x => x.GetHashCode() == intToken)) return NotFound();
+
+ var group = Users.Tokens.Find(x => x.GetHashCode() == intToken);
+ return Ok(group.Group);
+ }
+ }
+} \ No newline at end of file
diff --git a/DSACore/Controllers/ValuesController.cs b/DSACore/Controllers/ValuesController.cs
new file mode 100644
index 0000000..eb08898
--- /dev/null
+++ b/DSACore/Controllers/ValuesController.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+
+namespace DSACore.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class ValuesController : ControllerBase
+ {
+ // GET api/values
+ [HttpGet]
+ public ActionResult<IEnumerable<string>> Get()
+ {
+ return new string[] { "value1", "value2" };
+ }
+
+ // GET api/values/5
+ [HttpGet("{id}")]
+ public ActionResult<string> Get(int id)
+ {
+ return "value";
+ }
+
+ // POST api/values
+ [HttpPost]
+ public void Post([FromBody] string value)
+ {
+ }
+
+ // PUT api/values/5
+ [HttpPut("{id}")]
+ public void Put(int id, [FromBody] string value)
+ {
+ }
+
+ // DELETE api/values/5
+ [HttpDelete("{id}")]
+ public void Delete(int id)
+ {
+ }
+ }
+}