diff options
Diffstat (limited to 'DSACore')
-rw-r--r-- | DSACore/Auxiliary/WeaponImporter.cs | 1 | ||||
-rw-r--r-- | DSACore/Controllers/CommandsController.cs | 4 | ||||
-rw-r--r-- | DSACore/Controllers/LobbyController.cs | 32 | ||||
-rw-r--r-- | DSACore/Controllers/TokensController.cs | 28 | ||||
-rw-r--r-- | DSACore/DSACore.csproj | 6 | ||||
-rw-r--r-- | DSACore/DSA_Game/Dsa.cs | 2 | ||||
-rw-r--r-- | DSACore/FireBase/Database.cs | 2 | ||||
-rw-r--r-- | DSACore/Hubs/Login.cs (renamed from DSACore/Hubs/ChatHub.cs) | 68 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/Advantage.cs (renamed from DSACore/Models/Database/Advantage.cs) | 5 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/CharSpell.cs (renamed from DSACore/Models/Database/CharSpell.cs) | 5 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/DatabaseChar.cs (renamed from DSACore/Models/Database/DatabaseChar.cs) | 4 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/Field.cs (renamed from DSACore/Models/Database/Field.cs) | 5 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/GeneralSpell.cs (renamed from DSACore/Models/Database/GeneralSpell.cs) | 7 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/GroupChar.cs (renamed from DSACore/Models/Database/GroupChar.cs) | 7 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/Inventory.cs (renamed from DSACore/Models/Database/Inventory.cs) | 7 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/Talent.cs (renamed from DSACore/Models/Database/Talent.cs) | 5 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/Weapon.cs (renamed from DSACore/Models/Database/Weapon.cs) | 5 | ||||
-rw-r--r-- | DSACore/Models/Database/DSA/WeaponTalent.cs (renamed from DSACore/Models/Database/WeaponTalent.cs) | 2 | ||||
-rw-r--r-- | DSACore/Models/Database/Groups/DSAGroup.cs | 10 | ||||
-rw-r--r-- | DSACore/Models/Database/Groups/Group.cs (renamed from DSACore/Models/Database/Group.cs) | 8 | ||||
-rw-r--r-- | DSACore/Models/Network/Token.cs | 21 | ||||
-rw-r--r-- | DSACore/Startup.cs | 2 |
22 files changed, 155 insertions, 81 deletions
diff --git a/DSACore/Auxiliary/WeaponImporter.cs b/DSACore/Auxiliary/WeaponImporter.cs index 8ed2b3f..635d477 100644 --- a/DSACore/Auxiliary/WeaponImporter.cs +++ b/DSACore/Auxiliary/WeaponImporter.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; using DSACore.FireBase; +using DSACore.Models.Database.DSA; using Group = System.Text.RegularExpressions.Group; namespace DSACore.Auxiliary diff --git a/DSACore/Controllers/CommandsController.cs b/DSACore/Controllers/CommandsController.cs index 5f27f63..d35690c 100644 --- a/DSACore/Controllers/CommandsController.cs +++ b/DSACore/Controllers/CommandsController.cs @@ -10,14 +10,14 @@ using Microsoft.AspNetCore.Mvc; namespace DSACore.Controllers { - [Route("api/[controller]")] + [Route("dsa/[controller]")] public class CommandsController : Controller { // GET: api/<controller> [HttpGet] public string Get() { - return "Dies ist die supa dolle Web Api"; + return "Usage: post the command to execute"; } // GET api/<controller>/5 diff --git a/DSACore/Controllers/LobbyController.cs b/DSACore/Controllers/LobbyController.cs new file mode 100644 index 0000000..a946184 --- /dev/null +++ b/DSACore/Controllers/LobbyController.cs @@ -0,0 +1,32 @@ +using DSACore.Models.Network; +using System; +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 Commands.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..453d477 --- /dev/null +++ b/DSACore/Controllers/TokensController.cs @@ -0,0 +1,28 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace DSACore.Controllers +{ + [Route("lobby/[controller]")] + [ApiController] + public class TokensController : Controller + { + + // GET + [HttpGet("{token}")] + public async Task<ActionResult<string>> Get(int token) + { + + if (!Hubs.Users.Tokens.Exists(x => x.GetHashCode() == token)) + { + return NotFound(); + } + + var group = Hubs.Users.Tokens.Find(x => x.GetHashCode() == token); + return Ok(group); + } + } +}
\ No newline at end of file diff --git a/DSACore/DSACore.csproj b/DSACore/DSACore.csproj index ad760c2..3d928e1 100644 --- a/DSACore/DSACore.csproj +++ b/DSACore/DSACore.csproj @@ -1,4 +1,4 @@ -<Project Sdk="Microsoft.NET.Sdk.Web"> +<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> @@ -18,4 +18,8 @@ <ProjectReference Include="..\FireBase\FireBase.csproj" /> </ItemGroup> + <ItemGroup> + <Compile Remove="Controllers\ValuesController.cs" /> + </ItemGroup> + </Project> diff --git a/DSACore/DSA_Game/Dsa.cs b/DSACore/DSA_Game/Dsa.cs index 3b2e4aa..cbdb734 100644 --- a/DSACore/DSA_Game/Dsa.cs +++ b/DSACore/DSA_Game/Dsa.cs @@ -16,7 +16,7 @@ namespace DSACore.DSA_Game public static class Dsa { #if DEBUG - public const string rootPath = "C:\\Users\\Dennis\\Source\\Repos\\DiscoBot\\DSACore\\";//"DiscoBot\\DSACore\\"; + public const string rootPath = "";//"C:\\Users\\Dennis\\Source\\Repos\\DiscoBot\\DSACore\\";//"DiscoBot\\DSACore\\"; #else public const string rootPath = "";//"DiscoBot\\DSACore\\"; #endif diff --git a/DSACore/FireBase/Database.cs b/DSACore/FireBase/Database.cs index db57381..15b76f0 100644 --- a/DSACore/FireBase/Database.cs +++ b/DSACore/FireBase/Database.cs @@ -6,6 +6,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using DSACore.Models.Database.DSA; +using DSACore.Models.Database.Groups; namespace DSACore.FireBase diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/Login.cs index 1994164..5f984e2 100644 --- a/DSACore/Hubs/ChatHub.cs +++ b/DSACore/Hubs/Login.cs @@ -12,28 +12,31 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace DSACore.Hubs { - public class ChatHub : Hub + public class Users : Hub { //private static Dictionary<string, User> UserGroup = new Dictionary<string, User>(); - private const string receiveMethod = "ReceiveMessage";//receiveMethod; + private const string ReceiveMethod = "ReceiveMessage";//receiveMethod; - private static List<Group> DSAGroups = new List<Group>(); + private static List<Group> DsaGroups {get; set; } + public static List<Token> Tokens { get;} = new List<Token>(); - static ChatHub() + static Users() { - DSAGroups = Database.GetGroups().Result; - DSAGroups.Add(new Group("login", "")); - DSAGroups.Add(new Group("online", "")); + DsaGroups = Database.GetGroups().Result; + DsaGroups.Add(new Group("login", "")); + DsaGroups.Add(new Group("online", "")); //AddGroups(); } + + [Obsolete] private static async void AddGroups() { - await Database.AddGroup(new Models.Database.Group { Name = "HalloWelt", Password = "valid" }); - await Database.AddGroup(new Models.Database.Group { Name = "Die Krassen Gamer", Password = "valid" }); - await Database.AddGroup(new Models.Database.Group { Name = "DSA", Password = "valid" }); - await Database.AddGroup(new Models.Database.Group { Name = "Die Überhelden", Password = "valid" }); + await Database.AddGroup(new Models.Database.Groups.Group { Name = "HalloWelt", Password = "valid" }); + await Database.AddGroup(new Models.Database.Groups.Group { Name = "Die Krassen Gamer", Password = "valid" }); + await Database.AddGroup(new Models.Database.Groups.Group { Name = "DSA", Password = "valid" }); + await Database.AddGroup(new Models.Database.Groups.Group { Name = "Die Überhelden", Password = "valid" }); } public async Task SendMessage(string user, string message) @@ -72,7 +75,7 @@ namespace DSACore.Hubs { case ResponseType.Caller: case ResponseType.Error: - await Clients.Caller.SendAsync(receiveMethod, ret.message); + await Clients.Caller.SendAsync(ReceiveMethod, ret.message); break; case ResponseType.Broadcast: await SendToGroup(ret.message); @@ -93,48 +96,48 @@ namespace DSACore.Hubs try { string group = getGroup(Context.ConnectionId).Name; - return Clients.Group(group).SendCoreAsync(receiveMethod, + return Clients.Group(group).SendCoreAsync(ReceiveMethod, new object[] {getUser(Context.ConnectionId).Name, message}); } catch (InvalidOperationException e) { - return Clients.Caller.SendCoreAsync(receiveMethod, + return Clients.Caller.SendCoreAsync(ReceiveMethod, new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); } } private Models.Network.Group getGroup(string id) { - return DSAGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))); + return DsaGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))); } private User getUser(string id) { - return DSAGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))).Users.First(z => z.ConnectionId.Equals(id)); + return DsaGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))).Users.First(z => z.ConnectionId.Equals(id)); } public async Task GetGroups() { - var test = Database.GetGroups(); - test.Wait(); - foreach (var group in test.Result) + var test = await Database.GetGroups(); + + foreach (var group in test) { - if (!DSAGroups.Exists(x => x.Name.Equals(group.Name))) + if (!DsaGroups.Exists(x => x.Name.Equals(group.Name))) { - DSAGroups.Add(group); + DsaGroups.Add(group); } } - await Clients.Caller.SendCoreAsync("ListGroups", new object[] { DSAGroups.Select(x => x.SendGroup()) }); + await Clients.Caller.SendCoreAsync("ListGroups", new object[] { DsaGroups.Select(x => x.SendGroup()) }); //throw new NotImplementedException("add database call to get groups"); } public async Task AddGroup(string group, string password) { - DSAGroups.Add(new Group(group, password)); - var Dgroup = new DSACore.Models.Database.Group { Name = group, Id = DSAGroups.Count - 1 }; + DsaGroups.Add(new Group(group, password)); + var Dgroup = new Models.Database.Groups.Group { Name = group, Id = DsaGroups.Count - 1 }; //Database.AddGroup(Dgroup); - await Clients.Caller.SendCoreAsync(receiveMethod, new[] { $"group {@group} sucessfully added" }); + await Clients.Caller.SendCoreAsync(ReceiveMethod, new[] { $"group {@group} sucessfully added" }); //throw new NotImplementedException("add database call to add groups"); } @@ -149,9 +152,9 @@ namespace DSACore.Hubs public async Task Login(string group, string user, string hash) { //string password = System.Text.Encoding.UTF8.GetString(hash); - if (hash == DSAGroups.First(x => x.Name == group).Password) + if (hash == DsaGroups.First(x => x.Name == group).Password) { - var gGroup = DSAGroups.First(x => x.Name.Equals(group)); + var gGroup = DsaGroups.First(x => x.Name.Equals(group)); if (!gGroup.Users.Exists(x => x.Name.Equals(user))) { await Groups.RemoveFromGroupAsync(Context.ConnectionId, "login"); @@ -160,6 +163,10 @@ namespace DSACore.Hubs await SendToGroup("Ein neuer Nutzer hat die Gruppe betreten"); await Clients.Caller.SendAsync("LoginResponse", 0); await Clients.Caller.SendAsync("PlayerStatusChanged", new[] {user, "online"}); + + Tokens.Add(new Token(group)); + await Clients.Caller.SendAsync("Token", Tokens.Last().GetHashCode()); + purgeTokens(); } else { @@ -173,6 +180,11 @@ namespace DSACore.Hubs } } + private void purgeTokens() + { + Tokens.RemoveAll(x => !x.IsValid()); + } + public override Task OnDisconnectedAsync(Exception exception) { Disconnect().Wait(); @@ -189,7 +201,7 @@ namespace DSACore.Hubs public async Task Disconnect() { await Groups.RemoveFromGroupAsync(Context.ConnectionId, "online"); - if (DSAGroups.Exists(x => x.Users.Exists(y => y.ConnectionId == Context.ConnectionId))) + if (DsaGroups.Exists(x => x.Users.Exists(y => y.ConnectionId == Context.ConnectionId))) { try { diff --git a/DSACore/Models/Database/Advantage.cs b/DSACore/Models/Database/DSA/Advantage.cs index 67965fc..2f0b443 100644 --- a/DSACore/Models/Database/Advantage.cs +++ b/DSACore/Models/Database/DSA/Advantage.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class Advantage { diff --git a/DSACore/Models/Database/CharSpell.cs b/DSACore/Models/Database/DSA/CharSpell.cs index 670488c..63d917a 100644 --- a/DSACore/Models/Database/CharSpell.cs +++ b/DSACore/Models/Database/DSA/CharSpell.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class CharSpell { diff --git a/DSACore/Models/Database/DatabaseChar.cs b/DSACore/Models/Database/DSA/DatabaseChar.cs index 9cd865f..8c51821 100644 --- a/DSACore/Models/Database/DatabaseChar.cs +++ b/DSACore/Models/Database/DSA/DatabaseChar.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using DSALib; -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class DatabaseChar { diff --git a/DSACore/Models/Database/Field.cs b/DSACore/Models/Database/DSA/Field.cs index b14d9da..5022768 100644 --- a/DSACore/Models/Database/Field.cs +++ b/DSACore/Models/Database/DSA/Field.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class Field { diff --git a/DSACore/Models/Database/GeneralSpell.cs b/DSACore/Models/Database/DSA/GeneralSpell.cs index f53081e..74b95d7 100644 --- a/DSACore/Models/Database/GeneralSpell.cs +++ b/DSACore/Models/Database/DSA/GeneralSpell.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class GeneralSpell : Talent { diff --git a/DSACore/Models/Database/GroupChar.cs b/DSACore/Models/Database/DSA/GroupChar.cs index 1dfc4ea..70b8fc1 100644 --- a/DSACore/Models/Database/GroupChar.cs +++ b/DSACore/Models/Database/DSA/GroupChar.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class GroupChar { diff --git a/DSACore/Models/Database/Inventory.cs b/DSACore/Models/Database/DSA/Inventory.cs index e6b47ec..69c7b08 100644 --- a/DSACore/Models/Database/Inventory.cs +++ b/DSACore/Models/Database/DSA/Inventory.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class Inventory { diff --git a/DSACore/Models/Database/Talent.cs b/DSACore/Models/Database/DSA/Talent.cs index aca65a4..a6de395 100644 --- a/DSACore/Models/Database/Talent.cs +++ b/DSACore/Models/Database/DSA/Talent.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class Talent { diff --git a/DSACore/Models/Database/Weapon.cs b/DSACore/Models/Database/DSA/Weapon.cs index b2f8a1e..24b334a 100644 --- a/DSACore/Models/Database/Weapon.cs +++ b/DSACore/Models/Database/DSA/Weapon.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class Weapon { diff --git a/DSACore/Models/Database/WeaponTalent.cs b/DSACore/Models/Database/DSA/WeaponTalent.cs index 4b98d24..869cb35 100644 --- a/DSACore/Models/Database/WeaponTalent.cs +++ b/DSACore/Models/Database/DSA/WeaponTalent.cs @@ -1,6 +1,6 @@ using System; -namespace DSACore.Models.Database +namespace DSACore.Models.Database.DSA { public class WeaponTalent { diff --git a/DSACore/Models/Database/Groups/DSAGroup.cs b/DSACore/Models/Database/Groups/DSAGroup.cs new file mode 100644 index 0000000..8f20278 --- /dev/null +++ b/DSACore/Models/Database/Groups/DSAGroup.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using DSACore.Models.Database.DSA; + +namespace DSACore.Models.Database.Groups +{ + public class DSAGroup : Group + { + public List<GroupChar> Chars { get; set; }= new List<GroupChar>(); + } +}
\ No newline at end of file diff --git a/DSACore/Models/Database/Group.cs b/DSACore/Models/Database/Groups/Group.cs index a7bb929..23e5f68 100644 --- a/DSACore/Models/Database/Group.cs +++ b/DSACore/Models/Database/Groups/Group.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database +namespace DSACore.Models.Database.Groups { public class Group { @@ -11,7 +6,6 @@ namespace DSACore.Models.Database public string Discord { get; set; } public string Password { get; set; } public int Id { get; set; } - public List<GroupChar> Chars { get; set; }= new List<GroupChar>(); } diff --git a/DSACore/Models/Network/Token.cs b/DSACore/Models/Network/Token.cs new file mode 100644 index 0000000..0021317 --- /dev/null +++ b/DSACore/Models/Network/Token.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.EntityFrameworkCore; + +namespace DSACore.Models.Network +{ + public class Token + { + public string Group { get; set; } + private DateTime creation = DateTime.Now; + + public Token(string @group) + { + Group = @group; + } + + public bool IsValid() + { + return DateTime.Now - creation < TimeSpan.FromMinutes(1); + } + } +}
\ No newline at end of file diff --git a/DSACore/Startup.cs b/DSACore/Startup.cs index f8f6dfd..1dcc690 100644 --- a/DSACore/Startup.cs +++ b/DSACore/Startup.cs @@ -62,7 +62,7 @@ namespace DSACore app.UseCors("CorsPolicy"); - app.UseSignalR(routes => { routes.MapHub<ChatHub>("/chatHub"); }); + app.UseSignalR(routes => { routes.MapHub<Users>("/login"); }); app.UseWebSockets(); |