source: binary-improvements2/WebServer/src/ConnectionHandler.cs@ 406

Last change on this file since 406 was 404, checked in by alloc, 22 months ago

Latest state including reworking to the permissions system

File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Net;
4
5namespace Webserver {
6 public class ConnectionHandler {
7 private readonly Dictionary<string, WebConnection> connections = new Dictionary<string, WebConnection> ();
8
9 public WebConnection IsLoggedIn (string _sessionId, IPAddress _ip) {
10 if (!connections.TryGetValue (_sessionId, out WebConnection con)) {
11 return null;
12 }
13
14// if (con.Age.TotalMinutes > parent.sessionTimeoutMinutes) {
15// connections.Remove (_sessionId);
16// return null;
17// }
18
19 if (!Equals (con.Endpoint, _ip)) {
20 connections.Remove (_sessionId);
21 return null;
22 }
23
24 con.UpdateUsage ();
25
26 return con;
27 }
28
29 public void LogOut (string _sessionId) {
30 connections.Remove (_sessionId);
31 }
32
33 public WebConnection LogIn (IPAddress _ip, string _username, PlatformUserIdentifierAbs _userId, PlatformUserIdentifierAbs _crossUserId = null) {
34 string sessionId = Guid.NewGuid ().ToString ();
35 WebConnection con = new WebConnection (sessionId, _ip, _username, _userId, _crossUserId);
36 connections.Add (sessionId, con);
37 return con;
38 }
39
40 public void SendLine (string _line) {
41 foreach (KeyValuePair<string, WebConnection> kvp in connections) {
42 kvp.Value.SendLine (_line);
43 }
44 }
45 }
46}
Note: See TracBrowser for help on using the repository browser.