From ad0a46175e7efbbd5bdf952aacc69d8a7750b05a Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Thu, 27 Sep 2018 23:46:43 +0200 Subject: implemented rudemetary groups --- DSACore/Hubs/ChatHub.cs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'DSACore/Hubs') diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs index 6af8c38..9cd7aed 100644 --- a/DSACore/Hubs/ChatHub.cs +++ b/DSACore/Hubs/ChatHub.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using DSACore.Models; using Microsoft.AspNetCore.SignalR; namespace DSACore.Hubs @@ -10,7 +11,35 @@ namespace DSACore.Hubs { public async Task SendMessage(string user, string message) { - await Clients.All.SendAsync("ReciveMessage", user, message); + string group = "default"; + var args = message.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); + var ident = args.First().Replace("!", ""); + if(args.Count>0){args.RemoveAt(0);} + + await SendToGroup(group, user, Commands.CommandHandler.ExecuteCommand(new Command{CharId = 0,CmdIdentifier = ident, CmdTexts = args, Name = user})); } + + private Task SendToGroup(string group, string user, string message) + { + return Clients.Group(group).SendCoreAsync("ReceiveMessage", new object[] { user, message }); + } + + public async Task Login(string group, string password) + { + if (password == "valid") + { + await Groups.AddToGroupAsync(Context.ConnectionId, group); + } + + await SendToGroup(group, "", "Ein neuer Nutzer hat die Gruppe betreten"); + } + + public async Task Disconnect(string group, string user) + { + await Groups.RemoveFromGroupAsync(Context.ConnectionId, group); + + await SendToGroup(group, user, "Connection lost"); + } + } } -- cgit v1.2.3-70-g09d2 From edb346d1e6599dbe48ec257f3536f6021163673c Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Fri, 28 Sep 2018 15:16:59 +0200 Subject: added some validation functionality --- DSACore/Hubs/ChatHub.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'DSACore/Hubs') diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs index 9cd7aed..c429d52 100644 --- a/DSACore/Hubs/ChatHub.cs +++ b/DSACore/Hubs/ChatHub.cs @@ -24,6 +24,11 @@ namespace DSACore.Hubs return Clients.Group(group).SendCoreAsync("ReceiveMessage", new object[] { user, message }); } + public async Task GetGroups() + { + await Clients.Caller.SendCoreAsync("ListGroups", new object[] { "TheCrew", "Testdata" }); + } + public async Task Login(string group, string password) { if (password == "valid") -- cgit v1.2.3-70-g09d2 From 04912687127303fd270b61f131cf68fd4aaae956 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Sat, 29 Sep 2018 05:49:13 +0200 Subject: modified user group authenth --- DSACore/Hubs/ChatHub.cs | 14 +++++++++----- DSACore/Models/User.cs | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 DSACore/Models/User.cs (limited to 'DSACore/Hubs') diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs index c429d52..a8bf883 100644 --- a/DSACore/Hubs/ChatHub.cs +++ b/DSACore/Hubs/ChatHub.cs @@ -9,14 +9,15 @@ namespace DSACore.Hubs { public class ChatHub : Hub { + private static Dictionary UserGroup; + public async Task SendMessage(string user, string message) { - string group = "default"; var args = message.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); var ident = args.First().Replace("!", ""); if(args.Count>0){args.RemoveAt(0);} - await SendToGroup(group, user, Commands.CommandHandler.ExecuteCommand(new Command{CharId = 0,CmdIdentifier = ident, CmdTexts = args, Name = user})); + await SendToGroup(UserGroup[Context.ConnectionId].Group, user, Commands.CommandHandler.ExecuteCommand(new Command{CharId = 0,CmdIdentifier = ident, CmdTexts = args, Name = user})); } private Task SendToGroup(string group, string user, string message) @@ -27,23 +28,26 @@ namespace DSACore.Hubs public async Task GetGroups() { await Clients.Caller.SendCoreAsync("ListGroups", new object[] { "TheCrew", "Testdata" }); + throw new NotImplementedException("add database call to get groups"); } public async Task Login(string group, string password) { if (password == "valid") { + UserGroup.Add(Context.ConnectionId, new User{Group = group}); await Groups.AddToGroupAsync(Context.ConnectionId, group); } await SendToGroup(group, "", "Ein neuer Nutzer hat die Gruppe betreten"); } - public async Task Disconnect(string group, string user) + public async Task Disconnect() { - await Groups.RemoveFromGroupAsync(Context.ConnectionId, group); + var user = UserGroup[Context.ConnectionId]; + await Groups.RemoveFromGroupAsync(Context.ConnectionId, user.Group); - await SendToGroup(group, user, "Connection lost"); + await SendToGroup(user.Group, user.Name, "Connection lost"); } } diff --git a/DSACore/Models/User.cs b/DSACore/Models/User.cs new file mode 100644 index 0000000..105e564 --- /dev/null +++ b/DSACore/Models/User.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace DSACore.Models +{ + public class User + { + public string Name { get; set; } + public string Group { get; set; } + } +} -- cgit v1.2.3-70-g09d2