diff options
author | uzvkl <dennis.kobert@student.kit.edu> | 2019-06-11 22:46:57 +0200 |
---|---|---|
committer | uzvkl <dennis.kobert@student.kit.edu> | 2019-06-11 22:46:57 +0200 |
commit | 2490ad5d31fe2ac778ff9303776f0e91f47a2862 (patch) | |
tree | 4b2b2b284897cd239ecbc3a2d4efa6d5d103057f /DSACore | |
parent | c80384ca8b729677d78934476e7b193b5327ae40 (diff) |
Organize groups to seperate connention management form gamelogic
Diffstat (limited to 'DSACore')
-rw-r--r-- | DSACore/Controllers/CommandsController.cs | 1 | ||||
-rw-r--r-- | DSACore/Controllers/LobbyController.cs | 3 | ||||
-rw-r--r-- | DSACore/DSACore.csproj | 5 | ||||
-rw-r--r-- | DSACore/Hubs/Login.cs | 18 | ||||
-rw-r--r-- | DSACore/Models/Network/Group.cs | 43 | ||||
-rw-r--r-- | DSACore/Models/Network/Token.cs | 21 | ||||
-rw-r--r-- | DSACore/Models/Network/User.cs | 9 | ||||
-rw-r--r-- | DSACore/Properties/DSACore-Audio-Sound.json | 7 | ||||
-rw-r--r-- | DSACore/Properties/DSALib-Auxiliary-CommandInfo.json (renamed from DSACore/Properties/DSACore-Auxiliary-CommandInfo.json) | 0 | ||||
-rw-r--r-- | DSACore/Properties/DSALib-DSA_Game-Characters-Character.json (renamed from DSACore/Properties/DSACore-DSA_Game-Characters-Character.json) | 0 |
10 files changed, 88 insertions, 19 deletions
diff --git a/DSACore/Controllers/CommandsController.cs b/DSACore/Controllers/CommandsController.cs index 2ab9c96..b6e0be2 100644 --- a/DSACore/Controllers/CommandsController.cs +++ b/DSACore/Controllers/CommandsController.cs @@ -1,4 +1,5 @@ using System; +using DSACore.Models.Network; using DSALib.Commands; using DSALib.Models.Network; using Microsoft.AspNetCore.Mvc; diff --git a/DSACore/Controllers/LobbyController.cs b/DSACore/Controllers/LobbyController.cs index c861eac..7890b4f 100644 --- a/DSACore/Controllers/LobbyController.cs +++ b/DSACore/Controllers/LobbyController.cs @@ -1,6 +1,7 @@ using System; -using DSALib.Models.Network; +using DSACore.Models.Network; using DSALib.Commands; +using DSALib.Models.Network; using Microsoft.AspNetCore.Mvc; namespace DSACore.Controllers diff --git a/DSACore/DSACore.csproj b/DSACore/DSACore.csproj index d730ea4..f7def31 100644 --- a/DSACore/DSACore.csproj +++ b/DSACore/DSACore.csproj @@ -6,7 +6,10 @@ </PropertyGroup> <ItemGroup> - <Folder Include="wwwroot\" /> + <Compile Remove="wwwroot\**" /> + <Content Remove="wwwroot\**" /> + <EmbeddedResource Remove="wwwroot\**" /> + <None Remove="wwwroot\**" /> </ItemGroup> <ItemGroup> diff --git a/DSACore/Hubs/Login.cs b/DSACore/Hubs/Login.cs index ebe0bae..f08c24a 100644 --- a/DSACore/Hubs/Login.cs +++ b/DSACore/Hubs/Login.cs @@ -4,12 +4,13 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using DSACore.Models.Network; using DSALib.Commands; using DSALib.DSA_Game.Characters; -using DSALib.Models.Network; using DSALib.FireBase; +using DSALib.Models.Network; using Microsoft.AspNetCore.SignalR; -using Group = DSALib.Models.Network.Group; +using Group = DSACore.Models.Network.Group; namespace DSACore.Hubs { @@ -19,9 +20,8 @@ namespace DSACore.Hubs private const string ReceiveMethod = "ReceiveMessage"; //receiveMethod; - static Users() - { - DsaGroups = Database.GetGroups().Result; + static Users() { + DsaGroups = Database.GetGroups().Result.Select(x=>new Group(x.Item1, x.Item2)).ToList(); DsaGroups.Add(new Group("login", "")); DsaGroups.Add(new Group("online", "")); //AddGroups(); @@ -103,11 +103,9 @@ namespace DSACore.Hubs .First(z => z.ConnectionId.Equals(id)); } - public async Task GetGroups() - { + public async Task GetGroups() { var test = await Database.GetGroups(); - - foreach (var group in test) + foreach (var group in test.Select(x => new Group(x.Item1, x.Item2)).ToList()) if (!DsaGroups.Exists(x => x.Name.Equals(group.Name))) DsaGroups.Add(group); @@ -128,7 +126,7 @@ namespace DSACore.Hubs { var group = getGroup(Context.ConnectionId); - await Database.AddChar(new Character(new MemoryStream(Encoding.UTF8.GetBytes(xml))), group); + await Database.AddChar(new Character(new MemoryStream(Encoding.UTF8.GetBytes(xml))), group.Name); //throw new NotImplementedException("add database call to add groups"); } diff --git a/DSACore/Models/Network/Group.cs b/DSACore/Models/Network/Group.cs new file mode 100644 index 0000000..efe12ee --- /dev/null +++ b/DSACore/Models/Network/Group.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; + +namespace DSACore.Models.Network +{ + public class Group + { + public Group(string name, string password) + { + Name = name; + Password = password; + } + + public Group(string name, int userOnline) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + } + + public string Name { get; set; } + public string Password { get; set; } + public List<User> Users { get; set; } = new List<User>(); + + public int UserCount => Users.Count; + + public SendGroup SendGroup() + { + return new SendGroup(Name, UserCount); + } + } + + public class SendGroup + { + public SendGroup(string name, int userCount) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + UserCount = userCount; + } + + public string Name { get; set; } + + public int UserCount { get; set; } + } +}
\ No newline at end of file diff --git a/DSACore/Models/Network/Token.cs b/DSACore/Models/Network/Token.cs new file mode 100644 index 0000000..451cafc --- /dev/null +++ b/DSACore/Models/Network/Token.cs @@ -0,0 +1,21 @@ +using System; + +namespace DSACore.Models.Network +{ + public class Token + { + private readonly DateTime creation = DateTime.Now; + + public Token(string group) + { + Group = group; + } + + public string Group { get; set; } + + public bool IsValid() + { + return DateTime.Now - creation < TimeSpan.FromMinutes(1); + } + } +}
\ No newline at end of file diff --git a/DSACore/Models/Network/User.cs b/DSACore/Models/Network/User.cs new file mode 100644 index 0000000..8b8008c --- /dev/null +++ b/DSACore/Models/Network/User.cs @@ -0,0 +1,9 @@ +namespace DSACore.Models.Network +{ + public class User + { + public string Name { get; set; } + public string ConnectionId { get; set; } + public int Char { get; set; } + } +}
\ No newline at end of file diff --git a/DSACore/Properties/DSACore-Audio-Sound.json b/DSACore/Properties/DSACore-Audio-Sound.json deleted file mode 100644 index 87a0e6b..0000000 --- a/DSACore/Properties/DSACore-Audio-Sound.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "Name": "Test", - "Url": "http", - "Volume": 100 - } -]
\ No newline at end of file diff --git a/DSACore/Properties/DSACore-Auxiliary-CommandInfo.json b/DSACore/Properties/DSALib-Auxiliary-CommandInfo.json index b9941f2..b9941f2 100644 --- a/DSACore/Properties/DSACore-Auxiliary-CommandInfo.json +++ b/DSACore/Properties/DSALib-Auxiliary-CommandInfo.json diff --git a/DSACore/Properties/DSACore-DSA_Game-Characters-Character.json b/DSACore/Properties/DSALib-DSA_Game-Characters-Character.json index fd387f5..fd387f5 100644 --- a/DSACore/Properties/DSACore-DSA_Game-Characters-Character.json +++ b/DSACore/Properties/DSALib-DSA_Game-Characters-Character.json |