From 6285967d1cf6e9322f584de761eea31ade32b3e5 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Mon, 1 Oct 2018 02:28:42 +0200 Subject: Completed Weapon import function to automagically load data from an dsa website into the database --- DSACore/Hubs/ChatHub.cs | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'DSACore/Hubs/ChatHub.cs') diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs index 46fde08..3403a17 100644 --- a/DSACore/Hubs/ChatHub.cs +++ b/DSACore/Hubs/ChatHub.cs @@ -53,7 +53,7 @@ namespace DSACore.Hubs private Task SendToGroup(string message) { string group = getGroup(Context.ConnectionId).Name; - return Clients.Group(group).SendCoreAsync("ReceiveMessage", new object[] { getUser(Context.ConnectionId), message }); + return Clients.Group(group).SendCoreAsync("ReceiveMessage", new object[] { getUser(Context.ConnectionId).Name, message }); } private Models.Network.Group getGroup(string id) @@ -78,7 +78,7 @@ namespace DSACore.Hubs } } - await Clients.Caller.SendCoreAsync("ListGroups", new object[] { DSAGroups }); + await Clients.Caller.SendCoreAsync("ListGroups", new object[] { DSAGroups.Select(x=>x.SendGroup()) }); //throw new NotImplementedException("add database call to get groups"); } @@ -99,26 +99,46 @@ namespace DSACore.Hubs //throw new NotImplementedException("add database call to add groups"); } - public async Task Login(string group, string user, string password) + public async Task Login(string group, string user, string hash) { - if (password == DSAGroups.First(x=>x.Name == group).Password) + //string password = System.Text.Encoding.UTF8.GetString(hash); + if (hash == 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); + + await SendToGroup("Ein neuer Nutzer hat die Gruppe betreten"); + } + else + { + + await Clients.Caller.SendAsync("ReceiveMessage", "Falsches Passwort!"); } + } - await SendToGroup("Ein neuer Nutzer hat die Gruppe betreten"); + public override Task OnDisconnectedAsync(Exception exception) + { + Disconnect().Wait(); + return base.OnDisconnectedAsync(exception); } public async Task Disconnect() { - var group = getGroup(Context.ConnectionId); + try + { + var group = getGroup(Context.ConnectionId); - await SendToGroup("Connection lost"); - var user = getUser(Context.ConnectionId); - group.Users.Remove(user); - await Groups.RemoveFromGroupAsync(Context.ConnectionId, group.Name); + var user = getUser(Context.ConnectionId); + await SendToGroup(user.Name + " disconnected from the Server"); + group.Users.Remove(user); + await Groups.RemoveFromGroupAsync(Context.ConnectionId, group.Name); + } + catch (Exception e) + { + Console.WriteLine(e); + //throw; + } } -- cgit v1.2.3-54-g00ecf