diff options
author | TrueKuehli <rctcoaster2000@hotmail.de> | 2018-09-29 21:52:45 +0200 |
---|---|---|
committer | TrueKuehli <rctcoaster2000@hotmail.de> | 2018-09-29 21:52:45 +0200 |
commit | f97f25ea54a0f888d2195d6868346854a2a005e0 (patch) | |
tree | 5ea9327de1d548a341f55ff4f13b89e09fb6b443 /DSACore/Hubs/ChatHub.cs | |
parent | 330c49947c82d3d66f65f03abcad75d57d3dc121 (diff) | |
parent | 33dc613fffad69c1c608e21eac6fcd3f2954ead8 (diff) |
Merge branch 'WebApi' of https://github.com/TrueDoctor/DiscoBot into WebApi
Diffstat (limited to 'DSACore/Hubs/ChatHub.cs')
-rw-r--r-- | DSACore/Hubs/ChatHub.cs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs index 484a350..6335183 100644 --- a/DSACore/Hubs/ChatHub.cs +++ b/DSACore/Hubs/ChatHub.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using DSACore.Models; +using DSACore.Models.Network; using Microsoft.AspNetCore.SignalR; namespace DSACore.Hubs @@ -18,8 +19,18 @@ namespace DSACore.Hubs var args = message.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); var ident = args.First().Replace("!", ""); if(args.Count>0){args.RemoveAt(0);} + + string group; + try + { + group = getGroup(Context.ConnectionId).Name; + await SendToGroup(group, user, Commands.CommandHandler.ExecuteCommand(new Command { CharId = 0, CmdIdentifier = ident, CmdTexts = args, Name = user })); + } + catch(InvalidOperationException e) + { + await Clients.Caller.SendCoreAsync("ReceiveMessage", new[] {"Nutzer ist in keiner Gruppe. Erst joinen!"}); + } - await SendToGroup(getGroup(Context.ConnectionId).Name, user, Commands.CommandHandler.ExecuteCommand(new Command{CharId = 0,CmdIdentifier = ident, CmdTexts = args, Name = user})); } private Task SendToGroup(string group, string user, string message) @@ -34,19 +45,20 @@ namespace DSACore.Hubs public async Task GetGroups() { - await Clients.Caller.SendCoreAsync("ListGroups", new object[] { Groups }); - throw new NotImplementedException("add database call to get groups"); + await Clients.Caller.SendCoreAsync("ListGroups", new object[] { DSAGroups }); + //throw new NotImplementedException("add database call to get groups"); } public async Task AddGroup(string group, string password) { - await Clients.Caller.SendCoreAsync("ListGroups", new object[] { Groups }); - throw new NotImplementedException("add database call to add groups"); + DSAGroups.Add(new Group{Name = group, Password = password}); + Clients.Caller.SendCoreAsync("ReceiveMessage", new[] {$"group {group} sucessfully added"}); + //throw new NotImplementedException("add database call to add groups"); } public async Task Login(string group, string user, string password) { - if (password == "valid") + if (password == DSAGroups.First(x=>x.Name == group).Password) { DSAGroups.First(x=>x.Name.Equals(group)).Users.Add(new User{ConnectionId = Context.ConnectionId, Name = user}); await Groups.AddToGroupAsync(Context.ConnectionId, group); |