summaryrefslogtreecommitdiff
path: root/DSACore/Hubs
diff options
context:
space:
mode:
Diffstat (limited to 'DSACore/Hubs')
-rw-r--r--DSACore/Hubs/ChatHub.cs26
1 files changed, 19 insertions, 7 deletions
diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs
index 6335183..e489b2e 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.FireBase;
using DSACore.Models;
using DSACore.Models.Network;
using Microsoft.AspNetCore.SignalR;
@@ -12,7 +13,17 @@ namespace DSACore.Hubs
{
//private static Dictionary<string, User> UserGroup = new Dictionary<string, User>();
- private static List<Group> DSAGroups = new List<Group>();
+ private static List<Group> DSAGroups = new List<Group>();
+
+ static ChatHub()
+ {
+ DSAGroups = Database.GetGroups().Result;
+ DSAGroups.Add(new Group("TheCrew", "valid"));
+ DSAGroups.Add(new Group("HalloWelt", "valid"));
+ DSAGroups.Add(new Group("DieKrassenGamer", "valid"));
+ DSAGroups.Add(new Group("DSA", "valid"));
+ DSAGroups.Add(new Group("DieÜberhelden", "valid"));
+ }
public async Task SendMessage(string user, string message)
{
@@ -20,15 +31,14 @@ namespace DSACore.Hubs
var ident = args.First().Replace("!", "");
if(args.Count>0){args.RemoveAt(0);}
- string group;
try
{
- group = getGroup(Context.ConnectionId).Name;
+ string 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 Clients.Caller.SendCoreAsync("ReceiveMessage", new object[] {"Nutzer ist in keiner Gruppe. Erst joinen!"});
}
}
@@ -38,7 +48,7 @@ namespace DSACore.Hubs
return Clients.Group(group).SendCoreAsync("ReceiveMessage", new object[] { user, message });
}
- private Group getGroup(string id)
+ private Models.Network.Group getGroup(string id)
{
return DSAGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id)));
}
@@ -51,8 +61,10 @@ namespace DSACore.Hubs
public async Task AddGroup(string group, string password)
{
- DSAGroups.Add(new Group{Name = group, Password = password});
- Clients.Caller.SendCoreAsync("ReceiveMessage", new[] {$"group {group} sucessfully added"});
+ DSAGroups.Add(new Group(group, password));
+ var Dgroup = new DSACore.Models.Database.Group{Name = group, Id = DSAGroups.Count-1};
+ Database.CreateGroup(Dgroup);
+ await Clients.Caller.SendCoreAsync("ReceiveMessage", new[] {$"group {@group} sucessfully added"});
//throw new NotImplementedException("add database call to add groups");
}