From e8ee7b69663a95d97b226266ebe3ccc95e13c309 Mon Sep 17 00:00:00 2001 From: "ivaylo.zhelev" Date: Sun, 31 Jan 2021 16:42:30 +0200 Subject: Major Business Logic Implementation * Added GameHub * Added Back-End Game Loop and Game Mechanics * Added End Game and Result message --- src/Web/PUSG.Web/Services/SessionService.cs | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Web/PUSG.Web/Services/SessionService.cs (limited to 'src/Web/PUSG.Web/Services/SessionService.cs') diff --git a/src/Web/PUSG.Web/Services/SessionService.cs b/src/Web/PUSG.Web/Services/SessionService.cs new file mode 100644 index 0000000..0e8e61a --- /dev/null +++ b/src/Web/PUSG.Web/Services/SessionService.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; + +namespace PUSG.Web.Static +{ + public class SessionService : ISessionService + { + private Dictionary users; + + public SessionService() + { + this.users = new Dictionary(); + this.LiveConnections = new List(); + } + + public Dictionary Users => this.users; + + public List LiveConnections { get; } + + public void AddUser(string connectionId, string username) + { + this.users[connectionId] = username; + } + + public KeyValuePair GetUser(string connectionId) + { + return this.users.SingleOrDefault(user => user.Key == connectionId); + } + + public bool IsLogged(string credential) + { + return this.users.ContainsKey(credential) || this.users.ContainsValue(credential); + } + + public void RemoveUser(string connectionId) + { + this.users.Remove(connectionId); + } + } +} -- cgit v1.3.1-26-gb76a