diff options
Diffstat (limited to 'DSACore/Hubs')
-rw-r--r-- | DSACore/Hubs/Login.cs | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/DSACore/Hubs/Login.cs b/DSACore/Hubs/Login.cs index 1f6ca39..f08c24a 100644 --- a/DSACore/Hubs/Login.cs +++ b/DSACore/Hubs/Login.cs @@ -4,11 +4,13 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using DSACore.Commands; -using DSACore.DSA_Game.Characters; -using DSACore.FireBase; using DSACore.Models.Network; +using DSALib.Commands; +using DSALib.DSA_Game.Characters; +using DSALib.FireBase; +using DSALib.Models.Network; using Microsoft.AspNetCore.SignalR; +using Group = DSACore.Models.Network.Group; namespace DSACore.Hubs { @@ -18,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(); @@ -30,25 +31,16 @@ namespace DSACore.Hubs public static List<Token> Tokens { get; } = new List<Token>(); - [Obsolete] - private static async void AddGroups() - { - 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) { try { var group = getGroup(Context.ConnectionId).Name; } - catch (InvalidOperationException e) + catch (InvalidOperationException) { - //await Clients.Caller.SendCoreAsync(receiveMethod, - // new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); + await Clients.Caller.SendCoreAsync(ReceiveMethod, + new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); } if (message[0] == '/') @@ -93,7 +85,7 @@ namespace DSACore.Hubs return Clients.Group(group).SendCoreAsync(ReceiveMethod, new object[] {getUser(Context.ConnectionId).Name, message}); } - catch (InvalidOperationException e) + catch (InvalidOperationException) { return Clients.Caller.SendCoreAsync(ReceiveMethod, new object[] {"Nutzer ist in keiner Gruppe. Erst joinen!"}); @@ -111,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); @@ -126,7 +116,7 @@ namespace DSACore.Hubs public async Task AddGroup(string group, string password) { DsaGroups.Add(new Group(group, password)); - var Dgroup = new Models.Database.Groups.Group {Name = group, Id = DsaGroups.Count - 1}; + var Dgroup = new DSALib.Models.Database.Groups.Group {Name = group, Id = DsaGroups.Count - 1}; //Database.AddGroup(Dgroup); await Clients.Caller.SendCoreAsync(ReceiveMethod, new[] {$"group {group} sucessfully added"}); //throw new NotImplementedException("add database call to add groups"); @@ -136,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"); } |