From eedd564c1490a1cc785a1a8bbfdc3e5987543e52 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Wed, 15 May 2019 23:05:47 +0200 Subject: change chathub url --- WebInterface/NodeJSServer/src/js/play.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'WebInterface') diff --git a/WebInterface/NodeJSServer/src/js/play.js b/WebInterface/NodeJSServer/src/js/play.js index af0f70d..2d4effe 100644 --- a/WebInterface/NodeJSServer/src/js/play.js +++ b/WebInterface/NodeJSServer/src/js/play.js @@ -2,7 +2,7 @@ import Interface from './modules/interface'; import UIManager from './modules/ui/uiManager'; import Networker from './modules/networking/networker'; -const SERVERURL = 'https://kobert.dev/dsa/api/chatHub'; +const SERVERURL = 'https://kobert.dev/api/Login'; let iface = new Interface(); let uiMan = new UIManager(iface); -- cgit v1.2.3-54-g00ecf From 163897120db77d45435ab1576aaa28f6d9409bf5 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Wed, 15 May 2019 23:08:09 +0200 Subject: see last commit --- WebInterface/NodeJSServer/src/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'WebInterface') diff --git a/WebInterface/NodeJSServer/src/js/index.js b/WebInterface/NodeJSServer/src/js/index.js index 407cd39..249adc9 100644 --- a/WebInterface/NodeJSServer/src/js/index.js +++ b/WebInterface/NodeJSServer/src/js/index.js @@ -2,7 +2,7 @@ import Interface from './modules/interface'; import UIManager from './modules/ui/uiManager'; import Networker from './modules/networking/networker'; -const SERVERURL = 'https://kobert.dev/dsa/api/chatHub'; +const SERVERURL = 'https://kobert.dev/api/Login'; let iface = new Interface(); let uiMan = new UIManager(iface); -- cgit v1.2.3-54-g00ecf From 91fc989eea5ee16c2f000064b5c040a6fe6f23b9 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Thu, 16 May 2019 01:10:10 +0200 Subject: Implement tokens --- DSACore/Auxiliary/WeaponImporter.cs | 1 + DSACore/Controllers/CommandsController.cs | 4 +- DSACore/Controllers/LobbyController.cs | 32 +++ DSACore/Controllers/TokensController.cs | 28 +++ DSACore/DSACore.csproj | 6 +- DSACore/DSA_Game/Dsa.cs | 2 +- DSACore/FireBase/Database.cs | 2 + DSACore/Hubs/ChatHub.cs | 216 ------------------- DSACore/Hubs/Login.cs | 228 +++++++++++++++++++++ DSACore/Models/Database/Advantage.cs | 19 -- DSACore/Models/Database/CharSpell.cs | 19 -- DSACore/Models/Database/DSA/Advantage.cs | 16 ++ DSACore/Models/Database/DSA/CharSpell.cs | 16 ++ DSACore/Models/Database/DSA/DatabaseChar.cs | 61 ++++++ DSACore/Models/Database/DSA/Field.cs | 16 ++ DSACore/Models/Database/DSA/GeneralSpell.cs | 20 ++ DSACore/Models/Database/DSA/GroupChar.cs | 13 ++ DSACore/Models/Database/DSA/Inventory.cs | 12 ++ DSACore/Models/Database/DSA/Talent.cs | 26 +++ DSACore/Models/Database/DSA/Weapon.cs | 50 +++++ DSACore/Models/Database/DSA/WeaponTalent.cs | 18 ++ DSACore/Models/Database/DatabaseChar.cs | 63 ------ DSACore/Models/Database/Field.cs | 19 -- DSACore/Models/Database/GeneralSpell.cs | 25 --- DSACore/Models/Database/Group.cs | 19 -- DSACore/Models/Database/GroupChar.cs | 18 -- DSACore/Models/Database/Groups/DSAGroup.cs | 10 + DSACore/Models/Database/Groups/Group.cs | 13 ++ DSACore/Models/Database/Inventory.cs | 15 -- DSACore/Models/Database/Talent.cs | 29 --- DSACore/Models/Database/Weapon.cs | 53 ----- DSACore/Models/Database/WeaponTalent.cs | 18 -- DSACore/Models/Network/Token.cs | 21 ++ DSACore/Startup.cs | 2 +- .../src/js/modules/ui/components/modal/modal.js | 1 - 35 files changed, 592 insertions(+), 519 deletions(-) create mode 100644 DSACore/Controllers/LobbyController.cs create mode 100644 DSACore/Controllers/TokensController.cs delete mode 100644 DSACore/Hubs/ChatHub.cs create mode 100644 DSACore/Hubs/Login.cs delete mode 100644 DSACore/Models/Database/Advantage.cs delete mode 100644 DSACore/Models/Database/CharSpell.cs create mode 100644 DSACore/Models/Database/DSA/Advantage.cs create mode 100644 DSACore/Models/Database/DSA/CharSpell.cs create mode 100644 DSACore/Models/Database/DSA/DatabaseChar.cs create mode 100644 DSACore/Models/Database/DSA/Field.cs create mode 100644 DSACore/Models/Database/DSA/GeneralSpell.cs create mode 100644 DSACore/Models/Database/DSA/GroupChar.cs create mode 100644 DSACore/Models/Database/DSA/Inventory.cs create mode 100644 DSACore/Models/Database/DSA/Talent.cs create mode 100644 DSACore/Models/Database/DSA/Weapon.cs create mode 100644 DSACore/Models/Database/DSA/WeaponTalent.cs delete mode 100644 DSACore/Models/Database/DatabaseChar.cs delete mode 100644 DSACore/Models/Database/Field.cs delete mode 100644 DSACore/Models/Database/GeneralSpell.cs delete mode 100644 DSACore/Models/Database/Group.cs delete mode 100644 DSACore/Models/Database/GroupChar.cs create mode 100644 DSACore/Models/Database/Groups/DSAGroup.cs create mode 100644 DSACore/Models/Database/Groups/Group.cs delete mode 100644 DSACore/Models/Database/Inventory.cs delete mode 100644 DSACore/Models/Database/Talent.cs delete mode 100644 DSACore/Models/Database/Weapon.cs delete mode 100644 DSACore/Models/Database/WeaponTalent.cs create mode 100644 DSACore/Models/Network/Token.cs (limited to 'WebInterface') diff --git a/DSACore/Auxiliary/WeaponImporter.cs b/DSACore/Auxiliary/WeaponImporter.cs index 8ed2b3f..635d477 100644 --- a/DSACore/Auxiliary/WeaponImporter.cs +++ b/DSACore/Auxiliary/WeaponImporter.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; using DSACore.FireBase; +using DSACore.Models.Database.DSA; using Group = System.Text.RegularExpressions.Group; namespace DSACore.Auxiliary diff --git a/DSACore/Controllers/CommandsController.cs b/DSACore/Controllers/CommandsController.cs index 5f27f63..d35690c 100644 --- a/DSACore/Controllers/CommandsController.cs +++ b/DSACore/Controllers/CommandsController.cs @@ -10,14 +10,14 @@ using Microsoft.AspNetCore.Mvc; namespace DSACore.Controllers { - [Route("api/[controller]")] + [Route("dsa/[controller]")] public class CommandsController : Controller { // GET: api/ [HttpGet] public string Get() { - return "Dies ist die supa dolle Web Api"; + return "Usage: post the command to execute"; } // GET api//5 diff --git a/DSACore/Controllers/LobbyController.cs b/DSACore/Controllers/LobbyController.cs new file mode 100644 index 0000000..a946184 --- /dev/null +++ b/DSACore/Controllers/LobbyController.cs @@ -0,0 +1,32 @@ +using DSACore.Models.Network; +using System; +using Microsoft.AspNetCore.Mvc; + +namespace DSACore.Controllers +{ + public class ScribbleController : Controller + { + [Route("[controller]")] + // GET: api/ + [HttpGet] + public string Get() + { + return "Usage: get /tokens/{Token}"; + } + + [HttpPost] + public string Post([FromBody]Command cmd) + { + try + { + return Commands.CommandHandler.ExecuteCommand(cmd).message; + } + catch (Exception e) + { + return $"Ein Fehler ist aufgetreten: \n {e.Message}"; + } + + } + + } +} \ No newline at end of file diff --git a/DSACore/Controllers/TokensController.cs b/DSACore/Controllers/TokensController.cs new file mode 100644 index 0000000..453d477 --- /dev/null +++ b/DSACore/Controllers/TokensController.cs @@ -0,0 +1,28 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace DSACore.Controllers +{ + [Route("lobby/[controller]")] + [ApiController] + public class TokensController : Controller + { + + // GET + [HttpGet("{token}")] + public async Task> Get(int token) + { + + if (!Hubs.Users.Tokens.Exists(x => x.GetHashCode() == token)) + { + return NotFound(); + } + + var group = Hubs.Users.Tokens.Find(x => x.GetHashCode() == token); + return Ok(group); + } + } +} \ No newline at end of file diff --git a/DSACore/DSACore.csproj b/DSACore/DSACore.csproj index ad760c2..3d928e1 100644 --- a/DSACore/DSACore.csproj +++ b/DSACore/DSACore.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.1 @@ -18,4 +18,8 @@ + + + + diff --git a/DSACore/DSA_Game/Dsa.cs b/DSACore/DSA_Game/Dsa.cs index 3b2e4aa..cbdb734 100644 --- a/DSACore/DSA_Game/Dsa.cs +++ b/DSACore/DSA_Game/Dsa.cs @@ -16,7 +16,7 @@ namespace DSACore.DSA_Game public static class Dsa { #if DEBUG - public const string rootPath = "C:\\Users\\Dennis\\Source\\Repos\\DiscoBot\\DSACore\\";//"DiscoBot\\DSACore\\"; + public const string rootPath = "";//"C:\\Users\\Dennis\\Source\\Repos\\DiscoBot\\DSACore\\";//"DiscoBot\\DSACore\\"; #else public const string rootPath = "";//"DiscoBot\\DSACore\\"; #endif diff --git a/DSACore/FireBase/Database.cs b/DSACore/FireBase/Database.cs index db57381..15b76f0 100644 --- a/DSACore/FireBase/Database.cs +++ b/DSACore/FireBase/Database.cs @@ -6,6 +6,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using DSACore.Models.Database.DSA; +using DSACore.Models.Database.Groups; namespace DSACore.FireBase diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs deleted file mode 100644 index 1994164..0000000 --- a/DSACore/Hubs/ChatHub.cs +++ /dev/null @@ -1,216 +0,0 @@ -using DSACore.DSA_Game.Characters; -using DSACore.FireBase; -using DSACore.Models.Network; -using Microsoft.AspNetCore.SignalR; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace DSACore.Hubs -{ - public class ChatHub : Hub - { - //private static Dictionary UserGroup = new Dictionary(); - - private const string receiveMethod = "ReceiveMessage";//receiveMethod; - - private static List DSAGroups = new List(); - - static ChatHub() - { - DSAGroups = Database.GetGroups().Result; - DSAGroups.Add(new Group("login", "")); - DSAGroups.Add(new Group("online", "")); - //AddGroups(); - } - - private static async void AddGroups() - { - await Database.AddGroup(new Models.Database.Group { Name = "HalloWelt", Password = "valid" }); - await Database.AddGroup(new Models.Database.Group { Name = "Die Krassen Gamer", Password = "valid" }); - await Database.AddGroup(new Models.Database.Group { Name = "DSA", Password = "valid" }); - await Database.AddGroup(new Models.Database.Group { Name = "Die Überhelden", Password = "valid" }); - } - - public async Task SendMessage(string user, string message) - { - try - { - string group = getGroup(Context.ConnectionId).Name; - } - catch (InvalidOperationException e) - { - //await Clients.Caller.SendCoreAsync(receiveMethod, - // new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); - } - - if (message[0] == '/') - { - var args = message.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); - - bool Timon = args.Any(x => x == "hallo"); - - var ident = args.First().Replace("/", ""); - if (args.Count > 0) - { - args.RemoveAt(0); - } - - var ret = Commands.CommandHandler.ExecuteCommand(new Command - { - CharId = 0, - CmdIdentifier = ident, - CmdTexts = args, - Name = user - }); - - switch (ret.ResponseType) - { - case ResponseType.Caller: - case ResponseType.Error: - await Clients.Caller.SendAsync(receiveMethod, ret.message); - break; - case ResponseType.Broadcast: - await SendToGroup(ret.message); - break; - } - - - } - else - { - await SendToGroup(message); - } - - } - - private Task SendToGroup(string message) - { - try - { - string group = getGroup(Context.ConnectionId).Name; - return Clients.Group(group).SendCoreAsync(receiveMethod, - new object[] {getUser(Context.ConnectionId).Name, message}); - } - catch (InvalidOperationException e) - { - return Clients.Caller.SendCoreAsync(receiveMethod, - new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); - } - } - - private Models.Network.Group getGroup(string id) - { - return DSAGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))); - } - - private User getUser(string id) - { - return DSAGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))).Users.First(z => z.ConnectionId.Equals(id)); - } - - public async Task GetGroups() - { - var test = Database.GetGroups(); - test.Wait(); - foreach (var group in test.Result) - { - if (!DSAGroups.Exists(x => x.Name.Equals(group.Name))) - { - DSAGroups.Add(group); - } - } - - await Clients.Caller.SendCoreAsync("ListGroups", new object[] { DSAGroups.Select(x => x.SendGroup()) }); - //throw new NotImplementedException("add database call to get groups"); - } - - public async Task AddGroup(string group, string password) - { - DSAGroups.Add(new Group(group, password)); - var Dgroup = new DSACore.Models.Database.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"); - } - - public async Task UploadChar(string xml) - { - var group = getGroup(Context.ConnectionId); - - await Database.AddChar(new Character(new MemoryStream(Encoding.UTF8.GetBytes(xml))), group); - //throw new NotImplementedException("add database call to add groups"); - } - - public async Task Login(string group, string user, string hash) - { - //string password = System.Text.Encoding.UTF8.GetString(hash); - if (hash == DSAGroups.First(x => x.Name == group).Password) - { - var gGroup = DSAGroups.First(x => x.Name.Equals(group)); - if (!gGroup.Users.Exists(x => x.Name.Equals(user))) - { - await Groups.RemoveFromGroupAsync(Context.ConnectionId, "login"); - await Groups.AddToGroupAsync(Context.ConnectionId, group); - gGroup.Users.Add(new User { ConnectionId = Context.ConnectionId, Name = user }); - await SendToGroup("Ein neuer Nutzer hat die Gruppe betreten"); - await Clients.Caller.SendAsync("LoginResponse", 0); - await Clients.Caller.SendAsync("PlayerStatusChanged", new[] {user, "online"}); - } - else - { - await Clients.Caller.SendAsync("LoginResponse", 1); - } - } - else - { - await Clients.Caller.SendAsync("LoginResponse", 2); - //await Clients.Caller.SendAsync(receiveMethod, "Falsches Passwort!"); - } - } - - public override Task OnDisconnectedAsync(Exception exception) - { - Disconnect().Wait(); - return base.OnDisconnectedAsync(exception); - } - - public override Task OnConnectedAsync() - { - Groups.AddToGroupAsync(Context.ConnectionId, "login").Wait(); - Groups.AddToGroupAsync(Context.ConnectionId, "online").Wait(); - return base.OnConnectedAsync(); - } - - public async Task Disconnect() - { - await Groups.RemoveFromGroupAsync(Context.ConnectionId, "online"); - if (DSAGroups.Exists(x => x.Users.Exists(y => y.ConnectionId == Context.ConnectionId))) - { - try - { - var group = getGroup(Context.ConnectionId); - - - var user = getUser(Context.ConnectionId); - - await Clients.Caller.SendAsync("PlayerStatusChanged", new[] { user.Name, "offline" }); - //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; - } - } - - } - - } -} diff --git a/DSACore/Hubs/Login.cs b/DSACore/Hubs/Login.cs new file mode 100644 index 0000000..5f984e2 --- /dev/null +++ b/DSACore/Hubs/Login.cs @@ -0,0 +1,228 @@ +using DSACore.DSA_Game.Characters; +using DSACore.FireBase; +using DSACore.Models.Network; +using Microsoft.AspNetCore.SignalR; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace DSACore.Hubs +{ + public class Users : Hub + { + //private static Dictionary UserGroup = new Dictionary(); + + private const string ReceiveMethod = "ReceiveMessage";//receiveMethod; + + private static List DsaGroups {get; set; } + public static List Tokens { get;} = new List(); + + static Users() + { + DsaGroups = Database.GetGroups().Result; + DsaGroups.Add(new Group("login", "")); + DsaGroups.Add(new Group("online", "")); + //AddGroups(); + } + + + [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 + { + string group = getGroup(Context.ConnectionId).Name; + } + catch (InvalidOperationException e) + { + //await Clients.Caller.SendCoreAsync(receiveMethod, + // new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); + } + + if (message[0] == '/') + { + var args = message.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); + + bool Timon = args.Any(x => x == "hallo"); + + var ident = args.First().Replace("/", ""); + if (args.Count > 0) + { + args.RemoveAt(0); + } + + var ret = Commands.CommandHandler.ExecuteCommand(new Command + { + CharId = 0, + CmdIdentifier = ident, + CmdTexts = args, + Name = user + }); + + switch (ret.ResponseType) + { + case ResponseType.Caller: + case ResponseType.Error: + await Clients.Caller.SendAsync(ReceiveMethod, ret.message); + break; + case ResponseType.Broadcast: + await SendToGroup(ret.message); + break; + } + + + } + else + { + await SendToGroup(message); + } + + } + + private Task SendToGroup(string message) + { + try + { + string group = getGroup(Context.ConnectionId).Name; + return Clients.Group(group).SendCoreAsync(ReceiveMethod, + new object[] {getUser(Context.ConnectionId).Name, message}); + } + catch (InvalidOperationException e) + { + return Clients.Caller.SendCoreAsync(ReceiveMethod, + new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); + } + } + + private Models.Network.Group getGroup(string id) + { + return DsaGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))); + } + + private User getUser(string id) + { + return DsaGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))).Users.First(z => z.ConnectionId.Equals(id)); + } + + public async Task GetGroups() + { + var test = await Database.GetGroups(); + + foreach (var group in test) + { + if (!DsaGroups.Exists(x => x.Name.Equals(group.Name))) + { + DsaGroups.Add(group); + } + } + + await Clients.Caller.SendCoreAsync("ListGroups", new object[] { DsaGroups.Select(x => x.SendGroup()) }); + //throw new NotImplementedException("add database call to get groups"); + } + + 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 }; + //Database.AddGroup(Dgroup); + await Clients.Caller.SendCoreAsync(ReceiveMethod, new[] { $"group {@group} sucessfully added" }); + //throw new NotImplementedException("add database call to add groups"); + } + + public async Task UploadChar(string xml) + { + var group = getGroup(Context.ConnectionId); + + await Database.AddChar(new Character(new MemoryStream(Encoding.UTF8.GetBytes(xml))), group); + //throw new NotImplementedException("add database call to add groups"); + } + + public async Task Login(string group, string user, string hash) + { + //string password = System.Text.Encoding.UTF8.GetString(hash); + if (hash == DsaGroups.First(x => x.Name == group).Password) + { + var gGroup = DsaGroups.First(x => x.Name.Equals(group)); + if (!gGroup.Users.Exists(x => x.Name.Equals(user))) + { + await Groups.RemoveFromGroupAsync(Context.ConnectionId, "login"); + await Groups.AddToGroupAsync(Context.ConnectionId, group); + gGroup.Users.Add(new User { ConnectionId = Context.ConnectionId, Name = user }); + await SendToGroup("Ein neuer Nutzer hat die Gruppe betreten"); + await Clients.Caller.SendAsync("LoginResponse", 0); + await Clients.Caller.SendAsync("PlayerStatusChanged", new[] {user, "online"}); + + Tokens.Add(new Token(group)); + await Clients.Caller.SendAsync("Token", Tokens.Last().GetHashCode()); + purgeTokens(); + } + else + { + await Clients.Caller.SendAsync("LoginResponse", 1); + } + } + else + { + await Clients.Caller.SendAsync("LoginResponse", 2); + //await Clients.Caller.SendAsync(receiveMethod, "Falsches Passwort!"); + } + } + + private void purgeTokens() + { + Tokens.RemoveAll(x => !x.IsValid()); + } + + public override Task OnDisconnectedAsync(Exception exception) + { + Disconnect().Wait(); + return base.OnDisconnectedAsync(exception); + } + + public override Task OnConnectedAsync() + { + Groups.AddToGroupAsync(Context.ConnectionId, "login").Wait(); + Groups.AddToGroupAsync(Context.ConnectionId, "online").Wait(); + return base.OnConnectedAsync(); + } + + public async Task Disconnect() + { + await Groups.RemoveFromGroupAsync(Context.ConnectionId, "online"); + if (DsaGroups.Exists(x => x.Users.Exists(y => y.ConnectionId == Context.ConnectionId))) + { + try + { + var group = getGroup(Context.ConnectionId); + + + var user = getUser(Context.ConnectionId); + + await Clients.Caller.SendAsync("PlayerStatusChanged", new[] { user.Name, "offline" }); + //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; + } + } + + } + + } +} diff --git a/DSACore/Models/Database/Advantage.cs b/DSACore/Models/Database/Advantage.cs deleted file mode 100644 index 67965fc..0000000 --- a/DSACore/Models/Database/Advantage.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class Advantage - { - public Advantage(string name, string value = "") - { - Name = name ?? throw new ArgumentNullException(nameof(name)); - Value = value ?? throw new ArgumentNullException(nameof(value)); - } - - public string Name { get; set; } - public string Value { get; set; } - } -} diff --git a/DSACore/Models/Database/CharSpell.cs b/DSACore/Models/Database/CharSpell.cs deleted file mode 100644 index 670488c..0000000 --- a/DSACore/Models/Database/CharSpell.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class CharSpell - { - public CharSpell(string representation, int value) - { - this.representation = representation ?? throw new ArgumentNullException(nameof(representation)); - this.value = value; - } - - public string representation { get; set; } - public int value { get; set; } - } -} diff --git a/DSACore/Models/Database/DSA/Advantage.cs b/DSACore/Models/Database/DSA/Advantage.cs new file mode 100644 index 0000000..2f0b443 --- /dev/null +++ b/DSACore/Models/Database/DSA/Advantage.cs @@ -0,0 +1,16 @@ +using System; + +namespace DSACore.Models.Database.DSA +{ + public class Advantage + { + public Advantage(string name, string value = "") + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + Value = value ?? throw new ArgumentNullException(nameof(value)); + } + + public string Name { get; set; } + public string Value { get; set; } + } +} diff --git a/DSACore/Models/Database/DSA/CharSpell.cs b/DSACore/Models/Database/DSA/CharSpell.cs new file mode 100644 index 0000000..63d917a --- /dev/null +++ b/DSACore/Models/Database/DSA/CharSpell.cs @@ -0,0 +1,16 @@ +using System; + +namespace DSACore.Models.Database.DSA +{ + public class CharSpell + { + public CharSpell(string representation, int value) + { + this.representation = representation ?? throw new ArgumentNullException(nameof(representation)); + this.value = value; + } + + public string representation { get; set; } + public int value { get; set; } + } +} diff --git a/DSACore/Models/Database/DSA/DatabaseChar.cs b/DSACore/Models/Database/DSA/DatabaseChar.cs new file mode 100644 index 0000000..8c51821 --- /dev/null +++ b/DSACore/Models/Database/DSA/DatabaseChar.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace DSACore.Models.Database.DSA +{ + public class DatabaseChar + { + public DatabaseChar() + { + } + + public DatabaseChar(int id, string name, string rasse, List skills, List talents, List advantages, List spells, List weaponTalents) + { + Id = id; + Name = name ?? throw new ArgumentNullException(nameof(name)); + Rasse = rasse ?? throw new ArgumentNullException(nameof(rasse)); + Skills = skills ?? throw new ArgumentNullException(nameof(skills)); + Talents = talents ?? throw new ArgumentNullException(nameof(talents)); + Advantages = advantages ?? throw new ArgumentNullException(nameof(advantages)); + Spells = spells ?? throw new ArgumentNullException(nameof(spells)); + WeaponTalents = weaponTalents ?? throw new ArgumentNullException(nameof(weaponTalents)); + } + + public int Id { get; set; } + + public string Name { get; set; } + + public string Rasse { get; set; } + + public List Skills { get; set; } = new List(); + + public List Talents { get; set; } = new List(); + + public List Advantages { get; set; } = new List(); + + public List Spells { get; set; } = new List(); + + public List WeaponTalents { get; set; } = new List(); + + + public static void LoadChar(DSA_Game.Characters.Character file, out GroupChar group, out DatabaseChar data) + { + group = new GroupChar(); + data = new DatabaseChar(); + + group.Name = file.Name.Split(' ').First(); + group.Weapon = new Weapon(); + group.Lp = group.LpMax = file.Lebenspunkte_Basis; + group.As = group.AsMax = file.Astralpunkte_Basis; + group.Weapon = new Weapon(); + + data.Name = file.Name; + data.Advantages = file.Vorteile.Select(x => new Advantage(x.Name, x.Value)).ToList(); + data.Skills = file.Eigenschaften.Select(x => new Field(x.Key, x.Value)).ToList(); + data.Spells = file.Zauber.Select(x => new CharSpell(x.Representation, x.Value)).ToList(); + data.Talents = file.Talente.Select(x => new Field(x.Name, x.Value)).ToList(); + data.WeaponTalents = file.Kampftalente.Select(x => new WeaponTalent(x.Name, x.At, x.Pa)).ToList(); + } + } +} diff --git a/DSACore/Models/Database/DSA/Field.cs b/DSACore/Models/Database/DSA/Field.cs new file mode 100644 index 0000000..5022768 --- /dev/null +++ b/DSACore/Models/Database/DSA/Field.cs @@ -0,0 +1,16 @@ +using System; + +namespace DSACore.Models.Database.DSA +{ + public class Field + { + public Field(string name, int value = 0) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + this.Value = value; + } + + public string Name { get; set; } + public int Value { get; set; } + } +} diff --git a/DSACore/Models/Database/DSA/GeneralSpell.cs b/DSACore/Models/Database/DSA/GeneralSpell.cs new file mode 100644 index 0000000..74b95d7 --- /dev/null +++ b/DSACore/Models/Database/DSA/GeneralSpell.cs @@ -0,0 +1,20 @@ +namespace DSACore.Models.Database.DSA +{ + public class GeneralSpell : Talent + { + public char Comlexity = 'A'; + + public GeneralSpell(string name, string roll, char comlexity = 'A') :base(name, roll) + { + Comlexity = comlexity; + } + + public GeneralSpell(string name, string roll) : base(name, roll) + { + } + + public GeneralSpell() + { + } + } +} diff --git a/DSACore/Models/Database/DSA/GroupChar.cs b/DSACore/Models/Database/DSA/GroupChar.cs new file mode 100644 index 0000000..70b8fc1 --- /dev/null +++ b/DSACore/Models/Database/DSA/GroupChar.cs @@ -0,0 +1,13 @@ +namespace DSACore.Models.Database.DSA +{ + public class GroupChar + { + public string Name { get; set; } + public int Id { get; set; } + public int Lp { get; set; } + public int LpMax { get; set; } + public int As { get; set; } + public int AsMax { get; set; } + public Weapon Weapon { get; set; } + } +} diff --git a/DSACore/Models/Database/DSA/Inventory.cs b/DSACore/Models/Database/DSA/Inventory.cs new file mode 100644 index 0000000..69c7b08 --- /dev/null +++ b/DSACore/Models/Database/DSA/Inventory.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace DSACore.Models.Database.DSA +{ + public class Inventory + { + public int Id { get; set; } + public Dictionary Items { get; set; } = new Dictionary(); + public Dictionary Food { get; set; } = new Dictionary(); + public List Weapons { get; set; } = new List(); + } +} diff --git a/DSACore/Models/Database/DSA/Talent.cs b/DSACore/Models/Database/DSA/Talent.cs new file mode 100644 index 0000000..a6de395 --- /dev/null +++ b/DSACore/Models/Database/DSA/Talent.cs @@ -0,0 +1,26 @@ +using System; + +namespace DSACore.Models.Database.DSA +{ + public class Talent + { + public Talent() + { + } + + public Talent(string name) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + } + + public Talent(string name, String roll) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + Roll = roll.Split('/'); + } + + public string Name { get; set; } + + public string[] Roll { get; set; } = new string[3]; + } +} diff --git a/DSACore/Models/Database/DSA/Weapon.cs b/DSACore/Models/Database/DSA/Weapon.cs new file mode 100644 index 0000000..24b334a --- /dev/null +++ b/DSACore/Models/Database/DSA/Weapon.cs @@ -0,0 +1,50 @@ +using System; + +namespace DSACore.Models.Database.DSA +{ + public class Weapon + { + public Weapon() + { + } + + public Weapon(string name, string damage, int weight, string weaponTalent, string price) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + Damage = damage ?? throw new ArgumentNullException(nameof(damage)); + Weight = weight; + WeaponTalent = weaponTalent ?? throw new ArgumentNullException(nameof(weaponTalent)); + Price = price; + } + + public string Name { get; set; } + public string Damage { get; set; } + public int Weight { get; set; } + public string WeaponTalent { get; set; } + public string Price { get; set; } + } + + public class MeleeWeapon : Weapon + { + public string TpKK { get; set; } + public int INI { get; set; } + public string MW { get; set; } + + public MeleeWeapon(string name, string damage, int weight, string weaponTalent, string price) : base(name, damage, weight, weaponTalent, price) + { + } + } + + public class RangedWeapon : Weapon + { + public int AtMod { get; set; } + public int KKMod { get; set; } + public string AtReach { get; set; } + public string TpReach { get; set; } + public int LoadTime { get; set; } + + public RangedWeapon(string name, string damage, int weight, string weaponTalent, string price) : base(name, damage, weight, weaponTalent, price) + { + } + } +} diff --git a/DSACore/Models/Database/DSA/WeaponTalent.cs b/DSACore/Models/Database/DSA/WeaponTalent.cs new file mode 100644 index 0000000..869cb35 --- /dev/null +++ b/DSACore/Models/Database/DSA/WeaponTalent.cs @@ -0,0 +1,18 @@ +using System; + +namespace DSACore.Models.Database.DSA +{ + public class WeaponTalent + { + public WeaponTalent(string name, int at, int pa) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + At = at; + Pa = pa; + } + + public string Name { get; set; } + public int At { get; set; } + public int Pa { get; set; } + } +} \ No newline at end of file diff --git a/DSACore/Models/Database/DatabaseChar.cs b/DSACore/Models/Database/DatabaseChar.cs deleted file mode 100644 index 9cd865f..0000000 --- a/DSACore/Models/Database/DatabaseChar.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using DSALib; - -namespace DSACore.Models.Database -{ - public class DatabaseChar - { - public DatabaseChar() - { - } - - public DatabaseChar(int id, string name, string rasse, List skills, List talents, List advantages, List spells, List weaponTalents) - { - Id = id; - Name = name ?? throw new ArgumentNullException(nameof(name)); - Rasse = rasse ?? throw new ArgumentNullException(nameof(rasse)); - Skills = skills ?? throw new ArgumentNullException(nameof(skills)); - Talents = talents ?? throw new ArgumentNullException(nameof(talents)); - Advantages = advantages ?? throw new ArgumentNullException(nameof(advantages)); - Spells = spells ?? throw new ArgumentNullException(nameof(spells)); - WeaponTalents = weaponTalents ?? throw new ArgumentNullException(nameof(weaponTalents)); - } - - public int Id { get; set; } - - public string Name { get; set; } - - public string Rasse { get; set; } - - public List Skills { get; set; } = new List(); - - public List Talents { get; set; } = new List(); - - public List Advantages { get; set; } = new List(); - - public List Spells { get; set; } = new List(); - - public List WeaponTalents { get; set; } = new List(); - - - public static void LoadChar(DSA_Game.Characters.Character file, out GroupChar group, out DatabaseChar data) - { - group = new GroupChar(); - data = new DatabaseChar(); - - group.Name = file.Name.Split(' ').First(); - group.Weapon = new Weapon(); - group.Lp = group.LpMax = file.Lebenspunkte_Basis; - group.As = group.AsMax = file.Astralpunkte_Basis; - group.Weapon = new Weapon(); - - data.Name = file.Name; - data.Advantages = file.Vorteile.Select(x => new Advantage(x.Name, x.Value)).ToList(); - data.Skills = file.Eigenschaften.Select(x => new Field(x.Key, x.Value)).ToList(); - data.Spells = file.Zauber.Select(x => new CharSpell(x.Representation, x.Value)).ToList(); - data.Talents = file.Talente.Select(x => new Field(x.Name, x.Value)).ToList(); - data.WeaponTalents = file.Kampftalente.Select(x => new WeaponTalent(x.Name, x.At, x.Pa)).ToList(); - } - } -} diff --git a/DSACore/Models/Database/Field.cs b/DSACore/Models/Database/Field.cs deleted file mode 100644 index b14d9da..0000000 --- a/DSACore/Models/Database/Field.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class Field - { - public Field(string name, int value = 0) - { - Name = name ?? throw new ArgumentNullException(nameof(name)); - this.Value = value; - } - - public string Name { get; set; } - public int Value { get; set; } - } -} diff --git a/DSACore/Models/Database/GeneralSpell.cs b/DSACore/Models/Database/GeneralSpell.cs deleted file mode 100644 index f53081e..0000000 --- a/DSACore/Models/Database/GeneralSpell.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class GeneralSpell : Talent - { - public char Comlexity = 'A'; - - public GeneralSpell(string name, string roll, char comlexity = 'A') :base(name, roll) - { - Comlexity = comlexity; - } - - public GeneralSpell(string name, string roll) : base(name, roll) - { - } - - public GeneralSpell() - { - } - } -} diff --git a/DSACore/Models/Database/Group.cs b/DSACore/Models/Database/Group.cs deleted file mode 100644 index a7bb929..0000000 --- a/DSACore/Models/Database/Group.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class Group - { - public string Name { get; set; } - public string Discord { get; set; } - public string Password { get; set; } - public int Id { get; set; } - public List Chars { get; set; }= new List(); - - } - - -} diff --git a/DSACore/Models/Database/GroupChar.cs b/DSACore/Models/Database/GroupChar.cs deleted file mode 100644 index 1dfc4ea..0000000 --- a/DSACore/Models/Database/GroupChar.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class GroupChar - { - public string Name { get; set; } - public int Id { get; set; } - public int Lp { get; set; } - public int LpMax { get; set; } - public int As { get; set; } - public int AsMax { get; set; } - public Weapon Weapon { get; set; } - } -} diff --git a/DSACore/Models/Database/Groups/DSAGroup.cs b/DSACore/Models/Database/Groups/DSAGroup.cs new file mode 100644 index 0000000..8f20278 --- /dev/null +++ b/DSACore/Models/Database/Groups/DSAGroup.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using DSACore.Models.Database.DSA; + +namespace DSACore.Models.Database.Groups +{ + public class DSAGroup : Group + { + public List Chars { get; set; }= new List(); + } +} \ No newline at end of file diff --git a/DSACore/Models/Database/Groups/Group.cs b/DSACore/Models/Database/Groups/Group.cs new file mode 100644 index 0000000..23e5f68 --- /dev/null +++ b/DSACore/Models/Database/Groups/Group.cs @@ -0,0 +1,13 @@ +namespace DSACore.Models.Database.Groups +{ + public class Group + { + public string Name { get; set; } + public string Discord { get; set; } + public string Password { get; set; } + public int Id { get; set; } + + } + + +} diff --git a/DSACore/Models/Database/Inventory.cs b/DSACore/Models/Database/Inventory.cs deleted file mode 100644 index e6b47ec..0000000 --- a/DSACore/Models/Database/Inventory.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class Inventory - { - public int Id { get; set; } - public Dictionary Items { get; set; } = new Dictionary(); - public Dictionary Food { get; set; } = new Dictionary(); - public List Weapons { get; set; } = new List(); - } -} diff --git a/DSACore/Models/Database/Talent.cs b/DSACore/Models/Database/Talent.cs deleted file mode 100644 index aca65a4..0000000 --- a/DSACore/Models/Database/Talent.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class Talent - { - public Talent() - { - } - - public Talent(string name) - { - Name = name ?? throw new ArgumentNullException(nameof(name)); - } - - public Talent(string name, String roll) - { - Name = name ?? throw new ArgumentNullException(nameof(name)); - Roll = roll.Split('/'); - } - - public string Name { get; set; } - - public string[] Roll { get; set; } = new string[3]; - } -} diff --git a/DSACore/Models/Database/Weapon.cs b/DSACore/Models/Database/Weapon.cs deleted file mode 100644 index b2f8a1e..0000000 --- a/DSACore/Models/Database/Weapon.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Database -{ - public class Weapon - { - public Weapon() - { - } - - public Weapon(string name, string damage, int weight, string weaponTalent, string price) - { - Name = name ?? throw new ArgumentNullException(nameof(name)); - Damage = damage ?? throw new ArgumentNullException(nameof(damage)); - Weight = weight; - WeaponTalent = weaponTalent ?? throw new ArgumentNullException(nameof(weaponTalent)); - Price = price; - } - - public string Name { get; set; } - public string Damage { get; set; } - public int Weight { get; set; } - public string WeaponTalent { get; set; } - public string Price { get; set; } - } - - public class MeleeWeapon : Weapon - { - public string TpKK { get; set; } - public int INI { get; set; } - public string MW { get; set; } - - public MeleeWeapon(string name, string damage, int weight, string weaponTalent, string price) : base(name, damage, weight, weaponTalent, price) - { - } - } - - public class RangedWeapon : Weapon - { - public int AtMod { get; set; } - public int KKMod { get; set; } - public string AtReach { get; set; } - public string TpReach { get; set; } - public int LoadTime { get; set; } - - public RangedWeapon(string name, string damage, int weight, string weaponTalent, string price) : base(name, damage, weight, weaponTalent, price) - { - } - } -} diff --git a/DSACore/Models/Database/WeaponTalent.cs b/DSACore/Models/Database/WeaponTalent.cs deleted file mode 100644 index 4b98d24..0000000 --- a/DSACore/Models/Database/WeaponTalent.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace DSACore.Models.Database -{ - public class WeaponTalent - { - public WeaponTalent(string name, int at, int pa) - { - Name = name ?? throw new ArgumentNullException(nameof(name)); - At = at; - Pa = pa; - } - - public string Name { get; set; } - public int At { get; set; } - public int Pa { get; set; } - } -} \ No newline at end of file diff --git a/DSACore/Models/Network/Token.cs b/DSACore/Models/Network/Token.cs new file mode 100644 index 0000000..0021317 --- /dev/null +++ b/DSACore/Models/Network/Token.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.EntityFrameworkCore; + +namespace DSACore.Models.Network +{ + public class Token + { + public string Group { get; set; } + private DateTime creation = DateTime.Now; + + public Token(string @group) + { + Group = @group; + } + + public bool IsValid() + { + return DateTime.Now - creation < TimeSpan.FromMinutes(1); + } + } +} \ No newline at end of file diff --git a/DSACore/Startup.cs b/DSACore/Startup.cs index f8f6dfd..1dcc690 100644 --- a/DSACore/Startup.cs +++ b/DSACore/Startup.cs @@ -62,7 +62,7 @@ namespace DSACore app.UseCors("CorsPolicy"); - app.UseSignalR(routes => { routes.MapHub("/chatHub"); }); + app.UseSignalR(routes => { routes.MapHub("/login"); }); app.UseWebSockets(); diff --git a/WebInterface/NodeJSServer/src/js/modules/ui/components/modal/modal.js b/WebInterface/NodeJSServer/src/js/modules/ui/components/modal/modal.js index 10a1be5..c4c5119 100644 --- a/WebInterface/NodeJSServer/src/js/modules/ui/components/modal/modal.js +++ b/WebInterface/NodeJSServer/src/js/modules/ui/components/modal/modal.js @@ -17,7 +17,6 @@ export default class Modal { modal.className = 'modal'; title.className = 'modal-title'; body.className = 'modal-body'; - title.textContent = titleString; modal.appendChild(title); -- cgit v1.2.3-54-g00ecf From aad1d69b5e2bb0c82f657f7693462fd95a91fb9f Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Thu, 16 May 2019 01:34:10 +0200 Subject: ifx typo in api url --- WebInterface/NodeJSServer/src/js/index.js | 2 +- WebInterface/NodeJSServer/src/js/play.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'WebInterface') diff --git a/WebInterface/NodeJSServer/src/js/index.js b/WebInterface/NodeJSServer/src/js/index.js index 249adc9..c8b5ca8 100644 --- a/WebInterface/NodeJSServer/src/js/index.js +++ b/WebInterface/NodeJSServer/src/js/index.js @@ -2,7 +2,7 @@ import Interface from './modules/interface'; import UIManager from './modules/ui/uiManager'; import Networker from './modules/networking/networker'; -const SERVERURL = 'https://kobert.dev/api/Login'; +const SERVERURL = 'https://kobert.dev/api/login'; let iface = new Interface(); let uiMan = new UIManager(iface); diff --git a/WebInterface/NodeJSServer/src/js/play.js b/WebInterface/NodeJSServer/src/js/play.js index 2d4effe..93508b3 100644 --- a/WebInterface/NodeJSServer/src/js/play.js +++ b/WebInterface/NodeJSServer/src/js/play.js @@ -2,7 +2,7 @@ import Interface from './modules/interface'; import UIManager from './modules/ui/uiManager'; import Networker from './modules/networking/networker'; -const SERVERURL = 'https://kobert.dev/api/Login'; +const SERVERURL = 'https://kobert.dev/api/login'; let iface = new Interface(); let uiMan = new UIManager(iface); -- cgit v1.2.3-54-g00ecf