using System; using System.Collections.Generic; using System.Net; namespace Webserver { public class ConnectionHandler { private readonly Dictionary connections = new Dictionary (); public WebConnection IsLoggedIn (string _sessionId, IPAddress _ip) { if (!connections.TryGetValue (_sessionId, out WebConnection con)) { return null; } // if (con.Age.TotalMinutes > parent.sessionTimeoutMinutes) { // connections.Remove (_sessionId); // return null; // } if (!Equals (con.Endpoint, _ip)) { connections.Remove (_sessionId); return null; } con.UpdateUsage (); return con; } public void LogOut (string _sessionId) { connections.Remove (_sessionId); } public WebConnection LogIn (PlatformUserIdentifierAbs _userId, IPAddress _ip) { string sessionId = Guid.NewGuid ().ToString (); WebConnection con = new WebConnection (sessionId, _ip, _userId); connections.Add (sessionId, con); return con; } public void SendLine (string _line) { foreach (KeyValuePair kvp in connections) { kvp.Value.SendLine (_line); } } } }